Skip to content

Commit 992cae4

Browse files
authored
[Frontend] Use experimental feature for layout prespecializations (#61451)
1 parent b815893 commit 992cae4

13 files changed

+386
-137
lines changed

benchmark/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ set(SWIFT_BENCH_MODULES
162162
single-source/RomanNumbers
163163
single-source/SIMDRandomMask
164164
single-source/SIMDReduceInteger
165-
single-source/SimpleArraySpecialization
165+
# Disabled while layout prespecializations are experimental
166+
#single-source/SimpleArraySpecialization
166167
single-source/SequenceAlgos
167168
single-source/SetTests
168169
single-source/SevenBoom
@@ -216,7 +217,8 @@ endif()
216217

217218
set(BENCH_LIBRARY_MODULES
218219
utils/TestsUtils
219-
utils/SimpleArray
220+
# Disabled while layout prespecializations are experimental
221+
#utils/SimpleArray
220222
)
221223

222224
set(BENCH_DRIVER_LIBRARY_MODULES

benchmark/Package.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ unsupportedTests.insert("ObjectiveCBridging")
1010
unsupportedTests.insert("ObjectiveCBridgingStubs")
1111
#endif
1212

13+
unsupportedTests.insert("SimpleArraySpecialization")
14+
1315
//===---
1416
// Single Source Libraries
1517
//
@@ -78,7 +80,7 @@ var multiSourceLibraries: [(parentSubDir: String, name: String)] = multiSourceLi
7880

7981
var products: [Product] = []
8082
products.append(.library(name: "TestsUtils", type: .static, targets: ["TestsUtils"]))
81-
products.append(.library(name: "SimpleArray", type: .static, targets: ["SimpleArray"]))
83+
//products.append(.library(name: "SimpleArray", type: .static, targets: ["SimpleArray"]))
8284
products.append(.library(name: "DriverUtils", type: .static, targets: ["DriverUtils"]))
8385
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
8486
products.append(.library(name: "ObjectiveCTests", type: .static, targets: ["ObjectiveCTests"]))
@@ -97,12 +99,13 @@ products += multiSourceLibraries.map {
9799

98100
var targets: [Target] = []
99101
targets.append(.target(name: "TestsUtils", path: "utils", sources: ["TestsUtils.swift"]))
100-
targets.append(.target(
101-
name: "SimpleArray",
102-
path: "utils",
103-
sources: ["SimpleArray.swift"],
104-
swiftSettings: [.unsafeFlags(["-Xfrontend",
105-
"-enable-experimental-layout-prespecialization"])]))
102+
// targets.append(.target(
103+
// name: "SimpleArray",
104+
// path: "utils",
105+
// sources: ["SimpleArray.swift"],
106+
// swiftSettings: [.unsafeFlags(["-Xfrontend",
107+
// "-enable-experimental-feature",
108+
// "LayoutPrespecialization"])]))
106109
targets.append(.systemLibrary(name: "LibProc", path: "utils/LibProc"))
107110
targets.append(
108111
.target(name: "DriverUtils",
@@ -136,7 +139,7 @@ targets.append(
136139
publicHeadersPath: "."))
137140
#endif
138141

139-
var singleSourceDeps: [Target.Dependency] = [.target(name: "TestsUtils"), .target(name: "SimpleArray")]
142+
var singleSourceDeps: [Target.Dependency] = [.target(name: "TestsUtils"), /* .target(name: "SimpleArray") */]
140143
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
141144
singleSourceDeps.append(.target(name: "ObjectiveCTests"))
142145
#endif
@@ -154,9 +157,7 @@ targets += singleSourceLibraries.map { name in
154157
return .target(name: name,
155158
dependencies: singleSourceDeps,
156159
path: "single-source",
157-
sources: ["\(name).swift"],
158-
swiftSettings: [.unsafeFlags(["-Xfrontend",
159-
"-enable-experimental-layout-prespecialization"])])
160+
sources: ["\(name).swift"])
160161
}
161162

162163
targets += cxxSingleSourceLibraries.map { name in

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,9 @@ function (swift_benchmark_compile_archopts)
354354
set(common_options
355355
"-c"
356356
"-target" "${target}"
357-
"-${BENCH_COMPILE_ARCHOPTS_OPT}" ${PAGE_ALIGNMENT_OPTION}
358-
"-Xfrontend" "-enable-experimental-layout-prespecialization")
357+
"-${BENCH_COMPILE_ARCHOPTS_OPT}" ${PAGE_ALIGNMENT_OPTION})
358+
#"-Xfrontend" "-enable-experimental-feature"
359+
#"-Xfrontend" "LayoutPrespecialization")
359360

360361
if(SWIFT_BENCHMARK_GENERATE_DEBUG_INFO)
361362
list(APPEND common_options "-g")

benchmark/utils/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ import SequenceAlgos
165165
import SetTests
166166
import SevenBoom
167167
import Sim2DArray
168-
import SimpleArraySpecialization
168+
//import SimpleArraySpecialization
169169
import SortArrayInClass
170170
import SortIntPyramids
171171
import SortLargeExistentials
@@ -349,7 +349,7 @@ register(SequenceAlgos.benchmarks)
349349
register(SetTests.benchmarks)
350350
register(SevenBoom.benchmarks)
351351
register(Sim2DArray.benchmarks)
352-
register(SimpleArraySpecialization.benchmarks)
352+
//register(SimpleArraySpecialization.benchmarks)
353353
register(SortArrayInClass.benchmarks)
354354
register(SortIntPyramids.benchmarks)
355355
register(SortLargeExistentials.benchmarks)

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6628,7 +6628,7 @@ ERROR(no_metadata_on_non_generic_param, none,
66286628
ERROR(experimental_no_metadata_feature_can_only_be_used_when_enabled,
66296629
none, "Can not use feature when experimental layout based"
66306630
" pre-specializations are disabled! Pass the frontend flag"
6631-
" -enable-experimental-layout-prespecialization to swift to enable "
6631+
" -enable-experimental-feature LayoutPrespecialization to swift to enable "
66326632
" the usage of this language feature", ())
66336633

66346634
#define UNDEFINE_DIAGNOSTIC_MACROS

include/swift/Option/FrontendOptions.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,6 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
317317
def enable_experimental_async_top_level :
318318
Flag<["-"], "enable-experimental-async-top-level">,
319319
HelpText<"Enable experimental concurrency in top-level code">;
320-
321-
def enable_experimental_layout_prespecialization :
322-
Flag<["-"], "enable-experimental-layout-prespecialization">,
323-
HelpText<"Enable experimental support for layout based pre-specializations">;
324320
}
325321

326322
// HIDDEN FLAGS

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
684684
Opts.Features.insert(Feature::ForwardModeDifferentiation);
685685
if (Args.hasArg(OPT_enable_experimental_additive_arithmetic_derivation))
686686
Opts.Features.insert(Feature::AdditiveArithmeticDerivedConformances);
687-
if (Args.hasArg(OPT_enable_experimental_layout_prespecialization))
688-
Opts.Features.insert(Feature::LayoutPrespecialization);
689687

690688
if (Args.hasArg(OPT_enable_experimental_opaque_type_erasure))
691689
Opts.Features.insert(Feature::OpaqueTypeErasure);

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,11 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
14891489
std::string pair = (llvm::Twine(lhs) + "=" + rhs).str();
14901490
GenericArgs.push_back(ArgSaver.save(pair));
14911491
});
1492+
1493+
if (LangOpts.hasFeature(Feature::LayoutPrespecialization)) {
1494+
genericSubInvocation.getLangOptions().Features.insert(
1495+
Feature::LayoutPrespecialization);
1496+
}
14921497
}
14931498

14941499
bool InterfaceSubContextDelegateImpl::extractSwiftInterfaceVersionAndArgs(

test/SILOptimizer/Inputs/pre_specialized_module.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,24 @@ public class SomeClass {
99

1010
@_specialize(exported: true, where T == Int)
1111
@_specialize(exported: true, where T == Double)
12-
@_specialize(exported: true, where @_noMetadata T : _Class)
1312
@_specialize(exported: true, availability: macOS 10.50, *; where T == SomeData)
1413
public func publicPrespecialized<T>(_ t: T) {
1514
}
1615

1716
@_specialize(exported: true, where T == Int)
18-
@_specialize(exported: true, where @_noMetadata T : _Class)
1917
@_specialize(exported: true, availability: macOS 10.50, *; where T == SomeData)
2018
@inlinable
2119
@inline(never)
2220
public func publicPrespecialized2<T>(_ t: T) { }
2321

2422
@_specialize(exported: true, where T == Int)
25-
@_specialize(exported: true, where @_noMetadata T : _Class)
2623
@_specialize(exported: true, availability: macOS 10.50, *; where T == SomeData)
2724
@inlinable
2825
@inline(never)
2926
public func publicPrespecializedThrows<T>(_ t: T) throws -> T { return t }
3027

3128
@_specialize(exported: true, where T == Int)
3229
@_specialize(exported: true, where T == Double)
33-
@_specialize(exported: true, where @_noMetadata T : _Class)
3430
@_alwaysEmitIntoClient
3531
@inline(never)
3632
internal func internalEmitIntoClientPrespecialized<T>(_ t: T) {
@@ -61,7 +57,6 @@ internal struct InternalThing2<T> {
6157
}
6258

6359
@_specialize(exported: true, where T == Int)
64-
@_specialize(exported: true, where @_noMetadata T : _Class)
6560
@inlinable
6661
func compute() -> T {
6762
return x
@@ -70,7 +65,6 @@ internal struct InternalThing2<T> {
7065
@inlinable
7166
var computedX : T {
7267
@_specialize(exported: true, where T == Int)
73-
@_specialize(exported: true, where @_noMetadata T : _Class)
7468
get {
7569
return x
7670
}
@@ -79,12 +73,10 @@ internal struct InternalThing2<T> {
7973
@inlinable
8074
var computedY : T {
8175
@_specialize(exported: true, where T == Int)
82-
@_specialize(exported: true, where @_noMetadata T : _Class)
8376
get {
8477
return x
8578
}
8679
@_specialize(exported: true, where T == Int)
87-
@_specialize(exported: true, where @_noMetadata T : _Class)
8880
set {
8981
x = newValue
9082
}
@@ -93,25 +85,21 @@ internal struct InternalThing2<T> {
9385
@inlinable
9486
var computedZ : T {
9587
@_specialize(exported: true, where T == Int)
96-
@_specialize(exported: true, where @_noMetadata T : _Class)
9788
_modify {
9889
yield &x
9990
}
10091
@_specialize(exported: true, where T == Int)
101-
@_specialize(exported: true, where @_noMetadata T : _Class)
10292
_read {
10393
yield x
10494
}
10595
}
10696
@inlinable
10797
subscript(_ i: Int) -> T {
10898
@_specialize(exported: true, where T == Int)
109-
@_specialize(exported: true, where @_noMetadata T : _Class)
11099
get {
111100
return x
112101
}
113102
@_specialize(exported: true, where T == Int)
114-
@_specialize(exported: true, where @_noMetadata T : _Class)
115103
set {
116104
}
117105
}
@@ -129,8 +117,3 @@ public func useInternalThing<T>(_ t: T) {
129117
x[1] = t
130118
print(x[1])
131119
}
132-
133-
@_specialize(exported: true, where @_noMetadata T : _Class, @_noMetadata V : _Class)
134-
public func publicPresepcializedMultipleIndirectResults<T, V>(_ t: T, _ v: V, _ x: Int64)-> (V, Int64, T) {
135-
return (v, x, t)
136-
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
@frozen
2+
public struct SomeData {
3+
public init() {}
4+
}
5+
6+
public class SomeClass {
7+
public init() {}
8+
}
9+
10+
@_specialize(exported: true, where T == Int)
11+
@_specialize(exported: true, where T == Double)
12+
@_specialize(exported: true, where @_noMetadata T : _Class)
13+
@_specialize(exported: true, availability: macOS 10.50, *; where T == SomeData)
14+
public func publicPrespecialized<T>(_ t: T) {
15+
}
16+
17+
@_specialize(exported: true, where T == Int)
18+
@_specialize(exported: true, where @_noMetadata T : _Class)
19+
@_specialize(exported: true, availability: macOS 10.50, *; where T == SomeData)
20+
@inlinable
21+
@inline(never)
22+
public func publicPrespecialized2<T>(_ t: T) { }
23+
24+
@_specialize(exported: true, where T == Int)
25+
@_specialize(exported: true, where @_noMetadata T : _Class)
26+
@_specialize(exported: true, availability: macOS 10.50, *; where T == SomeData)
27+
@inlinable
28+
@inline(never)
29+
public func publicPrespecializedThrows<T>(_ t: T) throws -> T { return t }
30+
31+
@_specialize(exported: true, where T == Int)
32+
@_specialize(exported: true, where T == Double)
33+
@_specialize(exported: true, where @_noMetadata T : _Class)
34+
@_alwaysEmitIntoClient
35+
@inline(never)
36+
internal func internalEmitIntoClientPrespecialized<T>(_ t: T) {
37+
}
38+
39+
@inlinable
40+
public func useInternalEmitIntoClientPrespecialized<T>(_ t: T) {
41+
internalEmitIntoClientPrespecialized(t)
42+
}
43+
44+
@inlinable
45+
public func publicInlineable<T>(_ t: T) {
46+
}
47+
48+
public struct ResilientThing {
49+
public init() {}
50+
}
51+
52+
@usableFromInline
53+
@frozen
54+
internal struct InternalThing2<T> {
55+
@usableFromInline
56+
var x : T
57+
58+
@usableFromInline
59+
init(_ t: T) {
60+
x = t
61+
}
62+
63+
@_specialize(exported: true, where T == Int)
64+
@_specialize(exported: true, where @_noMetadata T : _Class)
65+
@inlinable
66+
func compute() -> T {
67+
return x
68+
}
69+
70+
@inlinable
71+
var computedX : T {
72+
@_specialize(exported: true, where T == Int)
73+
@_specialize(exported: true, where @_noMetadata T : _Class)
74+
get {
75+
return x
76+
}
77+
}
78+
79+
@inlinable
80+
var computedY : T {
81+
@_specialize(exported: true, where T == Int)
82+
@_specialize(exported: true, where @_noMetadata T : _Class)
83+
get {
84+
return x
85+
}
86+
@_specialize(exported: true, where T == Int)
87+
@_specialize(exported: true, where @_noMetadata T : _Class)
88+
set {
89+
x = newValue
90+
}
91+
}
92+
93+
@inlinable
94+
var computedZ : T {
95+
@_specialize(exported: true, where T == Int)
96+
@_specialize(exported: true, where @_noMetadata T : _Class)
97+
_modify {
98+
yield &x
99+
}
100+
@_specialize(exported: true, where T == Int)
101+
@_specialize(exported: true, where @_noMetadata T : _Class)
102+
_read {
103+
yield x
104+
}
105+
}
106+
@inlinable
107+
subscript(_ i: Int) -> T {
108+
@_specialize(exported: true, where T == Int)
109+
@_specialize(exported: true, where @_noMetadata T : _Class)
110+
get {
111+
return x
112+
}
113+
@_specialize(exported: true, where T == Int)
114+
@_specialize(exported: true, where @_noMetadata T : _Class)
115+
set {
116+
}
117+
}
118+
}
119+
120+
@inlinable
121+
public func useInternalThing<T>(_ t: T) {
122+
var x = InternalThing2(t)
123+
print(x.compute())
124+
print(x.computedX)
125+
x.computedY = t
126+
print(x.computedY)
127+
x.computedZ = t
128+
print(x.computedZ)
129+
x[1] = t
130+
print(x[1])
131+
}
132+
133+
@_specialize(exported: true, where @_noMetadata T : _Class, @_noMetadata V : _Class)
134+
public func publicPresepcializedMultipleIndirectResults<T, V>(_ t: T, _ v: V, _ x: Int64)-> (V, Int64, T) {
135+
return (v, x, t)
136+
}

0 commit comments

Comments
 (0)