Skip to content

SimplifyKeyPath: insert the correct destroy operation for an operand of a removed keypath #79314

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
Feb 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ extension KeyPathInst : OnoneSimplifyable {
let builder = Builder(after: self, context)
for operand in self.operands {
if !operand.value.type.isTrivial(in: parentFunction) {
builder.createDestroyValue(operand: operand.value)
if operand.value.type.isAddress {
builder.createDestroyAddr(address: operand.value)
} else {
builder.createDestroyValue(operand: operand.value)
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/SILOptimizer/simplify_keypath_resilient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: %target-swift-frontend -primary-file %s -enable-library-evolution -emit-sil | %FileCheck %s

public enum E: Hashable {
case e
}

public struct S {
public var dict: [E: Int] = [:]
}

// Check that the keypath simplification does not crash when inserting a compensating destroy.

// CHECK-LABEL: sil @$s26simplify_keypath_resilient6testityyF :
// CHECK-NOT: keypath
// CHECK: } // end sil function '$s26simplify_keypath_resilient6testityyF'
@inlinable
public func testit() {
let _ = \S.dict[.e]
}