From e70c695ab9a910f4079088c439a2efbf5ab9c447 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 20 Dec 2010 15:23:24 -0800 Subject: [PATCH] rustc: Use the passed-in tydescs for take and drop glue in parametric fns. Also fix a level-of-indirection problem with tydesc params. --- src/comp/middle/trans.rs | 25 +++++++++++++++++++------ src/comp/middle/typeck.rs | 8 ++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 6353ca8a936..b9477e74796 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -293,7 +293,7 @@ fn type_of_fn(@crate_ctxt cx, auto ty_param_count = typeck.count_ty_params(fn_ty); auto i = 0u; while (i < ty_param_count) { - atys += T_tydesc(); + atys += T_ptr(T_tydesc()); i += 1u; } @@ -578,15 +578,28 @@ fn trans_malloc(@block_ctxt cx, @typeck.ty t) -> result { // returns an LLVM ValueRef of that field from the tydesc, generating the // tydesc if necessary. fn field_of_tydesc(@block_ctxt cx, @typeck.ty ty, int field) -> ValueRef { - auto tydesc = get_tydesc(cx.fcx.ccx, ty); + auto tydesc = get_tydesc(cx, ty); ret cx.build.GEP(tydesc, vec(C_int(0), C_int(field))); } -fn get_tydesc(@crate_ctxt cx, @typeck.ty ty) -> ValueRef { - if (!cx.tydescs.contains_key(ty)) { - make_tydesc(cx, ty); +fn get_tydesc(&@block_ctxt cx, @typeck.ty ty) -> ValueRef { + // Is the supplied type a type param? If so, return the passed-in tydesc. + alt (typeck.type_param(ty)) { + case (some[ast.def_id](?id)) { ret cx.fcx.lltydescs.get(id); } + case (none[ast.def_id]) { /* fall through */ } } - ret cx.tydescs.get(ty); + + // Does it contain a type param? If so, generate a derived tydesc. + if (typeck.count_ty_params(ty) > 0u) { + log "TODO: trans.get_tydesc(): generate a derived type descriptor"; + fail; + } + + // Otherwise, generate a tydesc if necessary, and return it. + if (!cx.fcx.ccx.tydescs.contains_key(ty)) { + make_tydesc(cx.fcx.ccx, ty); + } + ret cx.fcx.ccx.tydescs.get(ty); } fn make_tydesc(@crate_ctxt cx, @typeck.ty ty) { diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index ad9e0b6870f..19f2c0c1191 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -954,6 +954,14 @@ fn type_is_signed(@ty t) -> bool { fail; } +fn type_param(@ty t) -> option.t[ast.def_id] { + alt (t.struct) { + case (ty_param(?id)) { ret some[ast.def_id](id); } + case (_) { /* fall through */ } + } + ret none[ast.def_id]; +} + fn plain_ty(&sty st) -> @ty { ret @rec(struct=st, mut=ast.imm, cname=none[str]); }