Skip to content

Commit

Permalink
add mut decls to rustc and make them mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Mar 22, 2012
1 parent d7be4ab commit b653a18
Show file tree
Hide file tree
Showing 70 changed files with 956 additions and 924 deletions.
6 changes: 4 additions & 2 deletions mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X): \
$$(RUSTC_INPUTS) \
$$(TLIBRUSTC_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$<
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
-o $$@ $$<

$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
$$(COMPILER_CRATE) $$(COMPILER_INPUTS) \
Expand All @@ -62,7 +63,8 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
$$(TCORELIB_DEFAULT$(1)_T_$(2)_H_$(3)) \
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< && touch $$@
$$(STAGE$(1)_T_$(2)_H_$(3)) $$(ENFORCE_MUT_VARS_$(1)) \
-o $$@ $$< && touch $$@

endef

Expand Down
29 changes: 15 additions & 14 deletions src/rustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod write {
let opts = sess.opts;
if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); }
link_intrinsics(sess, llmod);
let pm = mk_pass_manager();
let mut pm = mk_pass_manager();
let td = mk_target_data(
sess.targ_cfg.target_strs.data_layout);
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
Expand Down Expand Up @@ -165,7 +165,7 @@ mod write {
llvm::LLVMPassManagerBuilderDispose(FPMB);

llvm::LLVMRunPassManager(fpm.llpm, llmod);
let threshold = 225u;
let mut threshold = 225u;
if opts.optimize == 3u { threshold = 275u; }

let MPMB = llvm::LLVMPassManagerBuilderCreate();
Expand Down Expand Up @@ -195,15 +195,15 @@ mod write {
let LLVMOptDefault = 2 as c_int; // -O2, -Os
let LLVMOptAggressive = 3 as c_int; // -O3

let CodeGenOptLevel;
let mut CodeGenOptLevel;
alt check opts.optimize {
0u { CodeGenOptLevel = LLVMOptNone; }
1u { CodeGenOptLevel = LLVMOptLess; }
2u { CodeGenOptLevel = LLVMOptDefault; }
3u { CodeGenOptLevel = LLVMOptAggressive; }
}

let FileType;
let mut FileType;
if opts.output_type == output_type_object ||
opts.output_type == output_type_exe {
FileType = LLVMObjectFile;
Expand Down Expand Up @@ -362,9 +362,9 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,

fn provided_link_metas(sess: session, c: ast::crate) ->
provided_metas {
let name: option<str> = none;
let vers: option<str> = none;
let cmh_items: [@ast::meta_item] = [];
let mut name: option<str> = none;
let mut vers: option<str> = none;
let mut cmh_items: [@ast::meta_item] = [];
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
attr::require_unique_names(sess, linkage_metas);
for meta: @ast::meta_item in linkage_metas {
Expand Down Expand Up @@ -433,7 +433,8 @@ fn build_link_meta(sess: session, c: ast::crate, output: str,
none {
let name =
{
let os = str::split_char(path::basename(output), '.');
let mut os =
str::split_char(path::basename(output), '.');
if (vec::len(os) < 2u) {
sess.fatal(#fmt("output file name %s doesn't\
appear to have an extension", output));
Expand Down Expand Up @@ -494,7 +495,7 @@ fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: link_meta) ->
}

fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str {
let hash = "";
let mut hash = "";
alt ccx.type_sha1s.find(t) {
some(h) { hash = h; }
none {
Expand All @@ -509,7 +510,7 @@ fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str {
// Name sanitation. LLVM will happily accept identifiers with weird names, but
// gas doesn't!
fn sanitize(s: str) -> str {
let result = "";
let mut result = "";
str::chars_iter(s) {|c|
alt c {
'@' { result += "_sbox_"; }
Expand All @@ -536,7 +537,7 @@ fn sanitize(s: str) -> str {
fn mangle(ss: path) -> str {
// Follow C++ namespace-mangling style

let n = "_ZN"; // Begin name-sequence.
let mut n = "_ZN"; // Begin name-sequence.

for s in ss {
alt s { path_name(s) | path_mod(s) {
Expand Down Expand Up @@ -597,7 +598,7 @@ fn link_binary(sess: session,
} else { ret filename; }
};
fn rmext(filename: str) -> str {
let parts = str::split_char(filename, '.');
let mut parts = str::split_char(filename, '.');
vec::pop(parts);
ret str::connect(parts, ".");
}
Expand Down Expand Up @@ -636,11 +637,11 @@ fn link_binary(sess: session,
if sess.targ_cfg.os == session::os_win32 { "gcc" } else { "cc" };
// The invocations of cc share some flags across platforms

let cc_args =
let mut cc_args =
[stage] + sess.targ_cfg.target_strs.cc_args +
["-o", output, obj_filename];

let lib_cmd;
let mut lib_cmd;
let os = sess.targ_cfg.os;
if os == session::os_macos {
lib_cmd = "-dynamiclib";
Expand Down
7 changes: 3 additions & 4 deletions src/rustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,13 @@ fn get_relative_to(abs1: path::path, abs2: path::path) -> path::path {
assert len2 > 0u;

let max_common_path = uint::min(len1, len2) - 1u;
let start_idx = 0u;
let mut start_idx = 0u;
while start_idx < max_common_path
&& split1[start_idx] == split2[start_idx] {
start_idx += 1u;
}

let path = [];

let mut path = [];
uint::range(start_idx, len1 - 1u) {|_i| path += [".."]; };

path += vec::slice(split2, start_idx, len2 - 1u);
Expand Down Expand Up @@ -179,7 +178,7 @@ fn get_install_prefix_rpath(cwd: path::path, target_triple: str) -> str {

fn minimize_rpaths(rpaths: [str]) -> [str] {
let set = map::str_hash::<()>();
let minimized = [];
let mut minimized = [];
for rpath in rpaths {
if !set.contains_key(rpath) {
minimized += [rpath];
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/back/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn declare_upcalls(targ_cfg: @session::config,
fn decl(llmod: ModuleRef, prefix: str, name: str,
tys: [TypeRef], rv: TypeRef) ->
ValueRef {
let arg_tys: [TypeRef] = [];
let mut arg_tys: [TypeRef] = [];
for t: TypeRef in tys { arg_tys += [t]; }
let fn_ty = T_fn(arg_tys, rv);
ret base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
Expand Down
18 changes: 9 additions & 9 deletions src/rustc/driver/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ fn highlight_lines(cm: codemap::codemap, sp: span,

// arbitrarily only print up to six lines of the error
let max_lines = 6u;
let elided = false;
let display_lines = lines.lines;
let mut elided = false;
let mut display_lines = lines.lines;
if vec::len(display_lines) > max_lines {
display_lines = vec::slice(display_lines, 0u, max_lines);
elided = true;
Expand All @@ -210,8 +210,8 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
if elided {
let last_line = display_lines[vec::len(display_lines) - 1u];
let s = #fmt["%s:%u ", fm.name, last_line + 1u];
let indent = str::len(s);
let out = "";
let mut indent = str::len(s);
let mut out = "";
while indent > 0u { out += " "; indent -= 1u; }
out += "...\n";
io::stderr().write_str(out);
Expand All @@ -221,22 +221,22 @@ fn highlight_lines(cm: codemap::codemap, sp: span,
// If there's one line at fault we can easily point to the problem
if vec::len(lines.lines) == 1u {
let lo = codemap::lookup_char_pos(cm, sp.lo);
let digits = 0u;
let num = (lines.lines[0] + 1u) / 10u;
let mut digits = 0u;
let mut num = (lines.lines[0] + 1u) / 10u;

// how many digits must be indent past?
while num > 0u { num /= 10u; digits += 1u; }

// indent past |name:## | and the 0-offset column location
let left = str::len(fm.name) + digits + lo.col + 3u;
let s = "";
let mut left = str::len(fm.name) + digits + lo.col + 3u;
let mut s = "";
while left > 0u { str::push_char(s, ' '); left -= 1u; }

s += "^";
let hi = codemap::lookup_char_pos(cm, sp.hi);
if hi.col != lo.col {
// the ^ already takes up one space
let width = hi.col - lo.col - 1u;
let mut width = hi.col - lo.col - 1u;
while width > 0u { str::push_char(s, '~'); width -= 1u; }
}
io::stderr().write_str(s + "\n");
Expand Down
16 changes: 8 additions & 8 deletions src/rustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn build_configuration(sess: session, argv0: str, input: str) ->
fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg {
// FIXME: It would be nice to use the parser to parse all varieties of
// meta_item here. At the moment we just support the meta_word variant.
let words = [];
let mut words = [];
for s: str in cfgspecs { words += [attr::mk_word_item(s)]; }
ret words;
}
Expand Down Expand Up @@ -106,8 +106,8 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
outputs: option<output_filenames>)
-> {crate: @ast::crate, tcx: option<ty::ctxt>} {
let time_passes = sess.opts.time_passes;
let crate = time(time_passes, "parsing",
bind parse_input(sess, cfg, input));
let mut crate = time(time_passes, "parsing",
bind parse_input(sess, cfg, input));
if upto == cu_parse { ret {crate: crate, tcx: none}; }

sess.building_library = session::building_library(
Expand Down Expand Up @@ -261,7 +261,7 @@ fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: str,
};
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);

let ann: pprust::pp_ann = pprust::no_ann();
let mut ann: pprust::pp_ann = pprust::no_ann();
alt ppm {
ppm_typed {
ann = {pre: ann_paren_for_expr,
Expand Down Expand Up @@ -362,7 +362,7 @@ fn build_session_options(match: getopts::match,

let parse_only = opt_present(match, "parse-only");
let no_trans = opt_present(match, "no-trans");
let lint_opts = [];
let mut lint_opts = [];
if opt_present(match, "no-lint-ctypes") {
lint_opts += [(lint::ctypes, false)];
}
Expand All @@ -388,7 +388,7 @@ fn build_session_options(match: getopts::match,
let time_llvm_passes = opt_present(match, "time-llvm-passes");
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
let target_opt = getopts::opt_maybe_str(match, "target");
let no_asm_comments = getopts::opt_present(match, "no-asm-comments");
let mut no_asm_comments = getopts::opt_present(match, "no-asm-comments");
alt output_type {
// unless we're emitting huamn-readable assembly, omit comments.
link::output_type_llvm_assembly | link::output_type_assembly {}
Expand Down Expand Up @@ -531,8 +531,8 @@ fn build_output_filenames(ifile: str,
ofile: option<str>,
sess: session)
-> output_filenames {
let obj_path = "";
let out_path: str = "";
let mut obj_path = "";
let mut out_path: str = "";
let sopts = sess.opts;
let stop_after_codegen =
sopts.output_type != link::output_type_exe ||
Expand Down
5 changes: 3 additions & 2 deletions src/rustc/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import rustc::syntax::codemap;
import rustc::driver::diagnostic;

fn version(argv0: str) {
let vers = "unknown version";
let mut vers = "unknown version";
let env_vers = #env["CFG_VERSION"];
if str::len(env_vers) != 0u { vers = env_vers; }
io::stdout().write_str(#fmt["%s %s\n", argv0, vers]);
Expand Down Expand Up @@ -73,7 +73,8 @@ fn run_compiler(args: [str], demitter: diagnostic::emitter) {
// Don't display log spew by default. Can override with RUST_LOG.
logging::console_off();

let args = args, binary = vec::shift(args);
let mut args = args;
let binary = vec::shift(args);

if vec::len(args) == 0u { usage(binary); ret; }

Expand Down
8 changes: 4 additions & 4 deletions src/rustc/front/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export native_abi;
// From a list of crate attributes get only the meta_items that impact crate
// linkage
fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
let metas: [@ast::meta_item] = [];
let mut metas: [@ast::meta_item] = [];
for attr: ast::attribute in find_attrs_by_name(attrs, "link") {
alt attr.node.value.node {
ast::meta_list(_, items) { metas += items; }
Expand Down Expand Up @@ -141,7 +141,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }

// Get the meta_items from inside a vector of attributes
fn attr_metas(attrs: [ast::attribute]) -> [@ast::meta_item] {
let mitems = [];
let mut mitems = [];
for a: ast::attribute in attrs { mitems += [attr_meta(a)]; }
ret mitems;
}
Expand Down Expand Up @@ -198,12 +198,12 @@ fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] {
}

// This is sort of stupid here, converting to a vec of mutables and back
let v: [mutable @ast::meta_item] = [mutable];
let mut v: [mutable @ast::meta_item] = [mutable];
for mi: @ast::meta_item in items { v += [mutable mi]; }

std::sort::quick_sort(lteq, v);

let v2: [@ast::meta_item] = [];
let mut v2: [@ast::meta_item] = [];
for mi: @ast::meta_item in v { v2 += [mi]; }
ret v2;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {

fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
#debug("building test vector from %u tests", vec::len(cx.testfns));
let descs = [];
let mut descs = [];
for test: test in cx.testfns {
let test_ = test; // Satisfy alias analysis
descs += [mk_test_desc_rec(cx, test_)];
Expand Down
10 changes: 5 additions & 5 deletions src/rustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,8 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
let kind: int = llvm::LLVMGetTypeKind(ty) as int;

fn tys_str(names: type_names, outer: [TypeRef], tys: [TypeRef]) -> str {
let s: str = "";
let first: bool = true;
let mut s: str = "";
let mut first: bool = true;
for t: TypeRef in tys {
if first { first = false; } else { s += ", "; }
s += type_to_str_inner(names, outer, t);
Expand All @@ -989,7 +989,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
ret "i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
}
9 {
let s = "fn(";
let mut s = "fn(";
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
let args: [TypeRef] = vec::from_elem::<TypeRef>(n_args, 0 as TypeRef);
Expand All @@ -1002,7 +1002,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
ret s;
}
10 {
let s: str = "{";
let mut s: str = "{";
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
let elts: [TypeRef] = vec::from_elem::<TypeRef>(n_elts, 0 as TypeRef);
unsafe {
Expand All @@ -1018,7 +1018,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
uint::str(llvm::LLVMGetArrayLength(ty) as uint) + "]";
}
12 {
let i: uint = 0u;
let mut i: uint = 0u;
for tout: TypeRef in outer0 {
i += 1u;
if tout as int == ty as int {
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ enum astencode_tag { // Reserves 0x50 -- 0x6f
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }

fn hash_path(&&s: str) -> uint {
let h = 5381u;
let mut h = 5381u;
for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
ret h;
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn visit_item(e: env, i: @ast::item) {
}
none { i.ident }
};
let already_added = false;
let mut already_added = false;
if vec::len(attr::find_attrs_by_name(i.attrs, "nolink")) == 0u {
already_added = !cstore::add_used_library(cstore, native_name);
}
Expand Down
Loading

0 comments on commit b653a18

Please sign in to comment.