mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
While skipping, if we encounter a token that looks
like it could be the start of a `/.../` regex
literal, fall back to parsing the function or type
body normally, as such a token could become a
regex literal. As such, it could treat `{` and
`}` as literal, or otherwise have contents that
would be lexically invalid Swift.
To avoid falling back in too many cases, we apply
the existing regex literal heuristics. Cases that
pass the heuristic fall back to regular parsing.
Cases that fail the heuristic are further checked
to make sure they wouldn't contain an unbalanced
`{` or `}`, but otherwise are allowed to be
skipped. This allows us to continue skipping for
most occurrences of infix and prefix `/`.
This is meant as a lower risk workaround to fix the
the issue, we ought to go back to handling regex
literals in the lexer.
Resolves rdar://95354010
63 lines
1.3 KiB
Swift
63 lines
1.3 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-frontend -parse -enable-bare-slash-regex -disable-availability-checking -experimental-skip-all-function-bodies -stats-output-dir %t %s
|
|
// RUN: %{python} %utils/process-stats-dir.py --set-csv-baseline %t/stats.csv %t
|
|
// RUN: %FileCheck -input-file %t/stats.csv %s
|
|
|
|
// REQUIRES: swift_in_compiler
|
|
|
|
// Make sure we can skip in all of the below cases.
|
|
|
|
// We don't appear to output a stats entry when it is 0.
|
|
// CHECK-NOT: {{"Parse.NumFunctionsParsed"}}
|
|
|
|
// Balanced `{}`, so okay.
|
|
func a() { / {}/ }
|
|
func b() { / \{}/ }
|
|
func c() { / {"{"}/ }
|
|
|
|
// Some cases of infix '/' that we should continue to skip.
|
|
func d() {
|
|
_ = 1 / 2 + 3 * 4
|
|
_ = 1 / 2 / 3 / 4
|
|
}
|
|
func e() {
|
|
let arr = [1, 2, 3]
|
|
_ = arr.reduce(0, /) / 2
|
|
|
|
func foo(_ i: Int, _ fn: () -> Void) {}
|
|
foo(1 / 2 / 3, { print("}}}{{{") })
|
|
}
|
|
|
|
// Some cases of prefix '/' that we should continue to skip.
|
|
prefix operator /
|
|
prefix func / <T> (_ x: T) -> T { x }
|
|
|
|
enum E {
|
|
case e
|
|
func foo<T>(_ x: T) {}
|
|
}
|
|
|
|
func f() {
|
|
_ = /E.e
|
|
(/E.e).foo(/0)
|
|
|
|
func foo<T, U>(_ x: T, _ y: U) {}
|
|
foo((/E.e), /E.e)
|
|
foo((/)(E.e), /E.e)
|
|
|
|
func bar<T>(_ x: T) -> Int { 0 }
|
|
_ = bar(/E.e) / 2
|
|
}
|
|
|
|
postfix operator /
|
|
prefix func / <T> (_ x: T) -> T { x }
|
|
|
|
// Some cases of postfix '/' that we should continue to skip.
|
|
func g() {
|
|
_ = 0/
|
|
_ = 0/ / 1/
|
|
_ = 1/ + 1/
|
|
_ = 1 + 2/
|
|
}
|