diff --git a/include/swift/AST/DiagnosticsFrontend.def b/include/swift/AST/DiagnosticsFrontend.def index 7f52123bed721..dd5a18ab55e4d 100644 --- a/include/swift/AST/DiagnosticsFrontend.def +++ b/include/swift/AST/DiagnosticsFrontend.def @@ -80,6 +80,8 @@ ERROR(error_unknown_arg,none, "unknown argument: '%0'", (StringRef)) ERROR(error_invalid_arg_value,none, "invalid value '%1' in '%0'", (StringRef, StringRef)) +ERROR(error_invalid_arg_combination,none, + "unsupported argument combination: '%0' and '%1'", (StringRef, StringRef)) WARNING(warning_invalid_locale_code,none, "unsupported locale code; supported locale codes are: '%0'", (StringRef)) WARNING(warning_locale_path_not_found,none, diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index 6c53cbc492fc0..93a277688027a 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -213,7 +213,8 @@ def dependency_scan_cache_remarks : Flag<["-"], "Rdependency-scan-cache">, HelpText<"Emit remarks indicating use of the serialized module dependency scanning cache.">; def enable_copy_propagation : Flag<["-"], "enable-copy-propagation">, - HelpText<"Run SIL copy propagation to shorten object lifetime.">; + HelpText<"Run SIL copy propagation with lexical lifetimes to shorten object " + "lifetimes while preserving variable lifetimes.">; def disable_copy_propagation : Flag<["-"], "disable-copy-propagation">, HelpText<"Don't run SIL copy propagation to preserve object lifetime.">; @@ -259,15 +260,18 @@ def enable_experimental_concurrency : Flag<["-"], "enable-experimental-concurrency">, HelpText<"Enable experimental concurrency model">; -def disable_lexical_lifetimes : - Flag<["-"], "disable-lexical-lifetimes">, - HelpText<"Disables early lexical lifetimes. Mutually exclusive with " - "-enable-lexical-lifetimes">; - +def enable_lexical_borrow_scopes : + Joined<["-"], "enable-lexical-borrow-scopes=">, + HelpText<"Whether to emit lexical borrow scopes (default: true)">, + MetaVarName<"true|false">; + def enable_lexical_lifetimes : + Joined<["-"], "enable-lexical-lifetimes=">, + HelpText<"Whether to enable lexical lifetimes">, + MetaVarName<"true|false">; +def enable_lexical_lifetimes_noArg : Flag<["-"], "enable-lexical-lifetimes">, - HelpText<"Enable lexical lifetimes. Mutually exclusive with " - "-disable-lexical-lifetimes">; + HelpText<"Enable lexical lifetimes">; def enable_experimental_move_only : Flag<["-"], "enable-experimental-move-only">, diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index cc60ba016612a..c286e25230226 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1449,21 +1449,88 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args, // -Ounchecked might also set removal of runtime asserts (cond_fail). Opts.RemoveRuntimeAsserts |= Args.hasArg(OPT_RemoveRuntimeAsserts); - // If experimental move only is enabled, always enable lexical lifetime as - // well. Move only depends on lexical lifetimes. - bool enableExperimentalLexicalLifetimes = - Args.hasArg(OPT_enable_lexical_lifetimes) || - Args.hasArg(OPT_enable_experimental_move_only); - // Error if both experimental lexical lifetimes and disable lexical lifetimes - // are both set. - if (enableExperimentalLexicalLifetimes && - Args.hasArg(OPT_disable_lexical_lifetimes)) { + Optional enableLexicalBorrowScopesFlag; + if (Arg *A = Args.getLastArg(OPT_enable_lexical_borrow_scopes)) { + enableLexicalBorrowScopesFlag = + llvm::StringSwitch>(A->getValue()) + .Case("true", true) + .Case("false", false) + .Default(None); + } + Optional enableLexicalLifetimesFlag; + if (Arg *A = Args.getLastArg(OPT_enable_lexical_lifetimes)) { + enableLexicalLifetimesFlag = + llvm::StringSwitch>(A->getValue()) + .Case("true", true) + .Case("false", false) + .Default(None); + } + if (Args.getLastArg(OPT_enable_lexical_lifetimes_noArg)) { + if (!enableLexicalLifetimesFlag.getValueOr(true)) { + // Error if lexical lifetimes have been disabled via the meta-var form + // and enabled via the flag. + Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination, + "enable-lexical-lifetimes", + "enable-lexical-lifetimes=false"); + return true; + } else { + enableLexicalLifetimesFlag = true; + } + } + + if (enableLexicalLifetimesFlag.getValueOr(false) && + !enableLexicalBorrowScopesFlag.getValueOr(true)) { + // Error if lexical lifetimes have been enabled but lexical borrow scopes-- + // on which they are dependent--have been disabled. + Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination, + "enable-lexical-lifetimes=true", + "enable-lexical-borrow-scopes=false"); return true; - } else { - if (enableExperimentalLexicalLifetimes) + } + + if (Args.hasArg(OPT_enable_experimental_move_only) && + (enableLexicalBorrowScopesFlag.getValueOr(false))) { + // Error if move-only is enabled and lexical borrow scopes--on which it + // depends--has been disabled. + Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination, + "enable-experimental-move-only", + "enable-lexical-borrow-scopes=false"); + return true; + } + + if (Args.hasArg(OPT_enable_experimental_move_only) && + (enableLexicalLifetimesFlag.getValueOr(false))) { + // Error if move-only is enabled and lexical lifetimes--on which it + // depends--has been disabled. + Diags.diagnose(SourceLoc(), diag::error_invalid_arg_combination, + "enable-experimental-move-only", + "enable-lexical-lifetimes=false"); + return true; + } + + // -enable-copy-propagation implies -enable-lexical-lifetimes unless + // otherwise specified. + if (Args.hasArg(OPT_enable_copy_propagation)) + Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate; + + // If move-only is enabled, always enable lexical lifetime as well. Move-only + // depends on lexical lifetimes. + if (Args.hasArg(OPT_enable_experimental_move_only)) + Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate; + + if (enableLexicalLifetimesFlag) { + if (*enableLexicalLifetimesFlag) { Opts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate; - if (Args.hasArg(OPT_disable_lexical_lifetimes)) + } else { + Opts.LexicalLifetimes = LexicalLifetimesOption::Early; + } + } + if (enableLexicalBorrowScopesFlag) { + if (*enableLexicalBorrowScopesFlag) { + Opts.LexicalLifetimes = LexicalLifetimesOption::Early; + } else { Opts.LexicalLifetimes = LexicalLifetimesOption::Off; + } } Opts.EnableCopyPropagation |= Args.hasArg(OPT_enable_copy_propagation); diff --git a/lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp b/lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp index 22c9f87ff1843..c989263a8eb01 100644 --- a/lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp +++ b/lib/SILOptimizer/Utils/CanonicalizeInstruction.cpp @@ -415,8 +415,8 @@ broadenSingleElementStores(StoreInst *storeInst, /// borrow scope--copy/destroy is insufficient by itself. /// /// FIXME: Technically this should be guarded by a compiler flag like -/// -enable-copy-propagation until SILGen protects scoped variables by borrow -/// scopes. +/// -enable-copy-propagation until SILGen protects scoped variables by +/// borrow scopes. static SILBasicBlock::iterator eliminateSimpleCopies(CopyValueInst *cvi, CanonicalizeInstruction &pass) { auto next = std::next(cvi->getIterator()); diff --git a/test/AutoDiff/validation-test/array.swift b/test/AutoDiff/validation-test/array.swift index 7eb460631ec52..f84d6f315838a 100644 --- a/test/AutoDiff/validation-test/array.swift +++ b/test/AutoDiff/validation-test/array.swift @@ -1,4 +1,4 @@ -// RUN: %target-run-simple-swift(-Xfrontend -disable-lexical-lifetimes) +// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false) // REQUIRES: executable_test diff --git a/test/AutoDiff/validation-test/optional.swift b/test/AutoDiff/validation-test/optional.swift index 83b273f9cb8b0..4a10255867a76 100644 --- a/test/AutoDiff/validation-test/optional.swift +++ b/test/AutoDiff/validation-test/optional.swift @@ -1,4 +1,4 @@ -// RUN: %target-run-simple-swift(-Xfrontend -disable-lexical-lifetimes) +// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false) // REQUIRES: executable_test diff --git a/test/AutoDiff/validation-test/optional_property.swift b/test/AutoDiff/validation-test/optional_property.swift index 414145a2244ef..8bf5eafe3cdf5 100644 --- a/test/AutoDiff/validation-test/optional_property.swift +++ b/test/AutoDiff/validation-test/optional_property.swift @@ -1,5 +1,5 @@ -// RUN: %target-run-simple-swift(-Xfrontend -disable-lexical-lifetimes) -// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -disable-lexical-lifetimes -module-name null -o /dev/null 2>&1 %s | %FileCheck %s +// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-borrow-scopes=false) +// RUN: %target-swift-emit-sil -Xllvm -debug-only=differentiation -enable-lexical-borrow-scopes=false -module-name null -o /dev/null 2>&1 %s | %FileCheck %s // REQUIRES: executable_test // REQUIRES: asserts diff --git a/test/Concurrency/Runtime/async_properties_actor.swift b/test/Concurrency/Runtime/async_properties_actor.swift index 0d2c5f0b02bba..06e0025a4eb07 100644 --- a/test/Concurrency/Runtime/async_properties_actor.swift +++ b/test/Concurrency/Runtime/async_properties_actor.swift @@ -1,4 +1,4 @@ -// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -enable-copy-propagation -Xfrontend -disable-availability-checking %import-libdispatch) | %FileCheck %s +// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -enable-copy-propagation -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-availability-checking %import-libdispatch) | %FileCheck %s // REQUIRES: executable_test // REQUIRES: concurrency diff --git a/test/DebugInfo/if-branchlocations.swift b/test/DebugInfo/if-branchlocations.swift index 0cdd228727226..fa03eeb2f103a 100644 --- a/test/DebugInfo/if-branchlocations.swift +++ b/test/DebugInfo/if-branchlocations.swift @@ -1,5 +1,5 @@ // RUN: %target-swift-frontend %s -emit-sil -disable-copy-propagation -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-NCP -// RUN: %target-swift-frontend %s -emit-sil -enable-copy-propagation -disable-lexical-lifetimes -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-CP +// RUN: %target-swift-frontend %s -emit-sil -enable-copy-propagation -enable-lexical-borrow-scopes=false -emit-verbose-sil -g -o - | %FileCheck %s --check-prefixes=CHECK,CHECK-CP class NSURL {} diff --git a/test/DebugInfo/linetable-do.swift b/test/DebugInfo/linetable-do.swift index 8b212dc3e1fab..576ae47afc6c9 100644 --- a/test/DebugInfo/linetable-do.swift +++ b/test/DebugInfo/linetable-do.swift @@ -1,6 +1,6 @@ // RUN: %target-swift-frontend -Xllvm -sil-full-demangle %s -emit-ir -g -o - | %FileCheck %s // RUN: %target-swift-frontend -Xllvm -sil-full-demangle -disable-copy-propagation %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-NCP %s -// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -enable-copy-propagation -disable-lexical-lifetimes %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-CP %s +// RUN: %target-swift-frontend -Xllvm -sil-full-demangle -enable-copy-propagation -enable-lexical-borrow-scopes=false %s -emit-sil -emit-verbose-sil -g -o - | %FileCheck --check-prefixes=CHECK-SIL,CHECK-CP %s import StdlibUnittest class Obj {} diff --git a/test/IRGen/debug_poison.swift b/test/IRGen/debug_poison.swift index e68044e964832..9359086c80a79 100644 --- a/test/IRGen/debug_poison.swift +++ b/test/IRGen/debug_poison.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -primary-file %s -emit-ir -Onone -enable-copy-propagation -disable-lexical-lifetimes | %FileCheck %s -DINT=i%target-ptrsize +// RUN: %target-swift-frontend -primary-file %s -emit-ir -Onone -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s -DINT=i%target-ptrsize // Test debug_value [poison] emission diff --git a/test/IRGen/unmanaged_objc_throw_func.swift b/test/IRGen/unmanaged_objc_throw_func.swift index e79760212e9d7..8c619801c2e1d 100644 --- a/test/IRGen/unmanaged_objc_throw_func.swift +++ b/test/IRGen/unmanaged_objc_throw_func.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir -enable-copy-propagation %s | %FileCheck %s +// RUN: %target-swift-frontend -emit-ir -enable-copy-propagation -enable-lexical-lifetimes=false %s | %FileCheck %s // REQUIRES: objc_interop // REQUIRES: optimized_stdlib diff --git a/test/Interpreter/builtin_bridge_object.swift b/test/Interpreter/builtin_bridge_object.swift index a391e63f11925..c6ee190825200 100644 --- a/test/Interpreter/builtin_bridge_object.swift +++ b/test/Interpreter/builtin_bridge_object.swift @@ -1,5 +1,5 @@ -// RUN: %target-run-simple-swift(-Onone -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -disable-lexical-lifetimes) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG -// RUN: %target-run-simple-swift(-O -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -disable-lexical-lifetimes) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s +// RUN: %target-run-simple-swift(-Onone -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -enable-lexical-borrow-scopes=false) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG +// RUN: %target-run-simple-swift(-O -parse-stdlib -Xfrontend -enable-copy-propagation -Xfrontend -enable-lexical-borrow-scopes=false) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s // REQUIRES: executable_test // REQUIRES: objc_interop diff --git a/test/SILOptimizer/OSLogFullOptTest.swift b/test/SILOptimizer/OSLogFullOptTest.swift index bb858e916bf4b..79e1244ba6771 100644 --- a/test/SILOptimizer/OSLogFullOptTest.swift +++ b/test/SILOptimizer/OSLogFullOptTest.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-ir -swift-version 5 -O -enable-copy-propagation -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize +// RUN: %target-swift-frontend -emit-ir -swift-version 5 -O -enable-copy-propagation -enable-lexical-lifetimes=false -primary-file %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize // // REQUIRES: VENDOR=apple // REQUIRES: swift_stdlib_no_asserts diff --git a/test/SILOptimizer/allocbox_to_stack.sil b/test/SILOptimizer/allocbox_to_stack.sil index 5b7b752037832..c864889c982db 100644 --- a/test/SILOptimizer/allocbox_to_stack.sil +++ b/test/SILOptimizer/allocbox_to_stack.sil @@ -1,4 +1,4 @@ -// RUN: %target-sil-opt -sil-print-debuginfo -enable-sil-verify-all %s -allocbox-to-stack -disable-lexical-lifetimes | %FileCheck %s +// RUN: %target-sil-opt -sil-print-debuginfo -enable-sil-verify-all %s -allocbox-to-stack -enable-lexical-borrow-scopes=false | %FileCheck %s sil_stage raw diff --git a/test/SILOptimizer/allocbox_to_stack_ownership.sil b/test/SILOptimizer/allocbox_to_stack_ownership.sil index 1650ebc8dab3a..8181671035c6f 100644 --- a/test/SILOptimizer/allocbox_to_stack_ownership.sil +++ b/test/SILOptimizer/allocbox_to_stack_ownership.sil @@ -1,4 +1,4 @@ -// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -disable-lexical-lifetimes | %FileCheck %s +// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -enable-lexical-borrow-scopes=false | %FileCheck %s sil_stage raw diff --git a/test/SILOptimizer/assemblyvision_remark/basic.swift b/test/SILOptimizer/assemblyvision_remark/basic.swift index a4607ed80534e..5c13d5db17b3f 100644 --- a/test/SILOptimizer/assemblyvision_remark/basic.swift +++ b/test/SILOptimizer/assemblyvision_remark/basic.swift @@ -1,4 +1,4 @@ -// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -disable-lexical-lifetimes +// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -enable-lexical-borrow-scopes=false // REQUIRES: optimized_stdlib,swift_stdlib_no_asserts public class Klass { diff --git a/test/SILOptimizer/assemblyvision_remark/basic_yaml.swift b/test/SILOptimizer/assemblyvision_remark/basic_yaml.swift index a650b1946347f..6cac91306c699 100644 --- a/test/SILOptimizer/assemblyvision_remark/basic_yaml.swift +++ b/test/SILOptimizer/assemblyvision_remark/basic_yaml.swift @@ -1,7 +1,7 @@ -// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -disable-lexical-lifetimes +// RUN: %target-swiftc_driver -O -Rpass-missed=sil-assembly-vision-remark-gen -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil %s -o /dev/null -Xfrontend -verify -Xfrontend -enable-lexical-borrow-scopes=false // RUN: %empty-directory(%t) -// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml -Xfrontend -disable-lexical-lifetimes %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s +// RUN: %target-swiftc_driver -wmo -O -Xllvm -sil-disable-pass=FunctionSignatureOpts -Xfrontend -enable-copy-propagation -emit-sil -save-optimization-record=yaml -save-optimization-record-path %t/note.yaml -Xfrontend -enable-lexical-borrow-scopes=false %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s // REQUIRES: optimized_stdlib,swift_stdlib_no_asserts diff --git a/test/SILOptimizer/diagnose_lifetime_issues.swift b/test/SILOptimizer/diagnose_lifetime_issues.swift index ebc4e1d90ccae..2b2fd9f38e62c 100644 --- a/test/SILOptimizer/diagnose_lifetime_issues.swift +++ b/test/SILOptimizer/diagnose_lifetime_issues.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-sil -disable-lexical-lifetimes -enable-copy-propagation %s -o /dev/null -verify +// RUN: %target-swift-frontend -emit-sil -enable-lexical-borrow-scopes=false -enable-copy-propagation %s -o /dev/null -verify class Delegate { func foo() { } diff --git a/test/SILOptimizer/diagnose_lifetime_issues_objc.swift b/test/SILOptimizer/diagnose_lifetime_issues_objc.swift index 235af58ff7b10..87e2228f7e105 100644 --- a/test/SILOptimizer/diagnose_lifetime_issues_objc.swift +++ b/test/SILOptimizer/diagnose_lifetime_issues_objc.swift @@ -1,4 +1,4 @@ -// RUN: %target-swift-frontend -emit-sil %s -disable-lexical-lifetimes -enable-copy-propagation -o /dev/null -verify +// RUN: %target-swift-frontend -emit-sil %s -enable-lexical-borrow-scopes=false -enable-copy-propagation -o /dev/null -verify // REQUIRES: objc_interop import Foundation diff --git a/test/SILOptimizer/opaque_values_mandatory.sil b/test/SILOptimizer/opaque_values_mandatory.sil index baff8f69b52c0..91a998b4211e7 100644 --- a/test/SILOptimizer/opaque_values_mandatory.sil +++ b/test/SILOptimizer/opaque_values_mandatory.sil @@ -1,7 +1,8 @@ // RUN: %target-sil-opt -diagnostics -enable-sil-opaque-values %s | \ // RUN: %target-sil-opt -Onone-performance -enable-sil-verify-all \ // RUN: -enable-sil-opaque-values -emit-sorted-sil \ -// RUN: -enable-ossa-modules -enable-copy-propagation | \ +// RUN: -enable-ossa-modules -enable-copy-propagation \ +// RUN: -enable-lexical-borrow-scopes | \ // RUN: %FileCheck %s import Builtin diff --git a/test/SILOptimizer/outliner.swift b/test/SILOptimizer/outliner.swift index b16ee288679d7..68557cd64b8d6 100644 --- a/test/SILOptimizer/outliner.swift +++ b/test/SILOptimizer/outliner.swift @@ -1,5 +1,5 @@ -// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -disable-lexical-lifetimes | %FileCheck %s -// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -disable-lexical-lifetimes | %FileCheck %s +// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s +// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s // REQUIRES: objc_interop // REQUIRES: optimized_stdlib diff --git a/test/SILOptimizer/sil_combine_apply_ossa.sil b/test/SILOptimizer/sil_combine_apply_ossa.sil index de18b09d757cc..e4dc98153dc13 100644 --- a/test/SILOptimizer/sil_combine_apply_ossa.sil +++ b/test/SILOptimizer/sil_combine_apply_ossa.sil @@ -1,4 +1,4 @@ -// RUN: %target-sil-opt -enable-ossa-modules -enable-copy-propagation -enable-sil-verify-all %s -sil-combine -sil-combine-disable-alloc-stack-opts | %FileCheck %s +// RUN: %target-sil-opt -enable-ossa-modules -enable-copy-propagation -enable-lexical-lifetimes=false -enable-sil-verify-all %s -sil-combine -sil-combine-disable-alloc-stack-opts | %FileCheck %s import Swift import Builtin diff --git a/test/SILOptimizer/sil_combine_ossa.sil b/test/SILOptimizer/sil_combine_ossa.sil index 827c42db0267f..0a565e557645c 100644 --- a/test/SILOptimizer/sil_combine_ossa.sil +++ b/test/SILOptimizer/sil_combine_ossa.sil @@ -2,7 +2,7 @@ // RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -generic-specializer | %FileCheck %s --check-prefix=CHECK_FORWARDING_OWNERSHIP_KIND // // FIXME: check copy-propagation output instead once it is the default mode -// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -enable-copy-propagation | %FileCheck %s --check-prefix=CHECK_COPYPROP +// RUN: %target-sil-opt -enable-objc-interop -enforce-exclusivity=none -enable-sil-verify-all %s -sil-combine -enable-copy-propagation -enable-lexical-lifetimes=false | %FileCheck %s --check-prefix=CHECK_COPYPROP // Declare this SIL to be canonical because some tests break raw SIL // conventions. e.g. address-type block args. -enforce-exclusivity=none is also diff --git a/tools/sil-opt/SILOpt.cpp b/tools/sil-opt/SILOpt.cpp index 226557fa780f7..d8f03256f5b5f 100644 --- a/tools/sil-opt/SILOpt.cpp +++ b/tools/sil-opt/SILOpt.cpp @@ -105,15 +105,16 @@ static llvm::cl::opt EnableExperimentalConcurrency("enable-experimental-concurrency", llvm::cl::desc("Enable experimental concurrency model.")); -static llvm::cl::opt EnableExperimentalLexicalLifetimes( - "enable-lexical-lifetimes", - llvm::cl::desc("Enable experimental lexical lifetimes. Mutually exclusive " - "with disable-lexical-lifetimes.")); +static llvm::cl::opt EnableLexicalLifetimes( + "enable-lexical-lifetimes", llvm::cl::init(false), + llvm::cl::desc("Enable lexical lifetimes. Mutually exclusive with " + "enable-lexical-borrow-scopes and " + "disable-lexical-lifetimes.")); -static llvm::cl::opt DisableLexicalLifetimes( - "disable-lexical-lifetimes", - llvm::cl::desc("Disable the default early lexical lifetimes. Mutually " - "exclusive with enable-lexical-lifetimes")); +static llvm::cl::opt + EnableLexicalBorrowScopes("enable-lexical-borrow-scopes", + llvm::cl::init(true), + llvm::cl::desc("Enable lexical borrow scopes.")); static llvm::cl::opt EnableExperimentalMoveOnly("enable-experimental-move-only", @@ -137,9 +138,9 @@ static llvm::cl::opt EnableOSSAModules( "this is disabled we do not serialize in OSSA " "form when optimizing.")); -static llvm::cl::opt EnableCopyPropagation( - "enable-copy-propagation", - llvm::cl::desc("Enable the copy propagation pass.")); +static llvm::cl::opt + EnableCopyPropagation("enable-copy-propagation", + llvm::cl::desc("Enable the copy propagation pass.")); static llvm::cl::opt DisableCopyPropagation( "disable-copy-propagation", @@ -526,21 +527,22 @@ int main(int argc, char **argv) { SILOpts.EnableCopyPropagation = EnableCopyPropagation; SILOpts.DisableCopyPropagation = DisableCopyPropagation; + if (EnableCopyPropagation) + SILOpts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate; + // Enable lexical lifetimes if it is set or if experimental move only is // enabled. This is because move only depends on lexical lifetimes being // enabled and it saved some typing ; ). - bool enableExperimentalLexicalLifetimes = - EnableExperimentalLexicalLifetimes | EnableExperimentalMoveOnly; - if (enableExperimentalLexicalLifetimes && DisableLexicalLifetimes) { - fprintf( - stderr, - "Error! Can not specify both -enable-lexical-lifetimes " - "and -disable-lexical-lifetimes!\n"); + bool enableLexicalLifetimes = + EnableLexicalLifetimes | EnableExperimentalMoveOnly; + if (enableLexicalLifetimes && !EnableLexicalBorrowScopes) { + fprintf(stderr, "Error! Cannot specify both -enable-lexical-lifetimes " + "and either -enable-lexical-borrow-scopes=false"); exit(-1); } - if (enableExperimentalLexicalLifetimes) + if (enableLexicalLifetimes) SILOpts.LexicalLifetimes = LexicalLifetimesOption::ExperimentalLate; - if (DisableLexicalLifetimes) + if (!EnableLexicalBorrowScopes) SILOpts.LexicalLifetimes = LexicalLifetimesOption::Off; serialization::ExtendedValidationInfo extendedInfo; diff --git a/validation-test/SILOptimizer/lexical-lifetimes.swift b/validation-test/SILOptimizer/lexical-lifetimes.swift index 1727970caeed1..8d66114471f98 100644 --- a/validation-test/SILOptimizer/lexical-lifetimes.swift +++ b/validation-test/SILOptimizer/lexical-lifetimes.swift @@ -1,4 +1,4 @@ -// RUN: %target-run-simple-swift(-Xfrontend -enable-lexical-lifetimes -Xfrontend -enable-copy-propagation) | %FileCheck %s +// RUN: %target-run-simple-swift(-Xfrontend -enable-copy-propagation) | %FileCheck %s // REQUIRES: executable_test