Pipeline
Current front-end compiler pipeline looks like the following:
Input is an input, Bold is a step, Italic is an artefact.
-> is used by, => produces
-
Source code -> Lexing & Parsing => AST
Understand the form of the user source code.
-
AST -> Item Collection, Item Resolution => NameEnvironment, ResolutionMap
We first construct the reachable environment and generate
DefIds for each item. Then we go through all thePaths and attach meaning to them, i.e. the item or local binding they refer to.It makes sense to collect on the AST as it is used to provide diagnostics to user code and AST is closer to what the user wrote.
-
AST, ResolutionMap -> AST Lowering => HIR
We lower the AST to a flat structure that is the HIR. HIR doesn’t care about structure and is much more convenient further down the (pipe)line.
-
HIR -> Type Collection => TypeEnvironment
Go through each item and compute their
ty::EarlyItemTy.Once, the collection phase is done, these are immediately resolved to
ty::LateTys. -
HIR, NameEnvironment, TypeEnvironment -> Inference (per function) => InferResult
-
HIR, InferResult -> Code Generation => Object