Skip to content
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
20 changes: 20 additions & 0 deletions SwiftCompilerSources/Sources/SIL/ApplySite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ extension ApplySite {
}

public func isAddressable(operand: Operand) -> Bool {
for targetOperand in argumentOperands {
guard !targetOperand.value.isEscapable else {
continue
}
if let dep = parameterDependence(target: targetOperand, source: operand), dep.isAddressable(for: operand.value) {
return true
}
}
if let dep = resultDependence(on: operand) {
return dep.isAddressable(for: operand.value)
}
Expand Down Expand Up @@ -399,3 +407,15 @@ extension FullApplySite {
return values
}
}

let addressableTest = Test("addressable_arguments") {
function, arguments, context in

let operand = arguments.takeOperand()
guard let apply = operand.instruction as? ApplySite, let argIdx = apply.calleeArgumentIndex(of: operand) else {
fatalError("tested operand must be an apply argument")
}
let isAddressable = apply.isAddressable(operand: operand)
print("Arg Index: \(argIdx) of Apply: \(apply)")
print(" isAddressable: \(isAddressable)")
}
3 changes: 2 additions & 1 deletion SwiftCompilerSources/Sources/SIL/Utilities/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ public func registerTests() {
borrowIntroducersTest,
enclosingValuesTest,
forwardingDefUseTest,
forwardingUseDefTest
forwardingUseDefTest,
addressableTest
)

registerTestThunk(testThunk)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// RUN: %target-sil-opt -test-runner %s \
// RUN: -module-name Swift \
// RUN: -enable-experimental-feature LifetimeDependence \
// RUN: -enable-experimental-feature AddressableTypes \
// RUN: -o /dev/null 2>&1 | %FileCheck %s

// REQUIRES: swift_in_compiler
// REQUIRES: swift_feature_LifetimeDependence
// REQUIRES: swift_feature_AddressableTypes

sil_stage raw

Expand Down Expand Up @@ -62,6 +64,11 @@ struct NEWrap : ~Escapable {
init() { }
}

@_addressableForDependencies
public struct InlineInt {
var i: Builtin.Int64
}

sil @coroutine : $@yield_once @convention(method) (@guaranteed NE) -> @yields @guaranteed NE

sil @capture : $@convention(thin) (@guaranteed NE) -> ()
Expand Down Expand Up @@ -347,3 +354,26 @@ bb0(%0 : @owned $NCNEInt):
%99 = tuple()
return %99 : $()
}

// =============================================================================
// isAddressable
// =============================================================================

sil [ossa] @addressableForInoutDepHelper : $@convention(thin) (@in_guaranteed InlineInt, @lifetime(borrow address_for_deps 0) @inout NE) -> () {
bb(%0 : $*InlineInt, %1 : $*NE):
%99 = tuple()
return %99 : $()
}

// CHECK-LABEL: begin running test 1 of 1 on addressableForInoutDep: addressable_arguments with: @instruction.operand[1]
// CHECK: Arg Index: 0 of Apply: %{{.*}} = apply %{{.*}}(%0, %1) : $@convention(thin) (@in_guaranteed InlineInt, @lifetime(borrow address_for_deps 0) @inout NE) -> ()
// CHECK: isAddressable: true
// CHECK-LABEL: end running test 1 of 1 on addressableForInoutDep: addressable_arguments with: @instruction.operand[1]
sil [ossa] @addressableForInoutDep : $@convention(thin) (@in_guaranteed InlineInt, @lifetime(borrow address_for_deps 0) @inout NE) -> () {
bb(%0 : $*InlineInt, %1 : $*NE):
%f = function_ref @addressableForInoutDepHelper : $@convention(thin) (@in_guaranteed InlineInt, @lifetime(borrow address_for_deps 0) @inout NE) -> ()
specify_test "addressable_arguments @instruction.operand[1]"
%call = apply %f(%0, %1) : $@convention(thin) (@in_guaranteed InlineInt, @lifetime(borrow address_for_deps 0) @inout NE) -> ()
%99 = tuple()
return %99 : $()
}