Skip to content

Commit 7f6ee0c

Browse files
committed
remove alias analysis and replace with borrowck
cc #2540
1 parent 8c6d439 commit 7f6ee0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+31
-1134
lines changed

doc/tutorial.md

+1-77
Original file line numberDiff line numberDiff line change
@@ -1382,83 +1382,7 @@ gets access to them.
13821382

13831383
## Safe references
13841384

1385-
There is one catch with this approach: sometimes the compiler can
1386-
*not* statically guarantee that the argument value at the caller side
1387-
will survive to the end of the call. Another argument might indirectly
1388-
refer to it and be used to overwrite it, or a closure might assign a
1389-
new value to it.
1390-
1391-
Fortunately, Rust tasks are single-threaded worlds, which share no
1392-
data with other tasks, and most data is immutable. This allows most
1393-
argument-passing situations to be proved safe without further
1394-
difficulty.
1395-
1396-
Take the following program:
1397-
1398-
~~~~
1399-
# fn get_really_big_record() -> int { 1 }
1400-
# fn myfunc(a: int) {}
1401-
fn main() {
1402-
let x = get_really_big_record();
1403-
myfunc(x);
1404-
}
1405-
~~~~
1406-
1407-
Here we know for sure that no one else has access to the `x` variable
1408-
in `main`, so we're good. But the call could also look like this:
1409-
1410-
~~~~
1411-
# fn myfunc(a: int, b: fn()) {}
1412-
# fn get_another_record() -> int { 1 }
1413-
# let mut x = 1;
1414-
myfunc(x, {|| x = get_another_record(); });
1415-
~~~~
1416-
1417-
Now, if `myfunc` first calls its second argument and then accesses its
1418-
first argument, it will see a different value from the one that was
1419-
passed to it.
1420-
1421-
In such a case, the compiler will insert an implicit copy of `x`,
1422-
*except* if `x` contains something mutable, in which case a copy would
1423-
result in code that behaves differently. If copying `x` might be
1424-
expensive (for example, if it holds a vector), the compiler will emit
1425-
a warning.
1426-
1427-
There are even more tricky cases, in which the Rust compiler is forced
1428-
to pessimistically assume a value will get mutated, even though it is
1429-
not sure.
1430-
1431-
~~~~
1432-
fn for_each(v: [mut @int], iter: fn(@int)) {
1433-
for v.each {|elt| iter(elt); }
1434-
}
1435-
~~~~
1436-
1437-
For all this function knows, calling `iter` (which is a closure that
1438-
might have access to the vector that's passed as `v`) could cause the
1439-
elements in the vector to be mutated, with the effect that it can not
1440-
guarantee that the boxes will live for the duration of the call. So it
1441-
has to copy them. In this case, this will happen implicitly (bumping a
1442-
reference count is considered cheap enough to not warn about it).
1443-
1444-
## The copy operator
1445-
1446-
If the `for_each` function given above were to take a vector of
1447-
`{mut a: int}` instead of `@int`, it would not be able to
1448-
implicitly copy, since if the `iter` function changes a copy of a
1449-
mutable record, the changes won't be visible in the record itself. If
1450-
we *do* want to allow copies there, we have to explicitly allow it
1451-
with the `copy` operator:
1452-
1453-
~~~~
1454-
type mutrec = {mut x: int};
1455-
fn for_each(v: [mut mutrec], iter: fn(mutrec)) {
1456-
for v.each {|elt| iter(copy elt); }
1457-
}
1458-
~~~~
1459-
1460-
Adding a `copy` operator is also the way to muffle warnings about
1461-
implicit copies.
1385+
*This system has recently changed. An explanantion is forthcoming.*
14621386

14631387
## Other uses of safe references
14641388

src/rustc/driver/driver.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
204204
let (root_map, mutbl_map) = time(
205205
time_passes, "borrow checking",
206206
bind middle::borrowck::check_crate(ty_cx, method_map, crate));
207-
let (copy_map, _ref_map) =
208-
time(time_passes, "alias checking",
209-
bind middle::alias::check_crate(ty_cx, crate));
210207
time(time_passes, "kind checking",
211208
bind kind::check_crate(ty_cx, method_map, last_use_map, crate));
212209
time(time_passes, "lint checking",
@@ -216,7 +213,7 @@ fn compile_upto(sess: session, cfg: ast::crate_cfg,
216213
let outputs = option::get(outputs);
217214

218215
let maps = {mutbl_map: mutbl_map, root_map: root_map,
219-
copy_map: copy_map, last_use_map: last_use_map,
216+
last_use_map: last_use_map,
220217
impl_map: impl_map, method_map: method_map,
221218
vtable_map: vtable_map};
222219

@@ -448,14 +445,6 @@ fn build_session_options(match: getopts::match,
448445
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
449446
let target_opt = getopts::opt_maybe_str(match, "target");
450447
let save_temps = getopts::opt_present(match, "save-temps");
451-
let borrowck = alt getopts::opt_maybe_str(match, "borrowck") {
452-
none { 0u }
453-
some("warn") { 1u }
454-
some("err") { 2u }
455-
some(_) {
456-
early_error(demitter, "borrowck may be warn or err")
457-
}
458-
};
459448
alt output_type {
460449
// unless we're emitting huamn-readable assembly, omit comments.
461450
link::output_type_llvm_assembly | link::output_type_assembly {}
@@ -504,8 +493,7 @@ fn build_session_options(match: getopts::match,
504493
test: test,
505494
parse_only: parse_only,
506495
no_trans: no_trans,
507-
debugging_opts: debugging_opts,
508-
borrowck: borrowck};
496+
debugging_opts: debugging_opts};
509497
ret sopts;
510498
}
511499

@@ -582,8 +570,7 @@ fn opts() -> [getopts::opt] {
582570
optmulti("Z"),
583571

584572
optmulti("cfg"), optflag("test"),
585-
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc"),
586-
optopt("borrowck")];
573+
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc")];
587574
}
588575

589576
type output_filenames = @{out_filename: str, obj_filename:str};

src/rustc/driver/session.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ type options =
6666
no_trans: bool,
6767

6868
debugging_opts: uint,
69-
70-
// temporary hack: 0=off,1=warn,2=err --> if 2, alias is disabled
71-
borrowck: uint,
7269
};
7370

7471
type crate_metadata = {name: str, data: [u8]};
@@ -181,8 +178,7 @@ fn basic_options() -> @options {
181178
test: false,
182179
parse_only: false,
183180
no_trans: false,
184-
debugging_opts: 0u,
185-
borrowck: 0u,
181+
debugging_opts: 0u
186182
}
187183
}
188184

src/rustc/metadata/common.rs

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ enum astencode_tag { // Reserves 0x50 -- 0x6f
116116
tag_table_param_bounds,
117117
tag_table_inferred_modes,
118118
tag_table_mutbl,
119-
tag_table_copy,
120119
tag_table_last_use,
121120
tag_table_spill,
122121
tag_table_method_map,

0 commit comments

Comments
 (0)