Permalink
Browse files

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

  • Loading branch information...
1 parent d53cfd2 commit e653d493fb8df74bd0583c4f32c882a590135ef1 @pcwalton pcwalton committed Sep 18, 2012
Showing with 179 additions and 40 deletions.
  1. +2 −0 src/fuzzer/fuzzer.rc
  2. +2 −0 src/libcore/core.rc
  3. +2 −0 src/libstd/std.rc
  4. +2 −0 src/libsyntax/syntax.rc
  5. +1 −1 src/rustc/driver/driver.rs
  6. +1 −0 src/rustc/driver/rustc.rs
  7. +8 −1 src/rustc/middle/lint.rs
  8. +23 −4 src/rustc/middle/ty.rs
  9. +2 −1 src/rustc/middle/typeck/astconv.rs
  10. +1 −1 src/rustc/middle/typeck/check/writeback.rs
  11. +2 −0 src/rustc/rustc.rc
  12. +1 −1 src/rustc/util/ppaux.rs
  13. +2 −0 src/rustdoc/rustdoc.rc
  14. +1 −0 src/test/auxiliary/cci_iter_lib.rs
  15. +3 −1 src/test/auxiliary/cci_nested_lib.rs
  16. +2 −0 src/test/bench/graph500-bfs.rs
  17. +2 −0 src/test/bench/msgsend-pipes-shared.rs
  18. +2 −0 src/test/bench/msgsend-pipes.rs
  19. +2 −0 src/test/bench/shootout-k-nucleotide-pipes.rs
  20. +2 −0 src/test/bench/shootout-mandelbrot.rs
  21. +2 −0 src/test/bench/shootout-pfib.rs
  22. +2 −0 src/test/bench/task-perf-word-count-generic.rs
  23. +4 −0 src/test/compile-fail/borrowck-unchecked-with-borrow.rs
  24. +2 −0 src/test/compile-fail/fn-variance-1.rs
  25. +2 −0 src/test/compile-fail/issue-2587-2.rs
  26. +2 −0 src/test/compile-fail/mode-inference-fail.rs
  27. +3 −1 src/test/compile-fail/pure-higher-order.rs
  28. +3 −1 src/test/compile-fail/regions-creating-enums.rs
  29. +2 −0 src/test/run-pass-fulldeps/qquote.rs
  30. +2 −0 src/test/run-pass/argument-passing.rs
  31. +2 −0 src/test/run-pass/assignability-trait.rs
  32. +2 −0 src/test/run-pass/auto_serialize.rs
  33. +2 −0 src/test/run-pass/block-iter-1.rs
  34. +2 −0 src/test/run-pass/block-iter-2.rs
  35. +2 −0 src/test/run-pass/cci_iter_exe.rs
  36. +2 −0 src/test/run-pass/cci_nested_exe.rs
  37. +2 −0 src/test/run-pass/class-impl-very-parameterized-trait.rs
  38. +3 −1 src/test/run-pass/class-implement-traits.rs
  39. +2 −0 src/test/run-pass/closure-inference.rs
  40. +2 −2 src/test/run-pass/expr-alt-generic-box2.rs
  41. +2 −2 src/test/run-pass/expr-alt-generic-unique2.rs
  42. +2 −3 src/test/run-pass/expr-alt-generic.rs
  43. +2 −3 src/test/run-pass/expr-block-generic-box2.rs
  44. +2 −3 src/test/run-pass/expr-block-generic-unique2.rs
  45. +2 −3 src/test/run-pass/expr-block-generic.rs
  46. +2 −0 src/test/run-pass/expr-copy.rs
  47. +2 −3 src/test/run-pass/expr-if-generic-box2.rs
  48. +1 −3 src/test/run-pass/expr-if-generic.rs
  49. +2 −0 src/test/run-pass/fixed-point-bind-box.rs
  50. +2 −0 src/test/run-pass/fixed-point-bind-unique.rs
  51. +2 −1 src/test/run-pass/fn-bare-spawn.rs
  52. +1 −1 src/test/run-pass/generic-temporary.rs
  53. +1 −0 src/test/run-pass/intrinsic-frame-address.rs
  54. +2 −0 src/test/run-pass/issue-2185.rs
  55. +3 −1 src/test/run-pass/issue-2611.rs
  56. +2 −0 src/test/run-pass/last-use-corner-cases.rs
  57. +2 −0 src/test/run-pass/monad.rs
  58. +2 −0 src/test/run-pass/operator-overloading.rs
  59. +1 −0 src/test/run-pass/reflect-visit-data.rs
  60. +3 −1 src/test/run-pass/regions-params.rs
  61. +2 −0 src/test/run-pass/resource-generic.rs
  62. +2 −0 src/test/run-pass/ret-break-cont-in-block.rs
  63. +2 −0 src/test/run-pass/sendfn-generic-fn.rs
  64. +3 −1 src/test/run-pass/sendfn-is-a-block.rs
  65. +2 −0 src/test/run-pass/static-impl.rs
  66. +1 −0 src/test/run-pass/static-method-test.rs
  67. +2 −0 src/test/run-pass/task-comm-0.rs
  68. +2 −0 src/test/run-pass/task-comm-10.rs
  69. +2 −0 src/test/run-pass/task-comm-11.rs
  70. +2 −0 src/test/run-pass/task-comm-13.rs
  71. +1 −0 src/test/run-pass/task-comm-14.rs
  72. +2 −0 src/test/run-pass/task-comm-15.rs
  73. +2 −0 src/test/run-pass/task-comm-3.rs
  74. +2 −0 src/test/run-pass/task-comm-7.rs
  75. +2 −0 src/test/run-pass/task-comm-9.rs
  76. +2 −0 src/test/run-pass/trait-generic.rs
  77. +2 −0 src/test/run-pass/type-param-constraints.rs
View
@@ -4,6 +4,8 @@
#[no_core];
+#[legacy_modes];
+
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];
View
@@ -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
@@ -10,6 +10,8 @@
#[no_core];
+#[legacy_modes];
+
#[allow(vecs_implicitly_copyable)];
#[deny(non_camel_case_types)];
View
@@ -8,6 +8,8 @@
#[no_core];
+#[legacy_modes];
+
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];
@@ -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,
@@ -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
@@ -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
@@ -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
@@ -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,
@@ -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
@@ -11,6 +11,8 @@
#[no_core];
+#[legacy_modes];
+
#[allow(vecs_implicitly_copyable)];
#[allow(non_camel_case_types)];
// #[warn(deprecated_pattern)];
View
@@ -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
@@ -11,6 +11,8 @@
#[no_core];
+#[legacy_modes];
+
#[allow(vecs_implicitly_copyable,
non_implicitly_copyable_typarams)];
#[allow(non_camel_case_types)];
@@ -1,4 +1,5 @@
#[link(name="cci_iter_lib", vers="0.0")];
+#[legacy_modes];
#[inline]
fn iter<T>(v: ~[T], f: fn(T)) {
@@ -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()};
-}
+}
@@ -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;
@@ -10,6 +10,8 @@
// xfail-pretty
+#[legacy_modes];
+
extern mod std;
use io::Writer;
use io::WriterUtil;
@@ -6,6 +6,8 @@
// xfail-pretty
+#[legacy_modes];
+
extern mod std;
use io::Writer;
use io::WriterUtil;
@@ -2,6 +2,8 @@
// multi tasking k-nucleotide
+#[legacy_modes];
+
extern mod std;
use std::map;
use std::map::HashMap;
@@ -12,6 +12,8 @@
//
// writes pbm image to output path
+#[legacy_modes];
+
extern mod std;
use io::WriterUtil;
use std::map::HashMap;
@@ -10,6 +10,8 @@
*/
+#[legacy_modes];
+
extern mod std;
use std::{time, getopts};
@@ -10,6 +10,8 @@
// xfail-pretty
+#[legacy_modes];
+
extern mod std;
use option = option;
@@ -1,3 +1,7 @@
+// xfail-test
+// xfail-fast
+#[legacy_modes];
+
fn impure(_i: int) {}
// check that unchecked alone does not override borrowck:
@@ -1,3 +1,5 @@
+#[legacy_modes];
+
fn takes_mut(&&x: @mut int) { }
fn takes_const(&&x: @const int) { }
fn takes_imm(&&x: @int) { }
@@ -1,3 +1,5 @@
+#[legacy_modes];
+
fn foo<T: Copy>(+_t: T) { fail; }
fn bar<T>(+_t: T) { fail; }
@@ -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().
@@ -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() {
-}
+}
@@ -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() {}
@@ -1,5 +1,7 @@
// xfail-pretty
+#[legacy_modes];
+
extern mod std;
extern mod syntax;
@@ -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;
@@ -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);
}
@@ -1,3 +1,5 @@
+#[legacy_modes];
+
extern mod std;
// These tests used to be separate files, but I wanted to refactor all
@@ -1,3 +1,5 @@
+#[legacy_modes];
+
fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(x); } }
fn main() {
@@ -1,3 +1,5 @@
+#[legacy_modes];
+
fn iter_vec<T>(v: ~[T], f: fn(T)) { for v.each |x| { f(x); } }
fn main() {
@@ -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() {
@@ -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::*;
@@ -1,3 +1,5 @@
+#[legacy_modes];
+
extern mod std;
use std::map::*;
@@ -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());
-}
+}
Oops, something went wrong.

0 comments on commit e653d49

Please sign in to comment.