@@ -24,33 +24,35 @@ pub struct Builder<'a, 'tcx: 'a> {
2424
2525 fn_span : Span ,
2626
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
2929 scopes : Vec < scope:: Scope < ' tcx > > ,
3030
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.
3636 scope_auxiliary : ScopeAuxiliaryVec ,
3737
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
4040 loop_scopes : Vec < scope:: LoopScope > ,
4141
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
4444 scope_datas : Vec < ScopeData > ,
4545
4646 var_decls : Vec < VarDecl < ' tcx > > ,
4747 var_indices : FnvHashMap < ast:: NodeId , u32 > ,
4848 temp_decls : Vec < TempDecl < ' tcx > > ,
4949 unit_temp : Option < Lvalue < ' tcx > > ,
5050
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.
5353 cached_resume_block : Option < BasicBlock > ,
54+ /// cached block with the RETURN terminator
55+ cached_return_block : Option < BasicBlock > ,
5456}
5557
5658struct CFG < ' tcx > {
@@ -180,12 +182,10 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
180182 var_indices : FnvHashMap ( ) ,
181183 unit_temp : None ,
182184 cached_resume_block : None ,
185+ cached_return_block : None
183186 } ;
184187
185188 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-
189189
190190 let mut arg_decls = None ; // assigned to `Some` in closures below
191191 let call_site_extent =
@@ -205,11 +205,12 @@ pub fn construct<'a,'tcx>(hir: Cx<'a,'tcx>,
205205 block. unit( )
206206 } ) ) ;
207207
208+ let return_block = builder. return_block ( ) ;
208209 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,
211212 TerminatorKind :: Return ) ;
212- end_block . unit ( )
213+ return_block . unit ( )
213214 } ) ;
214215
215216 assert ! (
@@ -290,6 +291,17 @@ impl<'a,'tcx> Builder<'a,'tcx> {
290291 }
291292 }
292293 }
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+ }
293305}
294306
295307///////////////////////////////////////////////////////////////////////////
0 commit comments