rustc: Thread the type store through everything that needs to access type structures

This commit is contained in:
Patrick Walton 2011-04-22 17:00:46 -07:00
parent 3d62c9adf3
commit e0eccaddb2
5 changed files with 412 additions and 383 deletions

View file

@ -546,7 +546,7 @@ fn get_tag_variants(session.session sess,
auto item = find_item(did._1, items);
auto ctor_ty = item_type(item, external_crate_id, tystore);
let vec[ty.t] arg_tys = vec();
alt (ty.struct(ctor_ty)) {
alt (ty.struct(tystore, ctor_ty)) {
case (ty.ty_fn(_, ?args, _)) {
for (ty.arg a in args) {
arg_tys += vec(a.ty);

View file

@ -52,11 +52,12 @@ const uint tag_index_table = 0x15u;
mod Encode {
type ctxt = rec(
fn(ast.def_id) -> str ds // Callback to translate defs to strs.
fn(ast.def_id) -> str ds, // Callback to translate defs to strs.
@ty.type_store tystore // The type store.
);
fn ty_str(@ctxt cx, ty.t t) -> str {
ret sty_str(cx, ty.struct(t));
ret sty_str(cx, ty.struct(cx.tystore, t));
}
fn mt_str(@ctxt cx, &ty.mt mt) -> str {
@ -332,11 +333,11 @@ fn encode_variant_id(&ebml.writer ebml_w, ast.def_id vid) {
ebml.end_tag(ebml_w);
}
fn encode_type(&ebml.writer ebml_w, ty.t typ) {
fn encode_type(@trans.crate_ctxt cx, &ebml.writer ebml_w, ty.t typ) {
ebml.start_tag(ebml_w, tag_items_data_item_type);
auto f = def_to_str;
auto ty_str_ctxt = @rec(ds=f);
auto ty_str_ctxt = @rec(ds=f, tystore=cx.tystore);
ebml_w.writer.write(_str.bytes(Encode.ty_str(ty_str_ctxt, typ)));
ebml.end_tag(ebml_w);
@ -379,7 +380,7 @@ fn encode_tag_variant_info(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_def_id(ebml_w, variant.node.id);
encode_kind(ebml_w, 'v' as u8);
encode_tag_id(ebml_w, did);
encode_type(ebml_w, trans.node_ann_type(cx, variant.node.ann));
encode_type(cx, ebml_w, trans.node_ann_type(cx, variant.node.ann));
if (_vec.len[ast.variant_arg](variant.node.args) > 0u) {
encode_symbol(cx, ebml_w, variant.node.id);
}
@ -396,7 +397,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
ebml.start_tag(ebml_w, tag_items_data_item);
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'c' as u8);
encode_type(ebml_w, trans.node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
ebml.end_tag(ebml_w);
}
@ -405,7 +406,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'f' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ebml_w, trans.node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
ebml.end_tag(ebml_w);
}
@ -426,7 +427,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ebml_w, trans.node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
ebml.end_tag(ebml_w);
}
case (ast.item_tag(?id, ?variants, ?tps, ?did, ?ann)) {
@ -434,7 +435,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 't' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ebml_w, trans.node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
for (ast.variant v in variants) {
encode_variant_id(ebml_w, v.node.id);
}
@ -448,7 +449,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_kind(ebml_w, 'o' as u8);
encode_type_param_count(ebml_w, tps);
auto fn_ty = trans.node_ann_type(cx, ann);
encode_type(ebml_w, fn_ty);
encode_type(cx, ebml_w, fn_ty);
encode_symbol(cx, ebml_w, odid.ctor);
ebml.end_tag(ebml_w);
@ -456,7 +457,7 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
encode_def_id(ebml_w, odid.ty);
encode_kind(ebml_w, 'y' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ebml_w, ty.ty_fn_ret(fn_ty));
encode_type(cx, ebml_w, ty.ty_fn_ret(cx.tystore, fn_ty));
ebml.end_tag(ebml_w);
}
}
@ -469,13 +470,13 @@ fn encode_info_for_native_item(@trans.crate_ctxt cx, &ebml.writer ebml_w,
case (ast.native_item_ty(_, ?did)) {
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'T' as u8);
encode_type(ebml_w, ty.mk_native(cx.tystore));
encode_type(cx, ebml_w, ty.mk_native(cx.tystore));
}
case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
encode_def_id(ebml_w, did);
encode_kind(ebml_w, 'F' as u8);
encode_type_param_count(ebml_w, tps);
encode_type(ebml_w, trans.node_ann_type(cx, ann));
encode_type(cx, ebml_w, trans.node_ann_type(cx, ann));
encode_symbol(cx, ebml_w, did);
}
}

File diff suppressed because it is too large Load diff

View file

@ -215,10 +215,10 @@ fn mk_native(@type_store ts) -> t { ret gen_ty(ts, ty_native); }
// Returns the one-level-deep type structure of the given type.
fn struct(t typ) -> sty { ret typ.struct; }
fn struct(@type_store tystore, t typ) -> sty { ret typ.struct; }
// Returns the canonical name of the given type.
fn cname(t typ) -> option.t[str] { ret typ.cname; }
fn cname(@type_store tystore, t typ) -> option.t[str] { ret typ.cname; }
// Stringification
@ -234,9 +234,10 @@ fn path_to_str(&ast.path pth) -> str {
ret result;
}
fn ty_to_str(&t typ) -> str {
fn ty_to_str(@type_store ts, &t typ) -> str {
fn fn_input_to_str(&rec(ast.mode mode, t ty) input) -> str {
fn fn_input_to_str(@type_store tystore,
&rec(ast.mode mode, t ty) input) -> str {
auto s;
if (mode_is_alias(input.mode)) {
s = "&";
@ -244,13 +245,14 @@ fn ty_to_str(&t typ) -> str {
s = "";
}
ret s + ty_to_str(input.ty);
ret s + ty_to_str(tystore, input.ty);
}
fn fn_to_str(ast.proto proto,
fn fn_to_str(@type_store tystore,
ast.proto proto,
option.t[ast.ident] ident,
vec[arg] inputs, t output) -> str {
auto f = fn_input_to_str;
auto f = bind fn_input_to_str(tystore, _);
auto s;
alt (proto) {
@ -274,22 +276,22 @@ fn ty_to_str(&t typ) -> str {
s += _str.connect(_vec.map[arg,str](f, inputs), ", ");
s += ")";
if (struct(output) != ty_nil) {
s += " -> " + ty_to_str(output);
if (struct(tystore, output) != ty_nil) {
s += " -> " + ty_to_str(tystore, output);
}
ret s;
}
fn method_to_str(&method m) -> str {
ret fn_to_str(m.proto, some[ast.ident](m.ident),
fn method_to_str(@type_store tystore, &method m) -> str {
ret fn_to_str(tystore, m.proto, some[ast.ident](m.ident),
m.inputs, m.output) + ";";
}
fn field_to_str(&field f) -> str {
ret mt_to_str(f.mt) + " " + f.ident;
fn field_to_str(@type_store tystore, &field f) -> str {
ret mt_to_str(tystore, f.mt) + " " + f.ident;
}
fn mt_to_str(&mt m) -> str {
fn mt_to_str(@type_store tystore, &mt m) -> str {
auto mstr;
alt (m.mut) {
case (ast.mut) { mstr = "mutable "; }
@ -297,34 +299,34 @@ fn ty_to_str(&t typ) -> str {
case (ast.maybe_mut) { mstr = "mutable? "; }
}
ret mstr + ty_to_str(m.ty);
ret mstr + ty_to_str(tystore, m.ty);
}
auto s = "";
alt (struct(typ)) {
case (ty_native) { s += "native"; }
case (ty_nil) { s += "()"; }
case (ty_bool) { s += "bool"; }
case (ty_int) { s += "int"; }
case (ty_float) { s += "float"; }
case (ty_uint) { s += "uint"; }
case (ty_machine(?tm)) { s += common.ty_mach_to_str(tm); }
case (ty_char) { s += "char"; }
case (ty_str) { s += "str"; }
case (ty_box(?tm)) { s += "@" + mt_to_str(tm); }
case (ty_vec(?tm)) { s += "vec[" + mt_to_str(tm) + "]"; }
case (ty_port(?t)) { s += "port[" + ty_to_str(t) + "]"; }
case (ty_chan(?t)) { s += "chan[" + ty_to_str(t) + "]"; }
case (ty_type) { s += "type"; }
alt (struct(ts, typ)) {
case (ty_native) { s += "native"; }
case (ty_nil) { s += "()"; }
case (ty_bool) { s += "bool"; }
case (ty_int) { s += "int"; }
case (ty_float) { s += "float"; }
case (ty_uint) { s += "uint"; }
case (ty_machine(?tm)) { s += common.ty_mach_to_str(tm); }
case (ty_char) { s += "char"; }
case (ty_str) { s += "str"; }
case (ty_box(?tm)) { s += "@" + mt_to_str(ts, tm); }
case (ty_vec(?tm)) { s += "vec[" + mt_to_str(ts, tm) + "]"; }
case (ty_port(?t)) { s += "port[" + ty_to_str(ts, t) + "]"; }
case (ty_chan(?t)) { s += "chan[" + ty_to_str(ts, t) + "]"; }
case (ty_type) { s += "type"; }
case (ty_tup(?elems)) {
auto f = mt_to_str;
auto f = bind mt_to_str(ts, _);
auto strs = _vec.map[mt,str](f, elems);
s += "tup(" + _str.connect(strs, ",") + ")";
}
case (ty_rec(?elems)) {
auto f = field_to_str;
auto f = bind field_to_str(ts, _);
auto strs = _vec.map[field,str](f, elems);
s += "rec(" + _str.connect(strs, ",") + ")";
}
@ -334,27 +336,27 @@ fn ty_to_str(&t typ) -> str {
s += "<tag#" + util.common.istr(id._0) + ":" +
util.common.istr(id._1) + ">";
if (_vec.len[t](tps) > 0u) {
auto f = ty_to_str;
auto f = bind ty_to_str(ts, _);
auto strs = _vec.map[t,str](f, tps);
s += "[" + _str.connect(strs, ",") + "]";
}
}
case (ty_fn(?proto, ?inputs, ?output)) {
s += fn_to_str(proto, none[ast.ident], inputs, output);
s += fn_to_str(ts, proto, none[ast.ident], inputs, output);
}
case (ty_native_fn(_, ?inputs, ?output)) {
s += fn_to_str(ast.proto_fn, none[ast.ident], inputs, output);
s += fn_to_str(ts, ast.proto_fn, none[ast.ident], inputs, output);
}
case (ty_obj(?meths)) {
alt (cname(typ)) {
alt (cname(ts, typ)) {
case (some[str](?cs)) {
s += cs;
}
case (_) {
auto f = method_to_str;
auto f = bind method_to_str(ts, _);
auto m = _vec.map[method,str](f, meths);
s += "obj {\n\t" + _str.connect(m, "\n\t") + "\n}";
}
@ -386,8 +388,8 @@ fn ty_to_str(&t typ) -> str {
type ty_walk = fn(t);
fn walk_ty(ty_walk walker, t ty) {
alt (struct(ty)) {
fn walk_ty(@type_store tystore, ty_walk walker, t ty) {
alt (struct(tystore, ty)) {
case (ty_nil) { /* no-op */ }
case (ty_bool) { /* no-op */ }
case (ty_int) { /* no-op */ }
@ -398,44 +400,44 @@ fn walk_ty(ty_walk walker, t ty) {
case (ty_str) { /* no-op */ }
case (ty_type) { /* no-op */ }
case (ty_native) { /* no-op */ }
case (ty_box(?tm)) { walk_ty(walker, tm.ty); }
case (ty_vec(?tm)) { walk_ty(walker, tm.ty); }
case (ty_port(?subty)) { walk_ty(walker, subty); }
case (ty_chan(?subty)) { walk_ty(walker, subty); }
case (ty_box(?tm)) { walk_ty(tystore, walker, tm.ty); }
case (ty_vec(?tm)) { walk_ty(tystore, walker, tm.ty); }
case (ty_port(?subty)) { walk_ty(tystore, walker, subty); }
case (ty_chan(?subty)) { walk_ty(tystore, walker, subty); }
case (ty_tag(?tid, ?subtys)) {
for (t subty in subtys) {
walk_ty(walker, subty);
walk_ty(tystore, walker, subty);
}
}
case (ty_tup(?mts)) {
for (mt tm in mts) {
walk_ty(walker, tm.ty);
walk_ty(tystore, walker, tm.ty);
}
}
case (ty_rec(?fields)) {
for (field fl in fields) {
walk_ty(walker, fl.mt.ty);
walk_ty(tystore, walker, fl.mt.ty);
}
}
case (ty_fn(?proto, ?args, ?ret_ty)) {
for (arg a in args) {
walk_ty(walker, a.ty);
walk_ty(tystore, walker, a.ty);
}
walk_ty(walker, ret_ty);
walk_ty(tystore, walker, ret_ty);
}
case (ty_native_fn(?abi, ?args, ?ret_ty)) {
for (arg a in args) {
walk_ty(walker, a.ty);
walk_ty(tystore, walker, a.ty);
}
walk_ty(walker, ret_ty);
walk_ty(tystore, walker, ret_ty);
}
case (ty_obj(?methods)) {
let vec[method] new_methods = vec();
for (method m in methods) {
for (arg a in m.inputs) {
walk_ty(walker, a.ty);
walk_ty(tystore, walker, a.ty);
}
walk_ty(walker, m.output);
walk_ty(tystore, walker, m.output);
}
}
case (ty_var(_)) { /* no-op */ }
@ -451,7 +453,7 @@ type ty_fold = fn(t) -> t;
fn fold_ty(@type_store tystore, ty_fold fld, t ty_0) -> t {
auto ty = ty_0;
alt (struct(ty)) {
alt (struct(tystore, ty)) {
case (ty_nil) { /* no-op */ }
case (ty_bool) { /* no-op */ }
case (ty_int) { /* no-op */ }
@ -552,13 +554,13 @@ fn fold_ty(@type_store tystore, ty_fold fld, t ty_0) -> t {
// Type utilities
fn rename(@type_store tystore, t typ, str new_cname) -> t {
ret gen_ty_full(tystore, struct(typ), some[str](new_cname));
ret gen_ty_full(tystore, struct(tystore, typ), some[str](new_cname));
}
// Returns a type with the structural part taken from `struct_ty` and the
// canonical name from `cname_ty`.
fn copy_cname(@type_store tystore, t struct_ty, t cname_ty) -> t {
ret gen_ty_full(tystore, struct(struct_ty), cname_ty.cname);
ret gen_ty_full(tystore, struct(tystore, struct_ty), cname_ty.cname);
}
// FIXME: remove me when == works on these tags.
@ -570,24 +572,24 @@ fn mode_is_alias(ast.mode m) -> bool {
fail;
}
fn type_is_nil(t ty) -> bool {
alt (struct(ty)) {
fn type_is_nil(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_nil) { ret true; }
case (_) { ret false; }
}
fail;
}
fn type_is_bool(t ty) -> bool {
alt (struct(ty)) {
fn type_is_bool(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_bool) { ret true; }
case (_) { ret false; }
}
}
fn type_is_structural(t ty) -> bool {
alt (struct(ty)) {
fn type_is_structural(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_tup(_)) { ret true; }
case (ty_rec(_)) { ret true; }
case (ty_tag(_,_)) { ret true; }
@ -598,8 +600,8 @@ fn type_is_structural(t ty) -> bool {
fail;
}
fn type_is_sequence(t ty) -> bool {
alt (struct(ty)) {
fn type_is_sequence(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_str) { ret true; }
case (ty_vec(_)) { ret true; }
case (_) { ret false; }
@ -608,7 +610,7 @@ fn type_is_sequence(t ty) -> bool {
}
fn sequence_element_type(@type_store tystore, t ty) -> t {
alt (struct(ty)) {
alt (struct(tystore, ty)) {
case (ty_str) { ret mk_mach(tystore, common.ty_u8); }
case (ty_vec(?mt)) { ret mt.ty; }
}
@ -616,8 +618,8 @@ fn sequence_element_type(@type_store tystore, t ty) -> t {
}
fn type_is_tup_like(t ty) -> bool {
alt (struct(ty)) {
fn type_is_tup_like(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_box(_)) { ret true; }
case (ty_tup(_)) { ret true; }
case (ty_rec(_)) { ret true; }
@ -627,9 +629,9 @@ fn type_is_tup_like(t ty) -> bool {
fail;
}
fn get_element_type(t ty, uint i) -> t {
check (type_is_tup_like(ty));
alt (struct(ty)) {
fn get_element_type(@type_store tystore, t ty, uint i) -> t {
check (type_is_tup_like(tystore, ty));
alt (struct(tystore, ty)) {
case (ty_tup(?mts)) {
ret mts.(i).ty;
}
@ -640,16 +642,16 @@ fn get_element_type(t ty, uint i) -> t {
fail;
}
fn type_is_box(t ty) -> bool {
alt (struct(ty)) {
fn type_is_box(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_box(_)) { ret true; }
case (_) { ret false; }
}
fail;
}
fn type_is_boxed(t ty) -> bool {
alt (struct(ty)) {
fn type_is_boxed(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_str) { ret true; }
case (ty_vec(_)) { ret true; }
case (ty_box(_)) { ret true; }
@ -660,8 +662,8 @@ fn type_is_boxed(t ty) -> bool {
fail;
}
fn type_is_scalar(t ty) -> bool {
alt (struct(ty)) {
fn type_is_scalar(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_nil) { ret true; }
case (ty_bool) { ret true; }
case (ty_int) { ret true; }
@ -678,34 +680,36 @@ fn type_is_scalar(t ty) -> bool {
// FIXME: should we just return true for native types in
// type_is_scalar?
fn type_is_native(t ty) -> bool {
alt (struct(ty)) {
fn type_is_native(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_native) { ret true; }
case (_) { ret false; }
}
fail;
}
fn type_has_dynamic_size(t ty) -> bool {
alt (struct(ty)) {
fn type_has_dynamic_size(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_tup(?mts)) {
auto i = 0u;
while (i < _vec.len[mt](mts)) {
if (type_has_dynamic_size(mts.(i).ty)) { ret true; }
if (type_has_dynamic_size(tystore, mts.(i).ty)) { ret true; }
i += 1u;
}
}
case (ty_rec(?fields)) {
auto i = 0u;
while (i < _vec.len[field](fields)) {
if (type_has_dynamic_size(fields.(i).mt.ty)) { ret true; }
if (type_has_dynamic_size(tystore, fields.(i).mt.ty)) {
ret true;
}
i += 1u;
}
}
case (ty_tag(_, ?subtys)) {
auto i = 0u;
while (i < _vec.len[t](subtys)) {
if (type_has_dynamic_size(subtys.(i))) { ret true; }
if (type_has_dynamic_size(tystore, subtys.(i))) { ret true; }
i += 1u;
}
}
@ -715,8 +719,8 @@ fn type_has_dynamic_size(t ty) -> bool {
ret false;
}
fn type_is_integral(t ty) -> bool {
alt (struct(ty)) {
fn type_is_integral(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_int) { ret true; }
case (ty_uint) { ret true; }
case (ty_machine(?m)) {
@ -739,8 +743,8 @@ fn type_is_integral(t ty) -> bool {
fail;
}
fn type_is_fp(t ty) -> bool {
alt (struct(ty)) {
fn type_is_fp(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_machine(?tm)) {
alt (tm) {
case (common.ty_f32) { ret true; }
@ -756,8 +760,8 @@ fn type_is_fp(t ty) -> bool {
fail;
}
fn type_is_signed(t ty) -> bool {
alt (struct(ty)) {
fn type_is_signed(@type_store tystore, t ty) -> bool {
alt (struct(tystore, ty)) {
case (ty_int) { ret true; }
case (ty_machine(?tm)) {
alt (tm) {
@ -773,8 +777,8 @@ fn type_is_signed(t ty) -> bool {
fail;
}
fn type_param(t ty) -> option.t[uint] {
alt (struct(ty)) {
fn type_param(@type_store tystore, t ty) -> option.t[uint] {
alt (struct(tystore, ty)) {
case (ty_param(?id)) { ret some[uint](id); }
case (_) { /* fall through */ }
}
@ -1217,15 +1221,15 @@ fn eq_ty_full(&t a, &t b) -> bool {
}
// Check canonical names.
alt (cname(a)) {
alt (a.cname) {
case (none[str]) {
alt (cname(b)) {
alt (b.cname) {
case (none[str]) { /* ok */ }
case (_) { ret false; }
}
}
case (some[str](?s_a)) {
alt (cname(b)) {
alt (b.cname) {
case (some[str](?s_b)) {
if (!_str.eq(s_a, s_b)) { ret false; }
}
@ -1235,7 +1239,7 @@ fn eq_ty_full(&t a, &t b) -> bool {
}
// Check structures.
ret equal_type_structures(struct(a), struct(b));
ret equal_type_structures(a.struct, b.struct);
}
// This is the equality function the public should use. It works as long as
@ -1300,9 +1304,9 @@ fn triv_ann(t typ) -> ast.ann {
}
// Returns the number of distinct type parameters in the given type.
fn count_ty_params(t ty) -> uint {
fn counter(@mutable vec[uint] param_indices, t ty) {
alt (struct(ty)) {
fn count_ty_params(@type_store tystore, t ty) -> uint {
fn counter(@type_store tystore, @mutable vec[uint] param_indices, t ty) {
alt (struct(tystore, ty)) {
case (ty_param(?param_idx)) {
auto seen = false;
for (uint other_param_idx in *param_indices) {
@ -1320,59 +1324,59 @@ fn count_ty_params(t ty) -> uint {
let vec[uint] v = vec(); // FIXME: typechecker botch
let @mutable vec[uint] param_indices = @mutable v;
auto f = bind counter(param_indices, _);
walk_ty(f, ty);
auto f = bind counter(tystore, param_indices, _);
walk_ty(tystore, f, ty);
ret _vec.len[uint](*param_indices);
}
fn type_contains_vars(t typ) -> bool {
fn checker(@mutable bool flag, t typ) {
alt (struct(typ)) {
fn type_contains_vars(@type_store tystore, t typ) -> bool {
fn checker(@type_store tystore, @mutable bool flag, t typ) {
alt (struct(tystore, typ)) {
case (ty_var(_)) { *flag = true; }
case (_) { /* fall through */ }
}
}
let @mutable bool flag = @mutable false;
auto f = bind checker(flag, _);
walk_ty(f, typ);
auto f = bind checker(tystore, flag, _);
walk_ty(tystore, f, typ);
ret *flag;
}
// Type accessors for substructures of types
fn ty_fn_args(t fty) -> vec[arg] {
alt (struct(fty)) {
fn ty_fn_args(@type_store tystore, t fty) -> vec[arg] {
alt (struct(tystore, fty)) {
case (ty.ty_fn(_, ?a, _)) { ret a; }
case (ty.ty_native_fn(_, ?a, _)) { ret a; }
}
fail;
}
fn ty_fn_proto(t fty) -> ast.proto {
alt (struct(fty)) {
fn ty_fn_proto(@type_store tystore, t fty) -> ast.proto {
alt (struct(tystore, fty)) {
case (ty.ty_fn(?p, _, _)) { ret p; }
}
fail;
}
fn ty_fn_abi(t fty) -> ast.native_abi {
alt (struct(fty)) {
fn ty_fn_abi(@type_store tystore, t fty) -> ast.native_abi {
alt (struct(tystore, fty)) {
case (ty.ty_native_fn(?a, _, _)) { ret a; }
}
fail;
}
fn ty_fn_ret(t fty) -> t {
alt (struct(fty)) {
fn ty_fn_ret(@type_store tystore, t fty) -> t {
alt (struct(tystore, fty)) {
case (ty.ty_fn(_, _, ?r)) { ret r; }
case (ty.ty_native_fn(_, _, ?r)) { ret r; }
}
fail;
}
fn is_fn_ty(t fty) -> bool {
alt (struct(fty)) {
fn is_fn_ty(@type_store tystore, t fty) -> bool {
alt (struct(tystore, fty)) {
case (ty.ty_fn(_, _, _)) { ret true; }
case (ty.ty_native_fn(_, _, _)) { ret true; }
case (_) { ret false; }
@ -1684,8 +1688,8 @@ mod Unify {
// something we'll probably need to develop over time.
// Simple structural type comparison.
fn struct_cmp(t expected, t actual) -> result {
if (struct(expected) == struct(actual)) {
fn struct_cmp(@ctxt cx, t expected, t actual) -> result {
if (struct(cx.tystore, expected) == struct(cx.tystore, actual)) {
ret ures_ok(expected);
}
@ -1850,7 +1854,7 @@ mod Unify {
a_meth.inputs, a_meth.output);
alt (r) {
case (ures_ok(?tfn)) {
alt (struct(tfn)) {
alt (struct(cx.tystore, tfn)) {
case (ty_fn(?proto, ?ins, ?out)) {
result_meths += vec(rec(inputs = ins,
output = out
@ -1890,12 +1894,12 @@ mod Unify {
// Fast path.
if (eq_ty(expected, actual)) { ret ures_ok(expected); }
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
// If the RHS is a variable type, then just do the appropriate
// binding.
case (ty.ty_var(?actual_id)) {
auto actual_n = get_or_create_set(cx, actual_id);
alt (struct(expected)) {
alt (struct(cx.tystore, expected)) {
case (ty.ty_var(?expected_id)) {
auto expected_n = get_or_create_set(cx, expected_id);
UFind.union(cx.sets, expected_n, actual_n);
@ -1931,7 +1935,7 @@ mod Unify {
ret ures_ok(result_ty);
}
case (ty.ty_bound_param(?actual_id)) {
alt (struct(expected)) {
alt (struct(cx.tystore, expected)) {
case (ty.ty_local(_)) {
log_err "TODO: bound param unifying with local";
fail;
@ -1945,21 +1949,21 @@ mod Unify {
case (_) { /* empty */ }
}
alt (struct(expected)) {
case (ty.ty_nil) { ret struct_cmp(expected, actual); }
case (ty.ty_bool) { ret struct_cmp(expected, actual); }
case (ty.ty_int) { ret struct_cmp(expected, actual); }
case (ty.ty_uint) { ret struct_cmp(expected, actual); }
case (ty.ty_machine(_)) { ret struct_cmp(expected, actual); }
case (ty.ty_float) { ret struct_cmp(expected, actual); }
case (ty.ty_char) { ret struct_cmp(expected, actual); }
case (ty.ty_str) { ret struct_cmp(expected, actual); }
case (ty.ty_type) { ret struct_cmp(expected, actual); }
case (ty.ty_native) { ret struct_cmp(expected, actual); }
case (ty.ty_param(_)) { ret struct_cmp(expected, actual); }
alt (struct(cx.tystore, expected)) {
case (ty.ty_nil) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_bool) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_int) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_uint) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_machine(_)) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_float) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_char) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_str) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_type) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_native) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_param(_)) { ret struct_cmp(cx, expected, actual); }
case (ty.ty_tag(?expected_id, ?expected_tps)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_tag(?actual_id, ?actual_tps)) {
if (expected_id._0 != actual_id._0 ||
expected_id._1 != actual_id._1) {
@ -2001,7 +2005,7 @@ mod Unify {
}
case (ty.ty_box(?expected_mt)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_box(?actual_mt)) {
auto mut;
alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
@ -2033,7 +2037,7 @@ mod Unify {
}
case (ty.ty_vec(?expected_mt)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_vec(?actual_mt)) {
auto mut;
alt (unify_mut(expected_mt.mut, actual_mt.mut)) {
@ -2065,7 +2069,7 @@ mod Unify {
}
case (ty.ty_port(?expected_sub)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_port(?actual_sub)) {
auto result = unify_step(cx,
expected_sub,
@ -2087,7 +2091,7 @@ mod Unify {
}
case (ty.ty_chan(?expected_sub)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_chan(?actual_sub)) {
auto result = unify_step(cx,
expected_sub,
@ -2109,7 +2113,7 @@ mod Unify {
}
case (ty.ty_tup(?expected_elems)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_tup(?actual_elems)) {
auto expected_len = _vec.len[ty.mt](expected_elems);
auto actual_len = _vec.len[ty.mt](actual_elems);
@ -2163,7 +2167,7 @@ mod Unify {
}
case (ty.ty_rec(?expected_fields)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_rec(?actual_fields)) {
auto expected_len = _vec.len[field](expected_fields);
auto actual_len = _vec.len[field](actual_fields);
@ -2227,7 +2231,7 @@ mod Unify {
}
case (ty.ty_fn(?ep, ?expected_inputs, ?expected_output)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_fn(?ap, ?actual_inputs, ?actual_output)) {
ret unify_fn(cx, ep, ap,
expected, actual,
@ -2243,7 +2247,7 @@ mod Unify {
case (ty.ty_native_fn(?e_abi, ?expected_inputs,
?expected_output)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_native_fn(?a_abi, ?actual_inputs,
?actual_output)) {
ret unify_native_fn(cx, e_abi, a_abi,
@ -2258,7 +2262,7 @@ mod Unify {
}
case (ty.ty_obj(?expected_meths)) {
alt (struct(actual)) {
alt (struct(cx.tystore, actual)) {
case (ty.ty_obj(?actual_meths)) {
ret unify_obj(cx, expected, actual,
expected_meths, actual_meths);
@ -2311,7 +2315,7 @@ mod Unify {
// Performs type binding substitution.
fn substitute(@ctxt cx, vec[t] set_types, t typ) -> t {
fn substituter(@ctxt cx, vec[t] types, t typ) -> t {
alt (struct(typ)) {
alt (struct(cx.tystore, typ)) {
case (ty_var(?id)) {
alt (cx.var_ids.find(id)) {
case (some[uint](?n)) {
@ -2443,8 +2447,8 @@ fn type_err_to_str(&ty.type_err err) -> str {
fn substitute_type_params(@type_store tystore,
vec[t] bindings,
t typ) -> t {
fn replacer(vec[t] bindings, t typ) -> t {
alt (struct(typ)) {
fn replacer(@type_store tystore, vec[t] bindings, t typ) -> t {
alt (struct(tystore, typ)) {
case (ty_bound_param(?param_index)) {
ret bindings.(param_index);
}
@ -2452,14 +2456,14 @@ fn substitute_type_params(@type_store tystore,
}
}
auto f = bind replacer(bindings, _);
auto f = bind replacer(tystore, bindings, _);
ret fold_ty(tystore, f, typ);
}
// Converts type parameters in a type to bound type parameters.
fn bind_params_in_type(@type_store tystore, t typ) -> t {
fn binder(@type_store tystore, t typ) -> t {
alt (struct(typ)) {
alt (struct(tystore, typ)) {
case (ty_bound_param(?index)) {
log_err "bind_params_in_type() called on type that already " +
"has bound params in it";

View file

@ -81,7 +81,7 @@ fn substitute_ty_params(&@crate_ctxt ccx,
vec[ty.t] supplied,
&span sp) -> ty.t {
fn substituter(@crate_ctxt ccx, vec[ty.t] supplied, ty.t typ) -> ty.t {
alt (struct(typ)) {
alt (struct(ccx.tystore, typ)) {
case (ty.ty_bound_param(?pid)) { ret supplied.(pid); }
case (_) { ret typ; }
}
@ -686,10 +686,10 @@ mod Collect {
ret @fold.respan[ast.native_item_](sp, item);
}
fn get_ctor_obj_methods(ty.t t) -> vec[method] {
alt (struct(t)) {
fn get_ctor_obj_methods(&@env e, ty.t t) -> vec[method] {
alt (struct(e.cx.tystore, t)) {
case (ty.ty_fn(_,_,?tobj)) {
alt (struct(tobj)) {
alt (struct(e.cx.tystore, tobj)) {
case (ty.ty_obj(?tm)) {
ret tm;
}
@ -712,7 +712,7 @@ mod Collect {
ast.obj_def_ids odid, ast.ann a) -> @ast.item {
check (e.cx.type_cache.contains_key(odid.ctor));
auto t = e.cx.type_cache.get(odid.ctor)._1;
let vec[method] meth_tys = get_ctor_obj_methods(t);
let vec[method] meth_tys = get_ctor_obj_methods(e, t);
let vec[@ast.method] methods = vec();
let vec[ast.obj_field] fields = vec();
@ -853,7 +853,8 @@ mod Unify {
alt (fcx.locals.find(id)) {
case (none[ty.t]) { ret none[ty.t]; }
case (some[ty.t](?existing_type)) {
if (ty.type_contains_vars(existing_type)) {
if (ty.type_contains_vars(fcx.ccx.tystore,
existing_type)) {
// Not fully resolved yet. The writeback phase
// will mop up.
ret none[ty.t];
@ -921,10 +922,10 @@ tag autoderef_kind {
NO_AUTODEREF;
}
fn strip_boxes(ty.t t) -> ty.t {
fn strip_boxes(@ty.type_store tystore, ty.t t) -> ty.t {
auto t1 = t;
while (true) {
alt (struct(t1)) {
alt (struct(tystore, t1)) {
case (ty.ty_box(?inner)) { t1 = inner.ty; }
case (_) { ret t1; }
}
@ -942,11 +943,11 @@ fn add_boxes(@crate_ctxt ccx, uint n, ty.t t) -> ty.t {
}
fn count_boxes(ty.t t) -> uint {
fn count_boxes(@ty.type_store tystore, ty.t t) -> uint {
auto n = 0u;
auto t1 = t;
while (true) {
alt (struct(t1)) {
alt (struct(tystore, t1)) {
case (ty.ty_box(?inner)) { n += 1u; t1 = inner.ty; }
case (_) { ret n; }
}
@ -984,9 +985,9 @@ mod Demand {
auto implicit_boxes = 0u;
if (adk == AUTODEREF_OK) {
expected_1 = strip_boxes(expected_1);
actual_1 = strip_boxes(actual_1);
implicit_boxes = count_boxes(actual);
expected_1 = strip_boxes(fcx.ccx.tystore, expected_1);
actual_1 = strip_boxes(fcx.ccx.tystore, actual_1);
implicit_boxes = count_boxes(fcx.ccx.tystore, actual);
}
let vec[mutable ty.t] ty_param_substs =
@ -1010,9 +1011,9 @@ mod Demand {
case (ures_err(?err, ?expected, ?actual)) {
fcx.ccx.sess.span_err(sp, "mismatched types: expected "
+ ty_to_str(expected) + " but found "
+ ty_to_str(actual) + " (" +
ty.type_err_to_str(err) + ")");
+ ty_to_str(fcx.ccx.tystore, expected) + " but found "
+ ty_to_str(fcx.ccx.tystore, actual) + " ("
+ ty.type_err_to_str(err) + ")");
// TODO: In the future, try returning "expected", reporting
// the error, and continue.
@ -1040,7 +1041,7 @@ fn variant_arg_types(@crate_ctxt ccx, &span sp, ast.def_id vid,
auto tpt = ty.lookup_item_type(ccx.sess, ccx.tystore, ccx.type_cache,
vid);
alt (struct(tpt._1)) {
alt (struct(ccx.tystore, tpt._1)) {
case (ty.ty_fn(_, ?ins, _)) {
// N-ary variant.
for (ty.arg arg in ins) {
@ -1109,7 +1110,7 @@ mod Pushdown {
// Take the variant's type parameters out of the expected
// type.
auto tag_tps;
alt (struct(expected)) {
alt (struct(fcx.ccx.tystore, expected)) {
case (ty.ty_tag(_, ?tps)) { tag_tps = tps; }
case (_) {
log_err "tag pattern type not actually a tag?!";
@ -1159,7 +1160,7 @@ mod Pushdown {
auto t = Demand.simple(fcx, e.span, expected,
ann_to_type(ann));
let vec[@ast.expr] es_1 = vec();
alt (struct(t)) {
alt (struct(fcx.ccx.tystore, t)) {
case (ty.ty_vec(?mt)) {
for (@ast.expr e_0 in es_0) {
es_1 += vec(pushdown_expr(fcx, mt.ty, e_0));
@ -1176,7 +1177,7 @@ mod Pushdown {
auto t = Demand.simple(fcx, e.span, expected,
ann_to_type(ann));
let vec[ast.elt] elts_1 = vec();
alt (struct(t)) {
alt (struct(fcx.ccx.tystore, t)) {
case (ty.ty_tup(?mts)) {
auto i = 0u;
for (ast.elt elt_0 in es_0) {
@ -1200,7 +1201,7 @@ mod Pushdown {
auto t = Demand.simple(fcx, e.span, expected,
ann_to_type(ann));
let vec[ast.field] fields_1 = vec();
alt (struct(t)) {
alt (struct(fcx.ccx.tystore, t)) {
case (ty.ty_rec(?field_mts)) {
alt (base_0) {
case (none[@ast.expr]) {
@ -1413,7 +1414,7 @@ mod Pushdown {
auto t = Demand.simple(fcx, e.span, expected,
ann_to_type(ann));
let @ast.expr es_1;
alt (struct(t)) {
alt (struct(fcx.ccx.tystore, t)) {
case (ty.ty_chan(?subty)) {
auto pt = ty.mk_port(fcx.ccx.tystore, subty);
es_1 = pushdown_expr(fcx, pt, es);
@ -1515,7 +1516,7 @@ fn writeback_local(&option.t[@fn_ctxt] env, &span sp, @ast.local local)
fn resolve_local_types_in_annotation(&option.t[@fn_ctxt] env, ast.ann ann)
-> ast.ann {
fn resolver(@fn_ctxt fcx, ty.t typ) -> ty.t {
alt (struct(typ)) {
alt (struct(fcx.ccx.tystore, typ)) {
case (ty.ty_local(?lid)) { ret fcx.locals.get(lid); }
case (_) { ret typ; }
}
@ -1604,7 +1605,7 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
fcx.ccx.type_cache, vdef._0);
auto ann = instantiate_path(fcx, p, tpt, pat.span);
alt (struct(t)) {
alt (struct(fcx.ccx.tystore, t)) {
// N-ary variants have function types.
case (ty.ty_fn(_, ?args, ?tag_ty)) {
auto arg_len = _vec.len[arg](args);
@ -1692,7 +1693,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto rt_0 = next_ty_var(fcx.ccx);
auto t_0;
alt (struct(expr_ty(fcx.ccx.tystore, f_0))) {
alt (struct(fcx.ccx.tystore, expr_ty(fcx.ccx.tystore, f_0))) {
case (ty.ty_fn(?proto, _, _)) {
t_0 = ty.mk_fn(fcx.ccx.tystore, proto, arg_tys_0, rt_0);
}
@ -1774,7 +1775,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
expr_ty(fcx.ccx.tystore, lhs_1),
rhs_0, AUTODEREF_OK);
auto t = strip_boxes(lhs_t0);
auto t = strip_boxes(fcx.ccx.tystore, lhs_t0);
alt (binop) {
case (ast.eq) { t = ty.mk_bool(fcx.ccx.tystore); }
case (ast.lt) { t = ty.mk_bool(fcx.ccx.tystore); }
@ -1801,7 +1802,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
rec(ty=oper_t, mut=mut));
}
case (ast.deref) {
alt (struct(oper_t)) {
alt (struct(fcx.ccx.tystore, oper_t)) {
case (ty.ty_box(?inner)) {
oper_t = inner.ty;
}
@ -1809,11 +1810,11 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
fcx.ccx.sess.span_err
(expr.span,
"dereferencing non-box type: "
+ ty_to_str(oper_t));
+ ty_to_str(fcx.ccx.tystore, oper_t));
}
}
}
case (_) { oper_t = strip_boxes(oper_t); }
case (_) { oper_t = strip_boxes(fcx.ccx.tystore, oper_t); }
}
auto ann = triv_ann(oper_t);
@ -1971,7 +1972,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto chan_t = ty.mk_chan(fcx.ccx.tystore, rhs_t);
auto lhs_1 = Pushdown.pushdown_expr(fcx, chan_t, lhs_0);
auto item_t;
alt (struct(expr_ty(fcx.ccx.tystore, lhs_1))) {
alt (struct(fcx.ccx.tystore, expr_ty(fcx.ccx.tystore, lhs_1))) {
case (ty.ty_chan(?it)) {
item_t = it;
}
@ -1994,7 +1995,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto port_t = ty.mk_port(fcx.ccx.tystore, lhs_t1);
auto rhs_1 = Pushdown.pushdown_expr(fcx, port_t, rhs_0);
auto item_t;
alt (struct(expr_ty(fcx.ccx.tystore, rhs_0))) {
alt (struct(fcx.ccx.tystore, expr_ty(fcx.ccx.tystore, rhs_0))) {
case (ty.ty_port(?it)) {
item_t = it;
}
@ -2164,7 +2165,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto proto_1;
let vec[ty.arg] arg_tys_1 = vec();
auto rt_1;
alt (struct(expr_ty(fcx.ccx.tystore, result._0))) {
alt (struct(fcx.ccx.tystore,
expr_ty(fcx.ccx.tystore, result._0))) {
case (ty.ty_fn(?proto, ?arg_tys, ?rt)) {
proto_1 = proto;
rt_1 = rt;
@ -2202,7 +2204,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
// Pull the return type out of the type of the function.
auto rt_1 = ty.mk_nil(fcx.ccx.tystore); // FIXME: typestate botch
alt (struct(expr_ty(fcx.ccx.tystore, f_1))) {
alt (struct(fcx.ccx.tystore, expr_ty(fcx.ccx.tystore, f_1))) {
case (ty.ty_fn(_,_,?rt)) { rt_1 = rt; }
case (ty.ty_native_fn(_, _, ?rt)) { rt_1 = rt; }
case (_) {
@ -2234,7 +2236,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
// Grab this method's type out of the current object type
// this_obj_ty is an ty.t
alt (struct(this_obj_ty)) {
alt (struct(fcx.ccx.tystore, this_obj_ty)) {
case (ty.ty_obj(?methods)) {
for (ty.method method in methods) {
if (method.ident == id) {
@ -2258,9 +2260,9 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto args_1 = result._1;
// Check the return type
alt (struct(expr_ty(fcx.ccx.tystore, f_1))) {
alt (struct(fcx.ccx.tystore, expr_ty(fcx.ccx.tystore, f_1))) {
case (ty.ty_fn(_,_,?rt)) {
alt (struct(rt)) {
alt (struct(fcx.ccx.tystore, rt)) {
case (ty.ty_nil) {
// This is acceptable
}
@ -2286,12 +2288,14 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
auto e_1 = check_expr(fcx, e);
auto t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
// FIXME: there are more forms of cast to support, eventually.
if (! (type_is_scalar(expr_ty(fcx.ccx.tystore, e_1)) &&
type_is_scalar(t_1))) {
if (! (type_is_scalar(fcx.ccx.tystore,
expr_ty(fcx.ccx.tystore, e_1)) &&
type_is_scalar(fcx.ccx.tystore, t_1))) {
fcx.ccx.sess.span_err(expr.span,
"non-scalar cast: " +
ty_to_str(expr_ty(fcx.ccx.tystore, e_1)) + " as " +
ty_to_str(t_1));
ty_to_str(fcx.ccx.tystore,
expr_ty(fcx.ccx.tystore, e_1)) + " as " +
ty_to_str(fcx.ccx.tystore, t_1));
}
auto ann = triv_ann(t_1);
@ -2374,7 +2378,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
let vec[field] base_fields = vec();
alt (struct(bexpr_t)) {
alt (struct(fcx.ccx.tystore, bexpr_t)) {
case (ty.ty_rec(?flds)) {
base_fields = flds;
}
@ -2412,8 +2416,9 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_field(?base, ?field, _)) {
auto base_1 = check_expr(fcx, base);
auto base_t = strip_boxes(expr_ty(fcx.ccx.tystore, base_1));
alt (struct(base_t)) {
auto base_t = strip_boxes(fcx.ccx.tystore,
expr_ty(fcx.ccx.tystore, base_1));
alt (struct(fcx.ccx.tystore, base_t)) {
case (ty.ty_tup(?args)) {
let uint ix = ty.field_num(fcx.ccx.sess,
expr.span, field);
@ -2462,25 +2467,26 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (_) {
fcx.ccx.sess.span_unimpl(expr.span,
"base type for expr_field in typeck.check_expr: " +
ty_to_str(base_t));
ty_to_str(fcx.ccx.tystore, base_t));
}
}
}
case (ast.expr_index(?base, ?idx, _)) {
auto base_1 = check_expr(fcx, base);
auto base_t = strip_boxes(expr_ty(fcx.ccx.tystore, base_1));
auto base_t = strip_boxes(fcx.ccx.tystore,
expr_ty(fcx.ccx.tystore, base_1));
auto idx_1 = check_expr(fcx, idx);
auto idx_t = expr_ty(fcx.ccx.tystore, idx_1);
alt (struct(base_t)) {
alt (struct(fcx.ccx.tystore, base_t)) {
case (ty.ty_vec(?mt)) {
if (! type_is_integral(idx_t)) {
if (! type_is_integral(fcx.ccx.tystore, idx_t)) {
fcx.ccx.sess.span_err
(idx.span,
"non-integral type of vec index: "
+ ty_to_str(idx_t));
+ ty_to_str(fcx.ccx.tystore, idx_t));
}
auto ann = triv_ann(mt.ty);
ret @fold.respan[ast.expr_](expr.span,
@ -2489,11 +2495,11 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
ann));
}
case (ty.ty_str) {
if (! type_is_integral(idx_t)) {
if (! type_is_integral(fcx.ccx.tystore, idx_t)) {
fcx.ccx.sess.span_err
(idx.span,
"non-integral type of str index: "
+ ty_to_str(idx_t));
+ ty_to_str(fcx.ccx.tystore, idx_t));
}
auto ann = triv_ann(ty.mk_mach(fcx.ccx.tystore,
common.ty_u8));
@ -2506,7 +2512,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
fcx.ccx.sess.span_err
(expr.span,
"vector-indexing bad type: "
+ ty_to_str(base_t));
+ ty_to_str(fcx.ccx.tystore, base_t));
}
}
}
@ -2521,7 +2527,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
case (ast.expr_chan(?x, _)) {
auto expr_1 = check_expr(fcx, x);
auto port_t = expr_ty(fcx.ccx.tystore, expr_1);
alt (struct(port_t)) {
alt (struct(fcx.ccx.tystore, port_t)) {
case (ty.ty_port(?subtype)) {
auto ct = ty.mk_chan(fcx.ccx.tystore, subtype);
auto ann = triv_ann(ct);
@ -2530,8 +2536,8 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
case (_) {
fcx.ccx.sess.span_err(expr.span,
"bad port type: "
+ ty_to_str(port_t));
"bad port type: " + ty_to_str(fcx.ccx.tystore,
port_t));
}
}
}