Skip to content

Remove feature guard on lifetime dependence inference #76588

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
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
11 changes: 8 additions & 3 deletions lib/AST/Builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2114,9 +2114,13 @@ static ValueDecl *getOnceOperation(ASTContext &Context,
static ValueDecl *getPolymorphicBinaryOperation(ASTContext &ctx,
Identifier id) {
BuiltinFunctionBuilder builder(ctx);
builder.addParameter(makeGenericParam());
builder.addParameter(makeGenericParam());
builder.setResult(makeGenericParam());

// Builtins of the form: func binOp<T>(_ t: T, _ t: T) -> T
auto genericParam = makeGenericParam();
builder.addConformanceRequirement(genericParam, KnownProtocolKind::Escapable);
builder.addParameter(genericParam);
builder.addParameter(genericParam);
builder.setResult(genericParam);
return builder.build(id);
}

Expand Down Expand Up @@ -2230,6 +2234,7 @@ static ValueDecl *getEmplace(ASTContext &ctx, Identifier id) {
BuiltinFunctionBuilder builder(ctx, /* genericParamCount */ 1);

auto T = makeGenericParam();
builder.addConformanceRequirement(T, KnownProtocolKind::Escapable);

auto fnParamTy = FunctionType::get(FunctionType::Param(ctx.TheRawPointerType),
ctx.TheEmptyTupleType,
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/ConformanceLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,10 @@ static bool conformsToInvertible(CanType type, InvertibleProtocolKind ip) {
if (type->is<SILPackType>())
return true;

if (type->is<SILTokenType>()) {
return true;
}

// The SIL types in the AST do not have real conformances, and should have
// been handled in SILType instead.
assert(!(type->is<SILBoxType,
Expand Down
6 changes: 0 additions & 6 deletions lib/AST/LifetimeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,6 @@ std::optional<LifetimeDependenceInfo> LifetimeDependenceInfo::inferMutatingSelf(

std::optional<llvm::ArrayRef<LifetimeDependenceInfo>>
LifetimeDependenceInfo::get(AbstractFunctionDecl *afd) {
if (!afd->getASTContext().LangOpts.hasFeature(Feature::NonescapableTypes)) {
return std::nullopt;
}
assert(isa<FuncDecl>(afd) || isa<ConstructorDecl>(afd));

if (afd->getAttrs().hasAttribute<LifetimeAttr>()) {
Expand All @@ -706,9 +703,6 @@ std::optional<llvm::ArrayRef<LifetimeDependenceInfo>>
LifetimeDependenceInfo::get(FunctionTypeRepr *funcRepr,
ArrayRef<SILParameterInfo> params,
ArrayRef<SILResultInfo> results, DeclContext *dc) {
if (!dc->getASTContext().LangOpts.hasFeature(Feature::NonescapableTypes)) {
return std::nullopt;
}
SmallVector<LifetimeDependenceInfo, 1> lifetimeDependencies;

auto getLifetimeDependenceFromDependsOnTypeModifier =
Expand Down
4 changes: 3 additions & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2633,9 +2633,11 @@ static ParamDecl *getParameterInfo(ClangImporter::Implementation *impl,
// Swift doesn't support default values of inout parameters.
// TODO: support default arguments of constructors
// (https://github.com/apple/swift/issues/70124)
// TODO: support params with template parameters
if (param->hasDefaultArg() && !isInOut &&
!isa<clang::CXXConstructorDecl>(param->getDeclContext()) &&
impl->isDefaultArgSafeToImport(param)) {
impl->isDefaultArgSafeToImport(param) &&
!param->isTemplated()) {
SwiftDeclSynthesizer synthesizer(*impl);
if (CallExpr *defaultArgExpr = synthesizer.makeDefaultArgument(
param, swiftParamTy, paramInfo->getParameterNameLoc())) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2718,8 +2718,8 @@ ParserResult<LifetimeAttr> Parser::parseLifetimeAttribute(SourceLoc atLoc,
SourceLoc loc) {
ParserStatus status;
if (!Context.LangOpts.hasFeature(Feature::NonescapableTypes)) {
diagnose(loc, diag::requires_experimental_feature, "lifetime attribute",
false, getFeatureName(Feature::NonescapableTypes));
diagnose(loc, diag::requires_experimental_feature, "@lifetime", false,
getFeatureName(Feature::NonescapableTypes));
status.setIsParseError();
return status;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/IR/SILModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ void SILModule::performOnceForPrespecializedImportedExtensions(
SmallVector<ModuleDecl *, 8> importedModules;
// Add the Swift module.
if (!isStdlibModule()) {
auto *SwiftStdlib = getASTContext().getStdlibModule(true);
auto *SwiftStdlib = getASTContext().getStdlibModule();
if (SwiftStdlib)
importedModules.push_back(SwiftStdlib);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class AttributeChecker : public AttributeVisitor<AttributeChecker> {

void visitUnsafeInheritExecutorAttr(UnsafeInheritExecutorAttr *attr);

bool visitLifetimeAttr(DeclAttribute *attr);
bool visitOwnershipAttr(DeclAttribute *attr);
void visitEagerMoveAttr(EagerMoveAttr *attr);
void visitNoEagerMoveAttr(NoEagerMoveAttr *attr);

Expand Down Expand Up @@ -403,7 +403,7 @@ void AttributeChecker::visitNoImplicitCopyAttr(NoImplicitCopyAttr *attr) {
}

if (auto *funcDecl = dyn_cast<FuncDecl>(D)) {
if (visitLifetimeAttr(attr))
if (visitOwnershipAttr(attr))
return;

// We only handle non-lvalue arguments today.
Expand Down Expand Up @@ -7480,7 +7480,7 @@ void AttributeChecker::visitUnsafeInheritExecutorAttr(
}
}

bool AttributeChecker::visitLifetimeAttr(DeclAttribute *attr) {
bool AttributeChecker::visitOwnershipAttr(DeclAttribute *attr) {
if (auto *funcDecl = dyn_cast<FuncDecl>(D)) {
auto declContext = funcDecl->getDeclContext();
// eagerMove attribute may only appear in type context
Expand All @@ -7493,7 +7493,7 @@ bool AttributeChecker::visitLifetimeAttr(DeclAttribute *attr) {
}

void AttributeChecker::visitEagerMoveAttr(EagerMoveAttr *attr) {
if (visitLifetimeAttr(attr))
if (visitOwnershipAttr(attr))
return;
if (auto *nominal = dyn_cast<NominalTypeDecl>(D)) {
if (nominal->getSelfTypeInContext()->isNoncopyable()) {
Expand All @@ -7517,7 +7517,7 @@ void AttributeChecker::visitEagerMoveAttr(EagerMoveAttr *attr) {
}

void AttributeChecker::visitNoEagerMoveAttr(NoEagerMoveAttr *attr) {
if (visitLifetimeAttr(attr))
if (visitOwnershipAttr(attr))
return;
// @_noEagerMove and @_eagerMove are opposites and can't be combined.
if (D->getAttrs().hasAttribute<EagerMoveAttr>()) {
Expand Down
5 changes: 2 additions & 3 deletions test/IRGen/builtins.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

// RUN: %target-swift-frontend -module-name builtins -parse-stdlib -Xllvm -sil-disable-pass=target-constant-folding -disable-access-control -primary-file %s -emit-ir -o - -disable-objc-attr-requires-foundation-module | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
// RUN: %target-swift-frontend -enable-builtin-module -module-name builtins -Xllvm -sil-disable-pass=target-constant-folding -disable-access-control -primary-file %s -emit-ir -o - -disable-objc-attr-requires-foundation-module | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime

// REQUIRES: CPU=x86_64 || CPU=arm64 || CPU=arm64e

import Swift
import Builtin

typealias Int = Builtin.Int32
typealias Bool = Builtin.Int1
Expand Down
6 changes: 3 additions & 3 deletions test/IRGen/polymorphic_builtins.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// This line tests that IRGen is properly turning the unspecialized builtins
// into traps.
//
// RUN: %target-swift-frontend -emit-ir -parse-as-library -parse-stdlib -Xllvm -sil-disable-pass=Simplification %s | %FileCheck %s
// RUN: %target-swift-frontend -enable-builtin-module -emit-ir -parse-as-library -Xllvm -sil-disable-pass=Simplification %s | %FileCheck %s

// Make sure we are not eliminating these builtins before IRGen runs. As part of
// the builtin's contract, we expect IRGen to convert them to traps, not
// anything before.
//
// RUN: %target-swift-frontend -emit-sil -parse-as-library -parse-stdlib -Xllvm -sil-disable-pass=Simplification %s | %FileCheck --check-prefix=SIL %s
// RUN: %target-swift-frontend -enable-builtin-module -emit-sil -parse-as-library -Xllvm -sil-disable-pass=Simplification %s | %FileCheck --check-prefix=SIL %s

import Swift
import Builtin

// SIL-LABEL: sil [transparent] @$s20polymorphic_builtins11_isConcrete4typeSbxm_tlF : $@convention(thin) <T> (@thick T.Type) -> Bool {
// SIL: builtin "isConcrete"<T>({{%[0-9]*}} : $@thick T.Type) : $Builtin.Int1
Expand Down
3 changes: 1 addition & 2 deletions test/Inputs/polymorphic_builtins.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

import Swift
import Builtin

// =============================================================================

Expand Down
10 changes: 5 additions & 5 deletions test/Interpreter/polymorphic_builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@

// RUN: %empty-directory(%t)

// RUN: %target-build-swift-dylib(%t/%target-library-name(mysimd)) -enable-library-evolution %S/../Inputs/polymorphic_builtins.swift -emit-module -emit-module-path %t/mysimd.swiftmodule -module-name mysimd -parse-stdlib -D DEBUG -Onone
// RUN: %target-build-swift-dylib(%t/%target-library-name(mysimd)) -enable-builtin-module -enable-library-evolution %S/../Inputs/polymorphic_builtins.swift -emit-module -emit-module-path %t/mysimd.swiftmodule -module-name mysimd -D DEBUG -Onone
// RUN: %target-codesign %t/%target-library-name(mysimd)

// RUN: %target-build-swift %s -L %t -I %t -lmysimd -parse-stdlib -Xfrontend -disable-access-control -Xfrontend -sil-verify-all %target-rpath(%t) -o %t/a.out -D DEBUG -Onone
// RUN: %target-build-swift -enable-builtin-module %s -L %t -I %t -lmysimd -Xfrontend -disable-access-control -Xfrontend -sil-verify-all %target-rpath(%t) -o %t/a.out -D DEBUG -Onone
// RUN: %target-codesign %t/a.out

// RUN: %target-run %t/a.out %t/%target-library-name(mysimd)

// RUN: %empty-directory(%t)

// RUN: %target-build-swift-dylib(%t/%target-library-name(mysimd)) -enable-library-evolution %S/../Inputs/polymorphic_builtins.swift -emit-module -emit-module-path %t/mysimd.swiftmodule -module-name mysimd -parse-stdlib -O
// RUN: %target-build-swift-dylib(%t/%target-library-name(mysimd)) -enable-builtin-module -enable-library-evolution %S/../Inputs/polymorphic_builtins.swift -emit-module -emit-module-path %t/mysimd.swiftmodule -module-name mysimd -O
// RUN: %target-codesign %t/%target-library-name(mysimd)

// RUN: %target-build-swift %s -L %t -I %t -lmysimd -parse-stdlib -Xfrontend -disable-access-control -Xfrontend -sil-verify-all %target-rpath(%t) -o %t/a.out -O
// RUN: %target-build-swift -enable-builtin-module %s -L %t -I %t -lmysimd -Xfrontend -disable-access-control -Xfrontend -sil-verify-all %target-rpath(%t) -o %t/a.out -O
// RUN: %target-codesign %t/a.out

// RUN: %target-run %t/a.out %t/%target-library-name(mysimd)

// REQUIRES: executable_test

import Swift
import Builtin
import StdlibUnittest
import mysimd

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -parse-stdlib -module-name ExportedLib
// swift-module-flags: -module-name ExportedLib

@_exported import SomeCModule

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swift-interface-format-version: 1.0
// swift-module-flags: -parse-stdlib -module-name SdkLib
// swift-module-flags: -module-name SdkLib

@_exported import ExportedLib

Expand Down
6 changes: 3 additions & 3 deletions test/ModuleInterface/ModuleCache/module-cache-options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -parse-stdlib -I %t -emit-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -emit-module -o /dev/null
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -parse-stdlib -I %t -module-cache-path %t/swiftcache -emit-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -parse-stdlib -I %t -module-cache-path %t/swiftcache -Xcc -fmodules-cache-path=%t/clangcache -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %t/main.swift
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -I %t -emit-module-interface-path %t/LeafModule.swiftinterface -module-name LeafModule %t/leaf.swift -emit-module -o /dev/null
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -I %t -module-cache-path %t/swiftcache -emit-module-interface-path %t/OtherModule.swiftinterface -module-name OtherModule %t/other.swift -emit-module -o /dev/null
// RUN: %target-swift-frontend -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -I %t -module-cache-path %t/swiftcache -Xcc -fmodules-cache-path=%t/clangcache -emit-module -o %t/TestModule.swiftmodule -module-name TestModule %t/main.swift

// RUN: NUM_SWIFT_MODULES=$(find %t/swiftcache -type f -name '*.swiftmodule' | wc -l)
// RUN: NUM_CLANG_MODULES=$(find %t/clangcache -type f -name '*.pcm' | wc -l)
Expand Down
6 changes: 3 additions & 3 deletions test/SILGen/builtins.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %target-swift-emit-silgen -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s
// RUN: %target-swift-emit-sil -Onone -parse-stdlib %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck -check-prefix=CANONICAL %s
// RUN: %target-swift-emit-silgen -enable-builtin-module %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s
// RUN: %target-swift-emit-sil -enable-builtin-module -Onone %s -disable-access-control -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck -check-prefix=CANONICAL %s

// REQUIRES: swift_in_compiler

import Swift
import Builtin

protocol ClassProto : class { }

Expand Down
4 changes: 3 additions & 1 deletion test/SILGen/polymorphic_builtins.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: %target-swift-frontend -parse-stdlib -emit-silgen %s | %FileCheck %s
// RUN: %target-swift-frontend -enable-builtin-module -emit-silgen %s | %FileCheck %s

import Builtin

// CHECK-LABEL: sil hidden [ossa] @$s20polymorphic_builtins{{.*}}concreteAddTest{{.*}} : $@convention(thin) (Builtin.Vec4xInt32, Builtin.Vec4xInt32) -> Builtin.Vec4xInt32 {
// CHECK: bb0([[ARG0:%.*]] : $Builtin.Vec4xInt32, [[ARG1:%.*]] : $Builtin.Vec4xInt32):
Expand Down
1 change: 1 addition & 0 deletions test/SILOptimizer/capture_promotion_generic_context.sil
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
sil_stage raw

import Builtin
import Swift

typealias Int = Builtin.Int32

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
sil_stage raw

import Builtin
import Swift

typealias Int = Builtin.Int32

Expand Down
6 changes: 4 additions & 2 deletions test/SILOptimizer/constant_propagation_stdlib.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// RUN: %target-swift-frontend -module-name constant_propagation_stdlib %s -parse-stdlib -emit-sil -o - | %FileCheck --check-prefix=CHECK-ONONE %s
// RUN: %target-swift-frontend -module-name constant_propagation_stdlib %s -parse-stdlib -emit-sil -o - -O | %FileCheck --check-prefix=CHECK-O %s
// RUN: %target-swift-frontend -module-name constant_propagation_stdlib %s -emit-sil -enable-builtin-module -o - | %FileCheck --check-prefix=CHECK-ONONE %s
// RUN: %target-swift-frontend -module-name constant_propagation_stdlib %s -emit-sil -enable-builtin-module -o - -O | %FileCheck --check-prefix=CHECK-O %s

// REQUIRES: swift_in_compiler

import Builtin

public struct MyInt {
var v: Builtin.Int32
}
Expand Down
4 changes: 2 additions & 2 deletions test/SILOptimizer/polymorphic_builtins_diagnostics.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-swift-frontend -parse-stdlib -emit-sil -verify %s
// RUN: %target-swift-frontend -emit-sil -enable-builtin-module -verify %s

import Swift
import Builtin

struct MyInt {
var i: Builtin.Int64
Expand Down
11 changes: 11 additions & 0 deletions test/Sema/lifetime_attr_nofeature.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-typecheck-verify-swift -disable-availability-checking
// REQUIRES: asserts

struct NE : ~Escapable { // expected-error{{type 'Escapable' requires -enable-experimental-feature NonescapableTypes}}

}

@lifetime(ne) // expected-error{{'@lifetime' attribute is only valid when experimental feature NonescapableTypes is enabled}} expected-error{{expected declaration}}
func derive(_ ne: NE) -> NE {
ne
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not %target-swift-frontend %s -typecheck
// REQUIRES: rdar136703549

enum ST:d
protocol a{typealias d:A.B{
{
Expand Down