Skip to content

Commit 9f99428

Browse files
committed
Guard the copy_block optimization with an experimental feature flag CopyBlockOptimization
1 parent d8fddc9 commit 9f99428

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyCopyBlock.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ extension CopyBlockInst : Simplifiable, SILCombineSimplifiable {
2828
/// ```
2929
///
3030
func simplify(_ context: SimplifyContext) {
31+
// Temporarily guarded with an experimental feature flag.
32+
if !context.options.hasFeature(.CopyBlockOptimization) {
33+
return
34+
}
35+
3136
if hasValidUses(block: self) {
3237
replaceBlock( self, with: operand.value, context)
3338
context.erase(instruction: self)

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
520520
/// Allow declarations of Swift runtime symbols using @_silgen_name.
521521
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
522522

523+
/// Optimize copies of ObjectiveC blocks.
524+
EXPERIMENTAL_FEATURE(CopyBlockOptimization, true)
525+
523526
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
524527
#undef EXPERIMENTAL_FEATURE
525528
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
429429
UNINTERESTING_FEATURE(SuppressCXXForeignReferenceTypeInitializers)
430430
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
431431
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)
432+
UNINTERESTING_FEATURE(CopyBlockOptimization)
432433

433434
static bool usesFeatureSwiftSettings(const Decl *decl) {
434435
// We just need to guard `#SwiftSettings`.

test/SILOptimizer/optimize_copy_block.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// RUN: %empty-directory(%t)
22
// RUN: split-file %s %t
3-
// RUN: %target-swift-frontend -I %t %t/test.swift -O -emit-sil | %FileCheck %s
3+
// RUN: %target-swift-frontend -I %t %t/test.swift -enable-experimental-feature CopyBlockOptimization -O -emit-sil | %FileCheck %s
44

55
// REQUIRES: objc_interop
6+
// REQUIRES: swift_feature_CopyBlockOptimization
67

78
//--- module.modulemap
89

test/SILOptimizer/simplify_copy_block.sil

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// RUN: %target-sil-opt %s -simplification -simplify-instruction=copy_block | %FileCheck %s
1+
// RUN: %target-sil-opt %s -enable-experimental-feature CopyBlockOptimization -simplification -simplify-instruction=copy_block | %FileCheck --check-prefix=CHECK --check-prefix=ENABLED %s
2+
// RUN: %target-sil-opt %s -simplification -simplify-instruction=copy_block | %FileCheck --check-prefix=CHECK --check-prefix=DISABLED %s
23

34
// REQUIRES: objc_interop
5+
// REQUIRES: swift_feature_CopyBlockOptimization
46

57
sil_stage canonical
68

@@ -9,9 +11,10 @@ import SwiftShims
911
import Builtin
1012

1113
// CHECK-LABEL: sil [ossa] @remove_copy_block :
12-
// CHECK-NOT: copy_block
13-
// CHECK: apply %0
14-
// CHECK-NOT: destroy_value
14+
// ENABLED-NOT: copy_block
15+
// ENABLED: apply %0
16+
// ENABLED-NOT: destroy_value
17+
// DISABLED: copy_block
1518
// CHECK: } // end sil function 'remove_copy_block'
1619
sil [ossa] @remove_copy_block : $@convention(thin) (@convention(block) @noescape () -> ()) -> () {
1720
bb0(%0 : @unowned $@convention(block) @noescape () -> ()):

0 commit comments

Comments
 (0)