@@ -6,8 +6,6 @@ mod stacked_tree;
66mod linked_tree;
77pub mod variable_scope;
88
9- use std:: mem;
10-
119use call_scope:: CallScope ;
1210use cf_scope:: CfScope ;
1311pub use cf_scope:: { CfScopeId , CfScopeKind } ;
@@ -28,7 +26,7 @@ use crate::{
2826pub struct Scoping < ' a > {
2927 pub call : Vec < CallScope < ' a > > ,
3028 pub variable : LinkedTree < ' a , VariableScopeId , VariableScope < ' a > > ,
31- pub cf : StackedTree < ' a , CfScopeId , CfScope < ' a > > ,
29+ pub cf : StackedTree < CfScopeId , CfScope < ' a > > ,
3230 pub root_cf_scope : CfScopeId ,
3331 pub try_catch_depth : Option < usize > ,
3432 pub current_callsite : AstKind2 < ' a > ,
@@ -40,8 +38,8 @@ impl<'a> Scoping<'a> {
4038 let mut variable = LinkedTree :: new_in ( factory. allocator ) ;
4139 let root_variable_scope =
4240 variable. push ( VariableScope :: new_in_with_this ( factory. allocator , factory. unknown ) ) ;
43- let mut cf = StackedTree :: new_in ( factory. allocator ) ;
44- let root_cf_scope = cf. push ( CfScope :: new ( CfScopeKind :: Root , factory . vec ( ) , false ) ) ;
41+ let cf = StackedTree :: new ( CfScope :: new ( CfScopeKind :: Root , factory. vec ( ) , false ) ) ;
42+ let root_cf_scope = cf. root ;
4543 factory. root_cf_scope = Some ( root_cf_scope) ;
4644 Scoping {
4745 call : vec ! [ CallScope :: new_in(
@@ -80,11 +78,11 @@ impl<'a> Analyzer<'a> {
8078 }
8179
8280 pub fn cf_scope ( & self ) -> & CfScope < ' a > {
83- self . scoping . cf . get_current ( )
81+ self . scoping . cf . current_data ( )
8482 }
8583
8684 pub fn cf_scope_mut ( & mut self ) -> & mut CfScope < ' a > {
87- self . scoping . cf . get_current_mut ( )
85+ self . scoping . cf . current_data_mut ( )
8886 }
8987
9088 pub fn variable_scope ( & self ) -> & VariableScope < ' a > {
@@ -111,9 +109,7 @@ impl<'a> Analyzer<'a> {
111109 let old_variable_scope_stack = self . replace_variable_scope ( info. func . lexical_scope ) ;
112110 let body_variable_scope = self . push_variable_scope ( ) ;
113111 let cf_scope_depth = self . push_cf_scope_with_deps (
114- CfScopeKind :: Function (
115- self . allocator . alloc ( FnCacheTrackingData :: new_in ( self . allocator , info) ) ,
116- ) ,
112+ CfScopeKind :: Function ( Box :: new ( FnCacheTrackingData :: new_in ( self . allocator , info) ) ) ,
117113 self . factory . vec1 ( info. call_dep ) ,
118114 false ,
119115 ) ;
@@ -133,17 +129,14 @@ impl<'a> Analyzer<'a> {
133129 pub fn pop_call_scope ( & mut self ) -> ( Entity < ' a > , FnCacheTrackingData < ' a > ) {
134130 let scope = self . scoping . call . pop ( ) . unwrap ( ) ;
135131 let ret_val = scope. ret_val ( self ) ;
136- let cf_scope_id = self . pop_cf_scope ( ) ;
137- let cf_scope = self . scoping . cf . get_mut ( cf_scope_id) ;
138- let CfScopeKind :: Function ( tracking_data) = & mut cf_scope. kind else {
132+ let cf_scope = self . pop_cf_scope ( ) ;
133+ let CfScopeKind :: Function ( tracking_data) = cf_scope. kind else {
139134 unreachable ! ( ) ;
140135 } ;
141- let tracking_data = mem:: take ( * tracking_data) ;
142-
143136 self . pop_variable_scope ( ) ;
144137 self . replace_variable_scope ( scope. old_variable_scope ) ;
145138 self . set_current_module ( scope. old_module ) ;
146- ( ret_val, tracking_data)
139+ ( ret_val, * tracking_data)
147140 }
148141
149142 pub fn push_variable_scope ( & mut self ) -> VariableScopeId {
@@ -180,23 +173,18 @@ impl<'a> Analyzer<'a> {
180173 ) ;
181174 }
182175
183- pub fn pop_cf_scope ( & mut self ) -> CfScopeId {
176+ pub fn pop_cf_scope ( & mut self ) -> CfScope < ' a > {
184177 self . scoping . cf . pop ( )
185178 }
186179
187180 pub fn pop_multiple_cf_scopes ( & mut self , count : usize ) -> Option < Dep < ' a > > {
188181 let mut exec_deps = self . factory . vec ( ) ;
189182 for _ in 0 ..count {
190- let id = self . scoping . cf . stack . pop ( ) . unwrap ( ) ;
191- if let Some ( dep) = self . scoping . cf . get_mut ( id ) . deps . collect ( self . factory ) {
183+ let mut scope = self . pop_cf_scope ( ) ;
184+ if let Some ( dep) = scope . deps . collect ( self . factory ) {
192185 exec_deps. push ( dep) ;
193186 }
194187 }
195188 if exec_deps. is_empty ( ) { None } else { Some ( self . dep ( exec_deps) ) }
196189 }
197-
198- pub fn pop_cf_scope_and_get_mut ( & mut self ) -> & mut CfScope < ' a > {
199- let id = self . pop_cf_scope ( ) ;
200- self . scoping . cf . get_mut ( id)
201- }
202190}
0 commit comments