Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

librustc: Copy or move upvars by value [breaking-change]. #14620

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1322685
by-value-upvars: update libs to accommodate new by-val closure semant…
pcwalton Jun 2, 2014
35db43c
bench updates post new by-value closure semantics.
pcwalton Jun 2, 2014
a5e1225
Update run-pass tests for new by-value closure semantics.
pcwalton Jun 2, 2014
6a30d5d
Update compiletest driver for new by-value closure semantics.
pcwalton Jun 2, 2014
b52dc68
by-value upvars: Switch rustc from calls to `time(..)` to an RAII Tim…
pnkfelix Jun 2, 2014
50cc68b
Switch rustc from calling `with_c_str(..)` to using RAII CStr via `to…
pcwalton Jun 2, 2014
084a47c
generalize unpack_datum! and unpack_result! macros.
pcwalton Jun 2, 2014
869d60d
eagerly-bind references to pass into by-value closures.
pcwalton Jun 2, 2014
efa9baf
libsyntax: eagerly-bind references to pass into by-value closures.
pcwalton Jun 2, 2014
ec60976
libsyntax: manually copy lambda exprs to accommodate by-val upvars.
pcwalton Jun 2, 2014
5b1441c
libsyntax Eagerly clone some data to accommodate by-value closures.
pcwalton Jun 2, 2014
d61dcfe
librustc Eagerly compute and bind some data to accommodate by-value c…
pcwalton Jun 2, 2014
59ea990
librustc::metadata accommodate by-val closures in filesearch and loader.
pcwalton Jun 2, 2014
f61b4af
librustc/libsyntax whitespace cleanup.
pcwalton Jun 2, 2014
715a0cd
Make RScopes structs non-copyable.
pcwalton Jun 2, 2014
8ad1253
librustc added `clone()` calls to placate new by-value closure changes.
pcwalton Jun 2, 2014
152e018
Update some doc examples to accommodate new by-value upvar closures.
pnkfelix Jun 2, 2014
816a4d3
librustc: Copy or move upvars by value [breaking-change].
pcwalton Jun 2, 2014
b846820
Update compile-fail tests for new by-value closure semantics.
pcwalton Jun 2, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ pub fn make_tests(config: &Config) -> Vec<test::TestDescAndFn> {
let file = file.clone();
debug!("inspecting file {}", file.display());
if is_test(config, &file) {
let t = make_test(config, &file, || {
let file_ptr = &file;
let t = make_test(config, file_ptr, || {
match config.mode {
Codegen => make_metrics_test_closure(config, &file),
_ => make_test_closure(config, &file)
Codegen => make_metrics_test_closure(config, file_ptr),
_ => make_test_closure(config, file_ptr)
}
});
tests.push(t)
Expand Down
96 changes: 55 additions & 41 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,57 +51,71 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut check_stdout = false;
let mut no_prefer_dynamic = false;
let mut no_pretty_expanded = false;
iter_header(testfile, |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns.push(ep),
None => ()
};

if compile_flags.is_none() {
compile_flags = parse_compile_flags(ln);
}

if run_flags.is_none() {
run_flags = parse_run_flags(ln);
}
{
let error_patterns_ptr = &mut error_patterns;
let aux_builds_ptr = &mut aux_builds;
let exec_env_ptr = &mut exec_env;
let compile_flags_ptr = &mut compile_flags;
let run_flags_ptr = &mut run_flags;
let pp_exact_ptr = &mut pp_exact;
let check_lines_ptr = &mut check_lines;
let force_host_ptr = &mut force_host;
let check_stdout_ptr = &mut check_stdout;
let no_prefer_dynamic_ptr = &mut no_prefer_dynamic;
let no_pretty_expanded_ptr = &mut no_pretty_expanded;
iter_header(testfile, |ln| {
match parse_error_pattern(ln) {
Some(ep) => error_patterns_ptr.push(ep),
None => ()
};

if compile_flags_ptr.is_none() {
*compile_flags_ptr = parse_compile_flags(ln);
}

if pp_exact.is_none() {
pp_exact = parse_pp_exact(ln, testfile);
}
if run_flags_ptr.is_none() {
*run_flags_ptr = parse_run_flags(ln);
}

if !force_host {
force_host = parse_force_host(ln);
}
if pp_exact_ptr.is_none() {
*pp_exact_ptr = parse_pp_exact(ln, testfile);
}

if !check_stdout {
check_stdout = parse_check_stdout(ln);
}
if !*force_host_ptr {
*force_host_ptr = parse_force_host(ln);
}

if !no_prefer_dynamic {
no_prefer_dynamic = parse_no_prefer_dynamic(ln);
}
if !*check_stdout_ptr {
*check_stdout_ptr = parse_check_stdout(ln);
}

if !no_pretty_expanded {
no_pretty_expanded = parse_no_pretty_expanded(ln);
}
if !*no_prefer_dynamic_ptr {
*no_prefer_dynamic_ptr = parse_no_prefer_dynamic(ln);
}

match parse_aux_build(ln) {
Some(ab) => { aux_builds.push(ab); }
None => {}
}
if !*no_pretty_expanded_ptr {
*no_pretty_expanded_ptr = parse_no_pretty_expanded(ln);
}

match parse_exec_env(ln) {
Some(ee) => { exec_env.push(ee); }
None => {}
}
match parse_aux_build(ln) {
Some(ab) => { aux_builds_ptr.push(ab); }
None => {}
}

match parse_check_line(ln) {
Some(cl) => check_lines.push(cl),
None => ()
};
match parse_exec_env(ln) {
Some(ee) => { exec_env_ptr.push(ee); }
None => {}
}

true
});
match parse_check_line(ln) {
Some(cl) => check_lines_ptr.push(cl),
None => ()
};

true
});
}

TestProps {
error_patterns: error_patterns,
Expand Down
50 changes: 28 additions & 22 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,32 +627,38 @@ fn parse_debugger_commands(file_path: &Path, debugger_prefix: &str)
let mut check_lines = vec!();
let mut counter = 1;
let mut reader = BufferedReader::new(File::open(file_path).unwrap());
for line in reader.lines() {
match line {
Ok(line) => {
if line.as_slice().contains("#break") {
breakpoint_lines.push(counter);
}

header::parse_name_value_directive(
line.as_slice(),
command_directive.to_string()).map(|cmd| {
commands.push(cmd)
});
{
let breakpoint_lines_ptr = &mut breakpoint_lines;
let commands_ptr = &mut commands;
let check_lines_ptr = &mut check_lines;
for line in reader.lines() {
match line {
Ok(line) => {
if line.as_slice().contains("#break") {
breakpoint_lines_ptr.push(counter);
}

header::parse_name_value_directive(
line.as_slice(),
check_directive.to_string()).map(|cmd| {
check_lines.push(cmd)
});
}
Err(e) => {
fatal(format_strbuf!("Error while parsing debugger commands: \
{}",
e))
header::parse_name_value_directive(
line.as_slice(),
command_directive.to_string()).map(|cmd| {
commands_ptr.push(cmd)
});

header::parse_name_value_directive(
line.as_slice(),
check_directive.to_string()).map(|cmd| {
check_lines_ptr.push(cmd)
});
}
Err(e) => {
fatal(format_strbuf!("Error while parsing debugger commands: \
{}",
e))
}
}
counter += 1;
}
counter += 1;
}

DebuggerCommands {
Expand Down
3 changes: 2 additions & 1 deletion src/doc/guide-container.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ let xs = [1,2,3,4,5];
let mut calls = 0;

{
let calls_ref = &mut calls;
let it = xs.iter().scan((), |_, x| {
calls += 1;
*calls_ref += 1;
if *x < 3 { Some(x) } else { None }});

// the iterator will only yield 1 and 2 before returning None
Expand Down
3 changes: 2 additions & 1 deletion src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,8 @@ access local variables in the enclosing scope.

~~~~
let mut max = 0;
let f = |x: int| if x > max { max = x };
let max_ref = &mut max;
let f = |x: int| if x > *max_ref { *max_ref = x };
for x in [1, 2, 3].iter() {
f(*x);
}
Expand Down
15 changes: 10 additions & 5 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,9 @@ mod tests {
#[bench]
pub fn bench_copy(b: &mut Bencher) {
let arena = TypedArena::new();
let arena_ptr = &arena;
b.iter(|| {
arena.alloc(Point {
arena_ptr.alloc(Point {
x: 1,
y: 2,
z: 3,
Expand All @@ -526,8 +527,9 @@ mod tests {
#[bench]
pub fn bench_copy_old_arena(b: &mut Bencher) {
let arena = Arena::new();
let arena_ptr = &arena;
b.iter(|| {
arena.alloc(|| {
arena_ptr.alloc(|| {
Point {
x: 1,
y: 2,
Expand All @@ -545,8 +547,9 @@ mod tests {
#[test]
pub fn test_noncopy() {
let arena = TypedArena::new();
let arena_ptr = &arena;
for _ in range(0, 100000) {
arena.alloc(Noncopy {
arena_ptr.alloc(Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
});
Expand All @@ -556,8 +559,9 @@ mod tests {
#[bench]
pub fn bench_noncopy(b: &mut Bencher) {
let arena = TypedArena::new();
let arena_ptr = &arena;
b.iter(|| {
arena.alloc(Noncopy {
arena_ptr.alloc(Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
})
Expand All @@ -577,8 +581,9 @@ mod tests {
#[bench]
pub fn bench_noncopy_old_arena(b: &mut Bencher) {
let arena = Arena::new();
let arena_ptr = &arena;
b.iter(|| {
arena.alloc(|| Noncopy {
arena_ptr.alloc(|| Noncopy {
string: "hello world".to_string(),
array: vec!( 1, 2, 3, 4, 5 ),
})
Expand Down
Loading