Commit Graph

48 Commits

Author SHA1 Message Date
Amritpan Kaur
15c219cd70 [Tests] Add tests. 2025-03-19 10:54:09 -07:00
Hamish Knight
b840730958 [IDE] Pass LangOptions to ide::isSourceInputComplete
Ensure we account for things like the enablement
of bare slash regex literals.
2024-10-17 14:04:34 +01:00
Hamish Knight
6a435960b7 Requestify regex pattern parsing
Instead of doing the pattern parsing in both the
C++ parser and ASTGen, factor out the parsing into
a request that returns the pattern to emit, regex
type, and version. This can then be lazily run
during type-checking.
2024-10-11 19:25:58 +01:00
Hamish Knight
7971056e21 [Sema] Fold SequenceExpr in pre-checking pre-walk
Doing it in the post-walk meant we ended up
walking the children twice, which lead to duplicate
diagnostics and incorrect inference of the
level of application for function references. Move
it to the pre-walk, ensuring that we resolve any
operator references before folding.
2024-07-29 00:07:45 +01:00
Rintaro Ishizaki
0e122544ca [CodeCompletion] Fix completion for 'catch' pattern bound values
Previously code completion for 'catch' pattern bound values didn't work
correctly because code completion type checker fails to type check the
value decl in the pattern.
That was because the body of the 'do' statement is not type checked, so
the thrown error is not determined, then falled backed to the default
'Never', which doesn't matches any patterns.
To resolve this, always type check the body when typechecking 'catch'
patterns. Also, pretends 'do {}' throws 'any Error' even without
any throwing expressions in the body.

rdar://126699879
2024-04-22 11:09:12 -07:00
Doug Gregor
ea836389f7 Suppress warnings about Never error types in catch clauses
Enabling typed throws has introduced some spurious warnings about error
values of `Never` type on top of the custom "unreachable" diagnostics
for catch clauses, so suppress the new warnings---they aren't helpful.
2024-01-04 09:37:35 -08:00
Rintaro Ishizaki
47f18d492e [ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
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.
2023-11-16 10:59:23 -08:00
Pavel Yaskevich
58ffca8f74 [ConstraintSystem] Don't produce partially matching note if none of the overloads matched 2023-05-09 14:11:38 -07:00
Hamish Knight
68075696eb [CS] A couple of minor improvements to operator diagnostics
- Simplify the fix locator when looking for a
fix already present in a pattern match, this
avoids us emitting both a diagnostic for the
argument conversion, and for a conformance failure.
- Include tuples in the diagnostic logic where
we emit a generic "operator cannot be applied"
diagnostic, as a conformance diagnostic is
unlikely to be helpful in that case.
2023-05-04 14:53:57 +01:00
Hamish Knight
af7134b884 Fully enable ExperimentalStringProcessing
Previously we would only enable by default when
`parseArgs` was called. However this wouldn't
enable it for clients such as LLDB, who provide
their own invocation. Switch the default to `true`
in the `LangOptions`, and remove some redundant
uses of `-enable-experimental-string-processing`.
The frontend flag remains, as it may be useful to
disable.

rdar://107419385
rdar://101765556
2023-03-31 18:10:39 +01:00
Pavel Yaskevich
bb1da5e599 [CSFix] Diagnose extraneous force unwraps in ambiguous context 2023-02-24 23:48:03 -08:00
Doug Gregor
8cbae04918 One last little test fix 2023-01-02 21:22:05 -08:00
Doug Gregor
1b14b5d356 Fixup some test cases 2023-01-02 21:22:05 -08:00
Doug Gregor
e263b0758a Ensure that there is at least one parse error in this test 2022-09-30 17:24:54 -07:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Hamish Knight
af713bc7e9 Merge pull request #59776 from hamishknight/loc-step 2022-07-01 10:39:14 +01:00
Stephen Canon
9afbddf2c3 Remove use of ~= in bare-slash-regex tests. 2022-06-30 15:23:37 -04:00
Hamish Knight
3ead014478 [test] Update a couple of regex diagnostic locations
The parser recovery work gives these slightly
better locations.
2022-06-29 15:27:54 +01:00
Hamish Knight
50b01fa66f Merge pull request #59525 from hamishknight/watch-this-space 2022-06-28 22:41:34 +01:00
Hamish Knight
6c091a5dc2 [test] Re-enable forward-slash-regex-skipping-allowed.swift
Adjust to account for output differences between
asserts and non-asserts builds.

rdar://95806819
2022-06-24 13:49:42 +01:00
Andrew Trick
7849345fe3 Temporarily disable test/StringProcessing/Parse/forward-slash-regex-skipping-allowed.swift
Test fails after:
Merge pull request #59641 from hamishknight/no-skip-slash
Commit e610a69dac by github
2022-06-23 14:28:43 -07:00
Hamish Knight
8d59eb08df [Parse] Ban trailing space for /.../ regex literals
Ban space and tab as the last character of a
`/.../` regex literal, unless escaped with a
backslash. This matches the banning of space and
tab as the first character, and helps avoid breaking
source in even more cases.
2022-06-23 20:38:28 +01:00
Hamish Knight
515945fc6d [Parse] Avoid skipping bodies with /.../ regex literals
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
2022-06-22 20:05:21 +01:00
Hamish Knight
350a01aeb0 [Parse] Expand unbalanced ) regex literal heuristic
Previously we would only check for a starting
character of `)` when performing a tentative
lex of a regex literal. Expand this to cover the
entire range of the regex literal, ensuring to
take escapes and custom character classes into
account.
2022-05-12 11:49:11 +01:00
Hamish Knight
9c62319be1 [Parse] Lenient prefix / parsing
Treat a prefix operator containing `/` the same as
the unapplied infix operator case, where we
tentatively lex. This means that we bail if there
is no closing `/` or the starting character is
invalid. This leaves binary operator containing
`/` in expression position as the last place where
we know that we definitely have a regex literal.
2022-05-12 11:49:10 +01:00
Hamish Knight
105ab3149a [Parse] Re-allow prefix operators containing / 2022-05-12 11:49:09 +01:00
Hamish Knight
ba28b6a19b [Parse] Split prefix operators from regex in the lexer
Teach the lexer not to consider `/` an operator
character when attempting to re-lex a regex
literal. This allows us to split off a prefix
operator.

Previously this was done after-the-fact in the
parser, but that didn't cover the unapplied infix
operator case, and didn't form a `tok::amp_prefix`
for `foo(&/.../)`, which led to a suboptimal
diagnostic.

This also now means we'll split an operator for
cases such as `foo(!/^/)` rather than treating it
as an unapplied infix operator.

rdar://92469917
2022-04-29 10:53:56 +01:00
Hamish Knight
f9a6a8b7e7 [test] Add some additional /.../ tests 2022-04-29 10:53:56 +01:00
Hamish Knight
5c3f6db997 [test] Update for new string processing changes
We now define a `~=` operator for `Regex`.
2022-04-28 18:45:52 +01:00
Rintaro Ishizaki
d292a95296 [SwiftCompiler/Regex] Use bridged DiagnosticEngine for error reporting
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
2022-04-22 22:53:46 -07:00
Richard Wei
72ebcded98 Integrate newer string processing (a0ed7e1)
Friend PR: apple/swift-experimental-string-processing#282.

Also remove the `-enable-experimental-pairwise-build-block` flag when building regex modules as the feature is already on by default.
2022-04-15 12:01:45 -07:00
Hamish Knight
f1a799037e [Parse] Introduce /.../ regex literals
Start parsing regex literals with `/.../`
delimiters.

rdar://83253726
2022-04-12 16:03:49 +01:00
Hamish Knight
5a8dff0a76 [Parse] Emit error on prefix operator containing /
When forward slash regex is enabled, start emitting
an error on prefix operators containing the
`/` character.
2022-04-12 16:03:48 +01:00
Hamish Knight
63b8db1659 Start using '-enable-bare-slash-regex'
Change the flag to imply
'-enable-experimental-string-processing', and
and update some tests to start using it.
2022-04-12 16:03:47 +01:00
Hamish Knight
51130bfb07 [test] Update regex literal tests 2022-04-04 11:51:41 +01:00
Hamish Knight
cb514646cd [test] Add some additional regex parsing tests 2022-03-21 19:26:10 +00:00
Hamish Knight
77cb08d767 [Parse] Better recover from regex error
Instead of returning a parser error, which results
in generic parser recovery that skips until the
next decl, return an `ErrorExpr` so we can
continue parsing.
2022-03-01 16:05:39 +00:00
Hamish Knight
611fd33f58 Update regex literal delimiters
Update the lexing code for the replacement of the
`'/.../'` and `'|...|'` delimiters with `#/.../#`
and `#|...|#` respectively, in addition to
allowing the `re'...'` delimiter.
2022-02-24 17:37:16 -08:00
Richard Wei
1b83efb512 Revert "Revert "[Regex] Switch regex match to Swift tuples."" 2022-02-11 01:32:45 -08:00
Mishal Shah
dcd9e8e84e Revert "[Regex] Switch regex match to Swift tuples." 2022-02-10 15:21:53 -08:00
Richard Wei
cf8e0fea12 [Regex] Switch regex match to Swift tuples.
Typed captures no longer use ad-hoc nominal tuples. We use Swift native tuples instead. See apple/swift-experimental-string-processing#127.

Update checkout tag to dev/6.
2022-02-09 16:21:57 -08:00
Richard Wei
e5175d595e [Regex] Infer 'Match' type of regex literals.
Applies swift-experimental-string-processing#68 in regex literal type inference. Regex literals with captures will have type `Regex<Tuple{n}<Substring, {Captures...}>>`. This is a temporary thing that allows us to define generic constraints on captures. We will switch back to native tuples once we have variadic generics.
2022-01-06 10:54:10 -08:00
Erik Eckstein
3d33f11e6c cmake/build-script: rename the libswift option to "bootstrapping"
In cmake, rename LIBSWIFT_BUILD_MODE to BOOTSTRAPPING_MODE.
Also, rename the lit feature "libswift" to "swift_in_compiler".
2021-12-22 11:31:52 +01:00
Michael Ilseman
7bff9da67d Revert "Revert "Merge pull request #40595 from hamishknight/straw-bales"" 2021-12-19 10:08:48 -07:00
Arnold Schwaighofer
9511994e52 Revert "Merge pull request #40595 from hamishknight/straw-bales"
This reverts commit a67a0436f7, reversing
changes made to 9965df76d0.

This commit or the earlier commit this commit is based on (#40531) broke the
incremental bot.
2021-12-18 11:02:37 -08:00
Hamish Knight
128f5d4bc6 Update regex literal lexing and emission
Update the lexing implementation to defer to the
regex library, which will pass back the pointer
from to resume lexing, and update the emission to
call the new `Regex(_regexString:version:)`
overload, that will accept the regex string with
delimiters.

Because this uses the library's lexing
implementation, the delimiters are now `'/.../'`
and `'|...|'` instead of plain `'...'`.
2021-12-17 18:05:31 +00:00
Richard Wei
300cbaba31 Integrate experimental string processing modules and enable end-to-end regex.
- Checkout apple/swift-experimental-string-processing using a tag.
- Build `_MatchingEngine` as part of libswift (`ExperimentalRegex`) using sources from the package.
- Parse regex literals using the parser from `_MatchingEngine`.
- Build both `_MatchingEngine` and `_StringProcessing` as part of core libs using sources from the package.
- Use `Regex<DynamicCaptures>` as the default regex type until we finalize apple/swift-experimental-string-processing#68.
2021-12-17 10:33:07 +00:00
Richard Wei
05363cd55a Regex literal runtime plumbing.
- Frontend: Implicitly import `_StringProcessing` when frontend flag `-enable-experimental-string-processing` is set.
- Type checker: Set a regex literal expression's type as `_StringProcessing.Regex<(Substring, DynamicCaptures)>`. `(Substring, DynamicCaptures)` is a temporary `Match` type that will help get us to an end-to-end working system. This will be replaced by actual type inference based a regex's pattern in a follow-up patch (soon).
- SILGen: Lower a regex literal expression to a call to `_StringProcessing.Regex.init(_regexString:)`.
- String processing runtime: Add `Regex`, `DynamicCaptures` (matching actual APIs in apple/swift-experimental-string-processing), and `Regex(_regexString:)`.

Upcoming:
- Build `_MatchingEngine` and `_StringProcessing` modules with sources from apple/swift-experimental-string-processing.
- Replace `DynamicCaptures` with inferred capture types.
2021-12-09 16:05:34 -08:00