Skip to content

Commit 6599b31

Browse files
committed
rustc: Don't return "result" types from glue helper functions. This allows glue to fail.
1 parent 37b5e91 commit 6599b31

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/comp/middle/trans.rs

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,7 +1658,7 @@ fn declare_tydesc(@local_ctxt cx, @ty.t t) {
16581658
}
16591659

16601660
tag make_generic_glue_helper_fn {
1661-
mgghf_single(val_and_ty_fn);
1661+
mgghf_single(fn(@block_ctxt cx, ValueRef v, @ty.t t));
16621662
mgghf_cmp;
16631663
}
16641664

@@ -1694,7 +1694,6 @@ fn make_generic_glue(@local_ctxt cx,
16941694
auto bcx = new_top_block_ctxt(fcx);
16951695
auto lltop = bcx.llbb;
16961696

1697-
auto re;
16981697
if (!ty.type_is_scalar(t)) {
16991698

17001699
// Any nontrivial glue is with values passed *by alias*; this is a
@@ -1729,39 +1728,40 @@ fn make_generic_glue(@local_ctxt cx,
17291728

17301729
alt (helper) {
17311730
case (mgghf_single(?single_fn)) {
1732-
re = single_fn(bcx, llval0, t);
1731+
single_fn(bcx, llval0, t);
17331732
}
17341733
case (mgghf_cmp) {
17351734
auto llrawptr1 = llvm.LLVMGetParam(llfn, 5u);
17361735
auto llval1 = bcx.build.BitCast(llrawptr0, llty);
17371736

17381737
auto llcmpval = llvm.LLVMGetParam(llfn, 6u);
17391738

1740-
re = make_cmp_glue(bcx, llval0, llval1, t, llcmpval);
1739+
make_cmp_glue(bcx, llval0, llval1, t, llcmpval);
17411740
}
17421741
}
17431742
} else {
1744-
re = res(bcx, C_nil());
1743+
bcx.build.RetVoid();
17451744
}
17461745

1747-
re.bcx.build.RetVoid();
1748-
17491746
// Tie up the llallocas -> lltop edge.
17501747
new_builder(fcx.llallocas).Br(lltop);
17511748

17521749
ret llfn;
17531750
}
17541751

1755-
fn make_take_glue(@block_ctxt cx, ValueRef v, @ty.t t) -> result {
1752+
fn make_take_glue(@block_ctxt cx, ValueRef v, @ty.t t) {
17561753
// NB: v is an *alias* of type t here, not a direct value.
1754+
auto bcx;
17571755
if (ty.type_is_boxed(t)) {
1758-
ret incr_refcnt_of_boxed(cx, cx.build.Load(v));
1756+
bcx = incr_refcnt_of_boxed(cx, cx.build.Load(v)).bcx;
17591757

17601758
} else if (ty.type_is_structural(t)) {
1761-
ret iter_structural_ty(cx, v, t,
1762-
bind take_ty(_, _, _));
1759+
bcx = iter_structural_ty(cx, v, t,
1760+
bind take_ty(_, _, _)).bcx;
1761+
} else {
1762+
bcx = cx;
17631763
}
1764-
ret res(cx, C_nil());
1764+
bcx.build.RetVoid();
17651765
}
17661766

17671767
fn incr_refcnt_of_boxed(@block_ctxt cx, ValueRef box_ptr) -> result {
@@ -1783,12 +1783,13 @@ fn incr_refcnt_of_boxed(@block_ctxt cx, ValueRef box_ptr) -> result {
17831783
ret res(next_cx, C_nil());
17841784
}
17851785

1786-
fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
1786+
fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) {
17871787
// NB: v0 is an *alias* of type t here, not a direct value.
1788+
auto rslt;
17881789
alt (t.struct) {
17891790
case (ty.ty_str) {
17901791
auto v = cx.build.Load(v0);
1791-
ret decr_refcnt_and_if_zero
1792+
rslt = decr_refcnt_and_if_zero
17921793
(cx, v, bind trans_non_gc_free(_, v),
17931794
"free string",
17941795
T_int(), C_int(0));
@@ -1803,10 +1804,10 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
18031804
ret trans_non_gc_free(res.bcx, v);
18041805
}
18051806
auto v = cx.build.Load(v0);
1806-
ret decr_refcnt_and_if_zero(cx, v,
1807-
bind hit_zero(_, v, t),
1808-
"free vector",
1809-
T_int(), C_int(0));
1807+
rslt = decr_refcnt_and_if_zero(cx, v,
1808+
bind hit_zero(_, v, t),
1809+
"free vector",
1810+
T_int(), C_int(0));
18101811
}
18111812

18121813
case (ty.ty_box(?body_mt)) {
@@ -1822,10 +1823,10 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
18221823
ret trans_non_gc_free(res.bcx, v);
18231824
}
18241825
auto v = cx.build.Load(v0);
1825-
ret decr_refcnt_and_if_zero(cx, v,
1826-
bind hit_zero(_, v, body_mt.ty),
1827-
"free box",
1828-
T_int(), C_int(0));
1826+
rslt = decr_refcnt_and_if_zero(cx, v,
1827+
bind hit_zero(_, v, body_mt.ty),
1828+
"free box",
1829+
T_int(), C_int(0));
18291830
}
18301831

18311832
case (ty.ty_port(_)) {
@@ -1834,10 +1835,10 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
18341835
vec(vp2i(cx, v)));
18351836
}
18361837
auto v = cx.build.Load(v0);
1837-
ret decr_refcnt_and_if_zero(cx, v,
1838-
bind hit_zero(_, v),
1839-
"free port",
1840-
T_int(), C_int(0));
1838+
rslt = decr_refcnt_and_if_zero(cx, v,
1839+
bind hit_zero(_, v),
1840+
"free port",
1841+
T_int(), C_int(0));
18411842
}
18421843

18431844
case (ty.ty_chan(_)) {
@@ -1846,10 +1847,10 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
18461847
vec(vp2i(cx, v)));
18471848
}
18481849
auto v = cx.build.Load(v0);
1849-
ret decr_refcnt_and_if_zero(cx, v,
1850-
bind hit_zero(_, v),
1851-
"free chan",
1852-
T_int(), C_int(0));
1850+
rslt = decr_refcnt_and_if_zero(cx, v,
1851+
bind hit_zero(_, v),
1852+
"free chan",
1853+
T_int(), C_int(0));
18531854
}
18541855

18551856
case (ty.ty_obj(_)) {
@@ -1880,10 +1881,10 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
18801881

18811882
auto boxptr = cx.build.Load(box_cell);
18821883

1883-
ret decr_refcnt_and_if_zero(cx, boxptr,
1884-
bind hit_zero(_, boxptr),
1885-
"free obj",
1886-
T_int(), C_int(0));
1884+
rslt = decr_refcnt_and_if_zero(cx, boxptr,
1885+
bind hit_zero(_, boxptr),
1886+
"free obj",
1887+
T_int(), C_int(0));
18871888
}
18881889

18891890
case (ty.ty_fn(_,_,_)) {
@@ -1919,27 +1920,26 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v0, @ty.t t) -> result {
19191920

19201921
auto boxptr = cx.build.Load(box_cell);
19211922

1922-
ret decr_refcnt_and_if_zero(cx, boxptr,
1923-
bind hit_zero(_, boxptr),
1924-
"free fn",
1925-
T_int(), C_int(0));
1923+
rslt = decr_refcnt_and_if_zero(cx, boxptr,
1924+
bind hit_zero(_, boxptr),
1925+
"free fn",
1926+
T_int(), C_int(0));
19261927
}
19271928

19281929
case (_) {
19291930
if (ty.type_is_structural(t)) {
1930-
ret iter_structural_ty(cx, v0, t,
1931-
bind drop_ty(_, _, _));
1931+
rslt = iter_structural_ty(cx, v0, t,
1932+
bind drop_ty(_, _, _));
19321933

19331934
} else if (ty.type_is_scalar(t) ||
19341935
ty.type_is_native(t) ||
19351936
ty.type_is_nil(t)) {
1936-
ret res(cx, C_nil());
1937+
rslt = res(cx, C_nil());
19371938
}
19381939
}
19391940
}
1940-
cx.fcx.lcx.ccx.sess.bug("bad type in trans.make_drop_glue_inner: " +
1941-
ty.ty_to_str(t));
1942-
fail;
1941+
1942+
rslt.bcx.build.RetVoid();
19431943
}
19441944

19451945
fn decr_refcnt_and_if_zero(@block_ctxt cx,
@@ -1986,8 +1986,8 @@ fn decr_refcnt_and_if_zero(@block_ctxt cx,
19861986
}
19871987

19881988
fn make_cmp_glue(@block_ctxt cx, ValueRef v0, ValueRef v1, @ty.t t,
1989-
ValueRef llop) -> result {
1990-
ret res(cx, C_nil()); // TODO
1989+
ValueRef llop) {
1990+
cx.build.RetVoid(); // TODO
19911991
}
19921992

19931993

0 commit comments

Comments
 (0)