-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SwiftCompilerSources] Bridged in-IR testing. #68813
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
[SwiftCompilerSources] Bridged in-IR testing. #68813
Conversation
82c8a63
to
487dc11
Compare
@swift-ci please test |
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.
nice!
I have a few comments
self.name._withStringRef { nameStr in | ||
registerFunctionTest( | ||
nameStr, | ||
unsafeBitCast(impl, to: UnsafeMutableRawPointer.self)) |
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.
Can you define the closure as @convention(c)
to avoid the unsafe bitcast? Like it's done for the run-function in registerPass
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.
Yep, with the FunctionTest as a global struct whose member can be called which does the unwrapping, that works. Fixed.
@_semantics("arc.immortal") | ||
public class FunctionTest { | ||
public var name: String | ||
init(name: String, impl: @convention(thin) (Function, TestArguments, 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.
I tried to follow the convention to not use abbreviations in function API names (which includes argument labels). Therefore I suggest impl:
-> implementation:
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.
Fixed.
import SILBridging | ||
|
||
@_semantics("arc.immortal") | ||
public class 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.
Does this really need to be a class? And does it need to bridge to C++ (via the swift object header)?
On the C++ side, a new FunctionTest is created anyway.
I think it can be a struct, similar to FunctionPass
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.
Thanks! Switched over to that.
{ bridgedFunction, bridgedTestArguments, bridgedFunctionTest, ctx in | ||
typealias Impl = @convention(thin) (Function, TestArguments, FunctionTest) -> () | ||
let impl = unsafeBitCast(ctx, to: Impl.self) | ||
impl(bridgedFunction.function, bridgedTestArguments.native, bridgedFunctionTest.native) |
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.
IIUC, the reason to pass the test to the closure is to get things like dominance info. In the spirit of swift passes, it's better to pass a TestContext
which can provide everything which is potentially needed by a test.
Though, it will be a problem that this context provides an analysis, like the dominator tree, because this is defined in the optimizer module. Anyway, that can be solved.
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.
Right, it's to make analyses available. Added a Bridged/TestContext that wraps a SwiftPassInvocation. Later on I'll add extensions to make the analyses available.
} | ||
|
||
@_semantics("arc.immortal") | ||
public class TestArguments { |
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.
again, does this need to be a bridged class?
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.
Nope, fixed.
487dc11
to
076c520
Compare
@swift-ci please test |
076c520
to
48035ab
Compare
@swift-ci please test |
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.
lgtm!
Just one thing: can you copy the top-level comment(s) from the C++ Test.h file over to the swift implementation (in Test.swift)? Feel free to do that in a follow-up PR.
There's no advantage to using an function_ref and it might be confusing.
Added the bridging types involved and the basic functionality.
48035ab
to
c9389e1
Compare
Yep! Done (with appropriate translation). |
@swift-ci please test |
To prove out that the bridging works.
c9389e1
to
36805c8
Compare
@swift-ci please test |
1 similar comment
@swift-ci please test |
@swift-ci please clean test linux platform |
@swift-ci please smoke test linux platform |
@swift-ci please test linux platform |
// | ||
// CASE STUDY: | ||
// Here's an example of how it works: | ||
// 0) A source file, NeatUtils.cpp contains |
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.
I guess this is supposed to be NeatUtils.swift
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.
Oops! #68924 .
Added the bridging types involved and the basic functionality.