@@ -191,36 +191,6 @@ enum TypeRootFilter {
191
191
TraitType ( String ) ,
192
192
}
193
193
194
- #[ derive( Clone , Hash , Eq , PartialEq , Debug ) ]
195
- enum TypeFilter {
196
- Unknown ,
197
- Never ,
198
- Placeholder ,
199
- TypeParam ( usize ) ,
200
- StringSlice ,
201
- StringArray ( usize ) ,
202
- U8 ,
203
- U16 ,
204
- U32 ,
205
- U64 ,
206
- U256 ,
207
- Bool ,
208
- Custom ( String ) ,
209
- B256 ,
210
- Contract ,
211
- ErrorRecovery ,
212
- Tuple ( usize , Vec < TypeFilter > ) ,
213
- Enum ( ParsedDeclId < EnumDeclaration > , Vec < TypeFilter > ) ,
214
- Struct ( ParsedDeclId < StructDeclaration > , Vec < TypeFilter > ) ,
215
- ContractCaller ( String ) ,
216
- Array ( usize , Box < TypeFilter > ) ,
217
- RawUntypedPtr ,
218
- RawUntypedSlice ,
219
- Ptr ( Box < TypeFilter > ) ,
220
- Slice ( Box < TypeFilter > ) ,
221
- TraitType ( String ) ,
222
- }
223
-
224
194
/// Map holding trait implementations for types.
225
195
///
226
196
/// Note: "impl self" blocks are considered traits and are stored in the
@@ -229,7 +199,7 @@ enum TypeFilter {
229
199
pub struct TraitMap {
230
200
trait_impls : TraitImpls ,
231
201
satisfied_cache : HashSet < u64 > ,
232
- insert_for_type_cache : HashMap < TypeFilter , im :: Vector < TypeId > > ,
202
+ insert_for_type_cache : HashMap < TypeRootFilter , Vec < TypeId > > ,
233
203
}
234
204
235
205
pub ( crate ) enum IsImplSelf {
@@ -252,8 +222,8 @@ impl TraitMap {
252
222
/// declarations for the key `(trait_name, type_id)` whenever possible.
253
223
#[ allow( clippy:: too_many_arguments) ]
254
224
pub ( crate ) fn insert (
255
- & mut self ,
256
225
handler : & Handler ,
226
+ module : & mut Module ,
257
227
trait_name : CallPath ,
258
228
trait_type_args : Vec < TypeArgument > ,
259
229
impl_type_parameters : Vec < TypeParameter > ,
@@ -311,7 +281,11 @@ impl TraitMap {
311
281
}
312
282
}
313
283
314
- let trait_impls = self . get_impls_mut ( engines, type_id) . clone ( ) ;
284
+ let trait_impls = module
285
+ . current_items_mut ( )
286
+ . implemented_traits
287
+ . get_impls_mut ( engines, type_id)
288
+ . clone ( ) ;
315
289
316
290
// check to see if adding this trait will produce a conflicting definition
317
291
for TraitEntry {
@@ -415,17 +389,17 @@ impl TraitMap {
415
389
if type_id_type_parameter
416
390
. type_id
417
391
. is_concrete ( engines, crate :: TreatNumericAs :: Abstract )
418
- && self
419
- . check_if_trait_constraints_are_satisfied_for_type (
420
- & Handler :: default ( ) ,
421
- type_id_type_parameter. type_id ,
422
- & map_type_id_type_parameter. trait_constraints ,
423
- impl_span,
424
- engines,
425
- TryInsertingTraitImplOnFailure :: Yes ,
426
- CodeBlockFirstPass :: No ,
427
- )
428
- . is_err ( )
392
+ && Self :: check_if_trait_constraints_are_satisfied_for_type (
393
+ & Handler :: default ( ) ,
394
+ module ,
395
+ type_id_type_parameter. type_id ,
396
+ & map_type_id_type_parameter. trait_constraints ,
397
+ impl_span,
398
+ engines,
399
+ TryInsertingTraitImplOnFailure :: Yes ,
400
+ CodeBlockFirstPass :: No ,
401
+ )
402
+ . is_err ( )
429
403
{
430
404
trait_constraints_safified = false ;
431
405
}
@@ -529,7 +503,7 @@ impl TraitMap {
529
503
} ) ;
530
504
531
505
// even if there is a conflicting definition, add the trait anyway
532
- self . insert_inner (
506
+ module . current_items_mut ( ) . implemented_traits . insert_inner (
533
507
trait_name,
534
508
impl_span. clone ( ) ,
535
509
trait_decl_span,
@@ -574,7 +548,7 @@ impl TraitMap {
574
548
let trait_map = TraitMap {
575
549
trait_impls,
576
550
satisfied_cache : HashSet :: default ( ) ,
577
- insert_for_type_cache : HashMap :: < TypeRootFilter , im :: Vector < TypeId > > :: new ( ) ,
551
+ insert_for_type_cache : HashMap :: < TypeRootFilter , Vec < TypeId > > :: new ( ) ,
578
552
} ;
579
553
580
554
self . extend ( trait_map, engines) ;
@@ -672,20 +646,6 @@ impl TraitMap {
672
646
type_id : TypeId ,
673
647
code_block_first_pass : CodeBlockFirstPass ,
674
648
) {
675
- let type_id = engines. te ( ) . get_unaliased_type_id ( type_id) ;
676
- let root_filter = TraitMap :: get_type_filter ( engines, type_id) ;
677
- if let Some ( values) = self . insert_for_type_cache . get_mut ( & root_filter) {
678
- let unify_checker = UnifyCheck :: non_dynamic_equality ( engines) . with_unify_ref_mut ( false ) ;
679
- if values. iter ( ) . any ( |v| unify_checker. check ( type_id, * v) ) {
680
- return ;
681
- } else {
682
- values. push_back ( type_id) ;
683
- }
684
- } else {
685
- self . insert_for_type_cache
686
- . insert ( root_filter, vec ! [ type_id] . into ( ) ) ;
687
- }
688
-
689
649
let type_id = engines. te ( ) . get_unaliased_type_id ( type_id) ;
690
650
691
651
let mut base_trait_map = TraitMap :: default ( ) ;
@@ -1075,11 +1035,6 @@ impl TraitMap {
1075
1035
* map_type_id,
1076
1036
* type_id,
1077
1037
) ;
1078
- type_id. subst ( & SubstTypesContext :: new (
1079
- engines,
1080
- & type_mapping,
1081
- matches ! ( code_block_first_pass, CodeBlockFirstPass :: No ) ,
1082
- ) ) ;
1083
1038
let trait_items: TraitItems = map_trait_items
1084
1039
. clone ( )
1085
1040
. into_iter ( )
@@ -1898,88 +1853,4 @@ impl TraitMap {
1898
1853
} => Self :: get_type_root_filter ( engines, referenced_type. type_id ) ,
1899
1854
}
1900
1855
}
1901
-
1902
- // This is used by the trait map to filter the entries into a HashMap with the return type string as key.
1903
- fn get_type_filter ( engines : & Engines , type_id : TypeId ) -> TypeFilter {
1904
- use TypeInfo :: * ;
1905
- match & * engines. te ( ) . get ( type_id) {
1906
- Unknown => TypeFilter :: Unknown ,
1907
- Never => TypeFilter :: Never ,
1908
- UnknownGeneric { .. } | Placeholder ( _) => TypeFilter :: Placeholder ,
1909
- TypeParam ( n) => TypeFilter :: TypeParam ( * n) ,
1910
- StringSlice => TypeFilter :: StringSlice ,
1911
- StringArray ( x) => TypeFilter :: StringArray ( x. val ( ) ) ,
1912
- UnsignedInteger ( x) => match x {
1913
- IntegerBits :: Eight => TypeFilter :: U8 ,
1914
- IntegerBits :: Sixteen => TypeFilter :: U16 ,
1915
- IntegerBits :: ThirtyTwo => TypeFilter :: U32 ,
1916
- IntegerBits :: SixtyFour => TypeFilter :: U64 ,
1917
- IntegerBits :: V256 => TypeFilter :: U256 ,
1918
- } ,
1919
- Boolean => TypeFilter :: Bool ,
1920
- Custom {
1921
- qualified_call_path : call_path,
1922
- ..
1923
- } => TypeFilter :: Custom ( call_path. call_path . suffix . to_string ( ) ) ,
1924
- B256 => TypeFilter :: B256 ,
1925
- Numeric => TypeFilter :: U64 , // u64 is the default
1926
- Contract => TypeFilter :: Contract ,
1927
- ErrorRecovery ( _) => TypeFilter :: ErrorRecovery ,
1928
- Tuple ( fields) => TypeFilter :: Tuple (
1929
- fields. len ( ) ,
1930
- fields
1931
- . iter ( )
1932
- . map ( |f| Self :: get_type_filter ( engines, f. type_id ) )
1933
- . collect :: < Vec < _ > > ( ) ,
1934
- ) ,
1935
- UntypedEnum ( _) => unreachable ! ( ) ,
1936
- UntypedStruct ( _) => unreachable ! ( ) ,
1937
- Enum ( decl_id) => {
1938
- // TODO Remove unwrap once #6475 is fixed
1939
- TypeFilter :: Enum (
1940
- engines. de ( ) . get_parsed_decl_id ( decl_id) . unwrap ( ) ,
1941
- engines
1942
- . de ( )
1943
- . get_enum ( decl_id)
1944
- . type_parameters
1945
- . iter ( )
1946
- . map ( |f| Self :: get_type_filter ( engines, f. type_id ) )
1947
- . collect :: < Vec < _ > > ( ) ,
1948
- )
1949
- }
1950
- Struct ( decl_id) => {
1951
- // TODO Remove unwrap once #6475 is fixed
1952
- TypeFilter :: Struct (
1953
- engines. de ( ) . get_parsed_decl_id ( decl_id) . unwrap ( ) ,
1954
- engines
1955
- . de ( )
1956
- . get_struct ( decl_id)
1957
- . type_parameters
1958
- . iter ( )
1959
- . map ( |f| Self :: get_type_filter ( engines, f. type_id ) )
1960
- . collect :: < Vec < _ > > ( ) ,
1961
- )
1962
- }
1963
- ContractCaller { abi_name, .. } => TypeFilter :: ContractCaller ( abi_name. to_string ( ) ) ,
1964
- Array ( type_argument, length) => TypeFilter :: Array (
1965
- length. val ( ) ,
1966
- Box :: new ( Self :: get_type_filter ( engines, type_argument. type_id ) ) ,
1967
- ) ,
1968
- RawUntypedPtr => TypeFilter :: RawUntypedPtr ,
1969
- RawUntypedSlice => TypeFilter :: RawUntypedSlice ,
1970
- Ptr ( type_argument) => TypeFilter :: Ptr ( Box :: new ( Self :: get_type_filter (
1971
- engines,
1972
- type_argument. type_id ,
1973
- ) ) ) ,
1974
- Slice ( type_argument) => TypeFilter :: Slice ( Box :: new ( Self :: get_type_filter (
1975
- engines,
1976
- type_argument. type_id ,
1977
- ) ) ) ,
1978
- Alias { ty, .. } => Self :: get_type_filter ( engines, ty. type_id ) ,
1979
- TraitType { name, .. } => TypeFilter :: TraitType ( name. to_string ( ) ) ,
1980
- Ref {
1981
- referenced_type, ..
1982
- } => Self :: get_type_filter ( engines, referenced_type. type_id ) ,
1983
- }
1984
- }
1985
1856
}
0 commit comments