rustc: Pass a "type context" around instead of directly passing the type store; prep for removing type annotations
This commit is contained in:
parent
b258060a94
commit
e102413aad
@ -73,13 +73,13 @@ fn compile_input(session.session sess,
|
||||
crate = resolve.resolve_crate(sess, crate);
|
||||
capture.check_for_captures(sess, crate);
|
||||
|
||||
auto tystore = ty.mk_type_store();
|
||||
auto typeck_result = typeck.check_crate(sess, tystore, crate);
|
||||
auto ty_cx = ty.mk_ctxt();
|
||||
auto typeck_result = typeck.check_crate(sess, ty_cx, crate);
|
||||
crate = typeck_result._0;
|
||||
auto type_cache = typeck_result._1;
|
||||
// FIXME: uncomment once typestate_check works
|
||||
// crate = typestate_check.check_crate(crate);
|
||||
trans.trans_crate(sess, crate, tystore, type_cache, output, shared,
|
||||
trans.trans_crate(sess, crate, ty_cx, type_cache, output, shared,
|
||||
optimize, verify, ot);
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,7 @@ tag resolve_result {
|
||||
// Callback to translate defs to strs or back.
|
||||
type str_def = fn(str) -> ast.def_id;
|
||||
|
||||
type pstate = rec(str rep, mutable uint pos, uint len,
|
||||
@ty.type_store tystore);
|
||||
type pstate = rec(str rep, mutable uint pos, uint len, ty.ctxt tcx);
|
||||
|
||||
fn peek(@pstate st) -> u8 {
|
||||
if (st.pos < st.len) {ret st.rep.(st.pos) as u8;}
|
||||
@ -63,9 +62,9 @@ fn next(@pstate st) -> u8 {
|
||||
ret ch as u8;
|
||||
}
|
||||
|
||||
fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> ty.t {
|
||||
fn parse_ty_str(str rep, str_def sd, ty.ctxt tcx) -> ty.t {
|
||||
auto len = _str.byte_len(rep);
|
||||
auto st = @rec(rep=rep, mutable pos=0u, len=len, tystore=tystore);
|
||||
auto st = @rec(rep=rep, mutable pos=0u, len=len, tcx=tcx);
|
||||
auto result = parse_ty(st, sd);
|
||||
if (st.pos != len) {
|
||||
log_err "parse_ty_str: incomplete parse, stopped at byte "
|
||||
@ -77,27 +76,27 @@ fn parse_ty_str(str rep, str_def sd, @ty.type_store tystore) -> ty.t {
|
||||
|
||||
fn parse_ty(@pstate st, str_def sd) -> ty.t {
|
||||
alt (next(st) as char) {
|
||||
case ('n') { ret ty.mk_nil(st.tystore); }
|
||||
case ('b') { ret ty.mk_bool(st.tystore); }
|
||||
case ('i') { ret ty.mk_int(st.tystore); }
|
||||
case ('u') { ret ty.mk_uint(st.tystore); }
|
||||
case ('l') { ret ty.mk_float(st.tystore); }
|
||||
case ('n') { ret ty.mk_nil(st.tcx); }
|
||||
case ('b') { ret ty.mk_bool(st.tcx); }
|
||||
case ('i') { ret ty.mk_int(st.tcx); }
|
||||
case ('u') { ret ty.mk_uint(st.tcx); }
|
||||
case ('l') { ret ty.mk_float(st.tcx); }
|
||||
case ('M') {
|
||||
alt (next(st) as char) {
|
||||
case ('b') { ret ty.mk_mach(st.tystore, common.ty_u8); }
|
||||
case ('w') { ret ty.mk_mach(st.tystore, common.ty_u16); }
|
||||
case ('l') { ret ty.mk_mach(st.tystore, common.ty_u32); }
|
||||
case ('d') { ret ty.mk_mach(st.tystore, common.ty_u64); }
|
||||
case ('B') { ret ty.mk_mach(st.tystore, common.ty_i8); }
|
||||
case ('W') { ret ty.mk_mach(st.tystore, common.ty_i16); }
|
||||
case ('L') { ret ty.mk_mach(st.tystore, common.ty_i32); }
|
||||
case ('D') { ret ty.mk_mach(st.tystore, common.ty_i64); }
|
||||
case ('f') { ret ty.mk_mach(st.tystore, common.ty_f32); }
|
||||
case ('F') { ret ty.mk_mach(st.tystore, common.ty_f64); }
|
||||
case ('b') { ret ty.mk_mach(st.tcx, common.ty_u8); }
|
||||
case ('w') { ret ty.mk_mach(st.tcx, common.ty_u16); }
|
||||
case ('l') { ret ty.mk_mach(st.tcx, common.ty_u32); }
|
||||
case ('d') { ret ty.mk_mach(st.tcx, common.ty_u64); }
|
||||
case ('B') { ret ty.mk_mach(st.tcx, common.ty_i8); }
|
||||
case ('W') { ret ty.mk_mach(st.tcx, common.ty_i16); }
|
||||
case ('L') { ret ty.mk_mach(st.tcx, common.ty_i32); }
|
||||
case ('D') { ret ty.mk_mach(st.tcx, common.ty_i64); }
|
||||
case ('f') { ret ty.mk_mach(st.tcx, common.ty_f32); }
|
||||
case ('F') { ret ty.mk_mach(st.tcx, common.ty_f64); }
|
||||
}
|
||||
}
|
||||
case ('c') { ret ty.mk_char(st.tystore); }
|
||||
case ('s') { ret ty.mk_str(st.tystore); }
|
||||
case ('c') { ret ty.mk_char(st.tcx); }
|
||||
case ('s') { ret ty.mk_str(st.tcx); }
|
||||
case ('t') {
|
||||
check(next(st) as char == '[');
|
||||
auto def = parse_def(st, sd);
|
||||
@ -106,13 +105,13 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
|
||||
params += vec(parse_ty(st, sd));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty.mk_tag(st.tystore, def, params);
|
||||
ret ty.mk_tag(st.tcx, def, params);
|
||||
}
|
||||
case ('p') { ret ty.mk_param(st.tystore, parse_int(st) as uint); }
|
||||
case ('@') { ret ty.mk_box(st.tystore, parse_mt(st, sd)); }
|
||||
case ('V') { ret ty.mk_vec(st.tystore, parse_mt(st, sd)); }
|
||||
case ('P') { ret ty.mk_port(st.tystore, parse_ty(st, sd)); }
|
||||
case ('C') { ret ty.mk_chan(st.tystore, parse_ty(st, sd)); }
|
||||
case ('p') { ret ty.mk_param(st.tcx, parse_int(st) as uint); }
|
||||
case ('@') { ret ty.mk_box(st.tcx, parse_mt(st, sd)); }
|
||||
case ('V') { ret ty.mk_vec(st.tcx, parse_mt(st, sd)); }
|
||||
case ('P') { ret ty.mk_port(st.tcx, parse_ty(st, sd)); }
|
||||
case ('C') { ret ty.mk_chan(st.tcx, parse_ty(st, sd)); }
|
||||
case ('T') {
|
||||
check(next(st) as char == '[');
|
||||
let vec[ty.mt] params = vec();
|
||||
@ -120,7 +119,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
|
||||
params += vec(parse_mt(st, sd));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty.mk_tup(st.tystore, params);
|
||||
ret ty.mk_tup(st.tcx, params);
|
||||
}
|
||||
case ('R') {
|
||||
check(next(st) as char == '[');
|
||||
@ -134,15 +133,15 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
|
||||
fields += vec(rec(ident=name, mt=parse_mt(st, sd)));
|
||||
}
|
||||
st.pos = st.pos + 1u;
|
||||
ret ty.mk_rec(st.tystore, fields);
|
||||
ret ty.mk_rec(st.tcx, fields);
|
||||
}
|
||||
case ('F') {
|
||||
auto func = parse_ty_fn(st, sd);
|
||||
ret ty.mk_fn(st.tystore, ast.proto_fn, func._0, func._1);
|
||||
ret ty.mk_fn(st.tcx, ast.proto_fn, func._0, func._1);
|
||||
}
|
||||
case ('W') {
|
||||
auto func = parse_ty_fn(st, sd);
|
||||
ret ty.mk_fn(st.tystore, ast.proto_iter, func._0, func._1);
|
||||
ret ty.mk_fn(st.tcx, ast.proto_iter, func._0, func._1);
|
||||
}
|
||||
case ('N') {
|
||||
auto abi;
|
||||
@ -152,7 +151,7 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
|
||||
case ('l') {abi = ast.native_abi_llvm;}
|
||||
}
|
||||
auto func = parse_ty_fn(st, sd);
|
||||
ret ty.mk_native_fn(st.tystore,abi,func._0,func._1);
|
||||
ret ty.mk_native_fn(st.tcx,abi,func._0,func._1);
|
||||
}
|
||||
case ('O') {
|
||||
check(next(st) as char == '[');
|
||||
@ -174,11 +173,11 @@ fn parse_ty(@pstate st, str_def sd) -> ty.t {
|
||||
output=func._1));
|
||||
}
|
||||
st.pos += 1u;
|
||||
ret ty.mk_obj(st.tystore, methods);
|
||||
ret ty.mk_obj(st.tcx, methods);
|
||||
}
|
||||
case ('X') { ret ty.mk_var(st.tystore, parse_int(st)); }
|
||||
case ('E') { ret ty.mk_native(st.tystore); }
|
||||
case ('Y') { ret ty.mk_type(st.tystore); }
|
||||
case ('X') { ret ty.mk_var(st.tcx, parse_int(st)); }
|
||||
case ('E') { ret ty.mk_native(st.tcx); }
|
||||
case ('Y') { ret ty.mk_type(st.tcx); }
|
||||
}
|
||||
}
|
||||
|
||||
@ -331,7 +330,7 @@ fn variant_tag_id(&ebml.doc d) -> ast.def_id {
|
||||
ret parse_def_id(ebml.doc_data(tagdoc));
|
||||
}
|
||||
|
||||
fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> ty.t {
|
||||
fn item_type(&ebml.doc item, int this_cnum, ty.ctxt tcx) -> ty.t {
|
||||
fn parse_external_def_id(int this_cnum, str s) -> ast.def_id {
|
||||
// FIXME: This is completely wrong when linking against a crate
|
||||
// that, in turn, links against another crate. We need a mapping
|
||||
@ -344,7 +343,7 @@ fn item_type(&ebml.doc item, int this_cnum, @ty.type_store tystore) -> ty.t {
|
||||
|
||||
auto tp = ebml.get_doc(item, metadata.tag_items_data_item_type);
|
||||
auto s = _str.unsafe_from_bytes(ebml.doc_data(tp));
|
||||
ret parse_ty_str(s, bind parse_external_def_id(this_cnum, _), tystore);
|
||||
ret parse_ty_str(s, bind parse_external_def_id(this_cnum, _), tcx);
|
||||
}
|
||||
|
||||
fn item_ty_param_count(&ebml.doc item, int this_cnum) -> uint {
|
||||
@ -506,12 +505,12 @@ fn lookup_def(session.session sess, int cnum, vec[ast.ident] path)
|
||||
ret some[ast.def](def);
|
||||
}
|
||||
|
||||
fn get_type(session.session sess, @ty.type_store tystore, ast.def_id def)
|
||||
fn get_type(session.session sess, ty.ctxt tcx, ast.def_id def)
|
||||
-> ty.ty_param_count_and_ty {
|
||||
auto external_crate_id = def._0;
|
||||
auto data = sess.get_external_crate(external_crate_id).data;
|
||||
auto item = lookup_item(def._1, data);
|
||||
auto t = item_type(item, external_crate_id, tystore);
|
||||
auto t = item_type(item, external_crate_id, tcx);
|
||||
|
||||
auto tp_count;
|
||||
auto kind_ch = item_kind(item);
|
||||
@ -532,9 +531,8 @@ fn get_symbol(session.session sess, ast.def_id def) -> str {
|
||||
ret item_symbol(item);
|
||||
}
|
||||
|
||||
fn get_tag_variants(session.session sess,
|
||||
@ty.type_store tystore,
|
||||
ast.def_id def) -> vec[trans.variant_info] {
|
||||
fn get_tag_variants(session.session sess, ty.ctxt tcx, ast.def_id def)
|
||||
-> vec[trans.variant_info] {
|
||||
auto external_crate_id = def._0;
|
||||
auto data = sess.get_external_crate(external_crate_id).data;
|
||||
auto items = ebml.get_doc(ebml.new_doc(data), metadata.tag_items);
|
||||
@ -544,9 +542,9 @@ fn get_tag_variants(session.session sess,
|
||||
auto variant_ids = tag_variant_ids(item, external_crate_id);
|
||||
for (ast.def_id did in variant_ids) {
|
||||
auto item = find_item(did._1, items);
|
||||
auto ctor_ty = item_type(item, external_crate_id, tystore);
|
||||
auto ctor_ty = item_type(item, external_crate_id, tcx);
|
||||
let vec[ty.t] arg_tys = vec();
|
||||
alt (ty.struct(tystore, ctor_ty)) {
|
||||
alt (ty.struct(tcx, ctor_ty)) {
|
||||
case (ty.ty_fn(_, ?args, _)) {
|
||||
for (ty.arg a in args) {
|
||||
arg_tys += vec(a.ty);
|
||||
|
@ -53,11 +53,11 @@ mod Encode {
|
||||
|
||||
type ctxt = rec(
|
||||
fn(ast.def_id) -> str ds, // Callback to translate defs to strs.
|
||||
@ty.type_store tystore // The type store.
|
||||
ty.ctxt tcx // The type context.
|
||||
);
|
||||
|
||||
fn ty_str(@ctxt cx, ty.t t) -> str {
|
||||
ret sty_str(cx, ty.struct(cx.tystore, t));
|
||||
ret sty_str(cx, ty.struct(cx.tcx, t));
|
||||
}
|
||||
|
||||
fn mt_str(@ctxt cx, &ty.mt mt) -> str {
|
||||
@ -337,7 +337,7 @@ 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, tystore=cx.tystore);
|
||||
auto ty_str_ctxt = @rec(ds=f, tcx=cx.tcx);
|
||||
ebml_w.writer.write(_str.bytes(Encode.ty_str(ty_str_ctxt, typ)));
|
||||
|
||||
ebml.end_tag(ebml_w);
|
||||
@ -457,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(cx, ebml_w, ty.ty_fn_ret(cx.tystore, fn_ty));
|
||||
encode_type(cx, ebml_w, ty.ty_fn_ret(cx.tcx, fn_ty));
|
||||
ebml.end_tag(ebml_w);
|
||||
}
|
||||
}
|
||||
@ -470,7 +470,7 @@ 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(cx, ebml_w, ty.mk_native(cx.tystore));
|
||||
encode_type(cx, ebml_w, ty.mk_native(cx.tcx));
|
||||
}
|
||||
case (ast.native_item_fn(_, _, _, ?tps, ?did, ?ann)) {
|
||||
encode_def_id(ebml_w, did);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -110,8 +110,8 @@ fn field_exprs(vec[ast.field] fields) -> vec [@ast.expr] {
|
||||
ret _vec.map[ast.field, @ast.expr](f, fields);
|
||||
}
|
||||
|
||||
fn plain_ann(@middle.ty.type_store tystore) -> ast.ann {
|
||||
ret ast.ann_type(middle.ty.mk_nil(tystore),
|
||||
fn plain_ann(middle.ty.ctxt tcx) -> ast.ann {
|
||||
ret ast.ann_type(middle.ty.mk_nil(tcx),
|
||||
none[vec[middle.ty.t]], none[@ts_ann]);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user