Skip to content

Move regex literal parsing logic from SwiftCompilerSources to ASTGen #68401

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

Closed

Conversation

DougGregor
Copy link
Member

ASTGen always builds with the host Swift compiler, without requiring bootstrapping, and is enabled in more places. Move the regex literal parsing logic there so it is enabled in more host environments, and makes use of CMake's Swift support. Enable all of the regex literal tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources, because they are no longer needed.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

Copy link
Contributor

@bnbarham bnbarham left a comment

Choose a reason for hiding this comment

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

Seems like maybe we should move lib/ASTGen to something like swiftlib. Or maybe this all just becomes SwiftCompilerSources once we've moved that across as well.

Also, woo!

Comment on lines 13 to 14
//import AST
//import Basic
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I forgot that I'd only commented them out

let offset = str.utf8.distance(from: str.startIndex, to: errorLoc)
diagLoc = _diagLoc.advanced(by: offset)
diagLoc = BridgedSourceLoc(raw: _diagLoc.advanced(by: offset))
Copy link
Contributor

Choose a reason for hiding this comment

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

SourceLoc_advanced(bridgedDiagnosticBaseLoc, SwiftInt(offset))

(there's other places that assume raw is the address, but it would be good if we didn't add more)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good point

@DougGregor
Copy link
Member Author

@swift-ci please clean smoke test Linux

@DougGregor
Copy link
Member Author

@swift-ci please clean smoke test macOS

@DougGregor DougGregor force-pushed the regex-literals-via-astgen branch from 118e8ef to 7159e72 Compare September 8, 2023 20:35
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

Seems like maybe we should move lib/ASTGen to something like swiftlib. Or maybe this all just becomes SwiftCompilerSources once we've moved that across as well.

I don't know if we want a swiftlib kind of thing, or a bunch of different libraries in various lib subdirectories. They're going to end up being intertwined with the C++ libraries.

@bnbarham
Copy link
Contributor

bnbarham commented Sep 8, 2023

Seems like maybe we should move lib/ASTGen to something like swiftlib. Or maybe this all just becomes SwiftCompilerSources once we've moved that across as well.

I don't know if we want a swiftlib kind of thing, or a bunch of different libraries in various lib subdirectories. They're going to end up being intertwined with the C++ libraries.

That's fine too, lib/ASTGen is just an odd mix now. SwiftCompilerSources and lib/ASTGen are also open-able as packages, we could do that in just lib as well but right now that would involve excluding all the other directories.

@finagolfin
Copy link
Member

Thanks for doing this: I just applied this pull to the Sep. 2 trunk source snapshot and was able to build a Swift compiler natively on Android that supports regex literals again and Macros for the first time. Any plans to backport this patch to 5.9?

@DougGregor
Copy link
Member Author

Thanks for doing this: I just applied this pull to the Sep. 2 trunk source snapshot and was able to build a Swift compiler natively on Android that supports regex literals again and Macros for the first time. Any plans to backport this patch to 5.9?

Fantastic! Yes, I'm going to address review comments and back port this patch to 5.9.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@finagolfin
Copy link
Member

I went ahead and backported this pull to 5.9, slapped it up as a gist so you don't have to repeat that work. Haven't tried compiling it with the 5.9 branch yet, will do that next.

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Nice!

Comment on lines 114 to 115
initializeSwiftParseModules();
initializeSwiftModules();
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be worth renaming initializeSwiftModules to something like initializeSwiftSILModules on the Swift side, and then defining initializeSwiftModules on the C side to call both that and initializeSwiftParseModules?

@xedin xedin removed their request for review September 15, 2023 14:56
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@finagolfin we've got Windows CI updated and macros support landed there (#68334), so now it's time to get this tested and merged

@DougGregor
Copy link
Member Author

@swift-ci please build toolchain Windows

@finagolfin
Copy link
Member

@DougGregor, sounds good, I'm currently cross-compiling my 5.9 version of this pull for Android. It appears that portions of #66044 will also need to be backported to 5.9, or the 5.9 version of this pull will have to be adapted for that bridging pull not being in 5.9.

@finagolfin
Copy link
Member

Linux CI failed when testing lldb:

Error output:
error: error while processing module import: error: <EXPR>:7:2: error: expected a macro identifier for a pound literal expression
#/Order from <(.*)>, type: (.*), count in dozen: ([0-9]+)/#

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@DougGregor
Copy link
Member Author

@swift-ci please test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please test

@finagolfin
Copy link
Member

This will need to be updated for #68408.

ASTGen always builds with the host Swift compiler, without requiring
bootstrapping, and is enabled in more places. Move the regex literal
parsing logic there so it is enabled in more host environments, and
makes use of CMake's Swift support. Enable all of the regex literal
tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources,
because they are no longer needed.
@DougGregor DougGregor force-pushed the regex-literals-via-astgen branch from 5f3625d to 3a3e467 Compare September 29, 2023 23:58
@DougGregor
Copy link
Member Author

Dusting this off now and resolving the conflicts.

@DougGregor
Copy link
Member Author

swiftlang/llvm-project#7550

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/llvm-project#7550

@swift-ci please test

@@ -35,11 +35,9 @@
// Regex lexing delivered via libSwift.
static RegexLiteralLexingFn regexLiteralLexingFn = nullptr;

#if SWIFT_SWIFT_PARSER
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not, it's just called SWIFT_BUILD_SWIFT_SYNTAX now. Was changed in the FetchContent PR. Do I regret that? Maybe a little.

We could totally get rid of it now, but I wouldn't for this PR personally.

Copy link
Member Author

Choose a reason for hiding this comment

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

ARGH. Force-pushed now that I realized this, about the same time you told me :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh, sorry for not noticing it in here in the first place!

@DougGregor DougGregor force-pushed the regex-literals-via-astgen branch from 4c4a16c to 773f511 Compare September 30, 2023 02:12
@DougGregor
Copy link
Member Author

swiftlang/llvm-project#7550

@swift-ci please test

@DougGregor
Copy link
Member Author

swiftlang/llvm-project#7550

@swift-ci please smoke test macOS

@DougGregor
Copy link
Member Author

The macOS test never actually got started properly. Trying again...

@DougGregor
Copy link
Member Author

swiftlang/llvm-project#7550

@swift-ci please test macOS

@compnerd
Copy link
Member

Please test with following PRs:
swiftlang/llvm-project#7550
swiftlang/swift-installer-scripts#210

@swift-ci please build toolchain Windows platform

@compnerd
Copy link
Member

compnerd commented Oct 1, 2023

Please test with following PRs:
swiftlang/llvm-project#7550
swiftlang/swift-installer-scripts#210

@swift-ci please build toolchain Windows platform

@DougGregor
Copy link
Member Author

swiftlang/llvm-project#7550

@swift-ci please test

@ahoppen ahoppen removed their request for review October 2, 2023 21:12
@finagolfin
Copy link
Member

I have backported this pull to Swift 5.9 and am happy to report a working Swift 5.9 package with regex literals again on Android in the Termux app. I also backported #66033 and #66044 there, as this pull relies on those changes that aren't in the 5.9 branch.

I've also backported #68408 and swiftlang/swift-syntax#2173 and applied some changes so Swift Syntax can be cross-compiled (which I'll upstream next), so that Macros work natively on Android.

@DougGregor
Copy link
Member Author

This was already done

@DougGregor DougGregor closed this Jan 29, 2024
@DougGregor DougGregor deleted the regex-literals-via-astgen branch January 29, 2024 18:49
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.

5 participants