@@ -200,36 +200,6 @@ enum TypeRootFilter {
200
200
TraitType ( String ) ,
201
201
}
202
202
203
- #[ derive( Clone , Hash , Eq , PartialEq , Debug ) ]
204
- enum TypeFilter {
205
- Unknown ,
206
- Never ,
207
- Placeholder ,
208
- TypeParam ( usize ) ,
209
- StringSlice ,
210
- StringArray ( usize ) ,
211
- U8 ,
212
- U16 ,
213
- U32 ,
214
- U64 ,
215
- U256 ,
216
- Bool ,
217
- Custom ( String ) ,
218
- B256 ,
219
- Contract ,
220
- ErrorRecovery ,
221
- Tuple ( usize , Vec < TypeFilter > ) ,
222
- Enum ( ParsedDeclId < EnumDeclaration > , Vec < TypeFilter > ) ,
223
- Struct ( ParsedDeclId < StructDeclaration > , Vec < TypeFilter > ) ,
224
- ContractCaller ( String ) ,
225
- Array ( usize , Box < TypeFilter > ) ,
226
- RawUntypedPtr ,
227
- RawUntypedSlice ,
228
- Ptr ( Box < TypeFilter > ) ,
229
- Slice ( Box < TypeFilter > ) ,
230
- TraitType ( String ) ,
231
- }
232
-
233
203
/// Map holding trait implementations for types.
234
204
///
235
205
/// Note: "impl self" blocks are considered traits and are stored in the
@@ -238,7 +208,6 @@ enum TypeFilter {
238
208
pub struct TraitMap {
239
209
trait_impls : TraitImpls ,
240
210
satisfied_cache : HashSet < u64 > ,
241
- insert_for_type_cache : HashMap < TypeFilter , im:: Vector < TypeId > > ,
242
211
}
243
212
244
213
pub ( crate ) enum IsImplSelf {
@@ -275,7 +244,6 @@ impl TraitMap {
275
244
engines : & Engines ,
276
245
) -> Result < ( ) , ErrorEmitted > {
277
246
let type_id = engines. te ( ) . get_unaliased_type_id ( type_id) ;
278
- let trait_map = & mut module. current_items_mut ( ) . implemented_traits ;
279
247
280
248
let mut type_id_type_parameters = match & * engines. te ( ) . get ( type_id) {
281
249
TypeInfo :: Enum ( decl_id) => engines. de ( ) . get_enum ( decl_id) . type_parameters . clone ( ) ,
@@ -324,7 +292,11 @@ impl TraitMap {
324
292
}
325
293
}
326
294
327
- let trait_impls = trait_map. get_impls_mut ( engines, type_id) . clone ( ) ;
295
+ let trait_impls = module
296
+ . current_items_mut ( )
297
+ . implemented_traits
298
+ . get_impls_mut ( engines, type_id)
299
+ . clone ( ) ;
328
300
329
301
// check to see if adding this trait will produce a conflicting definition
330
302
for TraitEntry {
@@ -428,7 +400,7 @@ impl TraitMap {
428
400
if type_id_type_parameter
429
401
. type_id
430
402
. is_concrete ( engines, crate :: TreatNumericAs :: Abstract )
431
- && TraitMap :: check_if_trait_constraints_are_satisfied_for_type (
403
+ && Self :: check_if_trait_constraints_are_satisfied_for_type (
432
404
& Handler :: default ( ) ,
433
405
module,
434
406
type_id_type_parameter. type_id ,
@@ -524,7 +496,7 @@ impl TraitMap {
524
496
} ) ;
525
497
526
498
// even if there is a conflicting definition, add the trait anyway
527
- trait_map . insert_inner (
499
+ module . current_items_mut ( ) . implemented_traits . insert_inner (
528
500
trait_name,
529
501
impl_span. clone ( ) ,
530
502
trait_decl_span,
@@ -569,7 +541,6 @@ impl TraitMap {
569
541
let trait_map = TraitMap {
570
542
trait_impls,
571
543
satisfied_cache : HashSet :: default ( ) ,
572
- insert_for_type_cache : HashMap :: < TypeRootFilter , im:: Vector < TypeId > > :: new ( ) ,
573
544
} ;
574
545
575
546
self . extend ( trait_map, engines) ;
@@ -602,7 +573,10 @@ impl TraitMap {
602
573
// If we have the same method in: impl<T> FromBytes for T
603
574
// and: impl FromBytes for DataPoint
604
575
// We keep the second implementation.
576
+ // We don't care for the order this is checked
577
+ #[ allow( clippy:: iter_over_hash_type) ]
605
578
for ( name, item) in oe. value . trait_items . iter ( ) {
579
+ #[ allow( clippy:: iter_over_hash_type) ]
606
580
for ( existing_name, existing_item) in
607
581
self_vec[ pos] . value . trait_items . iter ( )
608
582
{
@@ -1654,88 +1628,4 @@ impl TraitMap {
1654
1628
} => Self :: get_type_root_filter ( engines, referenced_type. type_id ) ,
1655
1629
}
1656
1630
}
1657
-
1658
- // This is used by the trait map to filter the entries into a HashMap with the return type string as key.
1659
- fn get_type_filter ( engines : & Engines , type_id : TypeId ) -> TypeFilter {
1660
- use TypeInfo :: * ;
1661
- match & * engines. te ( ) . get ( type_id) {
1662
- Unknown => TypeFilter :: Unknown ,
1663
- Never => TypeFilter :: Never ,
1664
- UnknownGeneric { .. } | Placeholder ( _) => TypeFilter :: Placeholder ,
1665
- TypeParam ( n) => TypeFilter :: TypeParam ( * n) ,
1666
- StringSlice => TypeFilter :: StringSlice ,
1667
- StringArray ( x) => TypeFilter :: StringArray ( x. val ( ) ) ,
1668
- UnsignedInteger ( x) => match x {
1669
- IntegerBits :: Eight => TypeFilter :: U8 ,
1670
- IntegerBits :: Sixteen => TypeFilter :: U16 ,
1671
- IntegerBits :: ThirtyTwo => TypeFilter :: U32 ,
1672
- IntegerBits :: SixtyFour => TypeFilter :: U64 ,
1673
- IntegerBits :: V256 => TypeFilter :: U256 ,
1674
- } ,
1675
- Boolean => TypeFilter :: Bool ,
1676
- Custom {
1677
- qualified_call_path : call_path,
1678
- ..
1679
- } => TypeFilter :: Custom ( call_path. call_path . suffix . to_string ( ) ) ,
1680
- B256 => TypeFilter :: B256 ,
1681
- Numeric => TypeFilter :: U64 , // u64 is the default
1682
- Contract => TypeFilter :: Contract ,
1683
- ErrorRecovery ( _) => TypeFilter :: ErrorRecovery ,
1684
- Tuple ( fields) => TypeFilter :: Tuple (
1685
- fields. len ( ) ,
1686
- fields
1687
- . iter ( )
1688
- . map ( |f| Self :: get_type_filter ( engines, f. type_id ) )
1689
- . collect :: < Vec < _ > > ( ) ,
1690
- ) ,
1691
- UntypedEnum ( _) => unreachable ! ( ) ,
1692
- UntypedStruct ( _) => unreachable ! ( ) ,
1693
- Enum ( decl_id) => {
1694
- // TODO Remove unwrap once #6475 is fixed
1695
- TypeFilter :: Enum (
1696
- engines. de ( ) . get_parsed_decl_id ( decl_id) . unwrap ( ) ,
1697
- engines
1698
- . de ( )
1699
- . get_enum ( decl_id)
1700
- . type_parameters
1701
- . iter ( )
1702
- . map ( |f| Self :: get_type_filter ( engines, f. type_id ) )
1703
- . collect :: < Vec < _ > > ( ) ,
1704
- )
1705
- }
1706
- Struct ( decl_id) => {
1707
- // TODO Remove unwrap once #6475 is fixed
1708
- TypeFilter :: Struct (
1709
- engines. de ( ) . get_parsed_decl_id ( decl_id) . unwrap ( ) ,
1710
- engines
1711
- . de ( )
1712
- . get_struct ( decl_id)
1713
- . type_parameters
1714
- . iter ( )
1715
- . map ( |f| Self :: get_type_filter ( engines, f. type_id ) )
1716
- . collect :: < Vec < _ > > ( ) ,
1717
- )
1718
- }
1719
- ContractCaller { abi_name, .. } => TypeFilter :: ContractCaller ( abi_name. to_string ( ) ) ,
1720
- Array ( type_argument, length) => TypeFilter :: Array (
1721
- length. val ( ) ,
1722
- Box :: new ( Self :: get_type_filter ( engines, type_argument. type_id ) ) ,
1723
- ) ,
1724
- RawUntypedPtr => TypeFilter :: RawUntypedPtr ,
1725
- RawUntypedSlice => TypeFilter :: RawUntypedSlice ,
1726
- Ptr ( type_argument) => TypeFilter :: Ptr ( Box :: new ( Self :: get_type_filter (
1727
- engines,
1728
- type_argument. type_id ,
1729
- ) ) ) ,
1730
- Slice ( type_argument) => TypeFilter :: Slice ( Box :: new ( Self :: get_type_filter (
1731
- engines,
1732
- type_argument. type_id ,
1733
- ) ) ) ,
1734
- Alias { ty, .. } => Self :: get_type_filter ( engines, ty. type_id ) ,
1735
- TraitType { name, .. } => TypeFilter :: TraitType ( name. to_string ( ) ) ,
1736
- Ref {
1737
- referenced_type, ..
1738
- } => Self :: get_type_filter ( engines, referenced_type. type_id ) ,
1739
- }
1740
- }
1741
1631
}
0 commit comments