@@ -7687,6 +7687,30 @@ void SILWitnessTable::verify(const SILModule &mod) const {
7687
7687
assert (witnessFunction->getLoweredFunctionType ()->getRepresentation () ==
7688
7688
SILFunctionTypeRepresentation::WitnessMethod &&
7689
7689
" Witnesses must have witness_method representation." );
7690
+
7691
+ if (mod.getStage () != SILStage::Lowered &&
7692
+ !mod.getASTContext ().LangOpts .hasFeature (Feature::Embedded)) {
7693
+ // Note the direction of the compatibility check: the witness
7694
+ // function must be compatible with being used as the requirement
7695
+ // type.
7696
+ auto baseInfo = witnessFunction->getModule ().Types .getConstantInfo (
7697
+ TypeExpansionContext::minimal (),
7698
+ entry.getMethodWitness ().Requirement );
7699
+ SmallString<32 > baseName;
7700
+ {
7701
+ llvm::raw_svector_ostream os (baseName);
7702
+ entry.getMethodWitness ().Requirement .print (os);
7703
+ }
7704
+
7705
+ SILVerifier (*witnessFunction, /* calleeCache=*/ nullptr ,
7706
+ /* SingleFunction=*/ true ,
7707
+ /* checkLinearLifetime=*/ false )
7708
+ .requireABICompatibleFunctionTypes (
7709
+ witnessFunction->getLoweredFunctionType (),
7710
+ baseInfo.getSILType ().castTo <SILFunctionType>(),
7711
+ " witness table entry for " + baseName + " must be ABI-compatible" ,
7712
+ *witnessFunction);
7713
+ }
7690
7714
}
7691
7715
}
7692
7716
@@ -7714,6 +7738,31 @@ void SILDefaultWitnessTable::verify(const SILModule &mod) const {
7714
7738
assert (witnessFunction->getLoweredFunctionType ()->getRepresentation () ==
7715
7739
SILFunctionTypeRepresentation::WitnessMethod &&
7716
7740
" Default witnesses must have witness_method representation." );
7741
+
7742
+ if (mod.getStage () != SILStage::Lowered &&
7743
+ !mod.getASTContext ().LangOpts .hasFeature (Feature::Embedded)) {
7744
+ // Note the direction of the compatibility check: the witness
7745
+ // function must be compatible with being used as the requirement
7746
+ // type.
7747
+ auto baseInfo = witnessFunction->getModule ().Types .getConstantInfo (
7748
+ TypeExpansionContext::minimal (),
7749
+ entry.getMethodWitness ().Requirement );
7750
+ SmallString<32 > baseName;
7751
+ {
7752
+ llvm::raw_svector_ostream os (baseName);
7753
+ entry.getMethodWitness ().Requirement .print (os);
7754
+ }
7755
+
7756
+ SILVerifier (*witnessFunction, /* calleeCache=*/ nullptr ,
7757
+ /* SingleFunction=*/ true ,
7758
+ /* checkLinearLifetime=*/ false )
7759
+ .requireABICompatibleFunctionTypes (
7760
+ witnessFunction->getLoweredFunctionType (),
7761
+ baseInfo.getSILType ().castTo <SILFunctionType>(),
7762
+ " default witness table entry for " + baseName +
7763
+ " must be ABI-compatible" ,
7764
+ *witnessFunction);
7765
+ }
7717
7766
}
7718
7767
}
7719
7768
0 commit comments