-
Notifications
You must be signed in to change notification settings - Fork 4
Compiler: Start implementing the type checker #228
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
base: main
Are you sure you want to change the base?
Conversation
|
I think the
|
|
Thinking about this more: a quantified type variable becomes
A type variable is only on eo of these ( So we would be able to use just one We could either have a map to map unification variables to their linked types, or keep using different variants. If we use different variants, it might make sense to have a variant for If we do that, I think that also solves the problem with the |
|
TODO: Environments should keep (in addition to schemes etc.) unique top-level definition indices/ids to be able to import the same top-level thing multiple times, via different imports. E.g. a library re-exports This is also a language design question, but we may also want to allow importing different things under the same name, and only fail when we use that thing. (instead of when we import it) If we design the data structures to allow this we may choose to not allow it later easily. So I think it makes sense to design for this. |
Questions and TODOs:
Do we want to allow higher-kinded types now, or later? Do we have any immediate use cases?
Should we represent kinds with types? (i.e. type-in-type)
In the interpreter we implementHashforTy, because we represent predicate sets asHashSet<Pred>andPredrefers toTys for the type arguments of traits. We can't do it automatically in Fir yet, so we'll have to manually implement a lot ofHashs. Also,FunArgsis currently using aHashSet. We may have to make it a sortedVec[(name: Id, ty: Ty)](for named arguments).But I wonder if there's a better representation of predicate sets thanHashSet[Pred]? It would be simpler if we could avoid hashing here, at least initially.Reminder: pred sets are not just for function contexts[Iterator[iter, item, exn], Eq[item]]etc. they also hold generated predicates, to be resolved later.Allowing duplicates could potentially generate a lot of redundant predicates, wasting time in the resolving phase. For example, every==in a function can generate aEq[t]predicate.I think using aVec[Pred]and linear search when adding may be good enough for now. TODO: Check the max. pred set size in the interpreter when running the programs in the repo.Predicate sets will be vectors, at least for now. See Predicate sets contain duplicate predicates #229 for the discussion.
In
TyEnv(in the interpreter) we currently maintain two maps, one for type variables, one for type constructors. But type variables are also treated as type constructors (just with no known constructors) in most places. AFAICS only in conversions we use the type var map to preserve sharing when the type AST mentions the same type variable.In the compiler we use
TyIdfor type constructors andLocalIdfor type variables. So the map will have a key type with the union of these.I wonder if it would make sense to have another map (three in total):
cons: ScopeMap[TyId, TyCon]: for mapping named types to type constructorsvars: ScopeSet[LocalId]: type variables in scope. In the compiler,TyCons for these don't have any information anyway, so a set should be OK.varConversions: ScopeMap[LocalId, Ty]: to be able to convert type variables in scope without breaking sharing.I think this will require adding one more variant to
Ty, to be able to distinguish type constructors from rigid type variables. E.g.: