Feature: Get rid of @T generic type sigils in favor of T

Should be entirely doable now that type params are explicitly listed everywhere, we might be able to do it in a pre-typecheck Pass by just walking the syntax tree with a scope stack of explicit type decls. It might also be doable in the type checker similarlyl it would require a bit more work but also turn every Generic Type into a Named type, removing a layer of complexity. (We might need to keep the Generic TypeInfo type.) Investigate that approach first.

Assigned to
1 year, 1 month ago
a month ago

~icefox 1 year, 2 days ago

So my approach was to just have a Pass that takes the declared type params and sticks them into a Symtbl, and then goes through the decl afterwards and each time it finds a Named("Foo") type it checks whether it's in the symtbl, and if so rewrites it to Generic("Foo"). The results are... surprisingly cursed. Consider the following:

type List(T) = struct
    dummy_data: T,

type Idx(Selff, Output) = struct
    idx: fn(Selff, I32) Output,

const ListIdx Idx(List(T), I32) = Idx {
    .idx = fn(selff List(T), i I32) I32 = 3 end

const IntListIdx Idx(List(I32), I32) = Idx {
    .idx = fn(selff List(I32), i I32) I32 = selff$.dummy_data end

If we recognize the T in ListIdx during parsing, that means we have to know the difference between List and T which means we have to have already parsed List. So that ain't happening.

To do it afterwards we have to still know about List, which is fine I guess we can predecl types. But it needs to turn Idx(Self, Output) into Idx(@Self, @Output) and Idx(List(T), I32) into Idx(List(@T), I32) which is.... something. idfk.

~icefox 1 year, 2 days ago

Is this really worth it? I am suddenly much less sure, seeing how many things were valid and unambiguous before this change and now need foo(thing @T) @T to be changed to foo(|T| thing T) T.

Strongly considering just keeping the sigil but switching it to foo(thing ~T) ~T or something else less obtrusive.

~icefox REPORTED CLOSED a month ago

Regardless, this is done and work out pretty ok, though it does require us to repeat ourselves sometimes.

Register here or Log in to comment, or comment via email.