Skip to content

Commit 73ae684

Browse files
committed
rustc: Don't resolve all type variables eagerly for paths
1 parent 80f86d1 commit 73ae684

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/comp/middle/typeck.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import middle::ty::pat_ty;
2323
import middle::ty::path_to_str;
2424
import middle::ty::ty_param_substs_opt_and_ty;
2525
import middle::ty::ty_to_str;
26-
import middle::ty::type_is_integral;
27-
import middle::ty::type_is_scalar;
2826
import middle::ty::ty_param_count_and_ty;
2927
import middle::ty::ty_nil;
3028
import middle::ty::unify::ures_ok;
@@ -76,22 +74,16 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn)
7674
case (ast::def_arg(?id)) {
7775
assert (fcx.locals.contains_key(id));
7876
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id));
79-
typ = ty::unify::resolve_all_vars(fcx.ccx.tcx, fcx.var_bindings,
80-
typ);
8177
ret tup(0u, typ);
8278
}
8379
case (ast::def_local(?id)) {
8480
assert (fcx.locals.contains_key(id));
8581
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id));
86-
typ = ty::unify::resolve_all_vars(fcx.ccx.tcx, fcx.var_bindings,
87-
typ);
8882
ret tup(0u, typ);
8983
}
9084
case (ast::def_obj_field(?id)) {
9185
assert (fcx.locals.contains_key(id));
9286
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id));
93-
typ = ty::unify::resolve_all_vars(fcx.ccx.tcx, fcx.var_bindings,
94-
typ);
9587
ret tup(0u, typ);
9688
}
9789
case (ast::def_fn(?id)) {
@@ -109,8 +101,6 @@ fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &span sp, &ast::def defn)
109101
case (ast::def_binding(?id)) {
110102
assert (fcx.locals.contains_key(id));
111103
auto typ = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(id));
112-
typ = ty::unify::resolve_all_vars(fcx.ccx.tcx, fcx.var_bindings,
113-
typ);
114104
ret tup(0u, typ);
115105
}
116106
case (ast::def_obj(?id)) {
@@ -194,19 +184,37 @@ fn ast_mode_to_mode(ast::mode mode) -> ty::mode {
194184
ret ty_mode;
195185
}
196186

197-
// Returns the one-level-deep structure of the given type.
198-
fn structure_of(&@fn_ctxt fcx, &span sp, ty::t typ) -> ty::sty {
187+
188+
// Type tests
189+
190+
fn structurally_resolved_type(&@fn_ctxt fcx, &span sp, ty::t typ) -> ty::t {
199191
auto r = ty::unify::resolve_type_structure(fcx.ccx.tcx, fcx.var_bindings,
200192
typ);
201193
alt (r) {
202-
case (fix_ok(?typ_s)) { ret ty::struct(fcx.ccx.tcx, typ_s); }
194+
case (fix_ok(?typ_s)) { ret typ_s; }
203195
case (fix_err(_)) {
204196
fcx.ccx.tcx.sess.span_err(sp, "the type of this value must be " +
205197
"known in this context");
206198
}
207199
}
208200
}
209201

202+
// Returns the one-level-deep structure of the given type.
203+
fn structure_of(&@fn_ctxt fcx, &span sp, ty::t typ) -> ty::sty {
204+
ret ty::struct(fcx.ccx.tcx, structurally_resolved_type(fcx, sp, typ));
205+
}
206+
207+
fn type_is_integral(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
208+
auto typ_s = structurally_resolved_type(fcx, sp, typ);
209+
ret ty::type_is_integral(fcx.ccx.tcx, typ_s);
210+
}
211+
212+
fn type_is_scalar(&@fn_ctxt fcx, &span sp, ty::t typ) -> bool {
213+
auto typ_s = structurally_resolved_type(fcx, sp, typ);
214+
ret ty::type_is_scalar(fcx.ccx.tcx, typ_s);
215+
}
216+
217+
210218
// Parses the programmer's textual representation of a type into our internal
211219
// notion of a type. `getter` is a function that returns the type
212220
// corresponding to a definition ID:
@@ -1984,9 +1992,8 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
19841992
check_expr(fcx, e);
19851993
auto t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
19861994
// FIXME: there are more forms of cast to support, eventually.
1987-
if (! (type_is_scalar(fcx.ccx.tcx,
1988-
expr_ty(fcx.ccx.tcx, e)) &&
1989-
type_is_scalar(fcx.ccx.tcx, t_1))) {
1995+
if (! (type_is_scalar(fcx, expr.span, expr_ty(fcx.ccx.tcx, e)) &&
1996+
type_is_scalar(fcx, expr.span, t_1))) {
19901997
fcx.ccx.tcx.sess.span_err(expr.span,
19911998
"non-scalar cast: " +
19921999
ty_to_str(fcx.ccx.tcx,
@@ -2148,7 +2155,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
21482155
auto idx_t = expr_ty(fcx.ccx.tcx, idx);
21492156
alt (structure_of(fcx, expr.span, base_t)) {
21502157
case (ty::ty_vec(?mt)) {
2151-
if (! type_is_integral(fcx.ccx.tcx, idx_t)) {
2158+
if (! type_is_integral(fcx, idx.span, idx_t)) {
21522159
fcx.ccx.tcx.sess.span_err
21532160
(idx.span,
21542161
"non-integral type of vec index: "
@@ -2157,7 +2164,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
21572164
write::ty_only_fixup(fcx, a.id, mt.ty);
21582165
}
21592166
case (ty::ty_str) {
2160-
if (! type_is_integral(fcx.ccx.tcx, idx_t)) {
2167+
if (! type_is_integral(fcx, idx.span, idx_t)) {
21612168
fcx.ccx.tcx.sess.span_err
21622169
(idx.span,
21632170
"non-integral type of str index: "

0 commit comments

Comments
 (0)