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

Typechecking logic for SIds is overcomplicated #182

Open
cd1m0 opened this issue Jul 6, 2022 · 0 comments
Open

Typechecking logic for SIds is overcomplicated #182

cd1m0 opened this issue Jul 6, 2022 · 0 comments
Assignees

Comments

@cd1m0
Copy link
Collaborator

cd1m0 commented Jul 6, 2022

The typing logic for SId is split between several functions: tcId, tcIdVariable, tcLetAnnotation, tcUserConstant, lookupFun, lookupVarDef, lookupTypeDef, tcIdBuiltinSymbol, tcIdImportUnitRef. Whats worse, there are 2 redundant styles of checking types:

a) Using an explicit stack of scopes (see lookupVarDef for an example)
b) A messy bunch of ifs all over the place. (see tcId for an example of this)

This logic is ugly, over-complicated and probably has a lot of buggy edge-cases with shadowing.

I think it would be cleaner if we had a single way to type-check SIds, just using a single explicit stack of scopes. In that case we would:

  1. Unify lookupVarDef, lookupFun, lookupTypeDef and tcLetAnnotationId into a single lookupDef function.
  2. Replace all the tc* functions with a single tcId function whose body will look almost exactly like the body of tcIdVariable
  3. We will add a new BuiltinsScope type for all the builtins (its not clear yet exactly where that will go).
  4. For every 2 types of DefSites we will need a test to determine how they get shadowed. For example for builtins and variables, we will need to see if a local variable called msg shadows the msg builtin. Similarly for variables and functions, we will need a test checking their precedence. And so on and so forth.

In practice, its probably better to first start with the tests in (4) and then begin implementing the code changes.

@cd1m0 cd1m0 self-assigned this Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant