Alias-ify walk, typeck, metadata. Cuts another 80kb off rustc.

This commit is contained in:
Graydon Hoare 2011-05-09 16:09:00 -07:00
parent 071ed380fb
commit 476442e48c
6 changed files with 153 additions and 150 deletions

@ -17,7 +17,7 @@ fn current_context(&env e) -> ast.def_id {
ret e.current_context.(Vec.len(e.current_context) - 1u);
}
fn enter_item(@env e, @ast.item i) {
fn enter_item(@env e, &@ast.item i) {
alt (i.node) {
case (ast.item_fn(?name, _, _, ?id, _)) {
Vec.push(e.current_context, id);
@ -29,7 +29,7 @@ fn enter_item(@env e, @ast.item i) {
}
}
fn leave_item(@env e, @ast.item i) {
fn leave_item(@env e, &@ast.item i) {
alt (i.node) {
case (ast.item_fn(?name, _, _, ?id, _)) {
Vec.pop(e.current_context);
@ -41,7 +41,7 @@ fn leave_item(@env e, @ast.item i) {
}
}
fn walk_expr(@env e, @ast.expr x) {
fn walk_expr(@env e, &@ast.expr x) {
alt (x.node) {
case (ast.expr_for(?d, _, _, _)) {
alt (d.node) {

@ -61,26 +61,26 @@ tag abbrev_ctxt {
mod Encode {
type ctxt = rec(
fn(ast.def_id) -> str ds, // Def -> str Callback.
fn(&ast.def_id) -> str ds, // Def -> str Callback.
ty.ctxt tcx, // The type context.
abbrev_ctxt abbrevs
);
fn cx_uses_abbrevs(@ctxt cx) -> bool {
fn cx_uses_abbrevs(&@ctxt cx) -> bool {
alt (cx.abbrevs) {
case (ac_no_abbrevs) { ret false; }
case (ac_use_abbrevs(_)) { ret true; }
}
}
fn ty_str(@ctxt cx, ty.t t) -> str {
fn ty_str(&@ctxt cx, &ty.t t) -> str {
assert (!cx_uses_abbrevs(cx));
auto sw = IO.string_writer();
enc_ty(sw.get_writer(), cx, t);
ret sw.get_str();
}
fn enc_ty(IO.writer w, @ctxt cx, ty.t t) {
fn enc_ty(&IO.writer w, &@ctxt cx, &ty.t t) {
alt (cx.abbrevs) {
case (ac_no_abbrevs) { enc_sty(w, cx, ty.struct(cx.tcx, t)); }
case (ac_use_abbrevs(?abbrevs)) {
@ -121,7 +121,7 @@ mod Encode {
}
}
fn enc_mt(IO.writer w, @ctxt cx, &ty.mt mt) {
fn enc_mt(&IO.writer w, &@ctxt cx, &ty.mt mt) {
alt (mt.mut) {
case (ast.imm) { }
case (ast.mut) { w.write_char('m'); }
@ -130,7 +130,7 @@ mod Encode {
enc_ty(w, cx, mt.ty);
}
fn enc_sty(IO.writer w, @ctxt cx, ty.sty st) {
fn enc_sty(&IO.writer w, &@ctxt cx, &ty.sty st) {
alt (st) {
case (ty.ty_nil) { w.write_char('n'); }
case (ty.ty_bool) { w.write_char('b'); }
@ -231,14 +231,14 @@ mod Encode {
}
}
fn enc_proto(IO.writer w, ast.proto proto) {
fn enc_proto(&IO.writer w, ast.proto proto) {
alt (proto) {
case (ast.proto_iter) { w.write_char('W'); }
case (ast.proto_fn) { w.write_char('F'); }
}
}
fn enc_ty_fn(IO.writer w, @ctxt cx, vec[ty.arg] args, ty.t out) {
fn enc_ty_fn(&IO.writer w, &@ctxt cx, &vec[ty.arg] args, &ty.t out) {
w.write_char('[');
for (ty.arg arg in args) {
if (arg.mode == ty.mo_alias) { w.write_char('&'); }
@ -252,14 +252,14 @@ mod Encode {
// Returns a Plain Old LLVM String.
fn C_postr(str s) -> ValueRef {
fn C_postr(&str s) -> ValueRef {
ret llvm.LLVMConstString(Str.buf(s), Str.byte_len(s), False);
}
// Path table encoding
fn encode_name(&EBML.writer ebml_w, str name) {
fn encode_name(&EBML.writer ebml_w, &str name) {
EBML.start_tag(ebml_w, tag_paths_data_name);
ebml_w.writer.write(Str.bytes(name));
EBML.end_tag(ebml_w);
@ -272,8 +272,8 @@ fn encode_def_id(&EBML.writer ebml_w, &ast.def_id id) {
}
fn encode_tag_variant_paths(&EBML.writer ebml_w,
vec[ast.variant] variants,
vec[str] path,
&vec[ast.variant] variants,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
for (ast.variant variant in variants) {
add_to_index(ebml_w, path, index, variant.node.name);
@ -285,16 +285,16 @@ fn encode_tag_variant_paths(&EBML.writer ebml_w,
}
fn add_to_index(&EBML.writer ebml_w,
vec[str] path,
&vec[str] path,
&mutable vec[tup(str, uint)] index,
str name) {
&str name) {
auto full_path = path + vec(name);
index += vec(tup(Str.connect(full_path, "."), ebml_w.writer.tell()));
}
fn encode_native_module_item_paths(&EBML.writer ebml_w,
&ast.native_mod nmod,
vec[str] path,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
for (@ast.native_item nitem in nmod.items) {
alt (nitem.node) {
@ -318,7 +318,7 @@ fn encode_native_module_item_paths(&EBML.writer ebml_w,
fn encode_module_item_paths(&EBML.writer ebml_w,
&ast._mod module,
vec[str] path,
&vec[str] path,
&mutable vec[tup(str, uint)] index) {
// TODO: only encode exported items
for (@ast.item it in module.items) {
@ -382,7 +382,7 @@ fn encode_module_item_paths(&EBML.writer ebml_w,
}
}
fn encode_item_paths(&EBML.writer ebml_w, @ast.crate crate)
fn encode_item_paths(&EBML.writer ebml_w, &@ast.crate crate)
-> vec[tup(str, uint)] {
let vec[tup(str, uint)] index = vec();
let vec[str] path = vec();
@ -401,23 +401,23 @@ fn encode_kind(&EBML.writer ebml_w, u8 c) {
EBML.end_tag(ebml_w);
}
fn def_to_str(ast.def_id did) -> str {
fn def_to_str(&ast.def_id did) -> str {
ret #fmt("%d:%d", did._0, did._1);
}
fn encode_type_param_count(&EBML.writer ebml_w, vec[ast.ty_param] tps) {
fn encode_type_param_count(&EBML.writer ebml_w, &vec[ast.ty_param] tps) {
EBML.start_tag(ebml_w, tag_items_data_item_ty_param_count);
EBML.write_vint(ebml_w.writer, Vec.len[ast.ty_param](tps));
EBML.end_tag(ebml_w);
}
fn encode_variant_id(&EBML.writer ebml_w, ast.def_id vid) {
fn encode_variant_id(&EBML.writer ebml_w, &ast.def_id vid) {
EBML.start_tag(ebml_w, tag_items_data_item_variant);
ebml_w.writer.write(Str.bytes(def_to_str(vid)));
EBML.end_tag(ebml_w);
}
fn encode_type(@trans.crate_ctxt cx, &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;
@ -427,14 +427,15 @@ fn encode_type(@trans.crate_ctxt cx, &EBML.writer ebml_w, ty.t typ) {
EBML.end_tag(ebml_w);
}
fn encode_symbol(@trans.crate_ctxt cx, &EBML.writer ebml_w, ast.def_id did) {
fn encode_symbol(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
&ast.def_id did) {
EBML.start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(Str.bytes(cx.item_symbols.get(did)));
EBML.end_tag(ebml_w);
}
fn encode_discriminant(@trans.crate_ctxt cx, &EBML.writer ebml_w,
ast.def_id did) {
fn encode_discriminant(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
&ast.def_id did) {
EBML.start_tag(ebml_w, tag_items_data_item_symbol);
ebml_w.writer.write(Str.bytes(cx.discrim_symbols.get(did)));
EBML.end_tag(ebml_w);
@ -453,10 +454,10 @@ fn encode_obj_type_id(&EBML.writer ebml_w, &ast.def_id id) {
}
fn encode_tag_variant_info(@trans.crate_ctxt cx, &EBML.writer ebml_w,
ast.def_id did, vec[ast.variant] variants,
fn encode_tag_variant_info(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
&ast.def_id did, &vec[ast.variant] variants,
&mutable vec[tup(int, uint)] index,
vec[ast.ty_param] ty_params) {
&vec[ast.ty_param] ty_params) {
for (ast.variant variant in variants) {
index += vec(tup(variant.node.id._1, ebml_w.writer.tell()));
@ -547,8 +548,8 @@ fn encode_info_for_item(@trans.crate_ctxt cx, &EBML.writer ebml_w,
}
}
fn encode_info_for_native_item(@trans.crate_ctxt cx, &EBML.writer ebml_w,
@ast.native_item nitem) {
fn encode_info_for_native_item(&@trans.crate_ctxt cx, &EBML.writer ebml_w,
&@ast.native_item nitem) {
EBML.start_tag(ebml_w, tag_items_data_item);
alt (nitem.node) {
case (ast.native_item_ty(_, ?did)) {
@ -567,7 +568,7 @@ fn encode_info_for_native_item(@trans.crate_ctxt cx, &EBML.writer ebml_w,
EBML.end_tag(ebml_w);
}
fn encode_info_for_items(@trans.crate_ctxt cx, &EBML.writer ebml_w)
fn encode_info_for_items(&@trans.crate_ctxt cx, &EBML.writer ebml_w)
-> vec[tup(int, uint)] {
let vec[tup(int, uint)] index = vec();
@ -603,7 +604,7 @@ fn hash_path(&str s) -> uint {
ret h;
}
fn create_index[T](vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
-> vec[vec[tup(T, uint)]] {
let vec[vec[tup(T, uint)]] buckets = vec();
for each (uint i in UInt.range(0u, 256u)) {
@ -619,8 +620,8 @@ fn create_index[T](vec[tup(T, uint)] index, fn(&T) -> uint hash_fn)
ret buckets;
}
fn encode_index[T](&EBML.writer ebml_w, vec[vec[tup(T, uint)]] buckets,
fn(IO.writer, &T) write_fn) {
fn encode_index[T](&EBML.writer ebml_w, &vec[vec[tup(T, uint)]] buckets,
fn(&IO.writer, &T) write_fn) {
auto writer = IO.new_writer_(ebml_w.writer);
EBML.start_tag(ebml_w, tag_index);
@ -650,16 +651,16 @@ fn encode_index[T](&EBML.writer ebml_w, vec[vec[tup(T, uint)]] buckets,
EBML.end_tag(ebml_w);
}
fn write_str(IO.writer writer, &str s) {
fn write_str(&IO.writer writer, &str s) {
writer.write_str(s);
}
fn write_int(IO.writer writer, &int n) {
fn write_int(&IO.writer writer, &int n) {
writer.write_be_uint(n as uint, 4u);
}
fn encode_metadata(@trans.crate_ctxt cx, @ast.crate crate)
fn encode_metadata(&@trans.crate_ctxt cx, &@ast.crate crate)
-> ValueRef {
auto string_w = IO.string_writer();
auto buf_w = string_w.get_writer().get_buf_writer();
@ -690,7 +691,7 @@ fn encode_metadata(@trans.crate_ctxt cx, @ast.crate crate)
ret C_postr(string_w.get_str());
}
fn write_metadata(@trans.crate_ctxt cx, @ast.crate crate) {
fn write_metadata(&@trans.crate_ctxt cx, &@ast.crate crate) {
auto llmeta = C_postr("");
if (cx.sess.get_opts().shared) {
llmeta = encode_metadata(cx, crate);

@ -3569,7 +3569,7 @@ fn collect_upvars(@block_ctxt cx, &ast.block bloc, &ast.def_id initial_decl)
hashmap[ast.def_id,()] decls
);
fn walk_expr(env e, @ast.expr expr) {
fn walk_expr(env e, &@ast.expr expr) {
alt (expr.node) {
case (ast.expr_path(?path, ?d, _)) {
alt (Option.get[ast.def](d)) {
@ -3589,7 +3589,7 @@ fn collect_upvars(@block_ctxt cx, &ast.block bloc, &ast.def_id initial_decl)
}
}
fn walk_decl(env e, @ast.decl decl) {
fn walk_decl(env e, &@ast.decl decl) {
alt (decl.node) {
case (ast.decl_local(?local)) {
e.decls.insert(local.id, ());
@ -6949,7 +6949,7 @@ fn new_walk_ctxt() -> @walk_ctxt {
ret @rec(mutable path=path);
}
fn enter_item(@walk_ctxt cx, @ast.item item) {
fn enter_item(@walk_ctxt cx, &@ast.item item) {
alt (item.node) {
case (ast.item_fn(?name, _, _, _, _)) {
Vec.push[str](cx.path, name);
@ -6964,7 +6964,7 @@ fn enter_item(@walk_ctxt cx, @ast.item item) {
}
}
fn leave_item(@walk_ctxt cx, @ast.item item) {
fn leave_item(@walk_ctxt cx, &@ast.item item) {
alt (item.node) {
case (ast.item_fn(_, _, _, _, _)) {
Vec.pop[str](cx.path);
@ -6979,7 +6979,7 @@ fn leave_item(@walk_ctxt cx, @ast.item item) {
}
}
fn collect_native_item(@crate_ctxt ccx, @walk_ctxt wcx, @ast.native_item i) {
fn collect_native_item(@crate_ctxt ccx, @walk_ctxt wcx, &@ast.native_item i) {
alt (i.node) {
case (ast.native_item_fn(?name, _, _, _, ?fid, ?ann)) {
ccx.native_items.insert(fid, i);
@ -6993,7 +6993,7 @@ fn collect_native_item(@crate_ctxt ccx, @walk_ctxt wcx, @ast.native_item i) {
}
}
fn collect_item_1(@crate_ctxt ccx, @walk_ctxt wcx, @ast.item i) {
fn collect_item_1(@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item i) {
enter_item(wcx, i);
alt (i.node) {
@ -7019,7 +7019,7 @@ fn collect_item_1(@crate_ctxt ccx, @walk_ctxt wcx, @ast.item i) {
}
}
fn collect_item_2(@crate_ctxt ccx, @walk_ctxt wcx, @ast.item i) {
fn collect_item_2(@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item i) {
enter_item(wcx, i);
alt (i.node) {
@ -7055,7 +7055,7 @@ fn collect_items(@crate_ctxt ccx, @ast.crate crate) {
walk.walk_crate(visitor2, *crate);
}
fn collect_tag_ctor(@crate_ctxt ccx, @walk_ctxt wcx, @ast.item i) {
fn collect_tag_ctor(@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item i) {
enter_item(wcx, i);
alt (i.node) {
@ -7083,7 +7083,7 @@ fn collect_tag_ctors(@crate_ctxt ccx, @ast.crate crate) {
// The constant translation pass.
fn trans_constant(@crate_ctxt ccx, @walk_ctxt wcx, @ast.item it) {
fn trans_constant(@crate_ctxt ccx, @walk_ctxt wcx, &@ast.item it) {
enter_item(wcx, it);
alt (it.node) {

@ -1046,7 +1046,7 @@ fn type_param(&ctxt cx, &t ty) -> Option.t[uint] {
ret none[uint];
}
fn def_to_str(ast.def_id did) -> str {
fn def_to_str(&ast.def_id did) -> str {
ret #fmt("%d:%d", did._0, did._1);
}

@ -77,14 +77,14 @@ type fn_ctxt = rec(ty.t ret_ty,
@crate_ctxt ccx);
// Used for ast_ty_to_ty() below.
type ty_getter = fn(ast.def_id) -> ty.ty_param_count_and_ty;
type ty_getter = fn(&ast.def_id) -> ty.ty_param_count_and_ty;
// Substitutes the user's explicit types for the parameters in a path
// expression.
fn substitute_ty_params(&@crate_ctxt ccx,
ty.t typ,
&ty.t typ,
uint ty_param_count,
vec[ty.t] supplied,
&vec[ty.t] supplied,
&span sp) -> ty.t {
fn substituter(@crate_ctxt ccx, vec[ty.t] supplied, ty.t typ) -> ty.t {
alt (struct(ccx.tcx, typ)) {
@ -112,7 +112,7 @@ fn substitute_ty_params(&@crate_ctxt ccx,
// Returns the type parameter count and the type for the given definition.
fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.span sp, &ast.def defn)
fn ty_param_count_and_ty_for_def(&@fn_ctxt fcx, &ast.span sp, &ast.def defn)
-> ty_param_count_and_ty {
alt (defn) {
case (ast.def_arg(?id)) {
@ -177,8 +177,8 @@ fn ty_param_count_and_ty_for_def(@fn_ctxt fcx, &ast.span sp, &ast.def defn)
// Instantiates the given path, which must refer to an item with the given
// number of type parameters and type.
fn instantiate_path(@fn_ctxt fcx, &ast.path pth, &ty_param_count_and_ty tpt,
&span sp) -> ast.ann {
fn instantiate_path(&@fn_ctxt fcx, &ast.path pth, &ty_param_count_and_ty tpt,
&span sp) -> ast.ann {
auto ty_param_count = tpt._0;
auto t = bind_params_in_type(fcx.ccx.tcx, tpt._1);
@ -224,25 +224,25 @@ fn ast_mode_to_mode(ast.mode mode) -> ty.mode {
// Parses the programmer's textual representation of a type into our internal
// notion of a type. `getter` is a function that returns the type
// corresponding to a definition ID.
fn ast_ty_to_ty(ty.ctxt tcx, ty_getter getter, &@ast.ty ast_ty) -> ty.t {
fn ast_arg_to_arg(ty.ctxt tcx,
ty_getter getter,
fn ast_ty_to_ty(&ty.ctxt tcx, &ty_getter getter, &@ast.ty ast_ty) -> ty.t {
fn ast_arg_to_arg(&ty.ctxt tcx,
&ty_getter getter,
&rec(ast.mode mode, @ast.ty ty) arg)
-> rec(ty.mode mode, ty.t ty) {
auto ty_mode = ast_mode_to_mode(arg.mode);
ret rec(mode=ty_mode, ty=ast_ty_to_ty(tcx, getter, arg.ty));
}
fn ast_mt_to_mt(ty.ctxt tcx,
ty_getter getter,
fn ast_mt_to_mt(&ty.ctxt tcx,
&ty_getter getter,
&ast.mt mt) -> ty.mt {
ret rec(ty=ast_ty_to_ty(tcx, getter, mt.ty), mut=mt.mut);
}
fn instantiate(ty.ctxt tcx,
ty_getter getter,
ast.def_id id,
vec[@ast.ty] args) -> ty.t {
fn instantiate(&ty.ctxt tcx,
&ty_getter getter,
&ast.def_id id,
&vec[@ast.ty] args) -> ty.t {
// TODO: maybe record cname chains so we can do
// "foo = int" like OCaml?
auto params_opt_and_ty = getter(id);
@ -324,7 +324,7 @@ fn ast_ty_to_ty(ty.ctxt tcx, ty_getter getter, &@ast.ty ast_ty) -> ty.t {
typ = instantiate(tcx, getter, id, path.node.types);
}
case (ast.def_ty_arg(?id)) { typ = ty.mk_param(tcx, id); }
case (_) {
case (_) {
tcx.sess.span_err(ast_ty.span,
"found type name used as a variable");
fail; }
@ -362,7 +362,7 @@ fn ast_ty_to_ty(ty.ctxt tcx, ty_getter getter, &@ast.ty ast_ty) -> ty.t {
// A convenience function to use a crate_ctxt to resolve names for
// ast_ty_to_ty.
fn ast_ty_to_ty_crate(@crate_ctxt ccx, &@ast.ty ast_ty) -> ty.t {
fn getter(@crate_ctxt ccx, ast.def_id id) -> ty.ty_param_count_and_ty {
fn getter(@crate_ctxt ccx, &ast.def_id id) -> ty.ty_param_count_and_ty {
ret ty.lookup_item_type(ccx.sess, ccx.tcx, ccx.type_cache, id);
}
auto f = bind getter(ccx, _);
@ -388,13 +388,13 @@ mod Collect {
ty.ctxt tcx);
type env = rec(@ctxt cx, ast.native_abi abi);
fn ty_of_fn_decl(@ctxt cx,
fn(&@ast.ty ast_ty) -> ty.t convert,
fn(&ast.arg a) -> arg ty_of_arg,
fn ty_of_fn_decl(&@ctxt cx,
&fn(&@ast.ty ast_ty) -> ty.t convert,
&fn(&ast.arg a) -> arg ty_of_arg,
&ast.fn_decl decl,
ast.proto proto,
vec[ast.ty_param] ty_params,
ast.def_id def_id) -> ty.ty_param_count_and_ty {
&vec[ast.ty_param] ty_params,
&ast.def_id def_id) -> ty.ty_param_count_and_ty {
auto input_tys = Vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output);
auto t_fn = ty.mk_fn(cx.tcx, proto, input_tys, output_ty);
@ -404,13 +404,13 @@ mod Collect {
ret tpt;
}
fn ty_of_native_fn_decl(@ctxt cx,
fn(&@ast.ty ast_ty) -> ty.t convert,
fn(&ast.arg a) -> arg ty_of_arg,
fn ty_of_native_fn_decl(&@ctxt cx,
&fn(&@ast.ty ast_ty) -> ty.t convert,
&fn(&ast.arg a) -> arg ty_of_arg,
&ast.fn_decl decl,
ast.native_abi abi,
vec[ast.ty_param] ty_params,
ast.def_id def_id) -> ty.ty_param_count_and_ty {
&vec[ast.ty_param] ty_params,
&ast.def_id def_id) -> ty.ty_param_count_and_ty {
auto input_tys = Vec.map[ast.arg,arg](ty_of_arg, decl.inputs);
auto output_ty = convert(decl.output);
auto t_fn = ty.mk_native_fn(cx.tcx, abi, input_tys, output_ty);
@ -420,7 +420,7 @@ mod Collect {
ret tpt;
}
fn getter(@ctxt cx, ast.def_id id) -> ty.ty_param_count_and_ty {
fn getter(@ctxt cx, &ast.def_id id) -> ty.ty_param_count_and_ty {
if (id._0 != cx.sess.get_targ_crate_num()) {
// This is a type we need to load in from the crate reader.
@ -458,9 +458,9 @@ mod Collect {
}
fn ty_of_obj(@ctxt cx,
ast.ident id,
&ast.ident id,
&ast._obj obj_info,
vec[ast.ty_param] ty_params) -> ty.ty_param_count_and_ty {
&vec[ast.ty_param] ty_params) -> ty.ty_param_count_and_ty {
auto f = bind ty_of_method(cx, _);
auto methods = Vec.map[@ast.method,method](f, obj_info.methods);
@ -473,8 +473,8 @@ mod Collect {
fn ty_of_obj_ctor(@ctxt cx,
&ast.ident id,
&ast._obj obj_info,
ast.def_id obj_ty_id,
vec[ast.ty_param] ty_params)
&ast.def_id obj_ty_id,
&vec[ast.ty_param] ty_params)
-> ty.ty_param_count_and_ty {
auto t_obj = ty_of_obj(cx, id, obj_info, ty_params);
let vec[arg] t_inputs = vec();
@ -490,7 +490,7 @@ mod Collect {
ret tup(t_obj._0, t_fn);
}
fn ty_of_item(@ctxt cx, @ast.item it) -> ty.ty_param_count_and_ty {
fn ty_of_item(&@ctxt cx, &@ast.item it) -> ty.ty_param_count_and_ty {
auto get = bind getter(cx, _);
auto convert = bind ast_ty_to_ty(cx.tcx, get, _);
@ -557,7 +557,7 @@ mod Collect {
}
}
fn ty_of_native_item(@ctxt cx, @ast.native_item it, ast.native_abi abi)
fn ty_of_native_item(&@ctxt cx, &@ast.native_item it, ast.native_abi abi)
-> ty.ty_param_count_and_ty {
alt (it.node) {
case (ast.native_item_fn(?ident, ?lname, ?fn_decl,
@ -584,7 +584,7 @@ mod Collect {
}
}
fn get_tag_variant_types(@ctxt cx, &ast.def_id tag_id,
fn get_tag_variant_types(&@ctxt cx, &ast.def_id tag_id,
&vec[ast.variant] variants,
&vec[ast.ty_param] ty_params)
-> vec[ast.variant] {
@ -856,7 +856,8 @@ mod Collect {
// Type unification
mod Unify {
fn simple(@fn_ctxt fcx, ty.t expected, ty.t actual) -> ty.Unify.result {
fn simple(&@fn_ctxt fcx, &ty.t expected,
&ty.t actual) -> ty.Unify.result {
// FIXME: horrid botch
let vec[mutable ty.t] param_substs =
vec(mutable ty.mk_nil(fcx.ccx.tcx));
@ -864,8 +865,8 @@ mod Unify {
ret with_params(fcx, expected, actual, param_substs);
}
fn with_params(@fn_ctxt fcx, ty.t expected, ty.t actual,
vec[mutable ty.t] param_substs) -> ty.Unify.result {
fn with_params(&@fn_ctxt fcx, &ty.t expected, &ty.t actual,
&vec[mutable ty.t] param_substs) -> ty.Unify.result {
auto cache_key = tup(expected, actual, param_substs);
alt (fcx.ccx.unify_cache.find(cache_key)) {
case (some[ty.Unify.result](?r)) {
@ -947,7 +948,7 @@ tag autoderef_kind {
NO_AUTODEREF;
}
fn strip_boxes(ty.ctxt tcx, ty.t t) -> ty.t {
fn strip_boxes(&ty.ctxt tcx, &ty.t t) -> ty.t {
auto t1 = t;
while (true) {
alt (struct(tcx, t1)) {
@ -958,7 +959,7 @@ fn strip_boxes(ty.ctxt tcx, ty.t t) -> ty.t {
fail;
}
fn add_boxes(@crate_ctxt ccx, uint n, ty.t t) -> ty.t {
fn add_boxes(&@crate_ctxt ccx, uint n, &ty.t t) -> ty.t {
auto t1 = t;
while (n != 0u) {
t1 = ty.mk_imm_box(ccx.tcx, t1);
@ -968,7 +969,7 @@ fn add_boxes(@crate_ctxt ccx, uint n, ty.t t) -> ty.t {
}
fn count_boxes(ty.ctxt tcx, ty.t t) -> uint {
fn count_boxes(&ty.ctxt tcx, &ty.t t) -> uint {
auto n = 0u;
auto t1 = t;
while (true) {
@ -987,12 +988,12 @@ fn count_boxes(ty.ctxt tcx, ty.t t) -> uint {
type ty_param_substs_and_ty = tup(vec[ty.t], ty.t);
mod Demand {
fn simple(@fn_ctxt fcx, &span sp, ty.t expected, ty.t actual) -> ty.t {
fn simple(&@fn_ctxt fcx, &span sp, &ty.t expected, &ty.t actual) -> ty.t {
let vec[ty.t] tps = vec();
ret full(fcx, sp, expected, actual, tps, NO_AUTODEREF)._1;
}
fn autoderef(@fn_ctxt fcx, &span sp, ty.t expected, ty.t actual,
fn autoderef(&@fn_ctxt fcx, &span sp, &ty.t expected, &ty.t actual,
autoderef_kind adk) -> ty.t {
let vec[ty.t] tps = vec();
ret full(fcx, sp, expected, actual, tps, adk)._1;
@ -1001,8 +1002,8 @@ mod Demand {
// Requires that the two types unify, and prints an error message if they
// don't. Returns the unified type and the type parameter substitutions.
fn full(@fn_ctxt fcx, &span sp, ty.t expected, ty.t actual,
vec[ty.t] ty_param_substs_0, autoderef_kind adk)
fn full(&@fn_ctxt fcx, &span sp, &ty.t expected, &ty.t actual,
&vec[ty.t] ty_param_substs_0, autoderef_kind adk)
-> ty_param_substs_and_ty {
auto expected_1 = expected;
@ -1050,7 +1051,7 @@ mod Demand {
// Returns true if the two types unify and false if they don't.
fn are_compatible(&@fn_ctxt fcx, ty.t expected, ty.t actual) -> bool {
fn are_compatible(&@fn_ctxt fcx, &ty.t expected, &ty.t actual) -> bool {
alt (Unify.simple(fcx, expected, actual)) {
case (ures_ok(_)) { ret true; }
case (ures_err(_, _, _)) { ret false; }
@ -1058,8 +1059,8 @@ fn are_compatible(&@fn_ctxt fcx, ty.t expected, ty.t actual) -> bool {
}
// Returns the types of the arguments to a tag variant.
fn variant_arg_types(@crate_ctxt ccx, &span sp, ast.def_id vid,
vec[ty.t] tag_ty_params) -> vec[ty.t] {
fn variant_arg_types(&@crate_ctxt ccx, &span sp, &ast.def_id vid,
&vec[ty.t] tag_ty_params) -> vec[ty.t] {
auto ty_param_count = Vec.len[ty.t](tag_ty_params);
let vec[ty.t] result = vec();
@ -1106,7 +1107,8 @@ mod Pushdown {
//
// TODO: enforce this via a predicate.
fn pushdown_pat(&@fn_ctxt fcx, ty.t expected, @ast.pat pat) -> @ast.pat {
fn pushdown_pat(&@fn_ctxt fcx, &ty.t expected,
&@ast.pat pat) -> @ast.pat {
auto p_1;
alt (pat.node) {
@ -1168,12 +1170,12 @@ mod Pushdown {
// TODO: enforce this via a predicate.
// TODO: This function is incomplete.
fn pushdown_expr(&@fn_ctxt fcx, ty.t expected, @ast.expr e)
fn pushdown_expr(&@fn_ctxt fcx, &ty.t expected, &@ast.expr e)
-> @ast.expr {
be pushdown_expr_full(fcx, expected, e, NO_AUTODEREF);
}
fn pushdown_expr_full(&@fn_ctxt fcx, ty.t expected, @ast.expr e,
fn pushdown_expr_full(&@fn_ctxt fcx, &ty.t expected, &@ast.expr e,
autoderef_kind adk) -> @ast.expr {
auto e_1;
@ -1496,7 +1498,7 @@ mod Pushdown {
}
// Push-down over typed blocks.
fn pushdown_block(&@fn_ctxt fcx, ty.t expected, &ast.block bloc)
fn pushdown_block(&@fn_ctxt fcx, &ty.t expected, &ast.block bloc)
-> ast.block {
alt (bloc.node.expr) {
case (some[@ast.expr](?e_0)) {
@ -1598,7 +1600,7 @@ fn resolve_local_types_in_block(&@fn_ctxt fcx, &ast.block block)
// AST fragment checking
fn check_lit(@crate_ctxt ccx, @ast.lit lit) -> ty.t {
fn check_lit(@crate_ctxt ccx, &@ast.lit lit) -> ty.t {
alt (lit.node) {
case (ast.lit_str(_)) { ret ty.mk_str(ccx.tcx); }
case (ast.lit_char(_)) { ret ty.mk_char(ccx.tcx); }
@ -1615,7 +1617,7 @@ fn check_lit(@crate_ctxt ccx, @ast.lit lit) -> ty.t {
fail; // not reached
}
fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
fn check_pat(&@fn_ctxt fcx, &@ast.pat pat) -> @ast.pat {
auto new_pat;
alt (pat.node) {
case (ast.pat_wild(_)) {
@ -1689,7 +1691,7 @@ fn check_pat(&@fn_ctxt fcx, @ast.pat pat) -> @ast.pat {
}
fn require_impure(&session.session sess,
&ast.purity f_purity, &span sp) -> () {
&ast.purity f_purity, &span sp) -> () {
alt (f_purity) {
case (ast.impure_fn) {
ret;
@ -1707,7 +1709,8 @@ fn get_function_purity(@crate_ctxt ccx, &ast.def_id d_id) -> ast.purity {
}
fn require_pure_call(@crate_ctxt ccx,
&ast.purity caller_purity, @ast.expr callee, &span sp) -> () {
&ast.purity caller_purity,
&@ast.expr callee, &span sp) -> () {
alt (caller_purity) {
case (ast.impure_fn) {
ret;
@ -1744,7 +1747,7 @@ fn require_pure_function(@crate_ctxt ccx, &ast.def_id d_id, &span sp) -> () {
}
}
fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
fn check_expr(&@fn_ctxt fcx, &@ast.expr expr) -> @ast.expr {
//fcx.ccx.sess.span_warn(expr.span, "typechecking expr " +
// util.common.expr_to_str(expr));
@ -1804,7 +1807,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
// A generic function for checking assignment expressions
fn check_assignment(&@fn_ctxt fcx, @ast.expr lhs, @ast.expr rhs)
fn check_assignment(&@fn_ctxt fcx, &@ast.expr lhs, &@ast.expr rhs)
-> tup(@ast.expr, @ast.expr, ast.ann) {
auto lhs_0 = check_expr(fcx, lhs);
auto rhs_0 = check_expr(fcx, rhs);
@ -1820,7 +1823,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
// A generic function for checking call expressions
fn check_call(&@fn_ctxt fcx, @ast.expr f, vec[@ast.expr] args)
fn check_call(&@fn_ctxt fcx, &@ast.expr f, &vec[@ast.expr] args)
-> tup(@ast.expr, vec[@ast.expr]) {
let vec[Option.t[@ast.expr]] args_opt_0 = vec();
@ -2686,7 +2689,7 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr {
}
}
fn next_ty_var(@crate_ctxt ccx) -> ty.t {
fn next_ty_var(&@crate_ctxt ccx) -> ty.t {
auto t = ty.mk_var(ccx.tcx, ccx.next_var_id);
ccx.next_var_id += 1;
ret t;
@ -2699,7 +2702,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
auto t;
t = ty.mk_nil(fcx.ccx.tcx);
alt (local.ty) {
case (none[@ast.ty]) {
// Auto slot. Do nothing for now.
@ -2712,7 +2715,7 @@ fn check_decl_local(&@fn_ctxt fcx, &@ast.decl decl) -> @ast.decl {
}
}
auto a_res = local.ann;
auto a_res = local.ann;
alt (a_res) {
case (ann_none) {
a_res = triv_ann(t);
@ -2807,8 +2810,8 @@ fn check_block(&@fn_ctxt fcx, &ast.block block) -> ast.block {
a=plain_ann(fcx.ccx.tcx)));
}
fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
@ast.expr e, ast.def_id id, ast.ann ann) -> @ast.item {
fn check_const(&@crate_ctxt ccx, &span sp, &ast.ident ident, &@ast.ty t,
&@ast.expr e, &ast.def_id id, &ast.ann ann) -> @ast.item {
// FIXME: this is kinda a kludge; we manufacture a fake "function context"
// for checking the initializer expression.
auto rty = ann_to_type(ann);
@ -2858,7 +2861,7 @@ fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl, ast.proto proto,
ccx.sess.span_err(body.span, "Non-boolean return type in pred");
}
}
case (_) {}
case (_) {}
}
auto block_wb = resolve_local_types_in_block(fcx, block_t);
@ -2894,7 +2897,7 @@ fn update_obj_fields(&@crate_ctxt ccx, @ast.item i) -> @crate_ctxt {
alt (i.node) {
case (ast.item_obj(_, ?ob, _, ?obj_def_ids, _)) {
let ast.def_id di = obj_def_ids.ty;
ret @rec(obj_fields = ob.fields,
ret @rec(obj_fields = ob.fields,
this_obj = some[ast.def_id](di) with *ccx);
}
case (_) {
@ -2935,10 +2938,10 @@ fn eq_unify_cache_entry(&unify_cache_entry a, &unify_cache_entry b) -> bool {
ret true;
}
fn mk_fn_purity_table(@ast.crate crate) -> @fn_purity_table {
fn mk_fn_purity_table(&@ast.crate crate) -> @fn_purity_table {
auto res = @new_def_hash[ast.purity]();
fn do_one(@fn_purity_table t, @ast.item i) -> () {
fn do_one(@fn_purity_table t, &@ast.item i) -> () {
alt (i.node) {
case (ast.item_fn(_, ?f, _, ?d_id, _)) {
t.insert(d_id, f.decl.purity);
@ -2958,8 +2961,7 @@ fn mk_fn_purity_table(@ast.crate crate) -> @fn_purity_table {
type typecheck_result = tup(@ast.crate, ty.type_cache);
fn check_crate(ty.ctxt tcx, @ast.crate crate)
-> typecheck_result {
fn check_crate(&ty.ctxt tcx, &@ast.crate crate) -> typecheck_result {
auto sess = tcx.sess;
auto result = Collect.collect_item_types(sess, tcx, crate);

@ -5,28 +5,28 @@ import std.Option.some;
import std.Option.none;
type ast_visitor =
rec(fn () -> bool keep_going,
fn () -> bool want_crate_directives,
fn (&ast.crate c) visit_crate_pre,
fn (&ast.crate c) visit_crate_post,
fn (@ast.crate_directive cd) visit_crate_directive_pre,
fn (@ast.crate_directive cd) visit_crate_directive_post,
fn (@ast.view_item i) visit_view_item_pre,
fn (@ast.view_item i) visit_view_item_post,
fn (@ast.native_item i) visit_native_item_pre,
fn (@ast.native_item i) visit_native_item_post,
fn (@ast.item i) visit_item_pre,
fn (@ast.item i) visit_item_post,
fn (&ast.block b) visit_block_pre,
fn (&ast.block b) visit_block_post,
fn (@ast.stmt s) visit_stmt_pre,
fn (@ast.stmt s) visit_stmt_post,
fn (@ast.decl d) visit_decl_pre,
fn (@ast.decl d) visit_decl_post,
fn (@ast.expr e) visit_expr_pre,
fn (@ast.expr e) visit_expr_post,
fn (@ast.ty t) visit_ty_pre,
fn (@ast.ty t) visit_ty_post);
rec(fn () -> bool keep_going,
fn () -> bool want_crate_directives,
fn (&ast.crate c) visit_crate_pre,
fn (&ast.crate c) visit_crate_post,
fn (&@ast.crate_directive cd) visit_crate_directive_pre,
fn (&@ast.crate_directive cd) visit_crate_directive_post,
fn (&@ast.view_item i) visit_view_item_pre,
fn (&@ast.view_item i) visit_view_item_post,
fn (&@ast.native_item i) visit_native_item_pre,
fn (&@ast.native_item i) visit_native_item_post,
fn (&@ast.item i) visit_item_pre,
fn (&@ast.item i) visit_item_post,
fn (&ast.block b) visit_block_pre,
fn (&ast.block b) visit_block_post,
fn (&@ast.stmt s) visit_stmt_pre,
fn (&@ast.stmt s) visit_stmt_post,
fn (&@ast.decl d) visit_decl_pre,
fn (&@ast.decl d) visit_decl_post,
fn (&@ast.expr e) visit_expr_pre,
fn (&@ast.expr e) visit_expr_post,
fn (&@ast.ty t) visit_ty_pre,
fn (&@ast.ty t) visit_ty_post);
fn walk_crate(&ast_visitor v, &ast.crate c) {
if (!v.keep_going()) { ret; }
@ -409,15 +409,15 @@ fn walk_expr(&ast_visitor v, @ast.expr e) {
fn def_keep_going() -> bool { ret true; }
fn def_want_crate_directives() -> bool { ret false; }
fn def_visit_crate(&ast.crate c) { }
fn def_visit_crate_directive(@ast.crate_directive c) { }
fn def_visit_view_item(@ast.view_item vi) { }
fn def_visit_native_item(@ast.native_item ni) { }
fn def_visit_item(@ast.item i) { }
fn def_visit_crate_directive(&@ast.crate_directive c) { }
fn def_visit_view_item(&@ast.view_item vi) { }
fn def_visit_native_item(&@ast.native_item ni) { }
fn def_visit_item(&@ast.item i) { }
fn def_visit_block(&ast.block b) { }
fn def_visit_stmt(@ast.stmt s) { }
fn def_visit_decl(@ast.decl d) { }
fn def_visit_expr(@ast.expr e) { }
fn def_visit_ty(@ast.ty t) { }
fn def_visit_stmt(&@ast.stmt s) { }
fn def_visit_decl(&@ast.decl d) { }
fn def_visit_expr(&@ast.expr e) { }
fn def_visit_ty(&@ast.ty t) { }
fn default_visitor() -> ast_visitor {