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