-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Test] Moved SIL function tests next to tested code. #67069
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
Conversation
b0c95db
to
9bb7889
Compare
@swift-ci please test |
@swift-ci please test macos platform |
include/swift/SIL/UnitTest.h
Outdated
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file defines test::FunctionTest. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's define FunctionTest
. Is it just any test that takes a SILFunction as input and produces any arbitrary output? I suppose this is a specific kind of "functional" test but that's not what the name refers to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a definition for this type just above it among the other header changes.
include/swift/SIL/UnitTest.h
Outdated
@@ -0,0 +1,102 @@ | |||
//===-- UnitTest.h - Testing based on test_specification insts -*- C++ --*-===// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular reason this is not called FunctionTest.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case we want to add a ModuleTest in here someday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped "Unit" here and elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
My main suggestion is to separate the C++ trickery for bypassing the layering violation that exists with pure SIL tests from the essential interface that test writers need to see. It is easy to confuse all of the abstraction in UnitTest.h
for extension points that need to be implemented, when they are all just implementation details that only exist to our particular cmake configuration happy.
In UnitTest.h
please add comments that explain the specific motivation for each weird abstraction or template argument. Like specifically mentioning that the template argument is designed to issue a compile-time error if the API is called outside of the SILOptimizer library.
I think the FunctionTest/Arguments interfaces are basically good as long as they can be implemented in Swift compiler source without any of the complexity that we need here for the C++ build.
b230004
to
794cfdb
Compare
Reorganized the header so that the parts relevant to people writing tests appear at the top with docs and are separated by ASCII art from the various implementation details. Doc'd the two tricks required for layering. I think the SwiftSources side will work pretty straightforwardly. With an enum for Argument. And a Dependencies protocol which the test-running pass will instantiate and pass to FunctionTest.run. It would then be extended in the SILOptimizer module with getAnalysis, getFunctionPass, etc. |
@swift-ci please test |
794cfdb
to
df48573
Compare
In preparation for moving unit test infrastructure there so that it can be used anywhere the SIL library is used.
Renamed UnitTest to FunctionTest. FunctionTests are now instantiated once as global objects--with their names and the code they are to run--at which time they are stored by name in a global registry. Moved the types to the SIL library. Together, these changes enable defining unit tests in the source file containing the code to be tested.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
-with-list-of-last-users-insertion-points. Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
-switch-enum. Moved the test next to the code it calls.
-enum-block. Moved the test next to the code it calls.
-enum-on-objc-class-optional. Moved the test next to the code it calls.
-enum-unreachable-blocks. Moved the test next to the code it calls.
-term-with-identical-dest-blocks. Moved the test next to the code it calls.
Moved the test next to the code it calls.
Moved the test next to the code it calls.
-liverange. Moved the test next to the code it calls.
df48573
to
22df319
Compare
@swift-ci please test |
Refactored the infrastructure for testing individual SIL utilites/arbitrary compiler code in the context of a SIL function.
Instead of creating a new class, now it's only necessary to instantiate a global FunctionTest. At instantiation, the name of the test and a lambda to run are provided. When the test running pass encounters a test_specification naming the test, the lambda is invoked.
The infrastructure is now (mostly) in the SIL library so that it can be used from any library that can import its headers. There is a bit of indirection in the FunctionTest/UnitTestRunner types in order to make this work without layering violations, but it is mostly transparent to the tests whose implementations changed very little.
The most interesting commit is
[Test] Refactored SIL "unit" tests.
.