Skip to content

Commit 9a8f8d0

Browse files
authored
Merge pull request #76643 from tshortli/rebaseline-specialize-attr-with-availability
AST: Make $SpecializeAttributeWithAvailability a baseline feature
2 parents b9228c8 + 0fb36a5 commit 9a8f8d0

File tree

7 files changed

+20
-45
lines changed

7 files changed

+20
-45
lines changed

include/swift/AST/PrintOptions.h

-4
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,6 @@ struct PrintOptions {
575575
/// compilers that might parse the result.
576576
bool PrintCompatibilityFeatureChecks = false;
577577

578-
/// Whether to print @_specialize attributes that have an availability
579-
/// parameter.
580-
bool PrintSpecializeAttributeWithAvailability = true;
581-
582578
/// Whether to always desugar array types from `[base_type]` to `Array<base_type>`
583579
bool AlwaysDesugarArraySliceTypes = false;
584580

include/swift/Basic/Features.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ BASELINE_LANGUAGE_FEATURE(BuiltinAllocVector, 0, "Builtin.allocVector")
162162
BASELINE_LANGUAGE_FEATURE(BuiltinTaskRunInline, 0, "Builtin.taskRunInline")
163163
BASELINE_LANGUAGE_FEATURE(BuiltinUnprotectedAddressOf, 0, "Builtin.unprotectedAddressOf")
164164
BASELINE_LANGUAGE_FEATURE(NewCxxMethodSafetyHeuristics, 0, "Only import C++ methods that return pointers (projections) on owned types as unsafe")
165-
SUPPRESSIBLE_LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability")
165+
BASELINE_LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability")
166166
BASELINE_LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment")
167167
BASELINE_LANGUAGE_FEATURE(BuiltinCreateTaskGroupWithFlags, 0, "Builtin.createTaskGroupWithFlags")
168168
BASELINE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor")

lib/AST/ASTPrinter.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -3061,14 +3061,6 @@ void PrintAST::printExtension(ExtensionDecl *decl) {
30613061
}
30623062
}
30633063

3064-
static void suppressingFeatureSpecializeAttributeWithAvailability(
3065-
PrintOptions &options,
3066-
llvm::function_ref<void()> action) {
3067-
llvm::SaveAndRestore<bool> scope(
3068-
options.PrintSpecializeAttributeWithAvailability, false);
3069-
action();
3070-
}
3071-
30723064
static void suppressingFeatureIsolatedAny(PrintOptions &options,
30733065
llvm::function_ref<void()> action) {
30743066
llvm::SaveAndRestore<bool> scope(options.SuppressIsolatedAny, true);

lib/AST/Attr.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -1465,12 +1465,6 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
14651465
if (Options.printPublicInterface() && !attr->getSPIGroups().empty())
14661466
return false;
14671467

1468-
// Don't print the _specialize attribute if we are asked to skip the ones
1469-
// with availability parameters.
1470-
if (!Options.PrintSpecializeAttributeWithAvailability &&
1471-
!attr->getAvailableAttrs().empty())
1472-
return false;
1473-
14741468
Printer << "@" << getAttrName() << "(";
14751469
auto exported = attr->isExported() ? "true" : "false";
14761470
auto kind = attr->isPartialSpecialization() ? "partial" : "full";

lib/AST/FeatureSet.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ static bool usesTypeMatching(Decl *decl, llvm::function_ref<bool(Type)> fn) {
5050
#define UNINTERESTING_FEATURE(FeatureName) \
5151
static bool usesFeature##FeatureName(Decl *decl) { return false; }
5252

53-
static bool usesFeatureSpecializeAttributeWithAvailability(Decl *decl) {
54-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
55-
for (auto specialize : func->getAttrs().getAttributes<SpecializeAttr>()) {
56-
if (!specialize->getAvailableAttrs().empty())
57-
return true;
58-
}
59-
}
60-
return false;
61-
}
62-
6353
// ----------------------------------------------------------------------------
6454
// MARK: - Upcoming Features
6555
// ----------------------------------------------------------------------------

test/ModuleInterface/features.swift

-16
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@
2323
// feature is old enough. The --implicit-check-not arguments to FileCheck above
2424
// verify that those guards no longer pollute the emitted interface.
2525

26-
// CHECK: #if compiler(>=5.3) && $SpecializeAttributeWithAvailability
27-
// CHECK: @_specialize(exported: true, kind: full, availability: macOS, introduced: 12; where T == Swift.Int)
28-
// CHECK: public func specializeWithAvailability<T>(_ t: T)
29-
// CHECK: #else
30-
// CHECK: public func specializeWithAvailability<T>(_ t: T)
31-
// CHECK: #endif
32-
@_specialize(exported: true, availability: macOS 12, *; where T == Int)
33-
public func specializeWithAvailability<T>(_ t: T) {
34-
}
35-
3626
// CHECK: public actor MyActor
3727
// CHECK: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
3828
// CHECK-NEXT: get
@@ -135,12 +125,6 @@ public func asyncIsh(@_inheritActorContext operation: @Sendable @escaping () asy
135125
@_unsafeInheritExecutor
136126
public func unsafeInheritExecutor() async {}
137127

138-
// CHECK: #if compiler(>=5.3) && $SpecializeAttributeWithAvailability
139-
// CHECK: @_specialize{{.*}}
140-
// CHECK: public func unsafeInheritExecutorAndSpecialize<T>(value: T) async
141-
@_unsafeInheritExecutor
142-
@_specialize(exported: true, availability: SwiftStdlib 5.1, *; where T == Int)
143-
public func unsafeInheritExecutorAndSpecialize<T>(value: T) async {}
144128

145129
// CHECK: @_unavailableFromAsync(message: "Test") public func unavailableFromAsyncFunc()
146130
@_unavailableFromAsync(message: "Test")
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test
3+
// R/UN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name Test -disable-experimental-parser-round-trip
4+
// RUN: %FileCheck %s --implicit-check-not "\$SpecializeAttributeWithAvailability" < %t.swiftinterface
5+
6+
// CHECK: @_specialize(exported: false, kind: full, where T == Swift.Double)
7+
// CHECK: public func specialize<T>(_ t: T)
8+
@_specialize(exported: false, where T == Double)
9+
public func specialize<T>(_ t: T) {}
10+
11+
// CHECK: @_specialize(exported: true, kind: full, availability: macOS, introduced: 12; where T == Swift.Int)
12+
// CHECK: public func specializeWithAvailability<T>(_ t: T)
13+
@_specialize(exported: true, availability: macOS 12, *; where T == Int)
14+
public func specializeWithAvailability<T>(_ t: T) {}
15+
16+
// CHECK: @_specialize(exported: true, kind: full, availability: macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *; where T == Swift.Int)
17+
// CHECK: public func specializeWithStdlibAvailability<T>(value: T) async
18+
@_specialize(exported: true, availability: SwiftStdlib 5.1, *; where T == Int)
19+
public func specializeWithStdlibAvailability<T>(value: T) async {}

0 commit comments

Comments
 (0)