Skip to content

Commit 90c1b46

Browse files
committed
Set no-unwind on glue functions that don't drop resources.
1 parent fa6c68a commit 90c1b46

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ fn declare_generic_glue(ccx: @crate_ctxt, t: ty::t, llfnty: TypeRef,
488488
note_unique_llvm_symbol(ccx, fn_nm);
489489
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty);
490490
set_glue_inlining(llfn, t);
491+
if name != "drop" || !ty::type_has_resources(t) {
492+
set_no_unwind(llfn);
493+
}
491494
ret llfn;
492495
}
493496

src/rustc/middle/ty.rs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
100100
export ty_var, mk_var;
101101
export ty_self, mk_self;
102102
export region, bound_region;
103-
export get, type_has_params, type_has_vars, type_has_regions, type_id;
103+
export get, type_has_params, type_has_vars, type_has_regions;
104+
export type_has_resources, type_id;
104105
export ty_var_id;
105106
export ty_to_def_id;
106107
export ty_fn_args;
@@ -235,6 +236,7 @@ type t_box = @{struct: sty,
235236
has_params: bool,
236237
has_vars: bool,
237238
has_regions: bool,
239+
has_resources: bool,
238240
o_def_id: option<ast::def_id>};
239241

240242
// To reduce refcounting cost, we're representing types as unsafe pointers
@@ -255,6 +257,7 @@ pure fn get(t: t) -> t_box unsafe {
255257
fn type_has_params(t: t) -> bool { get(t).has_params }
256258
fn type_has_vars(t: t) -> bool { get(t).has_vars }
257259
fn type_has_regions(t: t) -> bool { get(t).has_regions }
260+
fn type_has_resources(t: t) -> bool { get(t).has_resources }
258261
fn type_def_id(t: t) -> option<ast::def_id> { get(t).o_def_id }
259262
fn type_id(t: t) -> uint { get(t).id }
260263

@@ -478,13 +481,15 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
478481
some(t) { unsafe { ret unsafe::reinterpret_cast(t); } }
479482
_ {}
480483
}
481-
let mut has_params = false, has_vars = false, has_regions = false;
484+
let mut has_params = false, has_vars = false, has_regions = false,
485+
has_resources = false;
482486
fn derive_flags(&has_params: bool, &has_vars: bool, &has_regions: bool,
483-
tt: t) {
487+
&has_resources: bool, tt: t) {
484488
let t = get(tt);
485489
has_params |= t.has_params;
486490
has_vars |= t.has_vars;
487491
has_regions |= t.has_regions;
492+
has_resources |= t.has_resources;
488493
}
489494
fn derive_rflags(&has_vars: bool, &has_regions: bool, r: region) {
490495
has_regions = true;
@@ -494,9 +499,10 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
494499
}
495500
}
496501
fn derive_sflags(&has_params: bool, &has_vars: bool, &has_regions: bool,
497-
substs: substs) {
502+
&has_resources: bool, substs: substs) {
498503
for substs.tps.each {|tt|
499-
derive_flags(has_params, has_vars, has_regions, tt);
504+
derive_flags(has_params, has_vars, has_regions,
505+
has_resources, tt);
500506
}
501507
substs.self_r.iter { |r| derive_rflags(has_vars, has_regions, r) }
502508
}
@@ -506,56 +512,69 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
506512
}
507513
ty_evec(mt, vstore_slice(r)) {
508514
derive_rflags(has_vars, has_regions, r);
509-
derive_flags(has_params, has_vars, has_regions, mt.ty);
515+
derive_flags(has_params, has_vars, has_regions,
516+
has_resources, mt.ty);
510517
}
511518
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
512519
ty_str | ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
513520
ty_opaque_box {}
514521
ty_param(_, _) { has_params = true; }
515522
ty_var(_) | ty_self(_) { has_vars = true; }
516523
ty_enum(_, substs) | ty_class(_, substs) {
517-
derive_sflags(has_params, has_vars, has_regions, substs);
524+
derive_sflags(has_params, has_vars, has_regions,
525+
has_resources, substs);
518526
}
519527
ty_iface(_, tys) {
520528
for tys.each {|tt|
521-
derive_flags(has_params, has_vars, has_regions, tt);
529+
derive_flags(has_params, has_vars, has_regions,
530+
has_resources, tt);
522531
}
523532
}
524533
ty_box(m) | ty_uniq(m) | ty_vec(m) | ty_evec(m, _) | ty_ptr(m) {
525-
derive_flags(has_params, has_vars, has_regions, m.ty);
534+
derive_flags(has_params, has_vars, has_regions,
535+
has_resources, m.ty);
526536
}
527537
ty_rptr(r, m) {
528538
derive_rflags(has_vars, has_regions, r);
529-
derive_flags(has_params, has_vars, has_regions, m.ty);
539+
derive_flags(has_params, has_vars, has_regions,
540+
has_resources, m.ty);
530541
}
531542
ty_rec(flds) {
532543
for flds.each {|f|
533-
derive_flags(has_params, has_vars, has_regions, f.mt.ty);
544+
derive_flags(has_params, has_vars, has_regions,
545+
has_resources, f.mt.ty);
534546
}
535547
}
536548
ty_tup(ts) {
537549
for ts.each {|tt| derive_flags(has_params, has_vars,
538-
has_regions, tt); }
550+
has_regions, has_resources, tt); }
539551
}
540552
ty_fn(f) {
541553
for f.inputs.each {|a|
542-
derive_flags(has_params, has_vars, has_regions, a.ty);
554+
derive_flags(has_params, has_vars, has_regions,
555+
has_resources, a.ty);
543556
}
544-
derive_flags(has_params, has_vars, has_regions, f.output);
557+
derive_flags(has_params, has_vars, has_regions,
558+
has_resources, f.output);
545559
}
546560
ty_res(_, tt, substs) {
547-
derive_flags(has_params, has_vars, has_regions, tt);
548-
derive_sflags(has_params, has_vars, has_regions, substs);
561+
has_resources = true;
562+
derive_flags(has_params, has_vars, has_regions,
563+
has_resources, tt);
564+
derive_sflags(has_params, has_vars, has_regions,
565+
has_resources, substs);
549566
}
550567
ty_constr(tt, _) {
551-
derive_flags(has_params, has_vars, has_regions, tt);
568+
derive_flags(has_params, has_vars, has_regions,
569+
has_resources, tt);
552570
}
553571
}
554572
let t = @{struct: st,
555573
id: cx.next_id,
556574
has_params: has_params,
557575
has_vars: has_vars,
558576
has_regions: has_regions,
577+
has_resources: has_resources,
559578
o_def_id: o_def_id};
560579
cx.interner.insert(key, t);
561580
cx.next_id += 1u;

0 commit comments

Comments
 (0)