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 PunTys 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:
TypedProgramis abstract over all possible backends and can be computed once.DefinitionGraphis 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::definitionsis 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 PunTys which can have DefinitionGraph-specific lowerings…
so really you should only recycle state created for a specific DefinitionGraph!
FIXME: unlike AliasTys, PunTys 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§
- AliasTy
- The Ty of a transparent type alias.
- Arg
- A function argument (input or output).
- ArrayTy
- The Ty of a fixed length array.
- Definition
Graph - A Dependency Graph of all the type/function definitions.
- EnumTy
- The Ty of an Enum.
- Enum
Variant Ty - An enum variant
- FieldTy
- A field of a
StructTyorUnionTy. - Func
- A function
- KdlScript
Type Error - An error that occured while processing the types of a program.
- PunBlock
Ty - A block for a
PunTy - PunTy
- The Ty of a Pun.
- RefTy
- The Ty of a reference (transparent pointer).
- Struct
Ty - The Ty of a nominal struct.
- Tagged
Ty - The Ty of a tagged union (rust-style enum).
- Tagged
Variant Ty - A variant for a tagged union.
- Typed
Program - A program that has had its symbolic types resolved to actual type ids.
- UnionTy
- The Ty of an untagged union.
Enums§
- Definition
- Kinds of definitions/declarations a backend should emit
- Primitive
Ty - A primitive
- Ty
- The actual structure of a type
Constants§
Functions§
- typeck
- Take a ParsedProgram and produce a TypedProgram for it!