11use ast:: types:: ASTType ;
22use astoir_hir:: ctx:: HIRContext ;
3+ use compiler_global_scope:: { entry:: GlobalStorageEntryType , key:: EntryKey } ;
34use compiler_typing:: { TypeParamType , raw:: RawType , references:: TypeReference , tree:: Type } ;
45use compiler_utils:: hash:: HashedString ;
56use diagnostics:: {
@@ -19,7 +20,10 @@ pub fn lower_ast_type<K: DiagnosticSpanOrigin>(
1920 ASTType :: Generic ( type_id, type_params, size_params, specifier) => {
2021 let hash = HashedString :: new ( type_id) . hash ;
2122
22- let mut t = match context. type_storage . get_type ( hash) {
23+ let mut t = match context
24+ . global_scope
25+ . get_type ( EntryKey { name_hash : hash } , origin)
26+ {
2327 Ok ( v) => v,
2428 Err ( _) => return Err ( make_cannot_find_type ( origin, & hash) . into ( ) ) ,
2529 } ;
@@ -33,11 +37,11 @@ pub fn lower_ast_type<K: DiagnosticSpanOrigin>(
3337 t = container. get_entry ( HashedString :: new ( specifier. unwrap ( ) ) ) ?
3438 }
3539
36- if t. get_type_params_count ( & context. type_storage ) != type_params. len ( ) {
40+ if t. get_type_params_count ( & context. global_scope , origin ) ? != type_params. len ( ) {
3741 return Err ( make_diff_type_specifiers (
3842 origin,
3943 & type_params. len ( ) ,
40- & t. get_type_params_count ( & context. type_storage ) ,
44+ & t. get_type_params_count ( & context. global_scope , origin ) ? ,
4145 )
4246 . into ( ) ) ;
4347 }
@@ -51,18 +55,26 @@ pub fn lower_ast_type<K: DiagnosticSpanOrigin>(
5155 let res = Type :: Generic ( t. clone ( ) , t_params, size_params) ;
5256
5357 if t. is_sized ( ) {
54- let lower = lower_sized_base_type ( context , & res, origin) ?;
58+ let lower = lower_sized_base_type ( & res, origin) ?;
5559
56- if context. type_storage . type_to_ind . contains_key ( & lower) {
60+ if context
61+ . global_scope
62+ . value_to_ind
63+ . contains_key ( & GlobalStorageEntryType :: Type ( lower. clone ( ) ) )
64+ {
5765 return Ok ( Type :: Generic ( t, vec ! [ ] , vec ! [ ] ) ) ;
5866 } else {
59- let ind = match context. type_storage . append_with_hash ( hash, lower) {
67+ let ind = match context. global_scope . append (
68+ EntryKey { name_hash : hash } ,
69+ GlobalStorageEntryType :: Type ( lower) ,
70+ origin,
71+ ) {
6072 Ok ( v) => v,
6173 Err ( _) => panic ! ( "Generic lowering type cannot be found on type_to_hash" ) ,
6274 } ;
6375
6476 return Ok ( Type :: Generic (
65- context. type_storage . types . vals [ ind] . clone ( ) ,
77+ context. global_scope . entries [ ind] . as_type_unsafe ( ) ,
6678 vec ! [ ] ,
6779 vec ! [ ] ,
6880 ) ) ;
@@ -106,13 +118,12 @@ pub fn lower_ast_type_struct<K: DiagnosticSpanOrigin, T: TypeParamType>(
106118}
107119
108120pub fn lower_sized_base_type < K : DiagnosticSpanOrigin > (
109- context : & HIRContext ,
110121 t : & Type ,
111122 origin : & K ,
112123) -> DiagnosticResult < RawType > {
113124 let data = t. get_generic_info ( ) ;
114125
115- match t. get_generic ( & context . type_storage ) {
126+ match t. get_generic ( ) {
116127 RawType :: SizedInteger ( e) => {
117128 if data. 1 . len ( ) != 1 {
118129 return Err ( make_diff_size_specifiers ( origin, & 1 , & data. 1 . len ( ) ) . into ( ) ) ;
0 commit comments