@@ -601,6 +601,7 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
601
601
CanSILFunctionType SubstCalleeType;
602
602
SubstitutionList Subs;
603
603
const HeapLayout &Layout;
604
+
604
605
public:
605
606
CaptureDescriptorBuilder (IRGenModule &IGM,
606
607
SILFunction &Caller,
@@ -630,6 +631,35 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
630
631
}
631
632
}
632
633
634
+ // / Give up if we captured an opened existential type. Eventually we
635
+ // / should figure out how to represent this.
636
+ static bool hasOpenedExistential (CanSILFunctionType OrigCalleeType,
637
+ const HeapLayout &Layout) {
638
+ if (!OrigCalleeType->isPolymorphic () ||
639
+ OrigCalleeType->isPseudogeneric ())
640
+ return false ;
641
+
642
+ auto &Bindings = Layout.getBindings ();
643
+ for (unsigned i = 0 ; i < Bindings.size (); ++i) {
644
+ // Skip protocol requirements (FIXME: for now?)
645
+ if (Bindings[i].Protocol != nullptr )
646
+ continue ;
647
+
648
+ if (Bindings[i].TypeParameter ->hasOpenedExistential ())
649
+ return true ;
650
+ }
651
+
652
+ auto ElementTypes = Layout.getElementTypes ().slice (
653
+ Layout.hasBindings () ? 1 : 0 );
654
+ for (auto ElementType : ElementTypes) {
655
+ auto SwiftType = ElementType.getSwiftRValueType ();
656
+ if (SwiftType->hasOpenedExistential ())
657
+ return true ;
658
+ }
659
+
660
+ return false ;
661
+ }
662
+
633
663
// / Slice off the NecessaryBindings struct at the beginning, if it's there.
634
664
// / We'll keep track of how many things are in the bindings struct with its
635
665
// / own count in the capture descriptor.
@@ -660,8 +690,9 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
660
690
continue ;
661
691
662
692
auto Source = SourceBuilder.createClosureBinding (i);
663
- auto BindingType = Caller.mapTypeOutOfContext (Bindings[i].TypeParameter );
664
- SourceMap.push_back ({BindingType->getCanonicalType (), Source});
693
+ auto BindingType = Bindings[i].TypeParameter ;
694
+ auto InterfaceType = Caller.mapTypeOutOfContext (BindingType);
695
+ SourceMap.push_back ({InterfaceType->getCanonicalType (), Source});
665
696
}
666
697
667
698
// Check if any requirements were fulfilled by metadata stored inside a
@@ -701,10 +732,9 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
701
732
// parameters.
702
733
auto Src = Path.getMetadataSource (SourceBuilder, Root);
703
734
704
- auto SubstType =
705
- Caller.mapTypeOutOfContext (
706
- GenericParam.subst (SubstMap, None));
707
- SourceMap.push_back ({SubstType->getCanonicalType (), Src});
735
+ auto SubstType = GenericParam.subst (SubstMap);
736
+ auto InterfaceType = Caller.mapTypeOutOfContext (SubstType);
737
+ SourceMap.push_back ({InterfaceType->getCanonicalType (), Src});
708
738
});
709
739
710
740
return SourceMap;
@@ -872,11 +902,13 @@ IRGenModule::getAddrOfCaptureDescriptor(SILFunction &Caller,
872
902
if (!IRGen.Opts .EnableReflectionMetadata )
873
903
return llvm::Constant::getNullValue (CaptureDescriptorPtrTy);
874
904
905
+ if (CaptureDescriptorBuilder::hasOpenedExistential (OrigCalleeType, Layout))
906
+ return llvm::Constant::getNullValue (CaptureDescriptorPtrTy);
907
+
875
908
CaptureDescriptorBuilder builder (*this , Caller,
876
909
OrigCalleeType, SubstCalleeType, Subs,
877
910
Layout);
878
911
auto var = builder.emit ();
879
-
880
912
return llvm::ConstantExpr::getBitCast (var, CaptureDescriptorPtrTy);
881
913
}
882
914
0 commit comments