Skip to content

Commit 3b5b29c

Browse files
committed
Reduce and clarify abuse of 'pure' in interner
1 parent 0125532 commit 3b5b29c

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

src/comp/middle/trans_common.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,7 @@ pure fn type_has_static_size(cx: @crate_ctxt, t: ty::t) -> bool {
833833
}
834834

835835
pure fn non_ty_var(cx: @crate_ctxt, t: ty::t) -> bool {
836-
// Not obviously referentially transparent, but
837-
// type interner shouldn't be changing at this point.
838-
// FIXME: how to make that clearer?
839-
let st = unchecked { ty::struct(cx.tcx, t) };
836+
let st = ty::struct(cx.tcx, t);
840837
alt st {
841838
ty::ty_var(_) { false }
842839
_ { true }

src/comp/middle/ty.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ fn sequence_element_type(cx: ctxt, ty: t) -> t {
841841
}
842842

843843
pure fn type_is_tup_like(cx: ctxt, ty: t) -> bool {
844-
let sty = unchecked { struct(cx, ty) };
844+
let sty = struct(cx, ty);
845845
alt sty {
846846
ty_box(_) | ty_rec(_) | ty_tup(_) | ty_tag(_,_) { true }
847847
_ { false }
@@ -1624,9 +1624,7 @@ fn ty_fn_abi(cx: ctxt, fty: t) -> ast::native_abi {
16241624
}
16251625

16261626
pure fn ty_fn_ret(cx: ctxt, fty: t) -> t {
1627-
// Should be pure, as type interner contents
1628-
// shouldn't change once set...
1629-
let sty = unchecked { struct(cx, fty) };
1627+
let sty = struct(cx, fty);
16301628
alt sty {
16311629
ty::ty_fn(_, _, r, _, _) { ret r; }
16321630
ty::ty_native_fn(_, _, r) { ret r; }

src/comp/syntax/util/interner.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ fn intern<@T>(itr: interner<T>, val: T) -> uint {
2828
}
2929
}
3030

31-
pure fn get<@T>(itr: interner<T>, idx: uint) -> T { ret itr.vect[idx]; }
32-
33-
pure fn len<T>(itr: interner<T>) -> uint { ret vec::len(itr.vect); }
31+
// |get| isn't "pure" in the traditional sense, because it can go from
32+
// failing to returning a value as items are interned. But for typestate,
33+
// where we first check a pred and then rely on it, ceasing to fail is ok.
34+
pure fn get<@T>(itr: interner<T>, idx: uint) -> T {
35+
unchecked {
36+
itr.vect[idx]
37+
}
38+
}
3439

40+
fn len<T>(itr: interner<T>) -> uint { ret vec::len(itr.vect); }

0 commit comments

Comments
 (0)