提交 f8bb5a3b 编写于 作者: M Michael Sullivan

Make ty::ctxt be boxed.

Arguably we should leave ty_ctxt as a bare rec and just always work with
boxes of it. This winds up being simpler and prettier, though.
上级 a9a1392b
......@@ -143,7 +143,7 @@ fn compile_input(session::session sess, ast::crate_cfg cfg, str input,
bind middle::tstate::ck::check_crate(ty_cx, crate));
}
time(time_passes, "alias checking",
bind middle::alias::check_crate(@ty_cx, crate));
bind middle::alias::check_crate(ty_cx, crate));
auto llmod =
time[llvm::llvm::ModuleRef](time_passes, "translation",
bind trans::trans_crate
......
......@@ -36,10 +36,10 @@
tag local_info { arg(ast::mode); objfield(ast::mutability); }
type ctx = rec(@ty::ctxt tcx,
type ctx = rec(ty::ctxt tcx,
std::map::hashmap[node_id, local_info] local_map);
fn check_crate(@ty::ctxt tcx, &@ast::crate crate) {
fn check_crate(ty::ctxt tcx, &@ast::crate crate) {
auto cx = @rec(tcx=tcx,
// Stores information about object fields and function
// arguments that's otherwise not easily available.
......@@ -149,7 +149,7 @@ fn visit_decl(&@ctx cx, &@ast::decl d, &scope sc, &vt[scope] v) {
fn check_call(&ctx cx, &@ast::expr f, &(@ast::expr)[] args, &scope sc) ->
rec(node_id[] root_vars, ty::t[] unsafe_ts) {
auto fty = ty::expr_ty(*cx.tcx, f);
auto fty = ty::expr_ty(cx.tcx, f);
auto arg_ts = fty_args(cx, fty);
let node_id[] roots = ~[];
let tup(uint, node_id)[] mut_roots = ~[];
......@@ -248,7 +248,7 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
case (ast::expr_call(?f, ?args_)) { args = args_; f }
};
auto i = 0u;
for (ty::arg arg_t in fty_args(cx, ty::expr_ty(*cx.tcx, f))) {
for (ty::arg arg_t in fty_args(cx, ty::expr_ty(cx.tcx, f))) {
if (arg_t.mode != ty::mo_val) {
auto mut_a = arg_t.mode == ty::mo_alias(true);
auto ok = true;
......@@ -354,15 +354,15 @@ fn check_for(&ctx cx, &@ast::local local, &@ast::expr seq, &ast::block block,
auto unsafe = alt (inner_mut(root.ds)) { some(?t) { ~[t] } _ { ~[] } };
// If this is a mutable vector, don't allow it to be touched.
auto seq_t = ty::expr_ty(*cx.tcx, seq);
alt (ty::struct(*cx.tcx, seq_t)) {
auto seq_t = ty::expr_ty(cx.tcx, seq);
alt (ty::struct(cx.tcx, seq_t)) {
ty::ty_vec(?mt) | ty::ty_ivec(?mt) {
if (mt.mut != ast::imm) { unsafe = ~[seq_t]; }
}
ty::ty_str | ty::ty_istr { /* no-op */ }
_ {
cx.tcx.sess.span_unimpl(seq.span, "unknown seq type " +
util::ppaux::ty_to_str(*cx.tcx, seq_t));
util::ppaux::ty_to_str(cx.tcx, seq_t));
}
}
auto new_sc =
......@@ -380,7 +380,7 @@ fn check_var(&ctx cx, &@ast::expr ex, &ast::path p, ast::node_id id,
auto def = cx.tcx.def_map.get(id);
if (!def_is_local(def, true)) { ret; }
auto my_defnum = ast::def_id_of_def(def)._1;
auto var_t = ty::expr_ty(*cx.tcx, ex);
auto var_t = ty::expr_ty(cx.tcx, ex);
for (restrict r in *sc) {
// excludes variables introduced since the alias was made
if (my_defnum < r.block_defnum) {
......@@ -523,7 +523,7 @@ fn expr_root(&ctx cx, @ast::expr ex, bool autoderef) ->
rec(@ast::expr ex, @deref[] ds) {
fn maybe_auto_unbox(&ctx cx, &ty::t t) ->
rec(ty::t t, option::t[deref] d) {
alt (ty::struct(*cx.tcx, t)) {
alt (ty::struct(cx.tcx, t)) {
case (ty::ty_box(?mt)) {
ret rec(t=mt.ty,
d=some(@rec(mut=mt.mut != ast::imm,
......@@ -541,9 +541,9 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable deref[] ds) {
alt ({ ex.node }) {
case (ast::expr_field(?base, ?ident)) {
auto auto_unbox =
maybe_auto_unbox(cx, ty::expr_ty(*cx.tcx, base));
maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, base));
auto mut = false;
alt (ty::struct(*cx.tcx, auto_unbox.t)) {
alt (ty::struct(cx.tcx, auto_unbox.t)) {
case (ty::ty_tup(?fields)) {
auto fnm = ty::field_num(cx.tcx.sess, ex.span, ident);
mut = fields.(fnm).mut != ast::imm;
......@@ -564,8 +564,8 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable deref[] ds) {
}
case (ast::expr_index(?base, _)) {
auto auto_unbox =
maybe_auto_unbox(cx, ty::expr_ty(*cx.tcx, base));
alt (ty::struct(*cx.tcx, auto_unbox.t)) {
maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, base));
alt (ty::struct(cx.tcx, auto_unbox.t)) {
case (ty::ty_vec(?mt)) {
ds += ~[@rec(mut=mt.mut != ast::imm,
kind=index,
......@@ -582,9 +582,9 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable deref[] ds) {
}
case (ast::expr_unary(?op, ?base)) {
if (op == ast::deref) {
auto base_t = ty::expr_ty(*cx.tcx, base);
auto base_t = ty::expr_ty(cx.tcx, base);
auto mut = false;
alt (ty::struct(*cx.tcx, base_t)) {
alt (ty::struct(cx.tcx, base_t)) {
case (ty::ty_box(?mt)) { mut = mt.mut != ast::imm; }
case (ty::ty_res(_, _, _)) {}
case (ty::ty_tag(_, _)) {}
......@@ -598,7 +598,7 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable deref[] ds) {
}
}
if (autoderef) {
auto auto_unbox = maybe_auto_unbox(cx, ty::expr_ty(*cx.tcx, ex));
auto auto_unbox = maybe_auto_unbox(cx, ty::expr_ty(cx.tcx, ex));
maybe_push_auto_unbox(auto_unbox.d, ds);
}
ret rec(ex=ex, ds=@ds);
......@@ -669,7 +669,7 @@ fn helper(&ty::ctxt tcx, ty::t needle, ty::t haystack, bool mut) -> bool {
_ { ret false; }
}
}
ret helper(*cx.tcx, needle, haystack, mut);
ret helper(cx.tcx, needle, haystack, mut);
}
fn def_is_local(&ast::def d, bool objfields_count) -> bool {
......@@ -681,7 +681,7 @@ fn def_is_local(&ast::def d, bool objfields_count) -> bool {
}
fn fty_args(&ctx cx, ty::t fty) -> ty::arg[] {
ret alt (ty::struct(*cx.tcx, ty::type_autoderef(*cx.tcx, fty))) {
ret alt (ty::struct(cx.tcx, ty::type_autoderef(cx.tcx, fty))) {
ty::ty_fn(_, ?args, _, _, _) | ty::ty_native_fn(_, ?args, _) { args }
};
}
......
......@@ -207,20 +207,20 @@
type creader_cache = hashmap[tup(int, uint, uint), ty::t];
type ctxt =
rec(@type_store ts,
session::session sess,
resolve::def_map def_map,
node_type_table node_types,
ast_map::map items,
freevars::freevar_map freevars,
// constr_table fn_constrs,
type_cache tcache,
creader_cache rcache,
hashmap[t, str] short_names_cache,
hashmap[t, bool] has_pointer_cache,
hashmap[t, bool] owns_heap_mem_cache,
hashmap[@ast::ty, option::t[t]] ast_ty_to_ty_cache);
@rec(@type_store ts,
session::session sess,
resolve::def_map def_map,
node_type_table node_types,
ast_map::map items,
freevars::freevar_map freevars,
// constr_table fn_constrs,
type_cache tcache,
creader_cache rcache,
hashmap[t, str] short_names_cache,
hashmap[t, bool] has_pointer_cache,
hashmap[t, bool] owns_heap_mem_cache,
hashmap[@ast::ty, option::t[t]] ast_ty_to_ty_cache);
type ty_ctxt = ctxt;
......@@ -405,23 +405,18 @@ fn mk_ctxt(session::session s, resolve::def_map dm,
auto tcache = new_def_hash[ty::ty_param_count_and_ty]();
auto ts = @interner::mk[@raw_t](hash_raw_ty, eq_raw_ty);
auto cx =
rec(ts=ts,
sess=s,
def_map=dm,
node_types=ntt,
items=amap,
freevars=freevars,
tcache=tcache,
rcache=mk_rcache(),
short_names_cache=map::mk_hashmap[ty::t,
str](ty::hash_ty, ty::eq_ty),
has_pointer_cache=map::mk_hashmap[ty::t,
bool](ty::hash_ty, ty::eq_ty),
owns_heap_mem_cache=map::mk_hashmap[ty::t,
bool](ty::hash_ty, ty::eq_ty),
ast_ty_to_ty_cache=map::mk_hashmap[@ast::ty,
option::t[t]](ast::hash_ty,
ast::eq_ty));
@rec(ts=ts,
sess=s,
def_map=dm,
node_types=ntt,
items=amap,
freevars=freevars,
tcache=tcache,
rcache=mk_rcache(),
short_names_cache=map::mk_hashmap(ty::hash_ty, ty::eq_ty),
has_pointer_cache=map::mk_hashmap(ty::hash_ty, ty::eq_ty),
owns_heap_mem_cache=map::mk_hashmap(ty::hash_ty, ty::eq_ty),
ast_ty_to_ty_cache=map::mk_hashmap(ast::hash_ty, ast::eq_ty));
populate_type_store(cx);
ret cx;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册