Skip to content

[Frontend] Removed enable-lexical-borrow-scopes flag. #71403

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 3 commits into from
Feb 6, 2024
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
3 changes: 0 additions & 3 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,6 @@ class ASTContext final {
FuncDecl *getMakeInvocationEncoderOnDistributedActorSystem(
AbstractFunctionDecl *thunk) const;

/// Indicates whether move-only / noncopyable types are supported.
bool supportsMoveOnlyTypes() const;

// Retrieve the declaration of
// DistributedInvocationEncoder.recordGenericSubstitution(_:).
//
Expand Down
4 changes: 0 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7706,10 +7706,6 @@ ERROR(copy_expression_not_passed_lvalue,none,
ERROR(copy_expression_cannot_be_used_with_noncopyable_types,none,
"'copy' cannot be applied to noncopyable types", ())

ERROR(moveOnly_requires_lexical_lifetimes,none,
"noncopyable types require lexical borrow scopes "
"(add -enable-lexical-borrow-scopes=true)", ())

// Experimental noncopyable feature diagnostics:
ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
none, "Can not use feature when experimental move only is disabled! Pass"
Expand Down
3 changes: 0 additions & 3 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
namespace swift {

enum class LexicalLifetimesOption : uint8_t {
// Do not insert lexical markers.
Off = 0,

// Insert lexical markers via lexical borrow scopes and the lexical flag on
// alloc_stacks produced from alloc_boxes, but strip them when lowering out of
// Raw SIL.
Expand Down
5 changes: 0 additions & 5 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,6 @@ def enable_experimental_concurrency :
Flag<["-"], "enable-experimental-concurrency">,
HelpText<"Enable experimental concurrency model">;

def enable_lexical_borrow_scopes :
Joined<["-"], "enable-lexical-borrow-scopes=">,
HelpText<"Whether to emit lexical borrow scopes (default: true)">,
MetaVarName<"true|false">;

def enable_experimental_move_only :
Flag<["-"], "enable-experimental-move-only">,
HelpText<"Enable experimental move only">;
Expand Down
7 changes: 3 additions & 4 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,10 +1075,9 @@ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const SILModule &M){
inline bool SILOptions::supportsLexicalLifetimes(const SILModule &mod) const {
switch (mod.getStage()) {
case SILStage::Raw:
// In raw SIL, lexical markers are used for diagnostics. These markers are
// present as long as the lexical lifetimes feature is not disabled
// entirely.
return LexicalLifetimes != LexicalLifetimesOption::Off;
// In raw SIL, lexical markers are used for diagnostics and are always
// present.
return true;
case SILStage::Canonical:
case SILStage::Lowered:
// In Canonical SIL, lexical markers are used to ensure that object
Expand Down
5 changes: 0 additions & 5 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6529,8 +6529,3 @@ Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) {
return nominalDecl->getDeclaredType();
return decl->getDeclaredInterfaceType();
}

bool ASTContext::supportsMoveOnlyTypes() const {
// currently the only thing holding back whether the types can appear is this.
return SILOpts.LexicalLifetimes != LexicalLifetimesOption::Off;
}
38 changes: 5 additions & 33 deletions lib/DriverTool/sil_opt_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,10 @@ struct SILOptOptions {
EnableExperimentalConcurrency = llvm::cl::opt<bool>("enable-experimental-concurrency",
llvm::cl::desc("Enable experimental concurrency model."));

llvm::cl::opt<llvm::cl::boolOrDefault>
EnableLexicalLifetimes = llvm::cl::opt<llvm::cl::boolOrDefault>(
"enable-lexical-lifetimes", llvm::cl::init(llvm::cl::BOU_UNSET),
llvm::cl::desc("Enable lexical lifetimes. Mutually exclusive with "
"enable-lexical-borrow-scopes and "
"disable-lexical-lifetimes."));

llvm::cl::opt<llvm::cl::boolOrDefault>
EnableLexicalBorrowScopes = llvm::cl::opt<llvm::cl::boolOrDefault>("enable-lexical-borrow-scopes",
llvm::cl::init(llvm::cl::BOU_UNSET),
llvm::cl::desc("Enable lexical borrow scopes."));
llvm::cl::opt<llvm::cl::boolOrDefault> EnableLexicalLifetimes =
llvm::cl::opt<llvm::cl::boolOrDefault>(
"enable-lexical-lifetimes", llvm::cl::init(llvm::cl::BOU_UNSET),
llvm::cl::desc("Enable lexical lifetimes."));

llvm::cl::opt<llvm::cl::boolOrDefault>
EnableExperimentalMoveOnly = llvm::cl::opt<llvm::cl::boolOrDefault>(
Expand Down Expand Up @@ -771,32 +764,11 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {

llvm::Optional<bool> enableLexicalLifetimes =
toOptionalBool(options.EnableLexicalLifetimes);
llvm::Optional<bool> enableLexicalBorrowScopes =
toOptionalBool(options.EnableLexicalBorrowScopes);

// 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 specifiedLexicalLifetimesEnabled =
enableExperimentalMoveOnly && *enableExperimentalMoveOnly &&
enableLexicalLifetimes && *enableLexicalLifetimes;
if (specifiedLexicalLifetimesEnabled && enableLexicalBorrowScopes &&
!*enableLexicalBorrowScopes) {
fprintf(
stderr,
"Error! Cannot specify both -enable-lexical-borrow-scopes=false and "
"either -enable-lexical-lifetimes or -enable-experimental-move-only.");
exit(-1);
}

if (enableLexicalLifetimes)
SILOpts.LexicalLifetimes =
*enableLexicalLifetimes ? LexicalLifetimesOption::On
: LexicalLifetimesOption::DiagnosticMarkersOnly;
if (enableLexicalBorrowScopes)
SILOpts.LexicalLifetimes =
*enableLexicalBorrowScopes
? LexicalLifetimesOption::DiagnosticMarkersOnly
: LexicalLifetimesOption::Off;

SILOpts.EnablePackMetadataStackPromotion =
options.EnablePackMetadataStackPromotion;
Expand Down
36 changes: 0 additions & 36 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2183,15 +2183,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.CopyPropagation = *specifiedCopyPropagationOption;
}

llvm::Optional<bool> enableLexicalBorrowScopesFlag;
if (Arg *A = Args.getLastArg(OPT_enable_lexical_borrow_scopes)) {
enableLexicalBorrowScopesFlag =
llvm::StringSwitch<llvm::Optional<bool>>(A->getValue())
.Case("true", true)
.Case("false", false)
.Default(llvm::None);
}

// Allow command line flags to override the default value of
// Opts.LexicalLifetimes. If no explicit flags are passed, then
// Opts.LexicalLifetimes retains its initial value.
Expand All @@ -2216,26 +2207,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
}
}

if (enableLexicalLifetimesFlag.value_or(false) &&
!enableLexicalBorrowScopesFlag.value_or(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;
}

if (Args.hasArg(OPT_enable_experimental_move_only) &&
!enableLexicalBorrowScopesFlag.value_or(true)) {
// 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;
}

// Unless overridden below, enabling copy propagation means enabling lexical
// lifetimes.
if (Opts.CopyPropagation == CopyPropagationOption::On) {
Expand All @@ -2262,13 +2233,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
}
}
if (enableLexicalBorrowScopesFlag) {
if (*enableLexicalBorrowScopesFlag) {
Opts.LexicalLifetimes = LexicalLifetimesOption::DiagnosticMarkersOnly;
} else {
Opts.LexicalLifetimes = LexicalLifetimesOption::Off;
}
}
if (specifiedDestroyHoistingOption)
Opts.DestroyHoisting = *specifiedDestroyHoistingOption;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2463,10 +2463,6 @@ class ConsumeOperatorCopyableAddressesCheckerPass
auto *fn = getFunction();
auto &astContext = fn->getASTContext();

// Only run this pass if the move only language feature is enabled.
if (!astContext.supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (getFunction()->wasDeserializedCanonical())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,6 @@ class ConsumeOperatorCopyableValuesCheckerPass : public SILFunctionTransform {
void run() override {
auto *fn = getFunction();

// Only run this pass if the move only language feature is enabled.
if (!fn->getASTContext().supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (fn->wasDeserializedCanonical())
return;
Expand Down
4 changes: 0 additions & 4 deletions lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ class MoveOnlyAddressCheckerTesterPass : public SILFunctionTransform {
void run() override {
auto *fn = getFunction();

// Only run this pass if the move only language feature is enabled.
if (!fn->getASTContext().supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (getFunction()->wasDeserializedCanonical())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class MoveOnlyBorrowToDestructureTransformPass : public SILFunctionTransform {
void run() override {
auto *fn = getFunction();

// Only run this pass if the move only language feature is enabled.
if (!fn->getASTContext().supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (getFunction()->wasDeserializedCanonical())
return;
Expand Down
4 changes: 0 additions & 4 deletions lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,6 @@ class MoveOnlyCheckerPass : public SILFunctionTransform {
void run() override {
auto *fn = getFunction();

// Only run this pass if the move only language feature is enabled.
if (!fn->getASTContext().supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (getFunction()->wasDeserializedCanonical())
return;
Expand Down
4 changes: 0 additions & 4 deletions lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ class MoveOnlyObjectCheckerTesterPass : public SILFunctionTransform {
void run() override {
auto *fn = getFunction();

// Only run this pass if the move only language feature is enabled.
if (!fn->getASTContext().supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (getFunction()->wasDeserializedCanonical())
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ struct MoveOnlyTempAllocationFromLetTester : SILFunctionTransform {
void run() override {
auto *fn = getFunction();

// Only run this pass if the move only language feature is enabled.
if (!fn->getASTContext().supportsMoveOnlyTypes())
return;

// Don't rerun diagnostics on deserialized functions.
if (getFunction()->wasDeserializedCanonical())
return;
Expand Down
3 changes: 0 additions & 3 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2390,9 +2390,6 @@ void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
}

void AttributeChecker::visitMoveOnlyAttr(MoveOnlyAttr *attr) {
if (!D->getASTContext().supportsMoveOnlyTypes())
D->diagnose(diag::moveOnly_requires_lexical_lifetimes);

if (isa<StructDecl>(D) || isa<EnumDecl>(D))
return;

Expand Down
8 changes: 0 additions & 8 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,10 +931,6 @@ InvertibleAnnotationRequest::evaluate(Evaluator &evaluator,
if (auto attr = decl->getAttrs().getAttribute<MoveOnlyAttr>()) {
assert((isa<StructDecl, EnumDecl, ClassDecl>(decl)));

// FIXME: just never allow lexical-lifetimes to be disabled?
if (!ctx.supportsMoveOnlyTypes())
decl->diagnose(diag::moveOnly_requires_lexical_lifetimes);

return InverseMarking::forInverse(Kind::LegacyExplicit,
attr->getLocation());
}
Expand All @@ -954,10 +950,6 @@ InvertibleAnnotationRequest::evaluate(Evaluator &evaluator,
if (!ctx.LangOpts.hasFeature(Feature::NoncopyableGenerics))
return InverseMarking::forInverse(Kind::None);

// FIXME: just never allow lexical-lifetimes to be disabled?
if (!ctx.supportsMoveOnlyTypes())
decl->diagnose(diag::moveOnly_requires_lexical_lifetimes);

/// The invertible protocol being targeted by this annotation request.

std::function<bool(Type)> isTarget = [&](Type t) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/debug_poison.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -primary-file %s -emit-ir -Onone -enable-copy-propagation -enable-lexical-borrow-scopes=false | %FileCheck %s -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -primary-file %s -emit-ir -Onone -enable-copy-propagation | %FileCheck %s -DINT=i%target-ptrsize
//
// This test is currently disabled because mandatory copy propagation
// is not part of the pipeline. It may be re-added to the pipeline,
Expand Down
10 changes: 4 additions & 6 deletions test/Interpreter/builtin_bridge_object.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// 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
// RUN: %target-run-simple-swift(-Onone -parse-stdlib -Xfrontend -enable-copy-propagation) | %FileCheck %s --check-prefixes=CHECK,CHECK-DBG
// RUN: %target-run-simple-swift(-O -parse-stdlib -Xfrontend -enable-copy-propagation) | %FileCheck --check-prefixes=CHECK,CHECK-OPT %s

// REQUIRES: executable_test
// REQUIRES: objc_interop
Expand Down Expand Up @@ -70,7 +70,6 @@ if true {
print(x === x1)
// CHECK-NEXT: true
print(x === x2)
// CHECK-OPT-NEXT: deallocated

print(nonPointerBits(bo) == 0)
// CHECK-NEXT: true
Expand All @@ -84,7 +83,7 @@ if true {
_fixLifetime(bo3)
_fixLifetime(bo4)
}
// CHECK-DBG-NEXT: deallocated
// CHECK-NEXT: deallocated
// CHECK-NEXT: deallocated

// Try with all spare bits set.
Expand All @@ -99,7 +98,6 @@ if true {
print(x === x1)
// CHECK-NEXT: true
print(x === x2)
// CHECK-OPT-NEXT: deallocated

print(nonPointerBits(bo) == NATIVE_SPARE_BITS)
// CHECK-NEXT: true
Expand All @@ -113,7 +111,7 @@ if true {
_fixLifetime(bo3)
_fixLifetime(bo4)
}
// CHECK-DBG-NEXT: deallocated
// CHECK-NEXT: deallocated
// CHECK-NEXT: deallocated


Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/allocbox_to_stack.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -sil-print-debuginfo -enable-sil-verify-all %s -allocbox-to-stack -enable-copy-propagation=requested-passes-only -enable-lexical-borrow-scopes=false | %FileCheck %s
// RUN: %target-sil-opt -sil-print-debuginfo -enable-sil-verify-all %s -allocbox-to-stack -enable-copy-propagation=requested-passes-only | %FileCheck %s

sil_stage raw

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/allocbox_to_stack_ownership.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -enable-copy-propagation=requested-passes-only -enable-lexical-borrow-scopes=false | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -enable-copy-propagation=requested-passes-only | %FileCheck %s

sil_stage raw

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/allocbox_to_stack_ownership_attrs.sil
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -enable-copy-propagation=requested-passes-only -enable-lexical-borrow-scopes=false | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -allocbox-to-stack -enable-copy-propagation=requested-passes-only | %FileCheck %s

sil_stage raw

Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/assemblyvision_remark/attributes.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -enable-lexical-borrow-scopes=false -emit-sil %s -verify -Osize -o /dev/null -module-name main
// RUN: %target-swift-frontend -enable-copy-propagation=requested-passes-only -emit-sil %s -verify -Osize -o /dev/null -module-name main
//
// NOTE: We only emit opt-remarks with -Osize,-O today! -O does drop way more
// stuff though, so we test with -Osize.
Expand Down
Loading