@@ -649,6 +649,53 @@ impl TypeSignature {
649
649
}
650
650
}
651
651
652
+ /// Canonicalize a type.
653
+ /// This method will convert types from previous epochs with the appropriate
654
+ /// types for the specified epoch.
655
+ pub fn canonicalize ( & self , epoch : & StacksEpochId ) -> TypeSignature {
656
+ match epoch {
657
+ StacksEpochId :: Epoch10
658
+ | StacksEpochId :: Epoch20
659
+ | StacksEpochId :: Epoch2_05
660
+ // Epoch-2.2 had a regression in canonicalization, so it must be preserved here.
661
+ | StacksEpochId :: Epoch22 => self . clone ( ) ,
662
+ // Note for future epochs: Epochs >= 2.3 should use the canonicalize_v2_1() routine
663
+ StacksEpochId :: Epoch21
664
+ | StacksEpochId :: Epoch23
665
+ | StacksEpochId :: Epoch24
666
+ | StacksEpochId :: Epoch25
667
+ | StacksEpochId :: Epoch30
668
+ | StacksEpochId :: Epoch31 => self . canonicalize_v2_1 ( ) ,
669
+ }
670
+ }
671
+
672
+ pub fn canonicalize_v2_1 ( & self ) -> TypeSignature {
673
+ match self {
674
+ SequenceType ( SequenceSubtype :: ListType ( list_type) ) => {
675
+ SequenceType ( SequenceSubtype :: ListType ( ListTypeData {
676
+ max_len : list_type. max_len ,
677
+ entry_type : Box :: new ( list_type. entry_type . canonicalize_v2_1 ( ) ) ,
678
+ } ) )
679
+ }
680
+ OptionalType ( inner_type) => OptionalType ( Box :: new ( inner_type. canonicalize_v2_1 ( ) ) ) ,
681
+ ResponseType ( inner_type) => ResponseType ( Box :: new ( (
682
+ inner_type. 0 . canonicalize_v2_1 ( ) ,
683
+ inner_type. 1 . canonicalize_v2_1 ( ) ,
684
+ ) ) ) ,
685
+ TupleType ( tuple_sig) => {
686
+ let mut canonicalized_fields = BTreeMap :: new ( ) ;
687
+ for ( field_name, field_type) in tuple_sig. get_type_map ( ) {
688
+ canonicalized_fields. insert ( field_name. clone ( ) , field_type. canonicalize_v2_1 ( ) ) ;
689
+ }
690
+ TypeSignature :: from ( TupleTypeSignature {
691
+ type_map : Arc :: new ( canonicalized_fields) ,
692
+ } )
693
+ }
694
+ TraitReferenceType ( trait_id) => CallableType ( CallableSubtype :: Trait ( trait_id. clone ( ) ) ) ,
695
+ _ => self . clone ( ) ,
696
+ }
697
+ }
698
+
652
699
/// Concretize the type. The input to this method may include
653
700
/// `ListUnionType` and the `CallableType` variant for a `principal.
654
701
/// This method turns these "temporary" types into actual types.
0 commit comments