Crate rustc_hir_analysis
source ·Expand description
typeck
The type checker is responsible for:
- Determining the type of each expression.
- Resolving methods and traits.
- Guaranteeing that most type rules are met. (“Most?”, you say, “why most?” Well, dear reader, read on.)
The main entry point is check_crate()
. Type checking operates in
several major phases:
-
The collect phase first passes over all items and determines their type, without examining their “innards”.
-
Variance inference then runs to compute the variance of each parameter.
-
Coherence checks for overlapping or orphaned impls.
-
Finally, the check phase then checks function bodies and so forth. Within the check phase, we check each function body one at a time (bodies of function expressions are checked as part of the containing function). Inference is used to supply types wherever they are unknown. The actual checking of a function itself has several phases (check, regionck, writeback), as discussed in the documentation for the
check
module.
The type checker is defined into various submodules which are documented independently:
-
astconv: converts the AST representation of types into the
ty
representation. -
collect: computes the types of each top-level item and enters them into the
tcx.types
table for later use. -
coherence: enforces coherence rules, builds some tables.
-
variance: variance inference
-
outlives: outlives inference
-
check: walks over function bodies and type checks them, inferring types for local variables, type parameters, etc as necessary.
-
infer: finds the types to use for each type variable such that all subtyping and assignment constraints are met. In essence, the check module specifies the constraints, and the infer module solves them.
Note
This API is completely unstable and subject to change.
Modules
ty.rs
representation.
The main routine here is ast_ty_to_ty()
; each use is parameterized by an
instance of AstConv
.ty
form from the HIR.rustc_hir_analysis
.