1
Fork 0

Reduce and clarify abuse of 'pure' in interner

This commit is contained in:
Jesse Ruderman 2011-09-24 16:33:26 -07:00
parent 0125532106
commit 3b5b29c7ec
3 changed files with 12 additions and 11 deletions

View file

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

View file

@ -841,7 +841,7 @@ fn sequence_element_type(cx: ctxt, ty: t) -> t {
}
pure fn type_is_tup_like(cx: ctxt, ty: t) -> bool {
let sty = unchecked { struct(cx, ty) };
let sty = struct(cx, ty);
alt sty {
ty_box(_) | ty_rec(_) | ty_tup(_) | ty_tag(_,_) { true }
_ { false }
@ -1624,9 +1624,7 @@ fn ty_fn_abi(cx: ctxt, fty: t) -> ast::native_abi {
}
pure fn ty_fn_ret(cx: ctxt, fty: t) -> t {
// Should be pure, as type interner contents
// shouldn't change once set...
let sty = unchecked { struct(cx, fty) };
let sty = struct(cx, fty);
alt sty {
ty::ty_fn(_, _, r, _, _) { ret r; }
ty::ty_native_fn(_, _, r) { ret r; }

View file

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