From 5347cac92d0d44b5f1ca2f3b742a3786b62335d7 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 3 Dec 2010 12:31:25 -0800 Subject: [PATCH] rustc: Handle n-ary tag constructors in iter_structural_ty (which lets us process their refcounts correctly) --- src/comp/middle/trans.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 86adb0406b4..378c01c2a7e 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -604,15 +604,28 @@ fn iter_structural_ty(@block_ctxt cx, alt (variant._1) { case (n_ary) { - // FIXME: broken at the moment, causes type_is_binding - // errors; need to unpack the fn type returned by - // ann_to_type. let vec[ValueRef] vals = vec(C_int(0), C_int(1), C_int(i as int)); - auto llfld = r.bcx.build.GEP(v, vals); - auto ty = typeck.ann_to_type(variants.(i).ann); - r = f(variant_cx, llfld, ty); - r.bcx.build.Br(next_cx.llbb); + auto llvar = variant_cx.build.GEP(v, vals); + + auto fn_ty = typeck.ann_to_type(variants.(i).ann); + alt (fn_ty.struct) { + case (typeck.ty_fn(?args, _)) { + auto j = 0u; + for (typeck.arg a in args) { + auto idx = vec(C_int(0), C_int(j as int)); + auto llfp = variant_cx.build.GEP(llvar, + idx); + auto llfld = variant_cx.build.Load(llfp); + auto res = f(variant_cx, llfld, a.ty); + variant_cx = res.bcx; + j += 1u; + } + } + case (_) { fail; } + } + + variant_cx.build.Br(next_cx.llbb); } case (nullary) { // Nothing to do.