|
14 | 14 | #include "swift/SIL/InstructionUtils.h"
|
15 | 15 | #include "swift/SIL/MemAccessUtils.h"
|
16 | 16 | #include "swift/AST/SubstitutionMap.h"
|
| 17 | +#include "swift/AST/ProtocolConformance.h" |
17 | 18 | #include "swift/Basic/Assertions.h"
|
18 | 19 | #include "swift/Basic/Defer.h"
|
19 | 20 | #include "swift/Basic/NullablePtr.h"
|
@@ -671,7 +672,20 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
|
671 | 672 | RuntimeEffect::MetaData | RuntimeEffect::Existential;
|
672 | 673 |
|
673 | 674 | case SILInstructionKind::InitExistentialRefInst:
|
674 |
| - impactType = inst->getOperand(0)->getType(); |
| 675 | + impactType = cast<InitExistentialRefInst>(inst)->getType(); |
| 676 | + // Make sure to get a diagnostic error in embedded swift for class existentials |
| 677 | + // where not all protocols of a composition are class bound. For example: |
| 678 | + // let existential: any ClassBound & NotClassBound = MyClass() |
| 679 | + // In future we might support this case and then we can remove this check. |
| 680 | + for (auto protoRef : cast<InitExistentialRefInst>(inst)->getConformances()) { |
| 681 | + if (protoRef.isConcrete()) { |
| 682 | + ProtocolConformance *conf = protoRef.getConcrete(); |
| 683 | + if (isa<NormalProtocolConformance>(conf) && |
| 684 | + !conf->getProtocol()->requiresClass()) { |
| 685 | + return RuntimeEffect::MetaData | RuntimeEffect::Existential; |
| 686 | + } |
| 687 | + } |
| 688 | + } |
675 | 689 | return RuntimeEffect::MetaData | RuntimeEffect::ExistentialClassBound;
|
676 | 690 |
|
677 | 691 | case SILInstructionKind::InitExistentialMetatypeInst:
|
|
0 commit comments