Skip to content

Commit 622ff07

Browse files
authored
Merge pull request #69009 from nate-chandler/swiftcompilersources/test-in-optimizer
[SwiftCompilerSources] Moved Test into Optimizer.
2 parents 18ce3ab + ae1f950 commit 622ff07

File tree

8 files changed

+23
-32
lines changed

8 files changed

+23
-32
lines changed

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public func initializeSwiftModules() {
2020
registerSwiftAnalyses()
2121
registerSwiftPasses()
2222
initializeSwiftParseModules()
23-
registerSILTests()
23+
registerOptimizerTests()
2424
}
2525

2626
private func registerPass(

SwiftCompilerSources/Sources/Optimizer/Utilities/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ swift_compiler_sources(Optimizer
1414
AccessUtils.swift
1515
SSAUpdater.swift
1616
StaticInitCloner.swift
17+
Test.swift
1718
)

SwiftCompilerSources/Sources/SIL/Test.swift renamed to SwiftCompilerSources/Sources/Optimizer/Utilities/Test.swift

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@
9090
//===----------------------------------------------------------------------===//
9191

9292
import Basic
93+
import SIL
9394
import SILBridging
95+
import OptimizerBridging
9496

9597
/// The primary interface to in-IR tests.
96-
public struct FunctionTest {
98+
struct FunctionTest {
9799
let name: String
98100
let invocation: FunctionTestInvocation
99101

@@ -104,7 +106,7 @@ public struct FunctionTest {
104106
}
105107

106108
/// The type of the closure passed to a FunctionTest.
107-
public typealias FunctionTestInvocation = @convention(thin) (Function, TestArguments, TestContext) -> ()
109+
typealias FunctionTestInvocation = @convention(thin) (Function, TestArguments, FunctionPassContext) -> ()
108110

109111
/// Wraps the arguments specified in the specify_test instruction.
110112
public struct TestArguments {
@@ -129,20 +131,8 @@ extension BridgedTestArguments {
129131
public var native: TestArguments { TestArguments(bridged: self) }
130132
}
131133

132-
/// An interface to the various analyses that are available.
133-
public struct TestContext {
134-
public var bridged: BridgedTestContext
135-
fileprivate init(bridged: BridgedTestContext) {
136-
self.bridged = bridged
137-
}
138-
}
139-
140-
extension BridgedTestContext {
141-
public var native: TestContext { TestContext(bridged: self) }
142-
}
143-
144134
/// Registration of each test in the SIL module.
145-
public func registerSILTests() {
135+
public func registerOptimizerTests() {
146136
// Register each test.
147137
registerFunctionTest(parseTestSpecificationTest)
148138

@@ -161,16 +151,18 @@ private func registerFunctionTest(_ test: FunctionTest) {
161151
/// actual test function.
162152
///
163153
/// This function is necessary because tests need to be written in terms of
164-
/// native Swift types (Function, TestArguments, TestContext) rather than their
165-
/// bridged variants, but such a function isn't representable in C++. This
166-
/// thunk unwraps the bridged types and invokes the real function.
154+
/// native Swift types (Function, TestArguments, BridgedPassContext)
155+
/// rather than their bridged variants, but such a function isn't representable
156+
/// in C++. This thunk unwraps the bridged types and invokes the real
157+
/// function.
167158
private func functionTestThunk(
168159
_ erasedInvocation: UnsafeMutableRawPointer,
169160
_ function: BridgedFunction,
170161
_ arguments: BridgedTestArguments,
171-
_ context: BridgedTestContext) {
162+
_ passInvocation: BridgedSwiftPassInvocation) {
172163
let invocation = uneraseInvocation(erasedInvocation)
173-
invocation(function.function, arguments.native, context.native)
164+
let context = FunctionPassContext(_bridged: BridgedPassContext(invocation: passInvocation.invocation))
165+
invocation(function.function, arguments.native, context)
174166
}
175167

176168
/// Bitcast a thin test closure to void *.

SwiftCompilerSources/Sources/SIL/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ add_swift_compiler_module(SIL
2424
Registration.swift
2525
SmallProjectionPath.swift
2626
SubstitutionMap.swift
27-
Test.swift
2827
Type.swift
2928
Utils.swift
3029
Value.swift

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import SILBridging
1616
public struct Operand : CustomStringConvertible, NoReflectionChildren {
1717
fileprivate let bridged: BridgedOperand
1818

19-
init(bridged: BridgedOperand) {
19+
public init(bridged: BridgedOperand) {
2020
self.bridged = bridged
2121
}
2222

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,14 +1657,13 @@ struct BridgedTestArguments {
16571657
BridgedFunction takeFunction() const;
16581658
};
16591659

1660-
struct BridgedTestContext {
1660+
struct BridgedSwiftPassInvocation {
16611661
swift::SwiftPassInvocation *_Nonnull invocation;
16621662
};
16631663

1664-
using SwiftNativeFunctionTestThunk = void (*_Nonnull)(void *_Nonnull,
1665-
BridgedFunction,
1666-
BridgedTestArguments,
1667-
BridgedTestContext);
1664+
using SwiftNativeFunctionTestThunk =
1665+
void (*_Nonnull)(void *_Nonnull, BridgedFunction, BridgedTestArguments,
1666+
BridgedSwiftPassInvocation);
16681667

16691668
void registerFunctionTestThunk(SwiftNativeFunctionTestThunk);
16701669

include/swift/SIL/Test.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class FunctionTest final {
167167
template <typename Analysis, typename Transform = SILFunctionTransform>
168168
Analysis *getAnalysis();
169169

170-
BridgedTestContext getContext();
170+
SwiftPassInvocation *getInvocation();
171171

172172
//===----------------------------------------------------------------------===//
173173
//=== MARK: Implementation Details ===

lib/SIL/Utils/Test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void FunctionTest::run(SILFunction &function, Arguments &arguments,
9999
} else {
100100
auto *fn = invocation.get<NativeSwiftInvocation>();
101101
Registry::get().getFunctionTestThunk()(fn, {&function}, {&arguments},
102-
getContext());
102+
{getInvocation()});
103103
}
104104
this->pass = nullptr;
105105
this->function = nullptr;
@@ -114,6 +114,6 @@ SILPassManager *FunctionTest::getPassManager() {
114114
return dependencies->getPassManager();
115115
}
116116

117-
BridgedTestContext FunctionTest::getContext() {
118-
return BridgedTestContext{dependencies->getInvocation()};
117+
SwiftPassInvocation *FunctionTest::getInvocation() {
118+
return dependencies->getInvocation();
119119
}

0 commit comments

Comments
 (0)