Skip to content

Commit 5316fe6

Browse files
committed
Add comments explaining integral type variables; fix typos
1 parent a01bdbe commit 5316fe6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/rustc/middle/typeck/infer.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,28 @@ is valid. This basically corresponds to the block nesting structure:
119119
the regions for outer block scopes are superregions of those for inner
120120
block scopes.
121121
122+
## Integral type variables
123+
124+
There is a third variety of type variable that we use only for
125+
inferring the types of unsuffixed integer literals. Integral type
126+
variables differ from general-purpose type variables in that there's
127+
no subtyping relationship among the various integral types, so instead
128+
of associating each variable with an upper and lower bound, we
129+
represent the set of possible integral types it can take on with an
130+
`int_ty_set`, which is a bitvector with one bit for each integral
131+
type. Because intersecting these sets with each other is simpler than
132+
merging bounds, we don't need to do so transactionally as we do for
133+
general-purpose type variables.
134+
135+
We could conceivably define a subtyping relationship among integral
136+
types based on their ranges, but we choose not to open that particular
137+
can of worms. Our strategy is to treat integral type variables as
138+
unknown until the typing context constrains them to a unique integral
139+
type, at which point they take on that type. If the typing context
140+
overconstrains the type, it's a type error; if we reach the point at
141+
which type variables must be resolved and an integral type variable is
142+
still underconstrained, it defaults to `int` as a last resort.
143+
122144
## GLB/LUB
123145
124146
Computing the greatest-lower-bound and least-upper-bound of two
@@ -829,7 +851,7 @@ impl unify_methods for infer_ctxt {
829851
}
830852
} else if nde_a.rank < nde_b.rank {
831853
#debug["vars(): b has smaller rank"];
832-
// b has geater rank, so a should redirect to b.
854+
// b has greater rank, so a should redirect to b.
833855
self.set(vb, a_id, redirect(b_id));
834856
self.set_var_to_merged_bounds(
835857
vb, b_id, a_bounds, b_bounds, nde_b.rank).then {||

0 commit comments

Comments
 (0)