Skip to content

[4.1] SIL: Fix zealous assert in verifier #14134

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
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2311,9 +2311,18 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
if (inst->isTypeDependentOperand(*use))
continue;
switch (inst->getKind()) {
case SILInstructionKind::MarkDependenceInst:
break;
case SILInstructionKind::ApplyInst:
case SILInstructionKind::TryApplyInst:
case SILInstructionKind::PartialApplyInst:
// Non-Mutating set pattern that allows a inout (that can't really
// write back.
if (auto *AI = dyn_cast<ApplyInst>(inst)) {
if (isa<PointerToThinFunctionInst>(AI->getCallee())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't get it. What does the function representation have to do with consuming-or-mutating arguments? I think this warrants a little more explanation.

break;
}
}
if (isConsumingOrMutatingApplyUse(use))
return true;
else
Expand Down
21 changes: 21 additions & 0 deletions test/SILGen/protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,27 @@ func modifyProperty<T : PropertyWithGetterSetter>(_ x: inout T) {
// CHECK: [[TEMPORARY:%.*]] = address_to_pointer [[TEMPORARY_ADDR]] : $*Int to $Builtin.RawPointer
// CHECK: apply [[CALLBACK]]<T>

public struct Val {
public var x: Int = 0
}

public protocol Proto {
var val: Val { get nonmutating set}
}

public func test(_ p: Proto) {
p.val.x += 1
}

// CHECK-LABEL: sil @$S9protocols4testyyAA5Proto_pF : $@convention(thin) (@in Proto) -> ()
// CHECK: [[OPEN:%.*]] = open_existential_addr immutable_access
// CHECK: [[MAT:%.*]] = witness_method $@opened("{{.*}}") Proto, #Proto.val!materializeForSet
// CHECK: [[BUF:%.*]] = apply [[MAT]]
// CHECK: [[WB:%.*]] = pointer_to_thin_function
// This use looks like it is mutating but really is not. We use to assert in the SIL verifier.
// CHECK: apply [[WB]]{{.*}}({{.*}}[[OPEN]]
// CHECK: return

// CHECK-LABEL: sil_witness_table hidden ClassWithGetter: PropertyWithGetter module protocols {
// CHECK-NEXT: method #PropertyWithGetter.a!getter.1: {{.*}} : @_T09protocols15ClassWithGetterCAA08PropertycD0A2aDP1aSivgTW
// CHECK-NEXT: }
Expand Down