Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support generics? #50

Open
Gankra opened this issue Jul 1, 2024 · 0 comments
Open

support generics? #50

Gankra opened this issue Jul 1, 2024 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@Gankra
Copy link
Owner

Gankra commented Jul 1, 2024

Generics are weird in that ideally they don't matter for ABI (at least in Rust/C++), thanks to monomorphization. So supporting generics would be a lot of work, for unclear benefit... but y'know extend that logic far enough and you reason away abi-cafe.

The only case fresh on my mind that relates to generics and ABIs causing problems is actually just a bug in generic functions resulting in varargs being invoked incorrectly (because analysis is done premonomorphization, oops!).

Catching that case would involve a lot more than this issue is proposing.


So right now we of course have a sort of generics with structural types, but the key "trick" here is that we essentially monomorphize all structural types before assigning them type ids (TyIdx). That is, &u32 and &i32 each get a different TyIdx and Ty. As a result, everything can key off of TyIdx for looking up facts about a type, computing type definition dependencies, and interning type names or whatnot.

Once you introduce the concept of a single struct "MyType<T>" { .. } definition which "MyType<i32>", "MyType<bool>", and "MyType<T>" all reference, you need to introduce some kind of "substitutions" system for talking about the types and the types of their fields.

One option would be to still fully monomorphize these types into their own TyIdx and Tys -- essentially generating MyType_u32 and so on -- but with some additional layer of abstraction for looking up a "type definition id". This would leave the complexity largely the same for codegen backends? I think?

@Gankra Gankra added enhancement New feature or request question Further information is requested labels Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant