Skip to content

SILVerifier: fix a wrong check for witness_method instructions #77972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message talks about opaque archetypes, what's the connection?

Copy link
Contributor Author

@eeckstein eeckstein Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SILPrinter prints the first type dependent operand as explicit operand. I don't know why.
So far it was the assumption that if the lookupType is an opened archetype then there is exactly 1 type dependent operand. But this is not true for opaque return types, because those have opened archetypes in the substitution list. This SILPrinter change "restores" the original behavior that the explicit operand is printed if the lookupType is an opened archetype.

*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()