diff options
| author | Patrick Walton <[email protected]> | 2011-03-09 12:22:08 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-09 12:53:12 -0800 |
| commit | 80fa01fb5784b91c05443daff0df6c607c2ce276 (patch) | |
| tree | 76ccc90dabfd6a4de8d75d3c1b905014b3e50be8 | |
| parent | rustc: Don't try to load dynamically-sized types when translating tag variant... (diff) | |
| download | rust-80fa01fb5784b91c05443daff0df6c607c2ce276.tar.xz rust-80fa01fb5784b91c05443daff0df6c607c2ce276.zip | |
rustc: Perform type parameter substitutions in static_size_of_tag()
| -rw-r--r-- | src/comp/middle/trans.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 2ad33968..ae9e408b 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -923,6 +923,18 @@ fn align_of(@block_ctxt cx, @ty.t t) -> result { ret dynamic_align_of(cx, t); } +// Returns the type parameters associated with the tag with the given ID. +fn ty_params_of_tag(@crate_ctxt cx, &ast.def_id tid) -> vec[ast.ty_param] { + alt (cx.items.get(tid).node) { + case (ast.item_tag(_, _, ?tps, _)) { ret tps; } + case (_) { + log "ty_params_of_tag(): tag ID doesn't actually refer to a " + + "tag item"; + fail; + } + } +} + // Computes the size of the data part of a non-dynamically-sized tag. fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint { if (ty.type_has_dynamic_size(t)) { @@ -947,6 +959,9 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint { } } + // Pull the type parameters out of the corresponding tag item. + let vec[ast.ty_param] ty_params = ty_params_of_tag(cx, tid); + // Compute max(variant sizes). auto max_size = 0u; auto variants = tag_variants(cx, tid); @@ -954,6 +969,9 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint { let vec[@ty.t] tys = variant_types(cx, variant); auto tup_ty = ty.plain_ty(ty.ty_tup(tys)); + // Perform any type parameter substitutions. + tup_ty = ty.substitute_ty_params(ty_params, subtys, tup_ty); + // Here we possibly do a recursive call. auto this_size = llsize_of_real(cx, type_of(cx, tup_ty)); |