Skip to content

Commit 1089ffd

Browse files
committed
---
yaml --- r: 149122 b: refs/heads/try2 c: 807def0 h: refs/heads/master v: v3
1 parent ea89fcb commit 1089ffd

File tree

2 files changed

+44
-12
lines changed

2 files changed

+44
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 844eab194063ad6500abe01e7f256140bdba28a3
8+
refs/heads/try2: 807def022a6540dde6727b9a438ea3b0eaafd9b5
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/region.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,42 @@ use syntax::ast_util::{stmt_id};
3636
/**
3737
The region maps encode information about region relationships.
3838
39-
- `scope_map` maps from:
40-
- an expression to the expression or block encoding the maximum
41-
(static) lifetime of a value produced by that expression. This is
42-
generally the innermost call, statement, match, or block.
43-
- a variable or binding id to the block in which that variable is declared.
44-
- `free_region_map` maps from:
45-
- a free region `a` to a list of free regions `bs` such that
46-
`a <= b for all b in bs`
39+
- `scope_map` maps from a scope id to the enclosing scope id; this is
40+
usually corresponding to the lexical nesting, though in the case of
41+
closures the parent scope is the innermost conditinal expression or repeating
42+
block
43+
44+
- `var_map` maps from a variable or binding id to the block in which
45+
that variable is declared.
46+
47+
- `free_region_map` maps from a free region `a` to a list of free
48+
regions `bs` such that `a <= b for all b in bs`
4749
- the free region map is populated during type check as we check
4850
each function. See the function `relate_free_regions` for
4951
more information.
50-
- `temporary_scopes` includes scopes where cleanups for temporaries occur.
51-
These are statements and loop/fn bodies.
52+
53+
- `rvalue_scopes` includes entries for those expressions whose cleanup
54+
scope is larger than the default. The map goes from the expression
55+
id to the cleanup scope id. For rvalues not present in this table,
56+
the appropriate cleanup scope is the innermost enclosing statement,
57+
conditional expression, or repeating block (see `terminating_scopes`).
58+
59+
- `terminating_scopes` is a set containing the ids of each statement,
60+
or conditional/repeating expression. These scopes are calling "terminating
61+
scopes" because, when attempting to find the scope of a temporary, by
62+
default we search up the enclosing scopes until we encounter the
63+
terminating scope. A conditional/repeating
64+
expression is one which is not guaranteed to execute exactly once
65+
upon entering the parent scope. This could be because the expression
66+
only executes conditionally, such as the expression `b` in `a && b`,
67+
or because the expression may execute many times, such as a loop
68+
body. The reason that we distinguish such expressions is that, upon
69+
exiting the parent scope, we cannot statically know how many times
70+
the expression executed, and thus if the expression creates
71+
temporaries we cannot know statically how many such temporaries we
72+
would have to cleanup. Therefore we ensure that the temporaries never
73+
outlast the conditional/repeating expression, preventing the need
74+
for dynamic checks and/or arbitrary amounts of stack space.
5275
*/
5376
pub struct RegionMaps {
5477
priv scope_map: RefCell<HashMap<ast::NodeId, ast::NodeId>>,
@@ -840,7 +863,16 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
840863
visit::FkItemFn(..) | visit::FkMethod(..) => {
841864
Context {parent: None, var_parent: None, ..cx}
842865
}
843-
visit::FkFnBlock(..) => cx
866+
visit::FkFnBlock(..) => {
867+
// FIXME(#3696) -- at present we are place the closure body
868+
// within the region hierarchy exactly where it appears lexically.
869+
// This is wrong because the closure may live longer
870+
// than the enclosing expression. We should probably fix this,
871+
// but the correct fix is a bit subtle, and I am also not sure
872+
// that the present approach is unsound -- it may not permit
873+
// any illegal programs. See issue for more details.
874+
cx
875+
}
844876
};
845877
visitor.visit_block(body, body_cx);
846878
}

0 commit comments

Comments
 (0)