Skip to content

[🦩] Add swiftASTGen library to build a C++ AST from a SwiftSyntax parse tree #61426

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

Merged
merged 29 commits into from
Oct 8, 2022

Conversation

DougGregor
Copy link
Member

Introduce a swiftASTGen library, written as a Swift module, which produces a C++ AST from the corresponding SwiftSyntax syntax tree as produced by the new Swift parser. Architecturally, this new library sits between the C++ AST library (since it constructs ASTs) and the C++ parser (whose entry points will be diverted through this library). This new code path intercepts the main entry point of the C++ parser, which parses "top-level" declarations, when the command-line option --enable-experimental-feature ParserASTGen. It doesn't do much yet; this pull request is primarily to get all of the major architectural pieces in place so we can iterate on them.

swiftASTGen depends on the CASTBridging layer, a painstakingly-crafted C API that is used to build and inspect C++ AST nodes, so they can be used from Swift. We cannot currently depend on Swift/C++ interoperability, because it is an experimental feature, whereas this library will need to be able to build with a host Swift compiler from up to a year ago.

The CMake build system is the only one that's able to produce a working compiler. There is also a Package.swift that makes it easier to build and work with the swiftASTGen library within IDEs, but it's mainly there for editing---it won't create something that can be meaningfully executed. Most things with the new Swift parser are better implemented/tested within or on top of the swift-syntax package.

@DougGregor DougGregor requested a review from zoecarver October 3, 2022 23:47
@DougGregor
Copy link
Member Author

This incorporates @zoecarver 's #60943, and cleans up some of the build system and integration bits so we can hopefully land it.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@zoecarver
Copy link
Contributor

Thank you for fixing this up, Doug!

@zoecarver zoecarver mentioned this pull request Oct 3, 2022
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets remove the xcworkspacedata file and Zoe's UserInterfaceState.xcuserstate.

@jpsim
Copy link
Contributor

jpsim commented Oct 6, 2022

FYI there's a zoecarver.xcuserdatad directory checked in here.

@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

This really doesn't do much now, and lots of stuff is likely to get reworked. We need to do a deep dive on a small part of the grammar (types and typealias is probably the smallest bit) and make things as clean and complete as possible, and see how that goes.

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall build structure looks good to me. I didn’t review any of the new Swift or C++ code because IIUC that’s not the intention of this PR.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

zoecarver and others added 11 commits October 7, 2022 10:18
(cherry picked from commit ddede20)
(cherry picked from commit 4e9e5fe)
(cherry picked from commit 1b1944e)
(cherry picked from commit d58a01d)
Only introduce it and its dependency when the new Swift parser is being
built, and rely more on existing logic to make sure we get the right
build/link flags.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

TO BE CLEAR, I have no idea what the flamingo is about. @zoecarver gonna hafta answer that one. I just work here.

@zoecarver
Copy link
Contributor

TO BE CLEAR, I have no idea what the flamingo is about. @zoecarver gonna hafta answer that one. I just work here.

Just keeping things organized...

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please test macOS

@DougGregor
Copy link
Member Author

Windows test failure is unrelated

Builds of Swift sources via CMake are not getting a target triple set,
so they pick up the host triple. This leads to spurious warnings about
linking in code built for a newer OS version (e.g., the one you're on)
into libraries with an older deployment target. It also breaks
building a cross-compiler. Always set the target triple.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain

@DougGregor DougGregor merged commit 2f06546 into swiftlang:main Oct 8, 2022
@DougGregor DougGregor deleted the astgen branch October 8, 2022 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants