remove modes from ty.rs

This commit is contained in:
Niko Matsakis 2012-08-10 10:49:31 -07:00
parent e1086b0175
commit 2082a979e7
16 changed files with 159 additions and 141 deletions

View File

@ -745,10 +745,10 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
ty::ty_opaque_closure_ptr(ck) => {
closure::make_opaque_cbox_free_glue(bcx, ck, v)
}
ty::ty_class(did,substs) => {
ty::ty_class(did, ref substs) => {
// Call the dtor if there is one
do option::map_default(ty::ty_dtor(bcx.tcx(), did), bcx) |dt_id| {
trans_class_drop(bcx, v, dt_id, did, substs)
trans_class_drop(bcx, v, dt_id, did, substs)
}
}
_ => bcx
@ -758,7 +758,7 @@ fn make_free_glue(bcx: block, v: ValueRef, t: ty::t) {
fn trans_class_drop(bcx: block, v0: ValueRef, dtor_did: ast::def_id,
class_did: ast::def_id,
substs: ty::substs) -> block {
substs: &ty::substs) -> block {
let drop_flag = GEPi(bcx, v0, ~[0u, 0u]);
do with_cond(bcx, IsNotNull(bcx, Load(bcx, drop_flag))) |cx| {
let mut bcx = cx;
@ -805,7 +805,7 @@ fn make_drop_glue(bcx: block, v0: ValueRef, t: ty::t) {
ty::ty_unboxed_vec(_) => {
tvec::make_drop_glue_unboxed(bcx, v0, t)
}
ty::ty_class(did, substs) => {
ty::ty_class(did, ref substs) => {
let tcx = bcx.tcx();
match ty::ty_dtor(tcx, did) {
some(dtor) => {
@ -1081,7 +1081,7 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
}
return next_cx;
}
ty::ty_class(did, substs) => {
ty::ty_class(did, ref substs) => {
// Take the drop bit into account
let classptr = if is_some(ty::ty_dtor(cx.tcx(), did)) {
GEPi(cx, av, ~[0u, 1u])
@ -1821,7 +1821,7 @@ fn autoderef(cx: block, e_id: ast::node_id,
t1 = mt.ty;
v1 = v;
}
ty::ty_enum(did, substs) => {
ty::ty_enum(did, ref substs) => {
let variants = ty::enum_variants(ccx.tcx, did);
if (*variants).len() != 1u || variants[0].args.len() != 1u {
break;
@ -2034,7 +2034,7 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> option<ty::t> {
ty::ty_box(mt) => {
some(ty::mk_opaque_box(tcx))
}
ty::ty_fn(fty) => {
ty::ty_fn(ref fty) => {
some(ty::mk_fn(tcx, {purity: ast::impure_fn,
proto: fty.proto,
bounds: @~[],
@ -2562,7 +2562,7 @@ fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
let mut llderef = false;
let fields = match ty::get(ty).struct {
ty::ty_rec(fs) => fs,
ty::ty_class(did, substs) => {
ty::ty_class(did, ref substs) => {
if option::is_some(ty::ty_dtor(bcx.tcx(), did)) {
llderef = true;
}
@ -3505,7 +3505,7 @@ fn trans_struct(block_context: block, span: span, fields: ~[ast::field],
// Get the class ID and its fields.
let class_fields, class_id, substitutions;
match ty::get(struct_type).struct {
ty::ty_class(existing_class_id, existing_substitutions) => {
ty::ty_class(existing_class_id, ref existing_substitutions) => {
class_id = existing_class_id;
substitutions = existing_substitutions;
class_fields = ty::lookup_class_fields(type_context, class_id);
@ -4858,8 +4858,9 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
else { selfptr };
// initialize fields to zero
let dsubsts = dummy_substs(psubsts.tys);
let fields = ty::class_items_as_mutable_fields(bcx_top.tcx(), parent_id,
dummy_substs(psubsts.tys));
&dsubsts);
let mut bcx = bcx_top;
// Initialize fields to zero so init assignments can validly
// drop their LHS

View File

@ -158,7 +158,7 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
let (bt, bv) = const_autoderef(cx, bt, bv);
let fields = match ty::get(bt).struct {
ty::ty_rec(fs) => fs,
ty::ty_class(did, substs) =>
ty::ty_class(did, ref substs) =>
ty::class_items_as_mutable_fields(cx.tcx, did, substs),
_ => cx.sess.span_bug(e.span,
~"field access on unknown type in const"),

View File

@ -221,7 +221,7 @@ impl reflector {
self.visit(~"leave_fn", extra);
}
ty::ty_class(did, substs) => {
ty::ty_class(did, ref substs) => {
let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
let fields = ty::class_items_as_fields(tcx, did, substs);
@ -241,7 +241,7 @@ impl reflector {
// not ideal. It'll work but will get costly on big enums. Maybe
// let the visitor tell us if it wants to visit only a particular
// variant?
ty::ty_enum(did, substs) => {
ty::ty_enum(did, ref substs) => {
let bcx = self.bcx;
let tcx = bcx.ccx().tcx;
let variants = ty::substd_enum_variants(tcx, did, substs);

View File

@ -324,7 +324,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
s
}
ty::ty_trait(_, _) => ~[shape_box_fn],
ty::ty_class(did, substs) => {
ty::ty_class(did, ref substs) => {
// same as records, unless there's a dtor
let tps = substs.tps;
let m_dtor_did = ty::ty_dtor(ccx.tcx, did);
@ -378,7 +378,7 @@ fn gen_enum_shapes(ccx: @crate_ctxt) -> ValueRef {
let mut enum_variants = ~[];
while i < ccx.shape_cx.tag_order.len() {
let {did, substs} = ccx.shape_cx.tag_order[i];
let variants = @ty::substd_enum_variants(ccx.tcx, did, substs);
let variants = @ty::substd_enum_variants(ccx.tcx, did, &substs);
do vec::iter(*variants) |v| {
offsets += ~[vec::len(data) as u16];
@ -678,7 +678,7 @@ fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
if cx.enum_sizes.contains_key(t) { return cx.enum_sizes.get(t); }
match ty::get(t).struct {
ty::ty_enum(tid, substs) => {
ty::ty_enum(tid, ref substs) => {
// Compute max(variant sizes).
let mut max_size = 0u;
let variants = ty::enum_variants(cx.tcx, tid);
@ -723,7 +723,7 @@ fn simplify_type(tcx: ty::ctxt, typ: ty::t) -> ty::t {
}
// Reduce a class type to a record type in which all the fields are
// simplified
ty::ty_class(did, substs) => {
ty::ty_class(did, ref substs) => {
let simpl_fields = (if is_some(ty::ty_dtor(tcx, did)) {
// remember the drop flag
~[{ident: @~"drop", mt: {ty:

View File

@ -179,11 +179,11 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
ty::ty_enum(did, _) => {
fill_type_of_enum(cx, did, t, llty);
}
ty::ty_class(did, ts) => {
ty::ty_class(did, ref substs) => {
// Only instance vars are record fields at runtime.
let fields = ty::lookup_class_fields(cx.tcx, did);
let mut tys = do vec::map(fields) |f| {
let t = ty::lookup_field_type(cx.tcx, did, f.id, ts);
let t = ty::lookup_field_type(cx.tcx, did, f.id, substs);
type_of(cx, t)
};

View File

@ -140,7 +140,7 @@ fn type_needs_inner(cx: ctx, use: uint, ty: ty::t,
let seen = @cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
for vec::each(v.args) |aty| {
let t = ty::subst(cx.ccx.tcx, substs, aty);
let t = ty::subst(cx.ccx.tcx, &substs, aty);
type_needs_inner(cx, use, t, seen);
}
}

View File

@ -1,3 +1,6 @@
#[warn(deprecated_mode)];
#[warn(deprecated_pattern)];
import std::{map, smallintmap};
import result::result;
import std::map::hashmap;
@ -575,7 +578,7 @@ fn mk_ctxt(s: session::session,
region_map: middle::region::region_map,
region_paramd_items: middle::region::region_paramd_items) -> ctxt {
pure fn hash_intern_key(k: &intern_key) -> uint {
hash_type_structure(k.struct) +
hash_type_structure(&k.struct) +
option::map_default(k.o_def_id, 0u, |d| ast_util::hash_def(&d))
}
let interner = map::hashmap(hash_intern_key, sys::shape_eq);
@ -615,11 +618,11 @@ fn mk_ctxt(s: session::session,
// Type constructors
fn mk_t(cx: ctxt, st: sty) -> t { mk_t_with_id(cx, st, none) }
fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, none) }
// Interns a type/name combination, stores the resulting box in cx.interner,
// and returns the box as cast to an unsafe ptr (see comments for t above).
fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: option<ast::def_id>) -> t {
let key = {struct: st, o_def_id: o_def_id};
match cx.interner.find(key) {
some(t) => unsafe { return unsafe::reinterpret_cast(t); },
@ -634,7 +637,7 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
}
}
}
fn sflags(substs: substs) -> uint {
fn sflags(substs: &substs) -> uint {
let mut f = 0u;
for substs.tps.each |tt| { f |= get(tt).flags; }
substs.self_r.iter(|r| f |= rflags(r));
@ -654,7 +657,8 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
ty_param(_) => flags |= has_params as uint,
ty_var(_) | ty_var_integral(_) => flags |= needs_infer as uint,
ty_self => flags |= has_self as uint,
ty_enum(_, substs) | ty_class(_, substs) | ty_trait(_, substs) => {
ty_enum(_, ref substs) | ty_class(_, ref substs)
| ty_trait(_, ref substs) => {
flags |= sflags(substs);
}
ty_box(m) | ty_uniq(m) | ty_evec(m, _) |
@ -667,7 +671,7 @@ fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
}
ty_rec(flds) => for flds.each |f| { flags |= get(f.mt.ty).flags; },
ty_tup(ts) => for ts.each |tt| { flags |= get(tt).flags; },
ty_fn(f) => {
ty_fn(ref f) => {
for f.inputs.each |a| { flags |= get(a.ty).flags; }
flags |= get(f.output).flags;
}
@ -718,7 +722,8 @@ fn mk_estr(cx: ctxt, t: vstore) -> t {
mk_t(cx, ty_estr(t))
}
fn mk_enum(cx: ctxt, did: ast::def_id, substs: substs) -> t {
fn mk_enum(cx: ctxt, did: ast::def_id, +substs: substs) -> t {
// take a copy of substs so that we own the vectors inside
mk_t(cx, ty_enum(did, substs))
}
@ -763,13 +768,16 @@ fn mk_rec(cx: ctxt, fs: ~[field]) -> t { mk_t(cx, ty_rec(fs)) }
fn mk_tup(cx: ctxt, ts: ~[t]) -> t { mk_t(cx, ty_tup(ts)) }
fn mk_fn(cx: ctxt, fty: fn_ty) -> t { mk_t(cx, ty_fn(fty)) }
// take a copy because we want to own the various vectors inside
fn mk_fn(cx: ctxt, +fty: fn_ty) -> t { mk_t(cx, ty_fn(fty)) }
fn mk_trait(cx: ctxt, did: ast::def_id, substs: substs) -> t {
fn mk_trait(cx: ctxt, did: ast::def_id, +substs: substs) -> t {
// take a copy of substs so that we own the vectors inside
mk_t(cx, ty_trait(did, substs))
}
fn mk_class(cx: ctxt, class_id: ast::def_id, substs: substs) -> t {
fn mk_class(cx: ctxt, class_id: ast::def_id, +substs: substs) -> t {
// take a copy of substs so that we own the vectors inside
mk_t(cx, ty_class(class_id, substs))
}
@ -845,7 +853,7 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
for fields.each |fl| { maybe_walk_ty(fl.mt.ty, f); }
}
ty_tup(ts) => { for ts.each |tt| { maybe_walk_ty(tt, f); } }
ty_fn(ft) => {
ty_fn(ref ft) => {
for ft.inputs.each |a| { maybe_walk_ty(a.ty, f); }
maybe_walk_ty(ft.output, f);
}
@ -853,18 +861,18 @@ fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
}
}
fn fold_sty_to_ty(tcx: ty::ctxt, sty: sty, foldop: fn(t) -> t) -> t {
fn fold_sty_to_ty(tcx: ty::ctxt, sty: &sty, foldop: fn(t) -> t) -> t {
mk_t(tcx, fold_sty(sty, foldop))
}
fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty {
fn fold_substs(substs: substs, fldop: fn(t) -> t) -> substs {
fn fold_sty(sty: &sty, fldop: fn(t) -> t) -> sty {
fn fold_substs(substs: &substs, fldop: fn(t) -> t) -> substs {
{self_r: substs.self_r,
self_ty: substs.self_ty.map(|t| fldop(t)),
tps: substs.tps.map(|t| fldop(t))}
}
match sty {
match *sty {
ty_box(tm) => {
ty_box({ty: fldop(tm.ty), mutbl: tm.mutbl})
}
@ -880,10 +888,10 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty {
ty_evec(tm, vst) => {
ty_evec({ty: fldop(tm.ty), mutbl: tm.mutbl}, vst)
}
ty_enum(tid, substs) => {
ty_enum(tid, ref substs) => {
ty_enum(tid, fold_substs(substs, fldop))
}
ty_trait(did, substs) => {
ty_trait(did, ref substs) => {
ty_trait(did, fold_substs(substs, fldop))
}
ty_rec(fields) => {
@ -898,32 +906,32 @@ fn fold_sty(sty: sty, fldop: fn(t) -> t) -> sty {
let new_ts = vec::map(ts, |tt| fldop(tt));
ty_tup(new_ts)
}
ty_fn(f) => {
ty_fn(ref f) => {
let new_args = vec::map(f.inputs, |a| {
let new_ty = fldop(a.ty);
{mode: a.mode, ty: new_ty}
});
let new_output = fldop(f.output);
ty_fn({inputs: new_args, output: new_output with f})
ty_fn({inputs: new_args, output: new_output with *f})
}
ty_rptr(r, tm) => {
ty_rptr(r, {ty: fldop(tm.ty), mutbl: tm.mutbl})
}
ty_class(did, substs) => {
ty_class(did, ref substs) => {
ty_class(did, fold_substs(substs, fldop))
}
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_closure_ptr(_) |
ty_opaque_box | ty_var(_) | ty_var_integral(_) |
ty_param(*) | ty_self => {
sty
*sty
}
}
}
// Folds types from the bottom up.
fn fold_ty(cx: ctxt, t0: t, fldop: fn(t) -> t) -> t {
let sty = fold_sty(get(t0).struct, |t| fold_ty(cx, fldop(t), fldop));
let sty = fold_sty(&get(t0).struct, |t| fold_ty(cx, fldop(t), fldop));
fldop(mk_t(cx, sty))
}
@ -950,7 +958,7 @@ fn fold_regions_and_ty(
fldt: fn(t: t) -> t) -> t {
fn fold_substs(
substs: substs,
substs: &substs,
fldr: fn(r: region) -> region,
fldt: fn(t: t) -> t) -> substs {
@ -975,19 +983,19 @@ fn fold_regions_and_ty(
let m_t = fldt(mt.ty);
ty::mk_evec(cx, {ty: m_t, mutbl: mt.mutbl}, vstore_slice(m_r))
}
ty_enum(def_id, substs) => {
ty_enum(def_id, ref substs) => {
ty::mk_enum(cx, def_id, fold_substs(substs, fldr, fldt))
}
ty_class(def_id, substs) => {
ty_class(def_id, ref substs) => {
ty::mk_class(cx, def_id, fold_substs(substs, fldr, fldt))
}
ty_trait(def_id, substs) => {
ty_trait(def_id, ref substs) => {
ty::mk_trait(cx, def_id, fold_substs(substs, fldr, fldt))
}
sty @ ty_fn(_) => {
ref sty @ ty_fn(_) => {
fold_sty_to_ty(cx, sty, |t| fldfnt(t))
}
sty => {
ref sty => {
fold_sty_to_ty(cx, sty, |t| fldt(t))
}
}
@ -1036,7 +1044,7 @@ fn fold_region(cx: ctxt, t0: t, fldop: fn(region, bool) -> region) -> t {
// do not recurse into functions, which introduce fresh bindings
t0
}
sty => {
ref sty => {
do fold_sty_to_ty(cx, sty) |t| {
do_fold(cx, t, under_r, fldop)
}
@ -1054,17 +1062,17 @@ fn subst_tps(cx: ctxt, tps: ~[t], typ: t) -> t {
if !tbox_has_flag(tb, has_params) { return typ; }
match tb.struct {
ty_param(p) => tps[p.idx],
sty => fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t))
ref sty => fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t))
}
}
fn substs_is_noop(substs: substs) -> bool {
fn substs_is_noop(substs: &substs) -> bool {
substs.tps.len() == 0u &&
substs.self_r.is_none() &&
substs.self_ty.is_none()
}
fn substs_to_str(cx: ctxt, substs: substs) -> ~str {
fn substs_to_str(cx: ctxt, substs: &substs) -> ~str {
fmt!{"substs(self_r=%s, self_ty=%s, tps=%?)",
substs.self_r.map_default(~"none", |r| region_to_str(cx, r)),
substs.self_ty.map_default(~"none", |t| ty_to_str(cx, t)),
@ -1072,7 +1080,7 @@ fn substs_to_str(cx: ctxt, substs: substs) -> ~str {
}
fn subst(cx: ctxt,
substs: substs,
substs: &substs,
typ: t) -> t {
debug!{"subst(substs=%s, typ=%s)",
@ -1085,7 +1093,7 @@ fn subst(cx: ctxt,
return r;
fn do_subst(cx: ctxt,
substs: substs,
substs: &substs,
typ: t) -> t {
let tb = get(typ);
if !tbox_has_flag(tb, needs_subst) { return typ; }
@ -1273,7 +1281,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
}
accum
}
ty_class(did, substs) => {
ty_class(did, ref substs) => {
// Any class with a dtor needs a drop
option::is_some(ty_dtor(cx, did)) || {
for vec::each(ty::class_items_as_fields(cx, did, substs)) |f| {
@ -1286,7 +1294,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
for elts.each |m| { if type_needs_drop(cx, m) { accum = true; } }
accum
}
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let variants = enum_variants(cx, did);
for vec::each(*variants) |variant| {
for variant.args.each |aty| {
@ -1298,7 +1306,7 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
}
accum
}
ty_fn(fty) => {
ty_fn(ref fty) => {
match fty.proto {
proto_bare | proto_block => false,
_ => true
@ -1352,7 +1360,7 @@ fn type_needs_unwind_cleanup_(cx: ctxt, ty: t,
ty_rec(_) | ty_tup(_) | ty_ptr(_) => {
true
}
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
for vec::each(*enum_variants(cx, did)) |v| {
for v.args.each |aty| {
let t = subst(cx, substs, aty);
@ -1621,7 +1629,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
}
// functions depend on the protocol
ty_fn(f) => proto_kind(f.proto),
ty_fn(ref f) => proto_kind(f.proto),
// Those with refcounts raise noncopyable to copyable,
// lower sendable to copyable. Therefore just set result to copyable.
@ -1682,7 +1690,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
lowest
}
ty_class(did, substs) => {
ty_class(did, ref substs) => {
// Classes are sendable if all their fields are sendable,
// likewise for copyable...
// also factor out this code, copied from the records case
@ -1707,7 +1715,7 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
}
// Enums lower to the lowest of their variants.
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let mut lowest = kind_top();
let variants = enum_variants(cx, did);
if vec::len(*variants) == 0u {
@ -1782,7 +1790,7 @@ fn type_size(cx: ctxt, ty: t) -> uint {
flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty))
}
ty_class(did, substs) => {
ty_class(did, ref substs) => {
let flds = class_items_as_fields(cx, did, substs);
flds.foldl(0, |s, f| s + type_size(cx, f.mt.ty))
}
@ -1791,7 +1799,7 @@ fn type_size(cx: ctxt, ty: t) -> uint {
tys.foldl(0, |s, t| s + type_size(cx, t))
}
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let variants = substd_enum_variants(cx, did, substs);
variants.foldl( // find max size of any variant
0,
@ -1885,7 +1893,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
false
}
ty_class(did, substs) => {
ty_class(did, ref substs) => {
vec::push(*seen, did);
let r = vec::any(class_items_as_fields(cx, did, substs),
|f| type_requires(cx, seen, r_ty, f.mt.ty));
@ -1901,7 +1909,7 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
false
}
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
vec::push(*seen, did);
let vs = enum_variants(cx, did);
let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| {
@ -1927,13 +1935,13 @@ fn is_instantiable(cx: ctxt, r_ty: t) -> bool {
!subtypes_require(cx, seen, r_ty, r_ty)
}
fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
fn type_structurally_contains(cx: ctxt, ty: t, test: fn(x: &sty) -> bool) ->
bool {
let sty = get(ty).struct;
let sty = &get(ty).struct;
debug!{"type_structurally_contains: %s", ty_to_str(cx, ty)};
if test(sty) { return true; }
match sty {
ty_enum(did, substs) => {
match *sty {
ty_enum(did, ref substs) => {
for vec::each(*enum_variants(cx, did)) |variant| {
for variant.args.each |aty| {
let sty = subst(cx, substs, aty);
@ -1950,7 +1958,7 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
}
return false;
}
ty_class(did, substs) => {
ty_class(did, ref substs) => {
for lookup_class_fields(cx, did).each |field| {
let ft = lookup_field_type(cx, did, field.id, substs);
if type_structurally_contains(cx, ft, test) { return true; }
@ -1973,7 +1981,7 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
return type_structurally_contains(cx, ty, |sty| {
match sty {
match *sty {
ty_uniq(_) |
ty_evec(_, vstore_uniq) |
ty_estr(vstore_uniq) => true,
@ -2021,7 +2029,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ty_evec(_, vstore_uniq) | ty_evec(_, vstore_box) |
ty_trait(_, _) | ty_rptr(_,_) | ty_opaque_box => result = false,
// Structural types
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let variants = enum_variants(cx, did);
for vec::each(*variants) |variant| {
let tup_ty = mk_tup(cx, variant.args);
@ -2045,7 +2053,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
}
ty_param(_) => result = false,
ty_opaque_closure_ptr(_) => result = true,
ty_class(did, substs) => {
ty_class(did, ref substs) => {
result = vec::any(lookup_class_fields(cx, did), |f| {
let fty = ty::lookup_item_type(cx, f.id);
let sty = subst(cx, substs, fty.ty);
@ -2076,7 +2084,7 @@ fn type_is_enum(ty: t) -> bool {
// constructors
fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
match get(ty).struct {
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let variants = enum_variants(cx, did);
let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
return !some_n_ary;
@ -2098,10 +2106,10 @@ fn type_param(ty: t) -> option<uint> {
// The parameter `expl` indicates if this is an *explicit* dereference. Some
// types---notably unsafe ptrs---can only be dereferenced explicitly.
fn deref(cx: ctxt, t: t, expl: bool) -> option<mt> {
deref_sty(cx, get(t).struct, expl)
deref_sty(cx, &get(t).struct, expl)
}
fn deref_sty(cx: ctxt, sty: sty, expl: bool) -> option<mt> {
match sty {
fn deref_sty(cx: ctxt, sty: &sty, expl: bool) -> option<mt> {
match *sty {
ty_rptr(_, mt) | ty_box(mt) | ty_uniq(mt) => {
some(mt)
}
@ -2110,7 +2118,7 @@ fn deref_sty(cx: ctxt, sty: sty, expl: bool) -> option<mt> {
some(mt)
}
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let variants = enum_variants(cx, did);
if vec::len(*variants) == 1u && vec::len(variants[0].args) == 1u {
let v_t = subst(cx, substs, variants[0].args[0]);
@ -2136,11 +2144,11 @@ fn type_autoderef(cx: ctxt, t: t) -> t {
// Returns the type and mutability of t[i]
fn index(cx: ctxt, t: t) -> option<mt> {
index_sty(cx, get(t).struct)
index_sty(cx, &get(t).struct)
}
fn index_sty(cx: ctxt, sty: sty) -> option<mt> {
match sty {
fn index_sty(cx: ctxt, sty: &sty) -> option<mt> {
match *sty {
ty_evec(mt, _) => some(mt),
ty_estr(_) => some({ty: mk_u8(cx), mutbl: ast::m_imm}),
_ => none
@ -2161,7 +2169,7 @@ fn br_hashmap<V:copy>() -> hashmap<bound_region, V> {
}
// Type hashing.
pure fn hash_type_structure(st: sty) -> uint {
pure fn hash_type_structure(st: &sty) -> uint {
pure fn hash_uint(id: uint, n: uint) -> uint { (id << 2u) + n }
pure fn hash_def(id: uint, did: ast::def_id) -> uint {
let h = (id << 2u) + (did.crate as uint);
@ -2185,11 +2193,11 @@ pure fn hash_type_structure(st: sty) -> uint {
re_bot => 4u
}
}
pure fn hash_substs(h: uint, substs: substs) -> uint {
pure fn hash_substs(h: uint, substs: &substs) -> uint {
let h = hash_subtys(h, substs.tps);
h + substs.self_r.map_default(0u, |r| hash_region(&r))
}
match st {
match *st {
ty_nil => 0u,
ty_bool => 1u,
ty_int(t) => match t {
@ -2213,7 +2221,7 @@ pure fn hash_type_structure(st: sty) -> uint {
ast::ty_f64 => 15u
},
ty_estr(_) => 16u,
ty_enum(did, substs) => {
ty_enum(did, ref substs) => {
let mut h = hash_def(18u, did);
hash_substs(h, substs)
}
@ -2226,7 +2234,7 @@ pure fn hash_type_structure(st: sty) -> uint {
for vec::each(fields) |f| { h = hash_subty(h, f.mt.ty); }
h
}
ty_fn(f) => {
ty_fn(ref f) => {
let mut h = 27u;
for vec::each(f.inputs) |a| { h = hash_subty(h, a.ty); }
hash_subty(h, f.output)
@ -2239,7 +2247,7 @@ pure fn hash_type_structure(st: sty) -> uint {
ty_bot => 34u,
ty_ptr(mt) => hash_subty(35u, mt.ty),
ty_uniq(mt) => hash_subty(37u, mt.ty),
ty_trait(did, substs) => {
ty_trait(did, ref substs) => {
let mut h = hash_def(40u, did);
hash_substs(h, substs)
}
@ -2247,7 +2255,7 @@ pure fn hash_type_structure(st: sty) -> uint {
ty_opaque_closure_ptr(ck_box) => 42u,
ty_opaque_closure_ptr(ck_uniq) => 43u,
ty_opaque_box => 44u,
ty_class(did, substs) => {
ty_class(did, ref substs) => {
let mut h = hash_def(45u, did);
hash_substs(h, substs)
}
@ -2280,28 +2288,28 @@ fn node_id_has_type_params(cx: ctxt, id: ast::node_id) -> bool {
// Type accessors for substructures of types
fn ty_fn_args(fty: t) -> ~[arg] {
match get(fty).struct {
ty_fn(f) => f.inputs,
ty_fn(ref f) => f.inputs,
_ => fail ~"ty_fn_args() called on non-fn type"
}
}
fn ty_fn_proto(fty: t) -> ast::proto {
match get(fty).struct {
ty_fn(f) => f.proto,
ty_fn(ref f) => f.proto,
_ => fail ~"ty_fn_proto() called on non-fn type"
}
}
pure fn ty_fn_ret(fty: t) -> t {
match get(fty).struct {
ty_fn(f) => f.output,
ty_fn(ref f) => f.output,
_ => fail ~"ty_fn_ret() called on non-fn type"
}
}
fn ty_fn_ret_style(fty: t) -> ast::ret_style {
match get(fty).struct {
ty_fn(f) => f.ret_style,
ty_fn(ref f) => f.ret_style,
_ => fail ~"ty_fn_ret_style() called on non-fn type"
}
}
@ -2321,7 +2329,7 @@ fn ty_region(ty: t) -> region {
}
// Returns a vec of all the input and output types of fty.
fn tys_in_fn_ty(fty: fn_ty) -> ~[t] {
fn tys_in_fn_ty(fty: &fn_ty) -> ~[t] {
vec::append_one(fty.inputs.map(|a| a.ty), fty.output)
}
@ -2348,7 +2356,7 @@ fn ty_var_integral_id(typ: t) -> tvi_vid {
}
// Type accessors for AST nodes
fn block_ty(cx: ctxt, b: ast::blk) -> t {
fn block_ty(cx: ctxt, b: &ast::blk) -> t {
return node_id_to_type(cx, b.node.id);
}
@ -2416,7 +2424,7 @@ fn get_fields(rec_ty:t) -> ~[field] {
}
}
fn method_idx(id: ast::ident, meths: ~[method]) -> option<uint> {
fn method_idx(id: ast::ident, meths: &[method]) -> option<uint> {
let mut i = 0u;
for meths.each |m| { if m.ident == id { return some(i); } i += 1u; }
return none;
@ -2473,7 +2481,7 @@ fn occurs_check(tcx: ctxt, sp: span, vid: tv_vid, rt: t) {
// Maintains a little union-set tree for inferred modes. `canon()` returns
// the current head value for `m0`.
fn canon<T:copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>,
m0: ast::inferable<T>) -> ast::inferable<T> {
+m0: ast::inferable<T>) -> ast::inferable<T> {
match m0 {
ast::infer(id) => match tbl.find(id) {
none => m0,
@ -2566,12 +2574,12 @@ fn ty_sort_str(cx: ctxt, t: t) -> ~str {
}
}
fn type_err_to_str(cx: ctxt, err: type_err) -> ~str {
fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
fn terr_vstore_kind_to_str(k: terr_vstore_kind) -> ~str {
match k { terr_vec => ~"[]", terr_str => ~"str" }
}
match err {
match *err {
terr_mismatch => return ~"types differ",
terr_ret_style_mismatch(expect, actual) => {
fn to_str(s: ast::ret_style) -> ~str {
@ -2635,7 +2643,7 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> ~str {
vstore_to_str(cx, a_vs)};
}
terr_in_field(err, fname) => {
return fmt!{"in field `%s`, %s", *fname, type_err_to_str(cx, *err)};
return fmt!{"in field `%s`, %s", *fname, type_err_to_str(cx, err)};
}
terr_sorts(exp, act) => {
return fmt!{"%s vs %s", ty_sort_str(cx, exp), ty_sort_str(cx, act)};
@ -2731,7 +2739,7 @@ type variant_info = @{args: ~[t], ctor_ty: t, name: ast::ident,
fn substd_enum_variants(cx: ctxt,
id: ast::def_id,
substs: substs) -> ~[variant_info] {
substs: &substs) -> ~[variant_info] {
do vec::map(*enum_variants(cx, id)) |variant_info| {
let substd_args = vec::map(variant_info.args,
|aty| subst(cx, substs, aty));
@ -2930,7 +2938,7 @@ fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty {
// Look up a field ID, whether or not it's local
// Takes a list of type substs in case the class is generic
fn lookup_field_type(tcx: ctxt, class_id: def_id, id: def_id,
substs: substs) -> ty::t {
substs: &substs) -> ty::t {
let t = if id.crate == ast::local_crate {
node_id_to_type(tcx, id.node)
@ -3056,23 +3064,27 @@ fn class_field_tys(items: ~[@class_member]) -> ~[field_ty] {
// Keep in mind that this function reports that all fields are
// mutable, regardless of how they were declared. It's meant to
// be used in trans.
fn class_items_as_mutable_fields(cx:ctxt, did: ast::def_id,
substs: substs) -> ~[field] {
fn class_items_as_mutable_fields(cx:ctxt,
did: ast::def_id,
substs: &substs) -> ~[field] {
class_item_fields(cx, did, substs, |_mt| m_mutbl)
}
// Same as class_items_as_mutable_fields, but doesn't change
// mutability.
fn class_items_as_fields(cx:ctxt, did: ast::def_id,
substs: substs) -> ~[field] {
fn class_items_as_fields(cx:ctxt,
did: ast::def_id,
substs: &substs) -> ~[field] {
class_item_fields(cx, did, substs, |mt| match mt {
class_mutable => m_mutbl,
class_immutable => m_imm })
}
fn class_item_fields(cx:ctxt, did: ast::def_id,
substs: substs, frob_mutability: fn(class_mutability) -> mutability)
fn class_item_fields(cx:ctxt,
did: ast::def_id,
substs: &substs,
frob_mutability: fn(class_mutability) -> mutability)
-> ~[field] {
let mut rslt = ~[];
for lookup_class_fields(cx, did).each |f| {
@ -3216,7 +3228,7 @@ fn normalize_ty(cx: ctxt, t: t) -> t {
// types, which isn't necessary after #2187
let t = mk_t(cx, mach_sty(cx.sess.targ_cfg, t));
let sty = fold_sty(get(t).struct, |t| { normalize_ty(cx, t) });
let sty = fold_sty(&get(t).struct, |t| { normalize_ty(cx, t) });
let t_norm = mk_t(cx, sty);
cx.normalized_cache.insert(t, t_norm);
return t_norm;

View File

@ -223,7 +223,7 @@ fn require_same_types(
match infer::mk_eqty(l_infcx, t1, t2) {
result::ok(()) => true,
result::err(terr) => {
result::err(ref terr) => {
l_tcx.sess.span_err(span, msg() + ~": " +
ty::type_err_to_str(l_tcx, terr));
false

View File

@ -125,7 +125,7 @@ fn ast_path_to_substs_and_ty<AC: ast_conv, RS: region_scope copy owned>(
let tps = path.types.map(|a_t| ast_ty_to_ty(self, rscope, a_t));
let substs = {self_r:self_r, self_ty:none, tps:tps};
{substs: substs, ty: ty::subst(tcx, substs, decl_ty)}
{substs: substs, ty: ty::subst(tcx, &substs, decl_ty)}
}
fn ast_path_to_ty<AC: ast_conv, RS: region_scope copy owned>(

View File

@ -547,13 +547,13 @@ impl @fn_ctxt {
self.node_types.insert(node_id, ty);
}
fn write_substs(node_id: ast::node_id, +substs: ty::substs) {
if !ty::substs_is_noop(substs) {
if !ty::substs_is_noop(&substs) {
self.node_type_substs.insert(node_id, substs);
}
}
fn write_ty_substs(node_id: ast::node_id, ty: ty::t,
+substs: ty::substs) {
let ty = ty::subst(self.tcx(), substs, ty);
let ty = ty::subst(self.tcx(), &substs, ty);
self.write_ty(node_id, ty);
self.write_substs(node_id, substs);
}
@ -604,7 +604,7 @@ impl @fn_ctxt {
}
fn report_mismatched_types(sp: span, e: ty::t, a: ty::t,
err: ty::type_err) {
err: &ty::type_err) {
self.ccx.tcx.sess.span_err(
sp,
fmt!{"mismatched types: expected `%s` but found `%s` (%s)",
@ -694,7 +694,7 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
}
// Otherwise, deref if type is derefable:
match ty::deref_sty(fcx.ccx.tcx, sty, false) {
match ty::deref_sty(fcx.ccx.tcx, &sty, false) {
none => return t1,
some(mt) => t1 = mt.ty
}
@ -782,15 +782,17 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty {
let tps = fcx.infcx.next_ty_vars(n_tps);
let substs = {self_r: self_r, self_ty: none, tps: tps};
let substd_ty = ty::subst(tcx, substs, raw_ty);
let substd_ty = ty::subst(tcx, &substs, raw_ty);
{substs: substs, ty: substd_ty}
}
// Only for fields! Returns <none> for methods>
// Indifferent to privacy flags
fn lookup_field_ty(tcx: ty::ctxt, class_id: ast::def_id,
items:~[ty::field_ty], fieldname: ast::ident,
substs: ty::substs) -> option<ty::t> {
fn lookup_field_ty(tcx: ty::ctxt,
class_id: ast::def_id,
items: &[ty::field_ty],
fieldname: ast::ident,
substs: &ty::substs) -> option<ty::t> {
let o_field = vec::find(items, |f| f.ident == fieldname);
do option::map(o_field) |f| {
@ -1201,7 +1203,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
else {
lookup_public_fields(tcx, base_id)
};
match lookup_field_ty(tcx, base_id, cls_items, field, substs) {
match lookup_field_ty(tcx, base_id, cls_items, field, &substs) {
some(field_ty) => {
// (2) look up what field's type is, and return it
fcx.write_ty(expr.id, field_ty);
@ -1354,7 +1356,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
_ => { /*ok*/ }
}
match ty::deref_sty(tcx, sty, true) {
match ty::deref_sty(tcx, &sty, true) {
some(mt) => { oprnd_t = mt.ty }
none => {
match sty {
@ -1773,7 +1775,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
tps: type_parameters
};
let struct_type = ty::subst(tcx, substitutions, raw_type);
let struct_type = ty::subst(tcx, &substitutions, raw_type);
// Look up the class fields and build up a map.
let class_fields = ty::lookup_class_fields(tcx, class_id);
@ -1802,7 +1804,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
some((field_id, false)) => {
let expected_field_type =
ty::lookup_field_type(tcx, class_id, field_id,
substitutions);
&substitutions);
bot |= check_expr(fcx,
field.node.expr,
some(expected_field_type));
@ -1855,7 +1857,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
let base_t = do_autoderef(fcx, expr.span, raw_base_t);
bot |= check_expr(fcx, idx, none);
let idx_t = fcx.expr_ty(idx);
match ty::index_sty(tcx, structure_of(fcx, expr.span, base_t)) {
let base_sty = structure_of(fcx, expr.span, base_t);
match ty::index_sty(tcx, &base_sty) {
some(mt) => {
require_integral(fcx, idx.span, idx_t);
fcx.write_ty(id, mt.ty);
@ -2122,7 +2125,7 @@ fn check_enum_variants(ccx: @crate_ctxt,
// Check that it is possible to represent this enum:
let mut outer = true, did = local_def(id);
if ty::type_structurally_contains(ccx.tcx, rty, |sty| {
match sty {
match *sty {
ty::ty_enum(id, _) if id == did => {
if outer { outer = false; false }
else { true }

View File

@ -67,7 +67,7 @@ fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path,
// Take the enum type params out of `expected`.
match structure_of(pcx.fcx, pat.span, expected) {
ty::ty_enum(_, expected_substs) => {
ty::ty_enum(_, ref expected_substs) => {
// check that the type of the value being matched is a subtype
// of the type of the pattern:
let pat_ty = fcx.node_ty(pat.id);
@ -236,7 +236,7 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
// Grab the class data that we care about.
let class_fields, class_id, substitutions;
match structure_of(fcx, pat.span, expected) {
ty::ty_class(cid, substs) => {
ty::ty_class(cid, ref substs) => {
class_id = cid;
substitutions = substs;
class_fields = ty::lookup_class_fields(tcx, class_id);

View File

@ -8,7 +8,7 @@ fn suptype(fcx: @fn_ctxt, sp: span,
// n.b.: order of actual, expected is reversed
match infer::mk_subty(fcx.infcx, actual, expected) {
result::ok(()) => { /* ok */ }
result::err(err) => {
result::err(ref err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
}
}
@ -19,7 +19,7 @@ fn eqtype(fcx: @fn_ctxt, sp: span,
match infer::mk_eqty(fcx.infcx, actual, expected) {
result::ok(()) => { /* ok */ }
result::err(err) => {
result::err(ref err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
}
}
@ -31,7 +31,7 @@ fn assign(fcx: @fn_ctxt, sp: span, borrow_lb: ast::node_id,
let expr_ty = fcx.expr_ty(expr);
match fcx.mk_assignty(expr, borrow_lb, expr_ty, expected) {
result::ok(()) => { /* ok */ }
result::err(err) => {
result::err(ref err) => {
fcx.report_mismatched_types(sp, expected, expr_ty, err);
}
}

View File

@ -20,7 +20,7 @@ fn replace_bound_regions_in_fn_ty(
none => none
};
let mut all_tys = ty::tys_in_fn_ty(*fn_ty);
let mut all_tys = ty::tys_in_fn_ty(fn_ty);
for self_ty.each |t| { vec::push(all_tys, t) }
@ -35,7 +35,8 @@ fn replace_bound_regions_in_fn_ty(
debug!{"br=%?", br};
mapf(br)
};
let t_fn = ty::fold_sty_to_ty(tcx, ty::ty_fn(*fn_ty), |t| {
let ty_fn = ty::ty_fn(*fn_ty);
let t_fn = ty::fold_sty_to_ty(tcx, &ty_fn, |t| {
replace_bound_regions(tcx, isr, t)
});
let t_self = self_ty.map(|t| replace_bound_regions(tcx, isr, t));

View File

@ -10,8 +10,10 @@ fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
})
}
fn lookup_vtables(fcx: @fn_ctxt, sp: span,
bounds: @~[ty::param_bounds], substs: ty::substs,
fn lookup_vtables(fcx: @fn_ctxt,
sp: span,
bounds: @~[ty::param_bounds],
substs: &ty::substs,
allow_unsafe: bool) -> vtable_res {
let tcx = fcx.ccx.tcx;
let mut result = ~[], i = 0u;
@ -156,7 +158,7 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t,
of_ty %s",
fcx.infcx.ty_to_str(trait_ty),
fcx.infcx.ty_to_str(of_ty)};
let of_ty = ty::subst(tcx, substs, of_ty);
let of_ty = ty::subst(tcx, &substs, of_ty);
relate_trait_tys(fcx, sp, trait_ty, of_ty);
// recursively process the bounds
@ -165,7 +167,7 @@ fn lookup_vtable(fcx: @fn_ctxt, sp: span, ty: ty::t, trait_ty: ty::t,
substs);
connect_trait_tps(fcx, sp, substs_f.tps,
trait_tps, im.did);
let subres = lookup_vtables(fcx, sp, im_bs, substs_f,
let subres = lookup_vtables(fcx, sp, im_bs, &substs_f,
false);
vec::push(found,
vtable_static(im.did, substs_f.tps,
@ -229,7 +231,7 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
match ex.node {
ast::expr_path(*) => {
match fcx.opt_node_ty_substs(ex.id) {
some(substs) => {
some(ref substs) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id));
let item_ty = ty::lookup_item_type(cx.tcx, did);
if has_trait_bounds(*item_ty.bounds) {
@ -259,7 +261,7 @@ fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
cx.vtable_map.insert(callee_id, lookup_vtables(fcx,
ex.span,
bounds,
substs,
&substs,
false));
}
}

View File

@ -410,7 +410,7 @@ class CoherenceChecker {
tps: type_parameters
};
return subst(self.crate_context.tcx, substitutions, polytype.ty);
return subst(self.crate_context.tcx, &substitutions, polytype.ty);
}
fn get_self_type_for_implementation(implementation: @Impl)

View File

@ -186,8 +186,7 @@ fn ensure_trait_methods(ccx: @crate_ctxt, id: ast::node_id) {
let substs = { self_r: none, self_ty: some(self_param),
tps: non_shifted_trait_tps + shifted_method_tps };
let ty = ty::subst(ccx.tcx, substs, ty::mk_fn(ccx.tcx, m.fty));
let ty = ty::subst(ccx.tcx, &substs, ty::mk_fn(ccx.tcx, m.fty));
let trait_ty = ty::node_id_to_type(ccx.tcx, id);
let bounds = @(*trait_bounds + ~[@~[ty::bound_trait(trait_ty)]]
+ *m.tps);
@ -293,7 +292,7 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span,
tps: vec::append(trait_substs.tps, dummy_tps)
};
let trait_fty = ty::mk_fn(tcx, trait_m.fty);
ty::subst(tcx, substs, trait_fty)
ty::subst(tcx, &substs, trait_fty)
};
require_same_types(
tcx, none, sp, impl_fty, trait_fty,