Skip to content

Commit 120893a

Browse files
committed
---
yaml --- r: 1434 b: refs/heads/master c: 19b2850 h: refs/heads/master v: v3
1 parent 4a2a17d commit 120893a

File tree

5 files changed

+57
-33
lines changed

5 files changed

+57
-33
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 88f0463c2bd6e7fd2af461afc5e83bd3417e3bc5
2+
refs/heads/master: 19b2850388f634b500e612d8f24bbcb8c0fa2f3c

trunk/src/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \
468468
generic-recursive-tag.rs \
469469
generic-tag-alt.rs \
470470
generic-tag-values.rs \
471-
generic-tag.rs \
472471
integral-indexing.rs \
473472
iter-range.rs \
474473
iter-ret.rs \

trunk/src/comp/middle/trans.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import std._int;
12
import std._str;
23
import std._uint;
34
import std._vec;
@@ -61,7 +62,8 @@ type glue_fns = rec(ValueRef activate_glue,
6162
tag arity { nullary; n_ary; }
6263
type tag_info = rec(type_handle th,
6364
mutable vec[tup(ast.def_id,arity)] variants,
64-
mutable uint size);
65+
mutable uint size,
66+
vec[ast.ty_param] ty_params);
6567

6668
state type crate_ctxt = rec(session.session sess,
6769
ModuleRef llmod,
@@ -1498,9 +1500,7 @@ fn iter_structural_ty(@block_ctxt cx,
14981500
i += 1;
14991501
}
15001502
}
1501-
case (ty.ty_tag(?tid, _)) {
1502-
// TODO: type params!
1503-
1503+
case (ty.ty_tag(?tid, ?tps)) {
15041504
check (cx.fcx.ccx.tags.contains_key(tid));
15051505
auto info = cx.fcx.ccx.tags.get(tid);
15061506
auto n_variants = _vec.len[tup(ast.def_id,arity)](info.variants);
@@ -1559,11 +1559,15 @@ fn iter_structural_ty(@block_ctxt cx,
15591559
auto llfldp =
15601560
variant_cx.build.GEP(llvarp, v);
15611561

1562+
auto ty_subst = ty.substitute_ty_params(
1563+
info.ty_params, tps, a.ty);
1564+
15621565
auto llfld =
15631566
load_scalar_or_boxed(variant_cx,
1564-
llfldp, a.ty);
1567+
llfldp,
1568+
ty_subst);
15651569

1566-
auto res = f(variant_cx, llfld, a.ty);
1570+
auto res = f(variant_cx, llfld, ty_subst);
15671571
variant_cx = res.bcx;
15681572
j += 1u;
15691573
}
@@ -4433,13 +4437,14 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
44334437
cx.items.insert(mid, i);
44344438
}
44354439

4436-
case (ast.item_tag(_, ?variants, _, ?tag_id)) {
4440+
case (ast.item_tag(_, ?variants, ?tps, ?tag_id)) {
44374441
auto vi = new_def_hash[uint]();
44384442
auto navi = new_def_hash[uint]();
44394443
let vec[tup(ast.def_id,arity)] variant_info = vec();
44404444
cx.tags.insert(tag_id, @rec(th=mk_type_handle(),
44414445
mutable variants=variant_info,
4442-
mutable size=0u));
4446+
mutable size=0u,
4447+
ty_params=tps));
44434448
cx.items.insert(tag_id, i);
44444449
}
44454450

trunk/src/comp/middle/ty.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ fn type_err_to_str(&ty.type_err err) -> str {
14501450
}
14511451
}
14521452

1453-
// Type parameter resolution, used in translation
1453+
// Type parameter resolution, used in translation and typechecking
14541454

14551455
fn resolve_ty_params(ty_params_and_ty ty_params_and_polyty,
14561456
@t monoty) -> vec[@t] {
@@ -1492,6 +1492,47 @@ fn resolve_ty_params(ty_params_and_ty ty_params_and_polyty,
14921492
ret result_tys;
14931493
}
14941494

1495+
// Performs type parameter replacement using the supplied mapping from
1496+
// parameter IDs to types.
1497+
fn replace_type_params(@t typ, hashmap[ast.def_id,@t] param_map) -> @t {
1498+
state obj param_replacer(hashmap[ast.def_id,@t] param_map) {
1499+
fn fold_simple_ty(@t typ) -> @t {
1500+
alt (typ.struct) {
1501+
case (ty_param(?param_def)) {
1502+
if (param_map.contains_key(param_def)) {
1503+
ret param_map.get(param_def);
1504+
} else {
1505+
ret typ;
1506+
}
1507+
}
1508+
case (_) {
1509+
ret typ;
1510+
}
1511+
}
1512+
}
1513+
}
1514+
auto replacer = param_replacer(param_map);
1515+
ret fold_ty(replacer, typ);
1516+
}
1517+
1518+
// Substitutes the type parameters specified by @ty_params with the
1519+
// corresponding types in @bound in the given type. The two vectors must have
1520+
// the same length.
1521+
fn substitute_ty_params(vec[ast.ty_param] ty_params, vec[@t] bound, @t ty)
1522+
-> @t {
1523+
auto ty_param_len = _vec.len[ast.ty_param](ty_params);
1524+
check (ty_param_len == _vec.len[@t](bound));
1525+
1526+
auto bindings = common.new_def_hash[@t]();
1527+
auto i = 0u;
1528+
while (i < ty_param_len) {
1529+
bindings.insert(ty_params.(i).id, bound.(i));
1530+
i += 1u;
1531+
}
1532+
1533+
ret replace_type_params(ty, bindings);
1534+
}
1535+
14951536
// Local Variables:
14961537
// mode: rust
14971538
// fill-column: 78;

trunk/src/comp/middle/typeck.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,6 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
147147
ret rec(mode=arg.mode, ty=ast_ty_to_ty(getter, arg.ty));
148148
}
149149

150-
fn replace_type_params(@ty.t t, ty_table param_map) -> @ty.t {
151-
state obj param_replacer(ty_table param_map) {
152-
fn fold_simple_ty(@ty.t t) -> @ty.t {
153-
alt (t.struct) {
154-
case (ty.ty_param(?param_def)) {
155-
if (param_map.contains_key(param_def)) {
156-
ret param_map.get(param_def);
157-
} else {
158-
ret t;
159-
}
160-
}
161-
case (_) {
162-
ret t;
163-
}
164-
}
165-
}
166-
}
167-
auto replacer = param_replacer(param_map);
168-
ret ty.fold_ty(replacer, t);
169-
}
170-
171150
fn instantiate(ty_getter getter, ast.def_id id,
172151
vec[@ast.ty] args) -> @ty.t {
173152
// TODO: maybe record cname chains so we can do
@@ -183,7 +162,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
183162
auto param = params.(i);
184163
param_map.insert(param.id, ast_ty_to_ty(getter, arg));
185164
}
186-
ret replace_type_params(ty_and_params.ty, param_map);
165+
ret ty.replace_type_params(ty_and_params.ty, param_map);
187166
}
188167

189168
auto mut = ast.imm;

0 commit comments

Comments
 (0)