-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[stdlib] Fix cc mismatch violation on swift_isClassType #39119
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
[stdlib] Fix cc mismatch violation on swift_isClassType #39119
Conversation
@swift-ci please smoke test |
I want to start a discussion about other cc violations of swift public APIs.
|
Maybe it would be best to cross-post to Swift Forums? We would get more eyes on the issue then. |
@MaxDesiatov Yeah, that's just a heads-up. I'll post a topic in forum |
@swift-ci please test Windows platform |
@_silgen_name("swift_isClassType") | ||
internal func _isClassType(_: Any.Type) -> Bool | ||
internal func _isClassType(_ type: Any.Type) -> Bool { | ||
return swift_isClassType(unsafeBitCast(type, to: UnsafeRawPointer.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.
I don't understand this. I guess I should look at the implementation. But this deserves a comment. You are passing the metatype structure as a pointer?
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.
According to here, a thick metatype is represented with a metadata pointer.
https://github.com/apple/swift/blob/dd32711a5f5c5bd28a6401fc3ede1a0bf344b49e/lib/IRGen/GenType.cpp#L2464-L2466
So the unsafeBitCast
is a safe operation. But I agree this is not clear to everyone, so it should be described in comments.
_isClassType is mainly called by compiler-generated code, but it's also called by stdlib. The call-site of stdlib used @_silgen_name to link the function, so it's called through swiftcc. However its cc is defined as C-cc, so caller and callee used different cc. This patch adds C-compatible decl of swift_isClassType in shims so that it can be called by stdlib with C-cc. This change doesn't break ABI because `_isClassType` in stdlib was defined as internal API.
c6e5268
to
9b13d1f
Compare
@swift-ci please smoke test |
Contra @jckarter, functions that are just working with pointer-sized argument and return types should match between C and The only concern I have about changing the CC for these functions is whether we'd have compile-time problems when linking IR coming from different translation units. |
Should it be possible to verify that with tests? What kind of breakage should we expect? |
The breakage I would expect is something like: if you LTO IR built with a previous compiler with IR built with a new compiler, you can end up with e.g. a |
It doesn't look to me like something that's feasible to cover with tests here. Is there anything else we can do with this PR to proceed? Do we need approvals from more people before this could be merged? |
Well, so, what I'm saying is that I would prefer your old PR that actually makes these functions |
It looks safe to use either CC for |
It seems there is no major use of Can we have approval and merge this patch? |
@swift-ci Please test |
Looks like Linux CI is having network issues. I'll try again in a little while. |
@swift-ci Please test |
@swift-ci please test |
Hi @tbkka, since CI is passing here, would you mind if this is merged? |
I'll run tests again just to make sure nothing's broken in the past couple months, then I'll merge. |
@swift-ci Please test |
_isClassType is mainly called by compiler-generated code, but it's also called by stdlib.
The call-site of stdlib used @_silgen_name to link the function, so it's called through swiftcc.
However its cc is defined as C-cc, so caller and callee used different cc. The definition is here: https://github.com/apple/swift/blob/6e3548797503b4a2bbabcebf7ffd156bc1cac245/stdlib/public/runtime/Casting.cpp#L1420-L1423
This patch adds C-compatible decl of swift_isClassType in shims so that it can be called by stdlib with C-cc.
This change doesn't break ABI because
_isClassType
in stdlib was defined as internal API.I sent a similar patch #30938 before, but it breaks ABI. So I re-started it from a safe point.
CC: @MaxDesiatov @jckarter