From ddccaa7d9c2aa05163e9944b9bfb6750daf5b340 Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 5 Feb 2024 16:13:30 -0800 Subject: [PATCH 1/3] [Frontend] Removed lexical-borrow-scope flag. Adding `move_value [lexical]` and `begin_borrow [lexical]` should happen all the time at this point. Remove the ability to omit these instructions and update the corresponding tests. --- include/swift/AST/DiagnosticsSema.def | 4 -- include/swift/Option/FrontendOptions.td | 5 -- lib/DriverTool/sil_opt_main.cpp | 38 ++------------- lib/Frontend/CompilerInvocation.cpp | 36 --------------- lib/Sema/TypeCheckAttr.cpp | 3 -- lib/Sema/TypeCheckDecl.cpp | 8 ---- test/IRGen/debug_poison.swift | 2 +- test/Interpreter/builtin_bridge_object.swift | 10 ++-- test/SILOptimizer/allocbox_to_stack.sil | 2 +- .../allocbox_to_stack_ownership.sil | 2 +- .../allocbox_to_stack_ownership_attrs.sil | 2 +- .../assemblyvision_remark/attributes.swift | 2 +- .../assemblyvision_remark/basic.swift | 30 +++++++++--- .../assemblyvision_remark/basic_yaml.swift | 46 ++++++++++++++++--- .../diagnose_lifetime_issues.swift | 12 ++--- .../diagnose_lifetime_issues_objc.swift | 4 +- test/SILOptimizer/outliner.swift | 4 +- .../moveonly_lexical_borrow_required.swift | 9 ---- ...r_on_import_into_module_without_flag.swift | 26 ----------- 19 files changed, 86 insertions(+), 159 deletions(-) delete mode 100644 test/Sema/moveonly_lexical_borrow_required.swift delete mode 100644 test/Serialization/moveonly_error_on_import_into_module_without_flag.swift diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 9ed5354cd0069..daea10438e964 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -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" diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index ea67f9261e6f6..91395296b7a0a 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -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">; diff --git a/lib/DriverTool/sil_opt_main.cpp b/lib/DriverTool/sil_opt_main.cpp index f801abe1e8063..dfe8fe89bf66a 100644 --- a/lib/DriverTool/sil_opt_main.cpp +++ b/lib/DriverTool/sil_opt_main.cpp @@ -228,17 +228,10 @@ struct SILOptOptions { EnableExperimentalConcurrency = llvm::cl::opt("enable-experimental-concurrency", llvm::cl::desc("Enable experimental concurrency model.")); - llvm::cl::opt - EnableLexicalLifetimes = llvm::cl::opt( - "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 - EnableLexicalBorrowScopes = llvm::cl::opt("enable-lexical-borrow-scopes", - llvm::cl::init(llvm::cl::BOU_UNSET), - llvm::cl::desc("Enable lexical borrow scopes.")); + llvm::cl::opt EnableLexicalLifetimes = + llvm::cl::opt( + "enable-lexical-lifetimes", llvm::cl::init(llvm::cl::BOU_UNSET), + llvm::cl::desc("Enable lexical lifetimes.")); llvm::cl::opt EnableExperimentalMoveOnly = llvm::cl::opt( @@ -771,32 +764,11 @@ int sil_opt_main(ArrayRef argv, void *MainAddr) { llvm::Optional enableLexicalLifetimes = toOptionalBool(options.EnableLexicalLifetimes); - llvm::Optional 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; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 520acdd2f8972..2f665568b8c21 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2183,15 +2183,6 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args, Opts.CopyPropagation = *specifiedCopyPropagationOption; } - llvm::Optional enableLexicalBorrowScopesFlag; - if (Arg *A = Args.getLastArg(OPT_enable_lexical_borrow_scopes)) { - enableLexicalBorrowScopesFlag = - llvm::StringSwitch>(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. @@ -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) { @@ -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; diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index dba607fb0b3fd..d8efa2f8a7187 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -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(D) || isa(D)) return; diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 3f404ffba1674..dca505b489b58 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -931,10 +931,6 @@ InvertibleAnnotationRequest::evaluate(Evaluator &evaluator, if (auto attr = decl->getAttrs().getAttribute()) { assert((isa(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()); } @@ -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 isTarget = [&](Type t) -> bool { diff --git a/test/IRGen/debug_poison.swift b/test/IRGen/debug_poison.swift index 4e188af41a271..d008965cbeb28 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 -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, diff --git a/test/Interpreter/builtin_bridge_object.swift b/test/Interpreter/builtin_bridge_object.swift index 1157c5c3a2769..6dd60c7c8ef87 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 -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 @@ -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 @@ -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. @@ -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 @@ -113,7 +111,7 @@ if true { _fixLifetime(bo3) _fixLifetime(bo4) } -// CHECK-DBG-NEXT: deallocated +// CHECK-NEXT: deallocated // CHECK-NEXT: deallocated diff --git a/test/SILOptimizer/allocbox_to_stack.sil b/test/SILOptimizer/allocbox_to_stack.sil index 8655669ca4469..2c6fd95d9d7ef 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 -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 diff --git a/test/SILOptimizer/allocbox_to_stack_ownership.sil b/test/SILOptimizer/allocbox_to_stack_ownership.sil index 8e15c4b2c30bb..36e8ea5c3e054 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 -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 diff --git a/test/SILOptimizer/allocbox_to_stack_ownership_attrs.sil b/test/SILOptimizer/allocbox_to_stack_ownership_attrs.sil index 5eb2929ccfa75..91e2ec22d35fa 100644 --- a/test/SILOptimizer/allocbox_to_stack_ownership_attrs.sil +++ b/test/SILOptimizer/allocbox_to_stack_ownership_attrs.sil @@ -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 diff --git a/test/SILOptimizer/assemblyvision_remark/attributes.swift b/test/SILOptimizer/assemblyvision_remark/attributes.swift index 5300d15cb4751..335fc3bcdbbc5 100644 --- a/test/SILOptimizer/assemblyvision_remark/attributes.swift +++ b/test/SILOptimizer/assemblyvision_remark/attributes.swift @@ -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. diff --git a/test/SILOptimizer/assemblyvision_remark/basic.swift b/test/SILOptimizer/assemblyvision_remark/basic.swift index 7f5916f50ad54..93826abf612cf 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 -enable-lexical-borrow-scopes=false +// 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 // REQUIRES: optimized_stdlib,swift_stdlib_no_asserts // REQUIRES: swift_in_compiler @@ -28,8 +28,12 @@ public func getGlobal() -> Klass { // ref is on the argument that necessitated its creation. public func useGlobal() { let x = getGlobal() - print(x) // expected-remark @:11 {{heap allocated ref of type}} - // expected-remark @-1:12 {{release of type}} + print(x) // expected-remark @:12 {{release of type}} + // expected-remark @-1:11 {{heap allocated ref of type}} + // expected-remark @-2:12 {{release of type}} + // expected-note@-4{{of 'x'}} + // expected-remark @-4:5 {{retain of type}} + // expected-note@-6{{of 'x'}} } public enum TrivialState { @@ -190,13 +194,21 @@ func castAsQuestionDiamondGEP2(x: KlassPair) { // expected-note @-4 {{of 'x.rhs'}} case let (.some(x1), .some(x2)): print(x1, x2) // expected-remark @:15 {{heap allocated ref of type}} - // expected-remark @-1 {{release of type}} + // expected-remark @-1 {{retain of type}} + // expected-remark @-2 {{retain of type}} + // expected-remark @-3 {{release of type}} + // expected-remark @-4 {{release of type}} + // expected-remark @-5 {{release of type}} case let (.some(x1), nil): print(x1) // expected-remark @:15 {{heap allocated ref of type}} - // expected-remark @-1 {{release of type}} + // expected-remark @-1 {{retain of type}} + // expected-remark @-2 {{release of type}} + // expected-remark @-3 {{release of type}} case let (nil, .some(x2)): print(x2) // expected-remark @:15 {{heap allocated ref of type}} - // expected-remark @-1 {{release of type}} + // expected-remark @-1 {{retain of type}} + // expected-remark @-2 {{release of type}} + // expected-remark @-3 {{release of type}} case (nil, nil): break } @@ -272,7 +284,11 @@ func allocateValue() { let k = Klass() // expected-remark @:13 {{heap allocated ref of type 'Klass'}} // expected-note @-1:9 {{of 'k'}} print(k) // expected-remark @:11 {{heap allocated ref of type}} - // expected-remark @-1:12 {{release of type}} + // expected-remark @-1:5 {{retain of type}} + // expected-note @-4:9 {{of 'k'}} + // expected-remark @-3:12 {{release of type}} + // expected-remark @-4:12 {{release of type}} + // expected-note @-7:9 {{of 'k'}} } @inline(never) diff --git a/test/SILOptimizer/assemblyvision_remark/basic_yaml.swift b/test/SILOptimizer/assemblyvision_remark/basic_yaml.swift index dae4e4a76cc27..8711c75986f1b 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 -enable-lexical-borrow-scopes=false +// 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 // 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 -enable-lexical-borrow-scopes=false %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 %s -o /dev/null && %FileCheck --input-file=%t/note.yaml %s // REQUIRES: optimized_stdlib,swift_stdlib_no_asserts // REQUIRES: swift_in_compiler @@ -83,8 +83,8 @@ public func getGlobal() -> Klass { // CHECK: --- !Missed // CHECK-NEXT: Pass: sil-assembly-vision-remark-gen // CHECK-NEXT: Name: sil.memory -// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', -// CHECK-NEXT: Line: [[# @LINE + 23]], Column: 11 } +// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', +// CHECK-NEXT: Line: [[# @LINE + 51 ]], Column: 11 } // CHECK-NEXT: Function: 'useGlobal()' // CHECK-NEXT: Args: // CHECK-NEXT: - String: 'heap allocated ref of type ''' @@ -94,14 +94,42 @@ public func getGlobal() -> Klass { // CHECK-NEXT: --- !Missed // CHECK-NEXT: Pass: sil-assembly-vision-remark-gen // CHECK-NEXT: Name: sil.memory -// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', -// CHECK-NEXT: Line: [[# @LINE + 12]], Column: 12 } +// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', +// CHECK-NEXT: Line: [[# @LINE + 40 ]], Column: 5 } +// CHECK-NEXT: Function: 'useGlobal()' +// CHECK-NEXT: Args: +// CHECK-NEXT: - String: 'retain of type ''' +// CHECK-NEXT: - ValueType: Klass +// CHECK-NEXT: - String: '''' +// CHECK-NEXT: - InferredValue: 'of ''x''' +// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', +// CHECK-NEXT: Line: [[# @LINE + 29 ]], Column: 9 } +// CHECK-NEXT: ... +// CHECK-NEXT: --- !Missed +// CHECK-NEXT: Pass: sil-assembly-vision-remark-gen +// CHECK-NEXT: Name: sil.memory +// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', +// CHECK-NEXT: Line: [[# @LINE + 26 ]], Column: 12 } // CHECK-NEXT: Function: 'useGlobal()' // CHECK-NEXT: Args: // CHECK-NEXT: - String: 'release of type ''' // CHECK-NEXT: - ValueType: // CHECK-NEXT: - String: '''' // CHECK-NEXT: ... +// CHECK-NEXT: --- !Missed +// CHECK-NEXT: Pass: sil-assembly-vision-remark-gen +// CHECK-NEXT: Name: sil.memory +// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', +// CHECK-NEXT: Line: [[# @LINE + 15 ]], Column: 12 } +// CHECK-NEXT: Function: 'useGlobal()' +// CHECK-NEXT: Args: +// CHECK-NEXT: - String: 'release of type ''' +// CHECK-NEXT: - ValueType: Klass +// CHECK-NEXT: - String: '''' +// CHECK-NEXT: - InferredValue: 'of ''x''' +// CHECK-NEXT: DebugLoc: { File: '{{.*}}basic_yaml.swift', +// CHECK-NEXT: Line: [[# @LINE + 4 ]], Column: 9 } +// CHECK-NEXT: ... public func useGlobal() { let x = getGlobal() @@ -109,5 +137,9 @@ public func useGlobal() { // releases are the end of the print. print(x) // expected-remark @:11 {{heap allocated ref of type}} // We test the type emission above since FileCheck can handle regex. - // expected-remark @-2:12 {{release of type}} + // expected-remark @-2:5 {{retain of type}} + // expected-note @-6 {{of 'x'}} + // expected-remark @-4:12 {{release of type}} + // expected-remark @-5:12 {{release of type}} + // expected-note @-9 {{of 'x'}} } diff --git a/test/SILOptimizer/diagnose_lifetime_issues.swift b/test/SILOptimizer/diagnose_lifetime_issues.swift index 2b2fd9f38e62c..b87d20d888a15 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 -enable-lexical-borrow-scopes=false -enable-copy-propagation %s -o /dev/null -verify +// RUN: %target-swift-frontend -emit-sil -enable-copy-propagation %s -o /dev/null -verify class Delegate { func foo() { } @@ -21,7 +21,7 @@ final class Container { func warningForDeadDelegate(container: Container) { let delegate = Delegate() - container.delegate = delegate // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}} + container.delegate = delegate container.callDelegate() } @@ -41,7 +41,7 @@ func noWarningWithFixLifetime(container: Container) { func warningWithControlFlow(container: Container, _ b: Bool) { let delegate = Delegate() - container.delegate = delegate // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}} + container.delegate = delegate if b { container.callDelegate() } @@ -55,7 +55,7 @@ func storeClosure(_ c: @escaping () -> ()) { func warningForDeadClosureCapture() { let k = Delegate() - storeClosure({ [weak k] in // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}} + storeClosure({ [weak k] in k!.foo() }) } @@ -70,7 +70,7 @@ func noWarningWithFixLifetime2() { func warningWithStoreWeakInCalledFunction() { let d = Delegate() - let c = Container(weakDelegate: d, strongDelegate: Delegate()) // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}} + let c = Container(weakDelegate: d, strongDelegate: Delegate()) c.callDelegate() } @@ -93,7 +93,7 @@ final class Testcl { func test_noset(_ c: StrongContainer) { let k = Delegate() c.noset(k) - wk = k // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}} + wk = k } } diff --git a/test/SILOptimizer/diagnose_lifetime_issues_objc.swift b/test/SILOptimizer/diagnose_lifetime_issues_objc.swift index 87e2228f7e105..188ec725e6c85 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 -enable-lexical-borrow-scopes=false -enable-copy-propagation -o /dev/null -verify +// RUN: %target-swift-frontend -emit-sil %s -enable-copy-propagation -o /dev/null -verify // REQUIRES: objc_interop import Foundation @@ -8,6 +8,6 @@ class MyServiceDelegate : NSObject, NSXPCListenerDelegate { } public func warningForDeadDelegate() { let delegate = MyServiceDelegate() let listener = NSXPCListener.service() - listener.delegate = delegate // expected-warning {{weak reference will always be nil because the referenced object is deallocated here}} + listener.delegate = delegate listener.resume() } diff --git a/test/SILOptimizer/outliner.swift b/test/SILOptimizer/outliner.swift index 1d1905925eb7e..e598e7eb08fb0 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 -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 +// RUN: %target-swift-frontend -Osize -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation | %FileCheck %s +// RUN: %target-swift-frontend -Osize -g -import-objc-header %S/Inputs/Outliner.h %s -emit-sil -enforce-exclusivity=unchecked -enable-copy-propagation | %FileCheck %s // REQUIRES: objc_interop // REQUIRES: optimized_stdlib diff --git a/test/Sema/moveonly_lexical_borrow_required.swift b/test/Sema/moveonly_lexical_borrow_required.swift deleted file mode 100644 index 058fcd8dc63b3..0000000000000 --- a/test/Sema/moveonly_lexical_borrow_required.swift +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %target-swift-frontend -typecheck %s -// RUN: %target-typecheck-verify-swift -enable-lexical-borrow-scopes=false - -@_moveOnly -public struct MO { // expected-error 2{{noncopyable types require lexical borrow scopes (add -enable-lexical-borrow-scopes=true)}} - let x = 0 -} - -public func whatever(_ mo: borrowing MO) {} diff --git a/test/Serialization/moveonly_error_on_import_into_module_without_flag.swift b/test/Serialization/moveonly_error_on_import_into_module_without_flag.swift deleted file mode 100644 index 239dded2355c5..0000000000000 --- a/test/Serialization/moveonly_error_on_import_into_module_without_flag.swift +++ /dev/null @@ -1,26 +0,0 @@ -// RUN: %empty-directory(%t) -// TODO: re-enable the simplification passes once rdar://104875010 is fixed -// RUN: %target-swift-frontend -Xllvm -sil-disable-pass=simplification -emit-module -o %t/Library.swiftmodule -module-name Library %S/Inputs/moveonly_deinit.swift -enable-experimental-feature MoveOnlyEnumDeinits - -// >>> make sure borrow scopes are required when using a move-only type from another module -// RUN: not %target-swift-frontend -DUSE_MOVEONLY_TYPE -typecheck -enable-experimental-feature MoveOnlyEnumDeinits -enable-lexical-borrow-scopes=false -I %t %s 2>&1 | %FileCheck %s --check-prefix CHECK-ERROR -// RUN: %target-swift-frontend -DUSE_MOVEONLY_TYPE -typecheck -I %t %s 2>&1 | %FileCheck %s --allow-empty - -// >>> try turning off lexical borrow scopes with no move-only types; shouldn't be an error. -// we have to pipe into FileCheck because -verify ignores errors from other files. -// RUN: %target-swift-frontend -enable-experimental-feature MoveOnlyEnumDeinits -enable-lexical-borrow-scopes=false -typecheck -I %t %s 2>&1 | %FileCheck %s --allow-empty - -// This test makes sure that if we import a move only type -// and do not have lexical borrow scopes enabled, we emit an error. - -import Library - -// CHECK-ERROR: Library.MoveOnlyStruct{{.*}} error: noncopyable types require lexical borrow scopes (add -enable-lexical-borrow-scopes=true) - -// CHECK-NOT: error - -#if USE_MOVEONLY_TYPE -func f(_ k: borrowing MoveOnlyStruct) {} -#endif - -func g(_ k: NormalStruct) {} From af1da401d91c9b9afdcbff4604c7b6c48c59a17a Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 5 Feb 2024 17:39:01 -0800 Subject: [PATCH 2/3] [Frontend] Removed dead case. It is no longer possible to have no lexical markers. Remove the corresponding case. --- include/swift/AST/SILOptions.h | 3 --- include/swift/SIL/SILModule.h | 7 +++---- lib/AST/ASTContext.cpp | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/swift/AST/SILOptions.h b/include/swift/AST/SILOptions.h index 0efd10ed39623..5261267fdc917 100644 --- a/include/swift/AST/SILOptions.h +++ b/include/swift/AST/SILOptions.h @@ -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. diff --git a/include/swift/SIL/SILModule.h b/include/swift/SIL/SILModule.h index 8535ebec666d7..d4e5f8a708160 100644 --- a/include/swift/SIL/SILModule.h +++ b/include/swift/SIL/SILModule.h @@ -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 diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 799d8daadd576..bfc0114735ab8 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -6532,5 +6532,5 @@ Type ASTContext::getNamedSwiftType(ModuleDecl *module, StringRef name) { bool ASTContext::supportsMoveOnlyTypes() const { // currently the only thing holding back whether the types can appear is this. - return SILOpts.LexicalLifetimes != LexicalLifetimesOption::Off; + return true; } From 336afca4776da0d63c2068a85d68c902b3b08a6d Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Mon, 5 Feb 2024 17:40:17 -0800 Subject: [PATCH 3/3] [SILOpt] Removed unreachable bailouts. Now that supportsMoveOnlyTypes is always true, these bailouts can't be reached. Delete the bailouts and the predicate. --- include/swift/AST/ASTContext.h | 3 --- lib/AST/ASTContext.cpp | 5 ----- .../Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp | 4 ---- .../Mandatory/ConsumeOperatorCopyableValuesChecker.cpp | 4 ---- lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp | 4 ---- .../Mandatory/MoveOnlyBorrowToDestructureTester.cpp | 4 ---- lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp | 4 ---- lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp | 4 ---- .../Mandatory/MoveOnlyTempAllocationFromLetTester.cpp | 4 ---- 9 files changed, 36 deletions(-) diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 0879139474e7e..ddb53ceee39c3 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -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(_:). // diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index bfc0114735ab8..05e7ffa651ae6 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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 true; -} diff --git a/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp b/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp index 180e929ec6044..858f2d17c5a35 100644 --- a/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp +++ b/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp @@ -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; diff --git a/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp b/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp index 4d2d115c21611..1bea3833d196b 100644 --- a/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp +++ b/lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableValuesChecker.cpp @@ -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; diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp index 334397919f332..ab75794bab6ad 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyAddressCheckerTester.cpp @@ -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; diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTester.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTester.cpp index 983d016f8d54c..b667dbba7712b 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTester.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyBorrowToDestructureTester.cpp @@ -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; diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp index 7b1847c2d4edf..eec43b8f30914 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyChecker.cpp @@ -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; diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp index 9cb4fb0ba299d..b90ce72d5654a 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyObjectCheckerTester.cpp @@ -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; diff --git a/lib/SILOptimizer/Mandatory/MoveOnlyTempAllocationFromLetTester.cpp b/lib/SILOptimizer/Mandatory/MoveOnlyTempAllocationFromLetTester.cpp index 8a172825a42e1..f51ad322f5e8b 100644 --- a/lib/SILOptimizer/Mandatory/MoveOnlyTempAllocationFromLetTester.cpp +++ b/lib/SILOptimizer/Mandatory/MoveOnlyTempAllocationFromLetTester.cpp @@ -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;