Skip to main content

Module canonical

Module canonical 

Source
Expand description

Canonicalization is the key to constructing a query in the middle of type inference. Ordinarily, it is not possible to store types from type inference in query keys, because they contain references to inference variables whose lifetimes are too short and so forth. Canonicalizing a value T1 using canonicalize_query produces two things:

  • a value T2 where each unbound inference variable has been replaced with a canonical variable;
  • a map M (of type CanonicalVarValues) from those canonical variables back to the original.

We can then do queries using T2. These will give back constraints on the canonical variables which can be translated, using the map M, into constraints in our source context. This process of translating the results back is done by the instantiate_query_result method.

For a more detailed look at what is happening here, check out the chapter in the rustc dev guide.

Re-exportsยง

pub use instantiate::CanonicalExt;
pub use instantiate::instantiate_value;
use rustc_index::IndexVec; ๐Ÿ”’
use rustc_middle::ty; ๐Ÿ”’
use rustc_middle::ty::GenericArg; ๐Ÿ”’
use rustc_middle::ty::Ty; ๐Ÿ”’
use rustc_middle::ty::TyCtxt; ๐Ÿ”’
use rustc_middle::ty::TypeFoldable; ๐Ÿ”’
use rustc_span::Span; ๐Ÿ”’
use crate::infer::InferCtxt; ๐Ÿ”’
use crate::infer::RegionVariableOrigin; ๐Ÿ”’

Modulesยง

canonicalizer ๐Ÿ”’
This module contains the โ€œcanonicalizerโ€ itself.
instantiate ๐Ÿ”’
This module contains code to instantiate new values into a Canonical<'tcx, T>.
ir
This crate is an abstraction layer, shared between rustc and rust-analyzer, to help with the overlapping responsibilities (like type inference and trait solving), reduce duplication, and maintain consistent behavior between the two implementations.
query_response
This module contains the code to instantiate a โ€œquery resultโ€, and in particular to extract out the resulting region obligations and encode them therein.

Structsยง

CanonicalParamEnvCache
OriginalQueryValues
When we canonicalize a value to form a query, we wind up replacing various parts of it with canonical variables. This struct stores those replaced bits to remember for when we process the query result.
QueryRegionConstraint
QueryRegionConstraints
QueryResponse
After we execute a query with a canonicalized key, we get back a Canonical<QueryResponse<..>>. You can use instantiate_query_result to access the data in this result.

Enumsยง

Certainty
Indicates whether or not we were able to prove the query to be true.

Type Aliasesยง

Canonical
CanonicalQueryInput
CanonicalQueryResponse
CanonicalVarKind
CanonicalVarKinds
CanonicalVarValues
Canonicalized