Crate cl_typeck

source ·
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:

  1. Traverse the AST, collecting all Items into item definitions
  2. Eagerly resolve use imports
  3. Traverse all definitions, and resolve the types for every item
  4. TODO: Construct a typed AST for expressions, and type-check them

Modules§