This reminds me of these slides on the Julia compiler and Zygote [1] that really impressed me at the time. Not only the compiler is incredibly smart, it also gives the programmer to a lot of tools to talk with it (the introspection macros, IR Tools, macros on AST, macros on IR - generated functions).
And maybe a little related, while traits are not a feature on the language, you can use this kind of compile-time optimizations to implement trait dispatch that the compiler will completely erase from the generated code, the so called holy traits [2].
[1] https://docs.google.com/presentation/d/1IiBLVU5Pj-48vzEMnuYE...
[2] https://invenia.github.io/blog/2019/11/06/julialang-features...