Skip to content

[5.7-04182022][SwiftCompiler/Regex] Use bridged DiagnosticEngine for error reporting #58509

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

rintaro
Copy link
Member

@rintaro rintaro commented Apr 28, 2022

Cherry-pick #58390 into release/5.7-04182022
This requires swiftlang/swift-experimental-string-processing#369

  • 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 rintaro requested a review from a team as a code owner April 28, 2022 23:00
@rintaro
Copy link
Member Author

rintaro commented Apr 28, 2022

@rintaro rintaro requested a review from airspeedswift April 28, 2022 23:01
@rintaro
Copy link
Member Author

rintaro commented Apr 28, 2022

@swift-ci Please nominate

@rintaro rintaro force-pushed the 5.7-04182022-regex_diagnostics branch from 7867b35 to 161479c Compare May 20, 2022 18:34
@rintaro
Copy link
Member Author

rintaro commented May 20, 2022

@rintaro rintaro force-pushed the 5.7-04182022-regex_diagnostics branch from 161479c to 858d3e1 Compare May 20, 2022 18:37
@rintaro
Copy link
Member Author

rintaro commented May 20, 2022

rintaro added 2 commits May 20, 2022 15:58
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)
(cherry picked from commit cec31b5)
…upport

(cherry picked from commit 79bbbf1)
(cherry picked from commit 2ab7d83)
@rintaro rintaro force-pushed the 5.7-04182022-regex_diagnostics branch from 7b31ef5 to 03f6a97 Compare May 20, 2022 22:58
@rintaro
Copy link
Member Author

rintaro commented May 20, 2022

@rintaro rintaro closed this Jun 2, 2022
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.

1 participant