r/ProgrammingLanguages • • Sep 02 '26

CTTI is Exponential, RTTI is Linear

https://www.gingerbill.org/article/2026/09/02/ctti-is-exponential-rtti-is-linear/
0 Upvotes

38 comments sorted by

View all comments

Show parent comment

3

u/CommonNoiter Sep 03 '26

I think if you allow your generics to support such features you usually end up with a type system that can perform arbitrary computations, then it's CTTI can perform computations at compile time and so can take forever (or at least as long as the type recursion limit is) while RTTI does it as runtime.

1

u/slaymaker1907 Sep 04 '26

I think the unique thing here is that you can get exponential code generation and not just that compilation can take an arbitrary amount of time.

1

u/CommonNoiter 3d ago

If your type system can perform an arbitrary amount of computations then surely you can add a function () -> Nat onto each of the types that are created temporarily which returns the sum of that method called on the types it creates (and the leaf types return some constant value derived in any way). This would result in an arbitrarily large amount of codegen unless your optimiser manages to inline everything.