about summary refs log tree commit diff
path: root/src/comp/front
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-06-07 11:20:51 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-06-09 13:11:29 +0200
commitbeda82ddf1f482f286a8d9af3402626dc56d6fea (patch)
treeb45a66e9755745a4991365627e142d7da90d56ca /src/comp/front
parent43fbb071261113a87dec53c3b923d3cbf71189bd (diff)
A revised, improved alias-checker
The old system tried to ensure that the location an alias pointed at
would retain its type. That turned out to not be strong enough in the
face of aliases to the inside of tags.

The new system instead proves that values pointed to by aliases are
not replaced (or invalidated in some other way) at all. It knows of
two sufficient conditions for this, and tries to prove at least of
them:

A) The alias is 'immutably rooted' in a local, and this local is not
   reassigned for the lifetime of the alias. Immutably rooted means
   the alias refers to the local itself, or to something reachable
   from the local through immutable dereferencing.

B) No value whose type might include the type of the 'inner mutable
   element' of the thing the alias refers to (for example, the box in
   rec(mutable x = @mutable int)) is from the outer scope is accessed
   for the lifetime of the alias. This means for functions, no other
   argument types may include the alias's inner mutable type. For alt,
   for each, and for, it means the body does not refer to any locals
   originating from outside their scope that include this type.

The lifetime of an alias in an alt, for each, or for body is defined
as the range from its definition to its last use, not to the point
where it goes out of scope. This makes working around these
restrictions somewhat less annoying. For example, you can assign to
your alt-ed value you don't refer to any bindings afterwards.
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 4f83ee7fa8d..fce15a556c6 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -11,6 +11,10 @@ type ident = str;
 type path_ = rec(vec[ident] idents, vec[@ty] types);
 type path = spanned[path_];
 
+fn path_name(&path p) -> str {
+    ret str::connect(p.node.idents, "::");
+}
+
 type crate_num = int;
 const crate_num local_crate = 0;
 type def_num = int;