-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove CBasicBridging + CASTBridging #69440
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
e572b4a
to
57384f4
Compare
#ifndef DECL | ||
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NONNULL(Id##Decl) | ||
#define DECL(Id, Parent) AST_BRIDGING_WRAPPER_NULLABLE(Id##Decl) |
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.
At this point I kind of wonder whether we're really gaining much from defining separate macros for can-be-nullable, and never-nullable, and should just stamp out nullable bridging wrappers for everything. My main worry with that initially was that it would unnecessarily pollute the type namespace, but at this point a good chunk of types need nullable wrappers anyways. In any case, I can explore that in a follow up.
include/swift/AST/ASTBridging.h
Outdated
|
||
SWIFT_END_NULLABILITY_ANNOTATIONS | ||
|
||
#ifndef PURE_BRIDGING_MODE | ||
// In _not_ PURE_BRIDGING_MODE, briding functions are inlined and therefore |
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 _not_ PURE_BRIDGING_MODE, briding functions are inlined and therefore | |
// In _not_ PURE_BRIDGING_MODE, bridging functions are inlined and therefore |
But also, why is that?
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.
Because the bridging functions can require C++ headers that we don't want to include in "pure bridging mode", since that can trigger the Windows and LLDB C++ interop issues. I can update the comment to explain this (FWIW I copied it from SILBridging.h)
include/swift/Basic/BasicBridging.h
Outdated
const void *_Nullable data; | ||
size_t numElements; |
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.
Suppose these should both start with an uppercase :(. Looks like other Bridged*
are similar too.
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.
Look again :) But yeah I should probably fix the others too
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.
Hah, nice. How far apart was your push and my hitting comment 😅? Doesn't have to be in this PR FWIW.
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.
Yeah I think I'll do this in a follow up
try withUTF8 { buffer in | ||
try body(BridgedString(data: buffer.baseAddress, length: buffer.count)) | ||
try body(BridgedStringRef(data: buffer.baseAddress, count: buffer.count)) | ||
} | ||
} | ||
} | ||
|
||
/// Allocate a copy of the given string as a null-terminated UTF-8 string. |
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.
Could/should uses of this use BridgedOwnedString
now?
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.
Yeah seems like it probably should
assert(!externalDef.isError()); | ||
swift_ASTGen_expandFreestandingMacro( | ||
&ctx.Diags, externalDef.opaqueHandle, | ||
static_cast<uint32_t>(externalDef.kind), discriminator->c_str(), | ||
getRawMacroRole(macroRole), astGenSourceFile, | ||
expansion->getSourceRange().Start.getOpaquePointerValue(), | ||
&evaluatedSourceOut); | ||
if (!evaluatedSourceOut.data) | ||
if (!evaluatedSourceOut.get().data()) |
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.
Not a huge fan of get
. unbridged
would match the bridging .cpp.
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.
Hmm yeah that seems fair enough
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.
Ah, I remember why I named it this way now, it's because it matches all the wrappers in SILBridging.h. If we want to change to unbridged
we probably ought to change those too. Not sure if you have any strong opinions on this @eeckstein?
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.
no strong opinions. We can change it
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!
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!
7324c42
to
4602196
Compare
Will address the rest of the feedback in a follow up |
Tweak the compiler flags such that it can be built from within Xcode. This is only useful when editing, but I find it very handy.
Improve APIs for BridgedStringRef, BridgedOwnedString, and BridgedSourceLoc.
Migrate onto BridgedStringRef, and the BasicBridging equivalents of BridgedSourceLoc and BridgedArrayRef.
These are `void *` on the C side.
Introduce a macro that can stamp out wrapper classes for underlying C++ pointers, and use it to define BridgedDiagnosticEngine in ASTBridging. Then, migrate users of BridgedDiagEngine onto it.
And renaming OptionalBridgedVarDecl to BridgedNullableVarDecl for consistency with the existing nullable AST node wrappers.
Merge with BasicBridging and ASTBridging respectively. The changes here should be pretty uncontroversial, I tried to keep it to just moving code about.
These are now stamped out by the ASTBridgingWrappers.
Move these into ASTBridgingWrappers.def.
These aren't needed in C++
Add a `Bridged` prefix to match the name being exposed to Swift, and to match the other bridging functions. Also while here, use `SWIFT_NAME` for some bridging functions that were missing it.
Sort AST node bridging functions into Expr, Stmt, Decl, and TypeRepr, and tweak the headers to use `MARK`.
Remove the default constructor footgun present with the struct implementations, and sprinkle some `SWIFT_NAME` and bridging utilities to make them nicer to work with.
These are now empty, and it seems like generally we ought to prefer putting the bridging logic on the BridgedXXX wrappers.
4602196
to
3cb74e9
Compare
@swift-ci please test |
🚢 |
Fix the build after swiftlang#69440
Merge CASTBridging and CBasicBridging with ASTBridging and BasicBridging respectively, allowing ASTGen to use C++ interop, and for both ASTGen and SwiftCompilerSources to share the same bridging code. There's more work that can be done here to improve the bridging (e.g we could potentially remove the
bridged
andunbridged
functions in ASTBridging.cpp now), but I'm leaving that for a future PR as there's already enough here.