1
- //! # Lattice Variables
1
+ //! # Lattice variables
2
2
//!
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.
6
5
//!
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
8
7
//! applied both to type variables, which represent types being inferred,
9
8
//! 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.)
11
10
//! In some cases, the functions are also generic with respect to the
12
11
//! operation on the lattice (GLB vs LUB).
13
12
//!
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
17
14
//!
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)
21
19
22
20
use super :: type_variable:: { TypeVariableOrigin , TypeVariableOriginKind } ;
23
21
use super :: InferCtxt ;
@@ -27,6 +25,11 @@ use rustc_middle::ty::relate::{RelateResult, TypeRelation};
27
25
use rustc_middle:: ty:: TyVar ;
28
26
use rustc_middle:: ty:: { self , Ty } ;
29
27
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).
30
33
pub trait LatticeDir < ' f , ' tcx > : TypeRelation < ' tcx > {
31
34
fn infcx ( & self ) -> & ' f InferCtxt < ' f , ' tcx > ;
32
35
@@ -41,6 +44,7 @@ pub trait LatticeDir<'f, 'tcx>: TypeRelation<'tcx> {
41
44
fn relate_bound ( & mut self , v : Ty < ' tcx > , a : Ty < ' tcx > , b : Ty < ' tcx > ) -> RelateResult < ' tcx , ( ) > ;
42
45
}
43
46
47
+ /// Relates two types using a given lattice.
44
48
pub fn super_lattice_tys < ' a , ' tcx : ' a , L > (
45
49
this : & mut L ,
46
50
a : Ty < ' tcx > ,
0 commit comments