@@ -11,9 +11,12 @@ pub type GlobalStorageIdentifier = usize;
1111
1212
1313#[ derive( Debug ) ]
14- pub struct GlobalScopeStorage < T , R , F , I > {
14+ pub struct GlobalScopeStorage < T , R > {
1515 pub entry_to_ind : HashMap < EntryKey , usize > ,
16- pub entries : Vec < GlobalStorageEntry < T , R , F , I > > ,
16+ pub entries : Vec < GlobalStorageEntry < T , R > > ,
17+
18+ pub descriptor_counter : usize ,
19+ pub impl_counter : usize
1720}
1821
1922
@@ -27,12 +30,12 @@ pub struct GlobalScopeStorage<T, R, F, I> {
2730///
2831/// # Safety
2932/// The `GlobalScopeStorage` enforces correctness for global scope types and strictly allows only one entry per name. globally.
30- impl < T : Clone , R : Clone , F : Clone , I : Clone > GlobalScopeStorage < T , R , F , I > {
33+ impl < T : Clone , R : Clone > GlobalScopeStorage < T , R > {
3134 pub fn new ( ) -> Self {
32- GlobalScopeStorage { entry_to_ind : HashMap :: new ( ) , entries : vec ! [ ] }
35+ GlobalScopeStorage { entry_to_ind : HashMap :: new ( ) , entries : vec ! [ ] , descriptor_counter : 0 , impl_counter : 0 }
3336 }
3437
35- pub fn append < K : DiagnosticSpanOrigin > ( & mut self , name : EntryKey , entry : GlobalStorageEntryType < T , R , F , I > , origin : & K ) -> MaybeDiagnostic {
38+ pub fn append < K : DiagnosticSpanOrigin > ( & mut self , name : EntryKey , entry : GlobalStorageEntryType < T , R > , origin : & K ) -> MaybeDiagnostic {
3639 if self . entry_to_ind . contains_key ( & name) {
3740 return Err ( make_already_in_scope ( origin, & name. name_hash ) . into ( ) )
3841 }
@@ -47,7 +50,7 @@ impl<T: Clone, R: Clone, F: Clone, I: Clone> GlobalScopeStorage<T, R, F, I> {
4750 Ok ( ( ) )
4851 }
4952
50- pub fn get_base < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < GlobalStorageEntryType < T , R , F , I > > {
53+ pub fn get_base < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < GlobalStorageEntryType < T , R > > {
5154 if !self . entry_to_ind . contains_key ( & name) {
5255 return Err ( make_cannot_find ( origin, & name. name_hash ) . into ( ) ) ;
5356 }
@@ -73,56 +76,56 @@ impl<T: Clone, R: Clone, F: Clone, I: Clone> GlobalScopeStorage<T, R, F, I> {
7376 } ;
7477 }
7578
76- pub fn get_function_base < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < F > {
79+ pub fn get_function_base < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < usize > {
7780 let base = self . get_base ( name, origin) ?;
7881
7982 return match base {
80- GlobalStorageEntryType :: Function ( hir , _ ) => Ok ( hir . clone ( ) ) ,
81- GlobalStorageEntryType :: ImplLessFunction ( hir ) => Ok ( hir . clone ( ) ) ,
82- GlobalStorageEntryType :: StructFunction ( hir , _, _ ) => Ok ( hir . clone ( ) ) ,
83+ GlobalStorageEntryType :: Function { descriptor_ind , impl_ind : _ } => Ok ( descriptor_ind ) ,
84+ GlobalStorageEntryType :: ImplLessFunction ( descriptor_ind ) => Ok ( descriptor_ind ) ,
85+ GlobalStorageEntryType :: StructFunction { descriptor_ind , impl_ind : _, struct_type : _ } => Ok ( descriptor_ind ) ,
8386
8487 _ => Err ( make_expected_simple_error ( origin, & "function" . to_string ( ) , & base) . into ( ) )
8588 } ;
8689 }
8790
88- pub fn get_function_impl < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < I > {
91+ pub fn get_function_impl < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < usize > {
8992 let base = self . get_base ( name, origin) ?;
9093
9194 return match base {
92- GlobalStorageEntryType :: Function ( _, i ) => Ok ( i . clone ( ) ) ,
93- GlobalStorageEntryType :: StructFunction ( _, i , _ ) => Ok ( i . clone ( ) ) ,
95+ GlobalStorageEntryType :: Function { descriptor_ind : _, impl_ind } => Ok ( impl_ind ) ,
96+ GlobalStorageEntryType :: StructFunction { descriptor_ind : _, impl_ind , struct_type : _ } => Ok ( impl_ind ) ,
9497
9598 _ => Err ( make_expected_simple_error ( origin, & "function with implementation" , & base) . into ( ) )
9699 } ;
97100 }
98101
99- pub fn get_implless_function < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < F > {
102+ pub fn get_implless_function < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < usize > {
100103 let base = self . get_base ( name, origin) ?;
101104
102105 return match base {
103- GlobalStorageEntryType :: ImplLessFunction ( hir ) => Ok ( hir . clone ( ) ) ,
106+ GlobalStorageEntryType :: ImplLessFunction ( descriptor_ind ) => Ok ( descriptor_ind ) ,
104107
105108 _ => Err ( make_expected_simple_error ( origin, & "function without implementation" , & base) . into ( ) )
106109 }
107110 }
108111
109- pub fn get_exact_function < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < ( F , I ) > {
112+ pub fn get_exact_function < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < ( usize , usize ) > {
110113 let base = self . get_base ( name, origin) ?;
111114
112115 return match base {
113- GlobalStorageEntryType :: Function ( hir , i ) => Ok ( ( hir . clone ( ) , i . clone ( ) ) ) ,
116+ GlobalStorageEntryType :: Function { descriptor_ind , impl_ind } => Ok ( ( descriptor_ind , impl_ind ) ) ,
114117
115118 _ => Err ( make_expected_simple_error ( origin, & "function" , & base) . into ( ) )
116119 }
117120 }
118121
119- pub fn get_exact_struct_function < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < ( F , I , R ) > {
122+ pub fn get_exact_struct_function < K : DiagnosticSpanOrigin > ( & self , name : EntryKey , origin : & K ) -> DiagnosticResult < ( usize , usize , R ) > {
120123 let base = self . get_base ( name, origin) ?;
121124
122125 return match base {
123- GlobalStorageEntryType :: StructFunction ( hir , i , o ) => {
124- if let GlobalStorageEntryType :: Type ( t) = self . entries [ o ] . entry_type . clone ( ) {
125- Ok ( ( hir , i , t) )
126+ GlobalStorageEntryType :: StructFunction { descriptor_ind , impl_ind , struct_type } => {
127+ if let GlobalStorageEntryType :: Type ( t) = self . entries [ struct_type ] . entry_type . clone ( ) {
128+ Ok ( ( descriptor_ind , impl_ind , t) )
126129 } else {
127130 Err ( make_expected_simple_error ( origin, & "type" , & self . entries [ 0 ] . entry_type ) . into ( ) )
128131 }
0 commit comments