Skip to content

Commit 04fc29f

Browse files
committed
[SwiftCompilerSources] Moved Test into Optimizer.
And changed the type of the context argument to FunctionPassContext.
1 parent ce4ba6c commit 04fc29f

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
@@ -13,4 +13,5 @@ swift_compiler_sources(Optimizer
1313
AccessUtils.swift
1414
SSAUpdater.swift
1515
StaticInitCloner.swift
16+
Test.swift
1617
)

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
@@ -88,10 +88,12 @@
8888
//===----------------------------------------------------------------------===//
8989

9090
import Basic
91+
import SIL
9192
import SILBridging
93+
import OptimizerBridging
9294

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

@@ -102,7 +104,7 @@ public struct FunctionTest {
102104
}
103105

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

107109
/// Wraps the arguments specified in the specify_test instruction.
108110
public struct TestArguments {
@@ -127,20 +129,8 @@ extension BridgedTestArguments {
127129
public var native: TestArguments { TestArguments(bridged: self) }
128130
}
129131

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

@@ -159,16 +149,18 @@ private func registerFunctionTest(_ test: FunctionTest) {
159149
/// actual test function.
160150
///
161151
/// This function is necessary because tests need to be written in terms of
162-
/// native Swift types (Function, TestArguments, TestContext) rather than their
163-
/// bridged variants, but such a function isn't representable in C++. This
164-
/// thunk unwraps the bridged types and invokes the real function.
152+
/// native Swift types (Function, TestArguments, BridgedPassContext)
153+
/// rather than their bridged variants, but such a function isn't representable
154+
/// in C++. This thunk unwraps the bridged types and invokes the real
155+
/// function.
165156
private func functionTestThunk(
166157
_ erasedInvocation: UnsafeMutableRawPointer,
167158
_ function: BridgedFunction,
168159
_ arguments: BridgedTestArguments,
169-
_ context: BridgedTestContext) {
160+
_ passInvocation: BridgedSwiftPassInvocation) {
170161
let invocation = uneraseInvocation(erasedInvocation)
171-
invocation(function.function, arguments.native, context.native)
162+
let context = FunctionPassContext(_bridged: BridgedPassContext(invocation: passInvocation.invocation))
163+
invocation(function.function, arguments.native, context)
172164
}
173165

174166
/// 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
@@ -23,7 +23,6 @@ add_swift_compiler_module(SIL
2323
Registration.swift
2424
SmallProjectionPath.swift
2525
SubstitutionMap.swift
26-
Test.swift
2726
Type.swift
2827
Utils.swift
2928
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
@@ -1562,14 +1562,13 @@ struct BridgedTestArguments {
15621562
BridgedFunction takeFunction() const;
15631563
};
15641564

1565-
struct BridgedTestContext {
1565+
struct BridgedSwiftPassInvocation {
15661566
swift::SwiftPassInvocation *_Nonnull invocation;
15671567
};
15681568

1569-
using SwiftNativeFunctionTestThunk = void (*_Nonnull)(void *_Nonnull,
1570-
BridgedFunction,
1571-
BridgedTestArguments,
1572-
BridgedTestContext);
1569+
using SwiftNativeFunctionTestThunk =
1570+
void (*_Nonnull)(void *_Nonnull, BridgedFunction, BridgedTestArguments,
1571+
BridgedSwiftPassInvocation);
15731572

15741573
void registerFunctionTestThunk(SwiftNativeFunctionTestThunk);
15751574

include/swift/SIL/Test.h

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

169-
BridgedTestContext getContext();
169+
SwiftPassInvocation *getInvocation();
170170

171171
//===----------------------------------------------------------------------===//
172172
//=== 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)