Skip to content

Commit cb35951

Browse files
committed
---
yaml --- r: 1310 b: refs/heads/master c: 13b7a35 h: refs/heads/master v: v3
1 parent f358539 commit cb35951

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
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: 8640f1991793e1c1ec0c45891bbcc5d3a7b05ebf
2+
refs/heads/master: 13b7a356f8ec1542a4f84009e2f1fcd278bafd54

trunk/src/comp/middle/trans.rs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,48 @@ fn field_of_tydesc(@block_ctxt cx, @ty.t t, int field) -> ValueRef {
889889
ret cx.build.GEP(tydesc, vec(C_int(0), C_int(field)));
890890
}
891891

892+
// Given a type containing ty params, build a vector containing a ValueRef for
893+
// each of the ty params it uses (from the current frame), as well as a vec
894+
// containing a def_id for each such param. This is used solely for
895+
// constructing derived tydescs.
896+
fn linearize_ty_params(@block_ctxt cx, @ty.t t)
897+
-> tup(vec[ast.def_id], vec[ValueRef]) {
898+
let vec[ValueRef] param_vals = vec();
899+
let vec[ast.def_id] param_defs = vec();
900+
type rr = rec(@block_ctxt cx,
901+
mutable vec[ValueRef] vals,
902+
mutable vec[ast.def_id] defs);
903+
904+
state obj folder(@rr r) {
905+
fn fold_simple_ty(@ty.t t) -> @ty.t {
906+
alt(t.struct) {
907+
case (ty.ty_param(?pid)) {
908+
let bool seen = false;
909+
for (ast.def_id d in r.defs) {
910+
if (d == pid) {
911+
seen = true;
912+
}
913+
}
914+
if (!seen) {
915+
r.vals += cx.fcx.lltydescs.get(pid);
916+
r.defs += pid;
917+
}
918+
}
919+
}
920+
ret t;
921+
}
922+
}
923+
924+
925+
auto x = @rec(cx = cx,
926+
mutable vals = param_vals,
927+
mutable defs = param_defs);
928+
929+
ty.fold_ty(folder(x), t);
930+
931+
ret tup(x.defs, x.vals);
932+
}
933+
892934
fn get_tydesc(&@block_ctxt cx, @ty.t t) -> ValueRef {
893935
// Is the supplied type a type param? If so, return the passed-in tydesc.
894936
alt (ty.type_param(t)) {
@@ -897,9 +939,10 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> ValueRef {
897939
}
898940

899941
// Does it contain a type param? If so, generate a derived tydesc.
942+
let uint n_params = ty.count_ty_params(t);
900943
if (ty.count_ty_params(t) > 0u) {
901-
log "TODO: trans.get_tydesc(): generate a derived type descriptor";
902-
fail;
944+
auto tys = linearize_ty_params(cx, t);
945+
cx.fcx.ccx.sess.unimpl("derived type descriptors");
903946
}
904947

905948
// Otherwise, generate a tydesc if necessary, and return it.

0 commit comments

Comments
 (0)