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

@ -4,6 +4,8 @@
#[no_core];
#[legacy_modes];
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];

View File

@ -31,6 +31,8 @@
// Don't link to core. We are core.
#[no_core];
#[legacy_modes];
#[warn(vecs_implicitly_copyable)];
#[deny(non_camel_case_types)];

View File

@ -10,6 +10,8 @@
#[no_core];
#[legacy_modes];
#[allow(vecs_implicitly_copyable)];
#[deny(non_camel_case_types)];

View File

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

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))

View File

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

View File

@ -1,4 +1,5 @@
#[link(name="cci_iter_lib", vers="0.0")];
#[legacy_modes];
#[inline]
fn iter<T>(v: ~[T], f: fn(T)) {

View File

@ -1,3 +1,5 @@
#[legacy_modes];
use dvec::DVec;
type entry<A,B> = {key: A, value: B};
@ -26,4 +28,4 @@ fn new_int_alist_2<B: Copy>() -> alist<int, B> {
#[inline]
fn eq_int(&&a: int, &&b: int) -> bool { a == b }
return {eq_fn: eq_int, data: DVec()};
}
}

View File

@ -4,6 +4,8 @@ An implementation of the Graph500 Breadth First Search problem in Rust.
*/
#[legacy_modes];
extern mod std;
use std::arc;
use std::time;

View File

@ -10,6 +10,8 @@
// xfail-pretty
#[legacy_modes];
extern mod std;
use io::Writer;
use io::WriterUtil;

View File

@ -6,6 +6,8 @@
// xfail-pretty
#[legacy_modes];
extern mod std;
use io::Writer;
use io::WriterUtil;

View File

@ -2,6 +2,8 @@
// multi tasking k-nucleotide
#[legacy_modes];
extern mod std;
use std::map;
use std::map::HashMap;

View File

@ -12,6 +12,8 @@
//
// writes pbm image to output path
#[legacy_modes];
extern mod std;
use io::WriterUtil;
use std::map::HashMap;

View File

@ -10,6 +10,8 @@
*/
#[legacy_modes];
extern mod std;
use std::{time, getopts};

View File

@ -10,6 +10,8 @@
// xfail-pretty
#[legacy_modes];
extern mod std;
use option = option;

View File

@ -1,3 +1,7 @@
// xfail-test
// xfail-fast
#[legacy_modes];
fn impure(_i: int) {}
// check that unchecked alone does not override borrowck:

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn takes_mut(&&x: @mut int) { }
fn takes_const(&&x: @const int) { }
fn takes_imm(&&x: @int) { }

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn foo<T: Copy>(+_t: T) { fail; }
fn bar<T>(+_t: T) { fail; }

View File

@ -1,3 +1,5 @@
#[legacy_modes];
// In this test, the mode gets inferred to ++ due to the apply_int(),
// but then we get a failure in the generic apply().

View File

@ -1,3 +1,5 @@
#[legacy_modes];
// Test rules governing higher-order pure fns.
pure fn range(from: uint, to: uint, f: fn(uint)) {
@ -45,4 +47,4 @@ fn print(i: uint) { error!("i=%u", i); }
pure fn noop(_i: uint) {}
fn main() {
}
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
enum ast {
num(uint),
add(&ast, &ast)
@ -30,4 +32,4 @@ fn map_nums(x: &ast, f: fn(uint) -> uint) -> &ast {
}
}
fn main() {}
fn main() {}

View File

@ -1,5 +1,7 @@
// xfail-pretty
#[legacy_modes];
extern mod std;
extern mod syntax;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn f1(a: {mut x: int}, &b: int, -c: int) -> int {
let r = a.x + b + c;
a.x = 0;

View File

@ -2,6 +2,8 @@
// making method calls, but only if there aren't any matches without
// it.
#[legacy_modes];
trait iterable<A> {
fn iterate(blk: fn(A) -> bool);
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
// These tests used to be separate files, but I wanted to refactor all

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(x); } }
fn main() {

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(x); } }
fn main() {

View File

@ -1,6 +1,8 @@
// xfail-fast - check-fast doesn't understand aux-build
// aux-build:cci_iter_lib.rs
#[legacy_modes];
extern mod cci_iter_lib;
fn main() {

View File

@ -1,6 +1,8 @@
// xfail-fast - check-fast doesn't understand aux-build
// aux-build:cci_nested_lib.rs
#[legacy_modes];
extern mod cci_nested_lib;
use cci_nested_lib::*;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
use std::map::*;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
trait noisy {
fn speak();
}
@ -56,4 +58,4 @@ fn main() {
assert(!nyan.eat());
for uint::range(1u, 10u) |_i| { make_speak(nyan); };
assert(nyan.eat());
}
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn foo(i: int) -> int { i + 1 }
fn apply<A>(f: fn(A) -> A, v: A) -> A { f(v) }

View File

@ -1,7 +1,7 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, eq: compare<T>) {

View File

@ -1,7 +1,7 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, eq: compare<T>) {

View File

@ -1,7 +1,6 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, eq: compare<T>) {

View File

@ -1,7 +1,6 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, eq: compare<T>) {

View File

@ -1,7 +1,6 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, eq: compare<T>) {

View File

@ -1,8 +1,7 @@
// -*- rust -*-
#[legacy_modes];
// Tests for standalone blocks as expressions with dynamic type sizes
type compare<T> = fn@(T, T) -> bool;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn f(arg: {mut a: int}) {
arg.a = 100;
}

View File

@ -1,7 +1,6 @@
// -*- rust -*-
#[legacy_modes];
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: Copy>(expected: T, not_expected: T, eq: compare<T>) {

View File

@ -1,7 +1,5 @@
// -*- rust -*-
#[legacy_modes];
// Tests for if as expressions with dynamic type sizes
type compare<T> = fn@(T, T) -> bool;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn fix_help<A, B>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
return f({|a|fix_help(f, a)}, x);
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn fix_help<A: Owned, B: Send>(f: extern fn(fn@(A) -> B, A) -> B, x: A) -> B {
return f({|a|fix_help(f, a)}, x);
}

View File

@ -1,4 +1,5 @@
// This is what the signature to spawn should look like with bare functions
#[legacy_modes];
fn spawn<T: Send>(val: T, f: extern fn(T)) {
f(val);
@ -10,4 +11,4 @@ fn f(&&i: int) {
fn main() {
spawn(100, f);
}
}

View File

@ -1,4 +1,4 @@
#[legacy_modes];
fn mk() -> int { return 1; }

View File

@ -1,3 +1,4 @@
#[legacy_modes];
#[abi = "rust-intrinsic"]
extern mod rusti {
fn frame_address(f: fn(*u8));

View File

@ -2,6 +2,8 @@
// However, the condition it was testing seemed complex enough to
// warrant still having a test, so I inlined the old definitions.
#[legacy_modes];
trait iterable<A> {
fn iter(blk: fn(A));
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
use iter::BaseIter;
trait FlatMapToVec<A> {
@ -10,4 +12,4 @@ impl<A:Copy> BaseIter<A>: FlatMapToVec<A> {
}
}
fn main() {}
fn main() {}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn main() {
// Make sure closing over can be a last use
let q = ~10;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
trait vec_monad<A> {
fn bind<B: Copy>(f: fn(A) -> ~[B]) -> ~[B];
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
struct Point {
x: int,
y: int

View File

@ -1,3 +1,4 @@
#[legacy_modes];
use intrinsic::{TyDesc, get_tydesc, visit_tydesc, TyVisitor};
use libc::c_void;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn region_identity(x: &r/uint) -> &r/uint { x }
fn apply<T>(t: T, f: fn(T) -> T) -> T { f(t) }
@ -12,4 +14,4 @@ fn parameterized(x: &uint) -> uint {
fn main() {
let x = 3u;
assert parameterized(&x) == 3u;
}
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
struct finish<T: Copy> {
arg: {val: T, fin: extern fn(T)},
drop { self.arg.fin(self.arg.val); }

View File

@ -1,3 +1,5 @@
#[legacy_modes];
use cmp::Eq;
fn iter<T>(v: ~[T], it: fn(T) -> bool) {

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
use comm::Chan;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn test(f: fn(uint) -> uint) -> uint {
return f(22u);
}
@ -5,4 +7,4 @@ fn test(f: fn(uint) -> uint) -> uint {
fn main() {
let y = test(fn~(x: uint) -> uint { return 4u * x; });
assert y == 88u;
}
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
use a::*;
trait plus {

View File

@ -1,3 +1,4 @@
#[legacy_modes];
// A trait for objects that can be used to do an if-then-else
// (No actual need for this to be static, but it is a simple test.)

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
use pipes::Chan;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
fn start(c: pipes::Chan<pipes::Chan<~str>>) {

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
fn start(c: pipes::Chan<pipes::Chan<int>>) {

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
use pipes::send;

View File

@ -1,3 +1,4 @@
#[legacy_modes];
fn main() {
let po = pipes::PortSet();

View File

@ -1,4 +1,6 @@
// xfail-win32
#[legacy_modes];
extern mod std;
fn start(c: pipes::Chan<int>, i0: int) {

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
use pipes::Chan;
use pipes::send;

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
fn main() { test00(); }

View File

@ -1,3 +1,5 @@
#[legacy_modes];
extern mod std;
fn main() { test00(); }

View File

@ -1,3 +1,5 @@
#[legacy_modes];
trait to_str {
fn to_str() -> ~str;
}

View File

@ -1,3 +1,5 @@
#[legacy_modes];
fn p_foo<T>(pinned: T) { }
fn s_foo<T: Copy>(shared: T) { }
fn u_foo<T: Send>(unique: T) { }