Skip to content

Split types into separate symbol table and type-level functions#1

Draft
krishnachittur wants to merge 4 commits intomainfrom
refactor-types
Draft

Split types into separate symbol table and type-level functions#1
krishnachittur wants to merge 4 commits intomainfrom
refactor-types

Conversation

@krishnachittur
Copy link
Copy Markdown
Collaborator

@krishnachittur krishnachittur commented Jun 7, 2025

This PR refactors types in order to make future improvements/additions to typing either. In particular, we

  1. split off a separate type-level symbol table for looking up type identifiers (e.g. names of structs, enums, aliases)
  2. break up Type into BaseType and ResolvedType, which allow us to cleanly express type-level functions like list, map, etc.
  3. store trees of type identifiers in the symbol table (e.g. map[string, list[Foo]]) to deduplicate types

In the longer term this should also unblock work on generic user-defined types.

TODO (for this PR)

  • Fix tests
  • Add new tests and verify parser

TODO after this PR

  • update StructDecl parsing to mutate in place in the type symbol table
    • add the newly defined Struct type to the type symbol table immediately after parsing attrs
    • each parsed function goes into the term symbol table (e.g. keyed Cat::meow, value fn[...]) AND the type symbol table (as a mutation of e.g. the Cat StructDecl)
      • function decl args get typed with type identifiers like everything else, so we can refer to a struct with "self" even if that struct gets mutated later
  • add uses_self to BaseType::Fn so that we can track those kinds of functions in the symbol table
  • handle ambiguous attribute access vs method call (e.g. cat.meow() could call a closure attribute, not just a method)
    • prioritize method calls when they exist, then access attributes
  • add struct default values to BaseType

@krishnachittur krishnachittur changed the title refactor(parser): split types into separate symbol table and functions Split types into separate symbol table and type-level functions Jun 8, 2025
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

Successfully merging this pull request may close these issues.

1 participant