rustc: Remove legacy mode inference, unless #[legacy_modes] is used

This commit is contained in:
Patrick Walton
2012-09-18 15:52:21 -07:00
parent d53cfd225a
commit e653d493fb
77 changed files with 181 additions and 42 deletions

View File

@@ -206,7 +206,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars,
region_map, rp_set, move lang_items);
region_map, rp_set, move lang_items, crate);
let (method_map, vtable_map) = time(time_passes, ~"typechecking", ||
typeck::check_crate(ty_cx,

View File

@@ -1,6 +1,7 @@
#[no_core];
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];
#[legacy_modes];
extern mod core(vers = "0.4");
extern mod std(vers = "0.4");

View File

@@ -13,7 +13,7 @@ use syntax::ast_util::{path_to_ident};
use syntax::print::pprust::{expr_to_str, mode_to_str, pat_to_str};
export lint, ctypes, unused_imports, while_true, path_statement, old_vecs;
export unrecognized_lint, non_implicitly_copyable_typarams;
export vecs_implicitly_copyable, implicit_copies;
export vecs_implicitly_copyable, implicit_copies, legacy_modes;
export level, allow, warn, deny, forbid;
export lint_dict, get_lint_dict, level_to_str;
export get_lint_level, get_lint_settings_level;
@@ -59,6 +59,8 @@ enum lint {
owned_heap_memory,
heap_memory,
legacy_modes,
// FIXME(#3266)--make liveness warnings lintable
// unused_variable,
// dead_assignment
@@ -179,6 +181,11 @@ fn get_lint_dict() -> lint_dict {
desc: ~"use of any structural records",
default: allow}),
(~"legacy modes",
@{lint: legacy_modes,
desc: ~"allow legacy modes",
default: forbid}),
/* FIXME(#3266)--make liveness warnings lintable
(~"unused_variable",
@{lint: unused_variable,

View File

@@ -319,6 +319,7 @@ type ctxt =
interner: HashMap<intern_key, t_box>,
mut next_id: uint,
vecs_implicitly_copyable: bool,
legacy_modes: bool,
cstore: metadata::cstore::cstore,
sess: session::session,
def_map: resolve::DefMap,
@@ -827,7 +828,19 @@ fn mk_ctxt(s: session::session,
freevars: freevars::freevar_map,
region_map: middle::region::region_map,
region_paramd_items: middle::region::region_paramd_items,
+lang_items: middle::lang_items::LanguageItems) -> ctxt {
+lang_items: middle::lang_items::LanguageItems,
crate: @ast::crate) -> ctxt {
let mut legacy_modes = false;
for crate.node.attrs.each |attribute| {
match attribute.node.value.node {
ast::meta_word(w) if w == ~"legacy_modes" => {
legacy_modes = true;
break;
}
_ => {}
}
}
let interner = map::HashMap();
let vecs_implicitly_copyable =
get_lint_level(s.lint_settings.default_settings,
@@ -836,6 +849,7 @@ fn mk_ctxt(s: session::session,
interner: interner,
mut next_id: 0u,
vecs_implicitly_copyable: vecs_implicitly_copyable,
legacy_modes: legacy_modes,
cstore: s.cstore,
sess: s,
def_map: dm,
@@ -1075,9 +1089,14 @@ pure fn mach_sty(cfg: @session::config, t: t) -> sty {
}
}
fn default_arg_mode_for_ty(ty: ty::t) -> ast::rmode {
if ty::type_is_immediate(ty) { ast::by_val }
else { ast::by_ref }
fn default_arg_mode_for_ty(tcx: ctxt, ty: ty::t) -> ast::rmode {
if ty::type_is_immediate(ty) {
ast::by_val
} else if tcx.legacy_modes {
ast::by_ref
} else {
ast::by_copy
}
}
// Returns the narrowest lifetime enclosing the evaluation of the expression

View File

@@ -432,7 +432,8 @@ fn ty_of_arg<AC: ast_conv, RS: region_scope Copy Owned>(
// tables in tcx but should never fail, because nothing else
// will have been unified with m yet:
_ => {
let m1 = ast::expl(ty::default_arg_mode_for_ty(ty));
let m1 = ast::expl(ty::default_arg_mode_for_ty(self.tcx(),
ty));
result::get(ty::unify_mode(
self.tcx(),
ty::expected_found {expected: m1,

View File

@@ -145,7 +145,7 @@ fn visit_expr(e: @ast::expr, wbcx: wb_ctxt, v: wb_vt) {
match (r_ty, input.mode) {
(Some(t), ast::infer(_)) => {
let tcx = wbcx.fcx.ccx.tcx;
let m_def = ty::default_arg_mode_for_ty(t);
let m_def = ty::default_arg_mode_for_ty(tcx, t);
ty::set_default_mode(tcx, input.mode, m_def);
}
_ => ()

View File

@@ -11,6 +11,8 @@
#[no_core];
#[legacy_modes];
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];
// #[warn(deprecated_pattern)];

View File

@@ -258,7 +258,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> ~str {
ast::infer(_) => ~"",
ast::expl(m) => {
if !ty::type_needs_infer(ty) &&
m == ty::default_arg_mode_for_ty(ty) {
m == ty::default_arg_mode_for_ty(cx, ty) {
~""
} else {
mode_to_str(ast::expl(m))