@@ -24,33 +24,35 @@ pub struct Builder<'a, 'tcx: 'a> {
24
24
25
25
fn_span : Span ,
26
26
27
- // the current set of scopes, updated as we traverse;
28
- // see the `scope` module for more details
27
+ /// the current set of scopes, updated as we traverse;
28
+ /// see the `scope` module for more details
29
29
scopes : Vec < scope:: Scope < ' tcx > > ,
30
30
31
- // for each scope, a span of blocks that defines it;
32
- // we track these for use in region and borrow checking,
33
- // but these are liable to get out of date once optimization
34
- // begins. They are also hopefully temporary, and will be
35
- // no longer needed when we adopt graph-based regions.
31
+ /// for each scope, a span of blocks that defines it;
32
+ /// we track these for use in region and borrow checking,
33
+ /// but these are liable to get out of date once optimization
34
+ /// begins. They are also hopefully temporary, and will be
35
+ /// no longer needed when we adopt graph-based regions.
36
36
scope_auxiliary : ScopeAuxiliaryVec ,
37
37
38
- // the current set of loops; see the `scope` module for more
39
- // details
38
+ /// the current set of loops; see the `scope` module for more
39
+ /// details
40
40
loop_scopes : Vec < scope:: LoopScope > ,
41
41
42
- // the vector of all scopes that we have created thus far;
43
- // we track this for debuginfo later
42
+ /// the vector of all scopes that we have created thus far;
43
+ /// we track this for debuginfo later
44
44
scope_datas : Vec < ScopeData > ,
45
45
46
46
var_decls : Vec < VarDecl < ' tcx > > ,
47
47
var_indices : FnvHashMap < ast:: NodeId , u32 > ,
48
48
temp_decls : Vec < TempDecl < ' tcx > > ,
49
49
unit_temp : Option < Lvalue < ' tcx > > ,
50
50
51
- // cached block with a RESUME terminator; we create this at the
52
- // first panic
51
+ /// cached block with the RESUME terminator; this is created
52
+ /// when first set of cleanups are built.
53
53
cached_resume_block : Option < BasicBlock > ,
54
+ /// cached block with the RETURN terminator
55
+ cached_return_block : Option < BasicBlock > ,
54
56
}
55
57
56
58
struct CFG < ' tcx > {
@@ -180,12 +182,10 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
180
182
var_indices : FnvHashMap ( ) ,
181
183
unit_temp : None ,
182
184
cached_resume_block : None ,
185
+ cached_return_block : None
183
186
} ;
184
187
185
188
assert_eq ! ( builder. cfg. start_new_block( ) , START_BLOCK ) ;
186
- let end_block = builder. cfg . start_new_block ( ) ;
187
- assert_eq ! ( end_block, BasicBlock :: end_block( ) ) ;
188
-
189
189
190
190
let mut arg_decls = None ; // assigned to `Some` in closures below
191
191
let call_site_extent =
@@ -205,11 +205,12 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
205
205
block. unit( )
206
206
} ) ) ;
207
207
208
+ let return_block = builder. return_block ( ) ;
208
209
builder. cfg . terminate ( block, call_site_scope_id, span,
209
- TerminatorKind :: Goto { target : end_block } ) ;
210
- builder. cfg . terminate ( end_block , call_site_scope_id, span,
210
+ TerminatorKind :: Goto { target : return_block } ) ;
211
+ builder. cfg . terminate ( return_block , call_site_scope_id, span,
211
212
TerminatorKind :: Return ) ;
212
- end_block . unit ( )
213
+ return_block . unit ( )
213
214
} ) ;
214
215
215
216
assert ! (
@@ -290,6 +291,17 @@ impl<'a,'tcx> Builder<'a,'tcx> {
290
291
}
291
292
}
292
293
}
294
+
295
+ fn return_block ( & mut self ) -> BasicBlock {
296
+ match self . cached_return_block {
297
+ Some ( rb) => rb,
298
+ None => {
299
+ let rb = self . cfg . start_new_block ( ) ;
300
+ self . cached_return_block = Some ( rb) ;
301
+ rb
302
+ }
303
+ }
304
+ }
293
305
}
294
306
295
307
///////////////////////////////////////////////////////////////////////////
0 commit comments