Module kdl_script::types
source · Expand description
The type checker and types!
The entry point is typeck
which is implicitly
handled by Compiler::compile_path
or Compiler::compile_string
and will produce a TypedProgram
.
You should then call TypedProgram::definition_graph
with your
target backend’s PunEnv
to resolve all the PunTy
s and get a
final DefinitionGraph
.
You should then call DefinitionGraph::definitions
with the set
of functions you want to emit (usually TypedProgram::all_funcs
)
to get the final forward-decls and definitions your target should emit
to generate its program.
If a test (function) fails, you can pass just that function to
DefinitionGraph::definitions
to get a minimized program for just
that one function.
The type system is phased like this to allow work to be reused and shared where possible. Each of the above “lowerings” represents increased levels of specificity:
TypedProgram
is abstract over all possible backends and can be computed once.DefinitionGraph
is for a concrete backend but still abstract over what parts of the program you might care about emitting. Computed once per backend config (PunEnv
).DefinitionGraph::definitions
is the final concrete program we want to emit.
In principle a backend emitting various configs for a single TypedProgram
can
share everything for a specific TyIdx
or FuncIdx
, except they need to be
careful about PunTy
s which can have DefinitionGraph
-specific lowerings…
so really you should only recycle state created for a specific DefinitionGraph
!
TODO: unlike AliasTy
s, PunTy
s really should completely evaporate in the
backend’s lowering. Perhaps we should do something in TypedProgram
to actually
make them transparent?
While performance isn’t a huge concern for this project, combinatorics do get kind of out of control so work sharing is kinda important, especially as the backends get more complex! Also it’s just nice to handle backend-agnostic issues once to keep things simple and correct.
Structs
- The Ty of a transparent type alias.
- A function argument (input or output).
- The Ty of a fixed length array.
- A Dependency Graph of all the type/function definitions.
- The Ty of an Enum.
- An enum variant
- A function
- An error that occured while processing the types of a program.
- A block for a
PunTy
- The Ty of a Pun.
- The Ty of a reference (transparent pointer).
- The Ty of a nominal struct.
- The Ty of a tagged union (rust-style enum).
- A variant for a tagged union.
- A program that has had its symbolic types resolved to actual type ids.
- The Ty of an untagged union.
Enums
- Kinds of definitions/declarations a backend should emit
- A primitive
- The actual structure of a type
Functions
- Take a ParsedProgram and produce a TypedProgram for it!
Type Aliases
- A function id
- A type id