Skip to content

Commit

Permalink
SILVerifier: fix a wrong check for witness_method instructions
Browse files Browse the repository at this point in the history
Consider that the lookup-type can be an opaque return type.

Also fixing the SILPrinter.

Fixes a verifier crash
swiftlang#77955
140939536
  • Loading branch information
eeckstein committed Dec 5, 2024
1 parent 4822920 commit d16a213
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/SIL/IR/SILPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,10 +2520,11 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
PrintOptions QualifiedSILTypeOptions =
PrintOptions::printQualifiedSILType();
QualifiedSILTypeOptions.CurrentModule = WMI->getModule().getSwiftModule();
*this << "$" << WMI->getLookupType() << ", " << WMI->getMember() << " : ";
auto lookupType = WMI->getLookupType();
*this << "$" << lookupType << ", " << WMI->getMember() << " : ";
WMI->getMember().getDecl()->getInterfaceType().print(
PrintState.OS, QualifiedSILTypeOptions);
if (!WMI->getTypeDependentOperands().empty()) {
if ((getLocalArchetypeOf(lookupType) || lookupType->hasDynamicSelfType()) && !WMI->getTypeDependentOperands().empty()) {
*this << ", ";
*this << getIDAndForcedPrintedType(WMI->getTypeDependentOperands()[0].get());
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4177,7 +4177,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
"Must have a type dependent operand for the opened archetype");
verifyLocalArchetype(AMI, lookupType);
} else {
require(AMI->getTypeDependentOperands().empty(),
require(AMI->getTypeDependentOperands().empty() || lookupType->hasLocalArchetype(),
"Should not have an operand for the opened existential");
}
if (!isa<ArchetypeType>(lookupType) && !isa<DynamicSelfType>(lookupType)) {
Expand Down
33 changes: 33 additions & 0 deletions test/SILOptimizer/propagate_opaque_return_type.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %target-run-simple-swift(-O -Xfrontend -sil-verify-all) | %FileCheck %s

protocol P {}
extension P {
func foo() -> some Sequence<Int> {
[1, 2, 3]
}
}

struct B {
let p: P

@inline(never)
func bar() {
for x in p.foo() {
print(x)
}
}
}


struct S : P {
var x = 0
}


let b = B(p: S())

// CHECK: 1
// CHECK-NEXT: 2
// CHECK-NEXT: 3
b.bar()

0 comments on commit d16a213

Please sign in to comment.