Skip to content

[5.7][SwiftCompiler/Regex] Use bridged DiagnosticEngine for error reporting #58390

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 2 commits into from
Apr 26, 2022

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 25, 2022

Cherry-pick #42583 into release/5.7

  • Explanation: Regex literal parsing is done by a module in SwiftCompilerModules written in Swift. Previously, lexing/parsing error reporting was done by passing back a pointer to a C-string that is allocated in heap memory, and was never deallocated (leak). Also previously, since the error message didn't have the source location information, the diagnostic used to always point the start of the literal, that was confusing. In this change, utilize the bridged DiagnosticEngine so we don't need to allocate C-string, and use the correct source location to diagnose
  • Scope: Regex literal lexing/parsing
  • Issues: rdar://92187284
  • Risk: Mid. This PR utilizes a new facility bridging the C++ DiagnosticEngine to Swift. That said, it's just a pointer to C++ DiagnosticEngine, and the actual diagnostic emitting logic is not new. So the risk it not too high.
  • Testing: Added regression test cases including some edge cases.
  • Reviewer: Hamish Knight (@hamishknight)

rintaro added 2 commits April 25, 2022 09:21
This fixes:
 * An issue where the diagnostic messages were leaked
 * Diagnose at correct position inside the regex literal

To do this:
 * Introduce 'Parse' SwiftCompiler module that is a bridging layer
   between '_CompilerRegexParser' and C++ libParse
 * Move libswiftParseRegexLiteral and libswiftLexRegexLiteral to 'Parse'

Also this change makes 'SwiftCompilerSources/Package.swift' be configured
by CMake so it can actually be built with 'swift-build'.

rdar://92187284
(cherry picked from commit d292a95)
@rintaro rintaro requested a review from a team as a code owner April 25, 2022 16:22
@rintaro
Copy link
Member Author

rintaro commented Apr 25, 2022

@rintaro rintaro merged commit 83fe0ee into swiftlang:release/5.7 Apr 26, 2022
@rintaro rintaro deleted the 5.7-regex_diagnostics branch April 26, 2022 23:27
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.

2 participants