Expand description
§The Conlang Type Checker
As a statically typed language, Conlang requires a robust type checker to enforce correctness.
This crate is a major work-in-progress.
§The Project™
Contains item definitions and type expression information.
Every definition is itself a module, and can contain arbitrarily nested items as part of the Module tree.
The Project keeps track of a global intern pool of definitions, which are trivially comparable by DefID. Note that, for item definitions, identical types in different modules DO NOT COMPARE EQUAL under this constraint. However, so-called “anonymous” types do not follow this rule, as their definitions are constructed dynamically and ensured to be unique.
§Namespaces
Within a Project, definitions are classified into two namespaces:
§Type Namespace:
- Modules
- Structs
- Enums
- Type aliases
§Value Namespace:
- Functions
- Constants
- Static variables
There is a key distinction between the two namespaces when it comes to Path traversal: Only items in the Type Namespace will be considered as an intermediate path target. This means items in the Value namespace are entirely opaque, and form a one-way barrier. Items outside a Value can be referred to within the Value, but items inside a Value cannot be referred to outside the Value.
§Order of operations:
Currently, the process of type resolution goes as follows:
- Traverse the AST, collecting all Items into item definitions
- Eagerly resolve
use
imports - Traverse all definitions, and resolve the types for every item
- TODO: Construct a typed AST for expressions, and type-check them
Modules§
- Implements type unification, used by the Hindley-Milner type inference algorithm
- Performs step 1 of type checking: Collecting all the names of things into Module units
- Performs step 2 of type checking: Evaluating type definitions
- WIP use-item importer. This performs eager import resolution on the AST