about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-03-09 12:22:08 -0800
committerPatrick Walton <pcwalton@mimiga.net>2011-03-09 12:53:12 -0800
commit80fa01fb5784b91c05443daff0df6c607c2ce276 (patch)
tree76ccc90dabfd6a4de8d75d3c1b905014b3e50be8 /src/comp
parentfcd195bb4ca47d4b3c7dfd3e6c14dc5771e139cc (diff)
downloadrust-80fa01fb5784b91c05443daff0df6c607c2ce276.tar.gz
rust-80fa01fb5784b91c05443daff0df6c607c2ce276.zip
rustc: Perform type parameter substitutions in static_size_of_tag()
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/trans.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 2ad339685b2..ae9e408bf10 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));