1- //! # Lattice Variables
1+ //! # Lattice variables
22//!
3- //! This file contains generic code for operating on inference variables
4- //! that are characterized by an upper- and lower-bound. The logic and
5- //! reasoning is explained in detail in the large comment in `infer.rs`.
3+ //! Generic code for operating on [lattices] of inference variables
4+ //! that are characterized by an upper- and lower-bound.
65//!
7- //! The code in here is defined quite generically so that it can be
6+ //! The code is defined quite generically so that it can be
87//! applied both to type variables, which represent types being inferred,
98//! and fn variables, which represent function types being inferred.
10- //! It may eventually be applied to their types as well, who knows.
9+ //! ( It may eventually be applied to their types as well.)
1110//! In some cases, the functions are also generic with respect to the
1211//! operation on the lattice (GLB vs LUB).
1312//!
14- //! Although all the functions are generic, we generally write the
15- //! comments in a way that is specific to type variables and the LUB
16- //! operation. It's just easier that way.
13+ //! ## Note
1714//!
18- //! In general all of the functions are defined parametrically
19- //! over a `LatticeValue`, which is a value defined with respect to
20- //! a lattice.
15+ //! Although all the functions are generic, for simplicity, comments in the source code
16+ //! generally refer to type variables and the LUB operation.
17+ //!
18+ //! [lattices]: https://en.wikipedia.org/wiki/Lattice_(order)
2119
2220use super :: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
2321use super :: InferCtxt ;
@@ -27,6 +25,11 @@ use rustc_middle::ty::relate::{RelateResult, TypeRelation};
2725use rustc_middle:: ty:: TyVar ;
2826use rustc_middle:: ty:: { self , Ty } ;
2927
28+ /// Trait for returning data about a lattice, and for abstracting
29+ /// over the "direction" of the lattice operation (LUB/GLB).
30+ ///
31+ /// GLB moves "down" the lattice (to smaller values); LUB moves
32+ /// "up" the lattice (to bigger values).
3033pub trait LatticeDir < ' f , ' tcx > : TypeRelation < ' tcx > {
3134 fn infcx ( & self ) -> & ' f InferCtxt < ' f , ' tcx > ;
3235
@@ -41,6 +44,7 @@ pub trait LatticeDir<'f, 'tcx>: TypeRelation<'tcx> {
4144 fn relate_bound ( & mut self , v : Ty < ' tcx > , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> RelateResult < ' tcx , ( ) > ;
4245}
4346
47+ /// Relates two types using a given lattice.
4448pub fn super_lattice_tys < ' a , ' tcx : ' a , L > (
4549 this : & mut L ,
4650 a : Ty < ' tcx > ,
0 commit comments