Skip to content

Commit 2b98ecc

Browse files
committed
Add a type_is_tup_like predicate that takes a block ctxt, and make some fns pure
1 parent 8613f28 commit 2b98ecc

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/comp/middle/trans_common.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -449,14 +449,14 @@ fn find_scope_cx(cx: @block_ctxt) -> @block_ctxt {
449449
// Accessors
450450
// TODO: When we have overloading, simplify these names!
451451

452-
fn bcx_tcx(bcx: @block_ctxt) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; }
453-
fn bcx_ccx(bcx: @block_ctxt) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; }
454-
fn bcx_lcx(bcx: @block_ctxt) -> @local_ctxt { ret bcx.fcx.lcx; }
455-
fn bcx_fcx(bcx: @block_ctxt) -> @fn_ctxt { ret bcx.fcx; }
456-
fn fcx_ccx(fcx: @fn_ctxt) -> @crate_ctxt { ret fcx.lcx.ccx; }
457-
fn fcx_tcx(fcx: @fn_ctxt) -> ty::ctxt { ret fcx.lcx.ccx.tcx; }
458-
fn lcx_ccx(lcx: @local_ctxt) -> @crate_ctxt { ret lcx.ccx; }
459-
fn ccx_tcx(ccx: @crate_ctxt) -> ty::ctxt { ret ccx.tcx; }
452+
pure fn bcx_tcx(bcx: @block_ctxt) -> ty::ctxt { bcx.fcx.lcx.ccx.tcx }
453+
pure fn bcx_ccx(bcx: @block_ctxt) -> @crate_ctxt { bcx.fcx.lcx.ccx }
454+
pure fn bcx_lcx(bcx: @block_ctxt) -> @local_ctxt { bcx.fcx.lcx }
455+
pure fn bcx_fcx(bcx: @block_ctxt) -> @fn_ctxt { bcx.fcx }
456+
pure fn fcx_ccx(fcx: @fn_ctxt) -> @crate_ctxt { fcx.lcx.ccx }
457+
pure fn fcx_tcx(fcx: @fn_ctxt) -> ty::ctxt { fcx.lcx.ccx.tcx }
458+
pure fn lcx_ccx(lcx: @local_ctxt) -> @crate_ctxt { lcx.ccx }
459+
pure fn ccx_tcx(ccx: @crate_ctxt) -> ty::ctxt { ccx.tcx }
460460

461461
// LLVM type constructors.
462462
fn T_void() -> TypeRef {
@@ -861,6 +861,11 @@ pure fn returns_non_ty_var(cx: @crate_ctxt, t: ty::t) -> bool {
861861
non_ty_var(cx, ty::ty_fn_ret(cx.tcx, t))
862862
}
863863

864+
pure fn type_is_tup_like(cx: @block_ctxt, t: ty::t) -> bool {
865+
let tcx = bcx_tcx(cx);
866+
ty::type_is_tup_like(tcx, t)
867+
}
868+
864869
//
865870
// Local Variables:
866871
// mode: rust

src/comp/middle/ty.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,11 @@ fn sequence_element_type(cx: ctxt, ty: t) -> t {
832832
}
833833
}
834834

835-
fn type_is_tup_like(cx: ctxt, ty: t) -> bool {
836-
alt struct(cx, ty) {
837-
ty_box(_) { ret true; }
838-
ty_rec(_) { ret true; }
839-
ty_tup(_) { ret true; }
840-
ty_tag(_, _) { ret true; }
841-
_ { ret false; }
835+
pure fn type_is_tup_like(cx: ctxt, ty: t) -> bool {
836+
let sty = unchecked { struct(cx, ty) };
837+
alt sty {
838+
ty_box(_) | ty_rec(_) | ty_tup(_) | ty_tag(_,_) { true }
839+
_ { false }
842840
}
843841
}
844842

0 commit comments

Comments
 (0)