rustc: Implement a new resolve pass behind a compile flag

This commit is contained in:
Patrick Walton 2012-05-22 10:54:12 -07:00
parent 0b1edb7f0e
commit f093d374ed
42 changed files with 4336 additions and 163 deletions

View file

@ -8,7 +8,9 @@ import std::map::{map,hashmap,int_hash,hash_from_strs};
import std::smallintmap::{map,smallintmap};
import io::writer_util;
import syntax::print::pprust::expr_to_str;
export lint, ctypes, unused_imports;
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
export unrecognized_warning, non_implicitly_copyable_typarams;
export vecs_not_implicitly_copyable, implicit_copies;
export level, ignore, warn, error;
export lookup_lint, lint_dict, get_lint_dict;
export get_warning_level, get_warning_settings_level;

View file

@ -283,7 +283,7 @@ class ir_maps {
some(var) {var}
none {
self.tcx.sess.span_bug(
span, "No variable registered for this id");
span, #fmt("No variable registered for id %d", node_id));
}
}
}

3946
src/rustc/middle/resolve3.rs Normal file

File diff suppressed because it is too large Load diff

View file

@ -39,14 +39,16 @@ import link::{mangle_internal_name_by_type_only,
mangle_exported_name};
import metadata::{csearch, cstore, encoder};
import metadata::common::link_meta;
import util::ppaux;
import util::ppaux::{ty_to_str, ty_to_short_str};
import syntax::diagnostic::expect;
import common::*;
import build::*;
import shape::*;
import type_of::*;
import common::*;
import type_of::type_of; // Issue #1873
import common::result;
import syntax::ast_map::{path, path_mod, path_name};
import std::smallintmap;
@ -511,7 +513,7 @@ fn declare_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
mut drop_glue: none,
mut free_glue: none,
mut visit_glue: none};
log(debug, "--- declare_tydesc " + ty_to_str(ccx.tcx, t));
log(debug, "--- declare_tydesc " + ppaux::ty_to_str(ccx.tcx, t));
ret inf;
}
@ -1106,14 +1108,14 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint,
some(_) { }
none {
#debug("+++ lazily_emit_tydesc_glue TAKE %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
let glue_fn = declare_generic_glue
(ccx, ti.ty, T_glue_fn(ccx), "take");
ti.take_glue = some(glue_fn);
make_generic_glue(ccx, ti.ty, glue_fn,
make_take_glue, "take");
#debug("--- lazily_emit_tydesc_glue TAKE %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
}
}
} else if field == abi::tydesc_field_drop_glue {
@ -1121,14 +1123,14 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint,
some(_) { }
none {
#debug("+++ lazily_emit_tydesc_glue DROP %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
let glue_fn =
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "drop");
ti.drop_glue = some(glue_fn);
make_generic_glue(ccx, ti.ty, glue_fn,
make_drop_glue, "drop");
#debug("--- lazily_emit_tydesc_glue DROP %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
}
}
} else if field == abi::tydesc_field_free_glue {
@ -1136,14 +1138,14 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint,
some(_) { }
none {
#debug("+++ lazily_emit_tydesc_glue FREE %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
let glue_fn =
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "free");
ti.free_glue = some(glue_fn);
make_generic_glue(ccx, ti.ty, glue_fn,
make_free_glue, "free");
#debug("--- lazily_emit_tydesc_glue FREE %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
}
}
} else if field == abi::tydesc_field_visit_glue {
@ -1151,14 +1153,14 @@ fn lazily_emit_tydesc_glue(ccx: @crate_ctxt, field: uint,
some(_) { }
none {
#debug("+++ lazily_emit_tydesc_glue VISIT %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
let glue_fn =
declare_generic_glue(ccx, ti.ty, T_glue_fn(ccx), "visit");
ti.visit_glue = some(glue_fn);
make_generic_glue(ccx, ti.ty, glue_fn,
make_visit_glue, "visit");
#debug("--- lazily_emit_tydesc_glue VISIT %s",
ty_to_str(ccx.tcx, ti.ty));
ppaux::ty_to_str(ccx.tcx, ti.ty));
}
}
}
@ -1383,7 +1385,7 @@ fn copy_val_no_check(bcx: block, action: copy_action, dst: ValueRef,
ret take_ty(bcx, dst, t);
}
ccx.sess.bug("unexpected type in trans::copy_val_no_check: " +
ty_to_str(ccx.tcx, t));
ppaux::ty_to_str(ccx.tcx, t));
}
@ -1422,7 +1424,7 @@ fn move_val(cx: block, action: copy_action, dst: ValueRef,
ret cx;
}
cx.sess().bug("unexpected type in trans::move_val: " +
ty_to_str(tcx, t));
ppaux::ty_to_str(tcx, t));
}
fn store_temp_expr(cx: block, action: copy_action, dst: ValueRef,
@ -1810,7 +1812,7 @@ fn autoderef(cx: block, e_id: ast::node_id,
let mut derefs = 0u;
while derefs < max {
#debug["autoderef(e_id=%d, v1=%s, t1=%s, derefs=%u)",
e_id, val_str(ccx.tn, v1), ty_to_str(ccx.tcx, t1),
e_id, val_str(ccx.tn, v1), ppaux::ty_to_str(ccx.tcx, t1),
derefs];
// root the autoderef'd value, if necessary:
@ -2140,7 +2142,6 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
for real_substs.each() |s| { assert !ty::type_has_params(s); }
for substs.each() |s| { assert !ty::type_has_params(s); }
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
let hash_id = make_mono_id(ccx, fn_id, substs, vtables, some(param_uses));
if vec::any(hash_id.params,
@ -2156,6 +2157,8 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
alt ccx.monomorphized.find(hash_id) {
some(val) {
#debug["leaving monomorphic fn %s",
ty::item_path_str(ccx.tcx, fn_id)];
ret {val: val, must_cast: must_cast};
}
none {}
@ -2286,6 +2289,8 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
}
};
ccx.monomorphizing.insert(fn_id, depth);
#debug["leaving monomorphic fn %s", ty::item_path_str(ccx.tcx, fn_id)];
{val: lldecl, must_cast: must_cast}
}
@ -3056,7 +3061,7 @@ fn adapt_borrowed_value(lv: lval_result,
_ {
bcx.tcx().sess.span_bug(
e.span, #fmt["cannot borrow a value of type %s",
ty_to_str(bcx.tcx(), e_ty)]);
ppaux::ty_to_str(bcx.tcx(), e_ty)]);
}
}
}
@ -3517,7 +3522,7 @@ fn add_root_cleanup(bcx: block, scope_id: ast::node_id,
#debug["add_root_cleanup(bcx=%s, scope_id=%d, root_loc=%s, ty=%s)",
bcx.to_str(), scope_id, val_str(bcx.ccx().tn, root_loc),
ty_to_str(bcx.ccx().tcx, ty)];
ppaux::ty_to_str(bcx.ccx().tcx, ty)];
let bcx_scope = find_bcx_for_scope(bcx, scope_id);
add_clean_temp_mem(bcx_scope, root_loc, ty);
@ -3614,7 +3619,8 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
alt check ty::get(expr_ty(bcx, e)).struct {
ty::ty_fn({proto, _}) {
#debug("translating fn_block %s with type %s",
expr_to_str(e), ty_to_str(tcx, expr_ty(bcx, e)));
expr_to_str(e),
ppaux::ty_to_str(tcx, expr_ty(bcx, e)));
ret closure::trans_expr_fn(bcx, proto, decl, body,
e.id, cap_clause, none, dest);
}
@ -3754,7 +3760,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
let ptr_ty = expr_ty(bcx, e);
let ptr_ptr_val = alloc_ty(bcx, ptr_ty);
#debug["ptr_ty = %s", ty_to_str(tcx, ptr_ty)];
#debug["ptr_ty = %s", ppaux::ty_to_str(tcx, ptr_ty)];
#debug["ptr_ptr_val = %s", val_str(ccx.tn, ptr_ptr_val)];
let void_ty = ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx),
@ -3947,7 +3953,7 @@ fn trans_fail_expr(bcx: block, sp_opt: option<span>,
} else {
bcx.sess().span_bug(
expr.span, "fail called with unsupported type " +
ty_to_str(tcx, e_ty));
ppaux::ty_to_str(tcx, e_ty));
}
}
_ { ret trans_fail(bcx, sp_opt, "explicit failure"); }
@ -4345,7 +4351,7 @@ fn alloc_ty(bcx: block, t: ty::t) -> ValueRef {
let _icx = bcx.insn_ctxt("alloc_ty");
let ccx = bcx.ccx();
let llty = type_of(ccx, t);
if ty::type_has_params(t) { log(error, ty_to_str(ccx.tcx, t)); }
if ty::type_has_params(t) { log(error, ppaux::ty_to_str(ccx.tcx, t)); }
assert !ty::type_has_params(t);
let val = alloca(bcx, llty);
ret val;

View file

@ -264,6 +264,9 @@ fn store_environment(bcx: block,
bcx = move_val(bcx, INIT, bound_data, src, ty);
}
env_ref(val, ty, owned) {
#debug["> storing %s into %s",
val_str(bcx.ccx().tn, val),
val_str(bcx.ccx().tn, bound_data)];
Store(bcx, val, bound_data);
}
env_ref(val, ty, owned_imm) {
@ -298,6 +301,8 @@ fn build_closure(bcx0: block,
#debug["Building closure: captured variable %?", cap_var];
let lv = trans_local_var(bcx, cap_var.def);
let nid = ast_util::def_id_of_def(cap_var.def).node;
#debug["Node id is %s",
syntax::ast_map::node_id_to_str(bcx.ccx().tcx.items, nid)];
let mut ty = node_id_type(bcx, nid);
alt cap_var.mode {
capture::cap_ref {

View file

@ -9,8 +9,7 @@ import lib::llvm::{ llvm, TypeRef, ValueRef,
ModuleRef, CallConv, Attribute,
StructRetAttribute, ByValAttribute,
SequentiallyConsistent, Acquire, Release,
Xchg, Add, Sub
};
Xchg };
import syntax::{ast, ast_util};
import back::{link, abi};
import common::*;
@ -830,42 +829,42 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
Store(bcx, old, fcx.llretptr);
}
"atomic_add" {
let old = AtomicRMW(bcx, Add,
let old = AtomicRMW(bcx, lib::llvm::Add,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
SequentiallyConsistent);
Store(bcx, old, fcx.llretptr);
}
"atomic_add_acq" {
let old = AtomicRMW(bcx, Add,
let old = AtomicRMW(bcx, lib::llvm::Add,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Acquire);
Store(bcx, old, fcx.llretptr);
}
"atomic_add_rel" {
let old = AtomicRMW(bcx, Add,
let old = AtomicRMW(bcx, lib::llvm::Add,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Release);
Store(bcx, old, fcx.llretptr);
}
"atomic_sub" {
let old = AtomicRMW(bcx, Sub,
let old = AtomicRMW(bcx, lib::llvm::Sub,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
SequentiallyConsistent);
Store(bcx, old, fcx.llretptr);
}
"atomic_sub_acq" {
let old = AtomicRMW(bcx, Sub,
let old = AtomicRMW(bcx, lib::llvm::Sub,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Acquire);
Store(bcx, old, fcx.llretptr);
}
"atomic_sub_rel" {
let old = AtomicRMW(bcx, Sub,
let old = AtomicRMW(bcx, lib::llvm::Sub,
get_param(decl, first_real_arg),
get_param(decl, first_real_arg + 1u),
Release);

View file

@ -81,6 +81,18 @@ fn traverse_public_mod(cx: ctx, m: _mod) {
if !traverse_exports(cx, m.view_items) {
// No exports, so every local item is exported
for vec::each(m.items) |item| { traverse_public_item(cx, item); }
} else {
// Make impls always reachable.
for vec::each(m.items) |item| {
alt item.node {
item_impl(*) {
traverse_public_item(cx, item);
}
_ {
// Nothing to do.
}
}
}
}
}

View file

@ -5,8 +5,6 @@ import lib::llvm::llvm;
import driver::session::session;
import std::map::hashmap;
import ty::*;
export type_of;
export type_of_dtor;
export type_of_explicit_args;
@ -174,7 +172,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
alt ty::get(t).struct {
ty::ty_class(did, ts) {
// Only instance vars are record fields at runtime.
let fields = lookup_class_fields(cx.tcx, did);
let fields = ty::lookup_class_fields(cx.tcx, did);
let mut tys = do vec::map(fields) |f| {
let t = ty::lookup_field_type(cx.tcx, did, f.id, ts);
type_of(cx, t)

View file

@ -11,11 +11,11 @@ import syntax::codemap::span;
import metadata::csearch;
import util::ppaux::region_to_str;
import util::ppaux::vstore_to_str;
import util::ppaux::{ty_to_str, tys_to_str, ty_constr_to_str};
import middle::lint::{get_warning_level, vecs_not_implicitly_copyable,
ignore};
import syntax::ast::*;
import syntax::print::pprust::*;
import util::ppaux::{ty_to_str, tys_to_str, ty_constr_to_str};
export tv_vid, tvi_vid, region_vid, vid;
export br_hashmap;
@ -105,7 +105,10 @@ export ty_uniq, mk_uniq, mk_imm_uniq, type_is_unique_box;
export ty_var, mk_var, type_is_var;
export ty_var_integral, mk_var_integral, type_is_var_integral;
export ty_self, mk_self, type_has_self;
export ty_class;
export region, bound_region, encl_region;
export re_bound, re_free, re_scope, re_static, re_var;
export br_self, br_anon, br_named;
export get, type_has_params, type_needs_infer, type_has_regions;
export type_has_resources, type_id;
export tbox_has_flag;
@ -2528,6 +2531,7 @@ fn iface_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
fn impl_iface(cx: ctxt, id: ast::def_id) -> option<t> {
if id.crate == ast::local_crate {
#debug("(impl_iface) searching for iface impl %?", id);
alt cx.items.find(id.node) {
some(ast_map::node_item(@{node: ast::item_impl(
_, _, some(@{id: id, _}), _, _), _}, _)) {
@ -2537,11 +2541,16 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option<t> {
_},_)) {
alt cx.def_map.find(id.node) {
some(def_ty(iface_id)) {
some(node_id_to_type(cx, id.node))
// XXX: Doesn't work cross-crate.
#debug("(impl_iface) found iface id %?", iface_id);
some(node_id_to_type(cx, iface_id.node))
}
_ {
cx.sess.bug("impl_iface: iface ref isn't in iface map \
and isn't bound to a def_ty");
some(x) {
cx.sess.bug(#fmt("impl_iface: iface ref is in iface map \
but is bound to %?", x));
}
none {
none
}
}
}

View file

@ -53,8 +53,6 @@ import middle::ty;
import middle::ty::{arg, field, node_type_table, mk_nil,
ty_param_bounds_and_ty, lookup_public_fields};
import middle::typeck::infer::methods;
import util::ppaux::{ty_to_str, tys_to_str, region_to_str,
bound_region_to_str, vstore_to_str};
import std::smallintmap;
import std::smallintmap::map;
import std::map;
@ -62,6 +60,8 @@ import std::map::{hashmap, int_hash};
import std::serialization::{serialize_uint, deserialize_uint};
import vec::each;
import syntax::print::pprust::*;
import util::ppaux::{ty_to_str, tys_to_str, region_to_str,
bound_region_to_str, vstore_to_str};
import util::common::{indent, indenter};
import std::list;
import list::{list, nil, cons};

View file

@ -74,6 +74,8 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
alt check ty::get(ity).struct {
ty::ty_iface(idid, substs) {
if iface_id == idid {
#debug("(checking vtable) @0 relating ty to iface ty
with did %?", idid);
relate_iface_tys(fcx, sp, iface_ty, ity);
ret vtable_param(n, n_bound);
}
@ -86,6 +88,9 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
}
ty::ty_iface(did, substs) if iface_id == did {
#debug("(checking vtable) @1 relating ty to iface ty with did %?",
did);
relate_iface_tys(fcx, sp, iface_ty, ty);
if !allow_unsafe {
for vec::each(*ty::iface_methods(tcx, did)) |m| {
@ -134,6 +139,10 @@ fn lookup_vtable(fcx: @fn_ctxt, isc: resolve::iscopes, sp: span,
}
// check that desired iface type unifies
#debug("(checking vtable) @2 relating iface ty %s to \
of_ty %s",
fcx.infcx.ty_to_str(iface_ty),
fcx.infcx.ty_to_str(of_ty));
let of_ty = ty::subst(tcx, substs, of_ty);
relate_iface_tys(fcx, sp, iface_ty, of_ty);
@ -186,6 +195,8 @@ fn connect_iface_tps(fcx: @fn_ctxt, sp: span, impl_tys: ~[ty::t],
let tcx = fcx.ccx.tcx;
let ity = option::get(ty::impl_iface(tcx, impl_did));
let iface_ty = ty::subst_tps(tcx, impl_tys, ity);
#debug("(connect iface tps) iface type is %?, impl did is %?",
ty::get(iface_ty).struct, impl_did);
alt check ty::get(iface_ty).struct {
ty::ty_iface(_, substs) {
vec::iter2(substs.tps, iface_tys,