Commit Graph

41 Commits

Author SHA1 Message Date
Doug Gregor
865c643cac Suppress Embedded Restriction diagnostics in code that won't be compiled as Embedded
When emitting diagnostics for the Embedded Swift restrictions outside
of Embedded Swift mode, consider `#if $Embedded` and `#if
hasFeature(Embedded)` configurations. If the code where we would emit
the diagnostic would be disabled in Embedded Swift by one of those
checks, don't emit the diagnostic. This helps code that can compile
either with Embedded or regular Swift stay within the restrictions on
Embedded Swift.
2025-09-15 07:10:00 -07:00
Anthony Latsis
5620abbad8 Bridging: Bridge swift::CharSourceRange directly 2025-07-15 21:34:48 +01:00
Anthony Latsis
6eb5d7d857 Bridging: Bridge swift::SourceLoc directly 2025-07-15 21:33:06 +01:00
Anthony Latsis
b40b192227 ASTBriding: Bridge swift::DiagnosticKind directly 2025-06-16 19:11:35 +01:00
Doug Gregor
235242e8b3 [Diagnostics] Use the swift-syntax formatting for invalid source locations, too
The diagnostics formatter from swift-syntax previously only handled
fully-formed diagnostics anchored at a particular syntax node.
Therefore, the compiler would fall back to the existing LLVM-based
diagnostic formatter for diagnostics that had no source location.

Adopt new API in the swift-syntax diagnostics formatter that renders a
diagnostic message without requiring source location information, so
that we consistently use the swift-syntax formatter when it is
selected (which is the default).
2025-04-18 15:36:43 -07:00
Doug Gregor
74fb36f9bc Translate Fix-Its from the C++ diagnostics into swift-syntax diagnostics
The swift-syntax diagnostic formatter doesn't actually print Fix-Its,
but at least they're available now.
2025-03-28 13:20:57 -07:00
Pavel Yaskevich
ac91d39a95 [DiagnosticBridge] NFC: Refactor addQueuedDiagnostic to use BridgedCharSourceRange for diagnostic highlights 2025-03-19 10:18:09 -07:00
Pavel Yaskevich
49f254f9f1 [DiagnosticBridge] NFC: Refactor addQueuedDiagnostic to use BridgedSourceLoc to diagnostic location 2025-03-19 09:54:41 -07:00
Pavel Yaskevich
2ee821164d [DiagnosticBridge] NFC: Refactor addQueuedDiagnostic to use BridgedStringRef instead of plain pointers 2025-03-19 09:54:36 -07:00
Doug Gregor
29b4f3ddbd [Diagnostics] Print category footnotes at the end of translation
When printing diagnostics, category names are printed as [#<category-name>]
at the end of a diagnostic. For all of the category names that are mentioned
in this manner, print "footnotes" at the end of compilation providing
documentation references to each category, e.g.,

    [#deprecated]: <http://example.com/deprecated>
    [#StrictMemorySafety]: <http://example.com/memory-safety>

Right now, these point into the markdown files in the installed toolchain,
same as the URLs behind references. That is subject to change in the future.
2025-03-09 14:36:51 -07:00
Doug Gregor
6f6b8dd071 [Diagnostics] Provide category name + documentation path
Bridge the category name and educational note computed for the Swift
compiler's diagnostics to the newly-introduced category field for
the swift-syntax diagnostics. This lets the swift-syntax renderer
introduce the category name and (optionally) link to the
documentation.
2025-03-03 22:49:33 -08:00
Rintaro Ishizaki
aae50a88c5 [ASTGen] Fix expanded macro buffer parsing and AST generation
Parse expanded buffer into dedicated syntax.

Also rename `BridgedGeneratedSourceFileKindAttribute` to
`BridgedGeneratedSourceFileKindAttributeFromClang` because C++ decl
(i.e. `GeneratedSourceInfo::Kind::AttributeFromClang`) was renamed a
while ago.
2025-02-21 09:56:36 -08:00
Rintaro Ishizaki
df2ada37df [ASTGen] Generate AvailableAttr
* Move `AvailabilitySpec` handling logic to AST, so they can be shared
  between libParse and ASTGen
* Requestify '-define-availability' arguments parsing and parse them
  with 'SwiftParser' according to the 'ParserASTGen' feature flag
* Implement 'AvailableAttr' generation in ASTGen
2025-02-04 23:40:01 -08:00
Rintaro Ishizaki
a0d7068162 Revert "Merge pull request #78280 from swiftlang/revert-77140-swift-lexical-lookup-validation"
This reverts commit ae88aaca8f, reversing
changes made to b0123bca14.
2024-12-20 16:37:36 -08:00
Ben Barham
e06d0b9357 Revert "[SwiftLexicalLookup] New unqualified lookup implementation validation" 2024-12-18 15:04:16 -08:00
Jakub Florek
5dbe202087 Merge pull request #77140 from MAJKFL/swift-lexical-lookup-validation
[SwiftLexicalLookup] New unqualified lookup implementation validation
2024-12-18 17:29:47 +01:00
Rintaro Ishizaki
71ca3e129a [ASTGen] Use syntax tree based interface hash 2024-12-12 09:51:09 -08:00
Jakub Florek
866f1c1c04 Merge branch 'main' into swift-lexical-lookup-validation 2024-11-26 09:37:23 +01:00
Rintaro Ishizaki
e153164677 [ASTGen] Handle '#sourceLocation' directives
Use `ExportedSourceFile.sourceLocationConverter.lineTable.virtualFiles`
to populate the information in `swift::SourceManger` and
`swift::SourceFile` when "parsing" with ASTGen
2024-11-21 08:23:08 -08:00
Jakub Florek
5b39ba66b8 Merge branch 'main' into swift-lexical-lookup-validation 2024-11-15 22:05:43 +01:00
Rintaro Ishizaki
1fc00ae248 [ASTGen] Remove LegacyParser ping-pong mechanism
Now that ASTGen should be able to generate most Swift code. Let's
remove "legacy parser" call-in, and remove the unhealthy cyclic
dependency between lib/Parse and ASTGen.
2024-11-14 22:46:43 -08:00
Jakub Florek
4b544e963a Merge branch 'main' into swift-lexical-lookup-validation 2024-11-13 15:54:30 +01:00
Rintaro Ishizaki
e566a746c8 [ASTGen] Support macro expanded buffer
* Make ExportedSourceFile hold any Syntax as the root node
* Move `ExportedSourceFileRequest::evaluate()` to `ParseRequests.cpp`
* Pass  the decl context and `GeneatedSourceFileInfo::Kind` to
  `swift_ASTGen_parseSourceFile()` to customize the parsing
* Make `ExportedSourceFile` to hold an arbitrary Syntax node
* Move round-trip checking into `ExportedSourceFileRequest::evaluate()`
* Split `parseSourceFileViaASTGen` completely from C++ parsing logic
  (in `ParseSourceFileRequest::evaluate()`)
* Remove 'ParserDiagnostics' experimental feature: Now that we have
  ParserASTGen mode which includes the swift-syntax parser diagnostics.
2024-11-05 11:00:33 -08:00
Hamish Knight
9d4a78678a [Sema] Add logic to diagnose regex feature availability
Add the necessary compiler-side logic to allow
the regex parsing library to hand back a set of
features for a regex literal, which can then be
diagnosed by ExprAvailabilityWalker if the
availability context isn't sufficient. No tests
as this only adds the necessary infrastructure,
we don't yet hand back the features from the regex
parsing library.
2024-10-28 17:09:47 +00:00
Jakub Florek
1d94844322 Add SwiftLexicalLookup validation. 2024-10-20 12:12:22 +02:00
Rintaro Ishizaki
aa456d19f1 [ASTGen] Rename 'swift/Bridging/Macros.h' to swift/Bridging/MacroEvaluation.h 2024-10-09 15:19:25 -07:00
Rintaro Ishizaki
b3b7d35edc [ASTGen] Rename macro related @_cdecl functions to swift_Macros_*
Rename @_cdecl name of functions moved to swiftMacros module.
Also move those function decls to dedicated 'Macros.h' header.
2024-10-02 15:22:17 -07:00
Doug Gregor
c241e782e0 Use SwiftIfConfig to determine where to emit new parser diagnostics 2024-08-22 22:33:53 -07:00
Doug Gregor
fc5ba4c7d5 Revert "Use SwiftIfConfig to determine where to emit new parser diagnostics"
This reverts commit 1da2631c4e.
2024-08-22 09:22:20 -07:00
Doug Gregor
1da2631c4e Use SwiftIfConfig to determine where to emit new parser diagnostics 2024-08-17 22:48:18 -07:00
Doug Gregor
a844f4fa0b Free memory allocated in Swift from Swift, not C++ 2024-08-02 10:04:29 -07:00
Doug Gregor
d06e40877f Re-implement SourceFile::getIfConfigClauseRanges on top of SwiftIfConfig
The SwiftIfConfig library provides APIs for evaluating and extracting
the active #if regions in source code. Use its "configured regions" API
along with the ASTContext-backed build configuration to reimplement the
extraction of active/inactive regions from the source.

This approach has the benefit of being effectively stateless: where the
existing solution relies on the C++ parser recording all of the `#if`
clauses it sees as it is parsing (and then might have to sort them later),
this version does a scan of source to collect the list without requiring
any other state. The newer implementation is also conceptually cleaner,
and can be shared with other clients that have their own take on the
build configuration.

The primary client of this information is the SourceKit request that
identifies "inactive" regions within the source file, which IDEs can
use to grey out inactive code within the current build configuration.
There is also some profiling information that uses it. Those clients
should be unaffected by this under-the-hood change.

For the moment, I'm leaving the old code path in place for compiler
builds that don't have swift-syntax. This should be considered
temporary, and that code should be removed in favor of request'ifying
this function and removing the incrementally-built state entirely.
2024-08-02 10:04:27 -07:00
Rintaro Ishizaki
2f7aa428db [Macros] In-process plugin server
Separate swift-syntax libs for the compiler and for the library plugins.
Compiler communicates with library plugins using serialized messages
just like executable plugins.

* `lib/swift/host/compiler/lib_Compiler*.dylib`(`lib/CompilerSwiftSyntax`):
  swift-syntax libraries for compiler. Library evolution is disabled.
* Compiler (`ASTGen` and `swiftIDEUtilsBridging`) only depends on
  `lib/swift/host/compiler` libraries.
* `SwiftInProcPluginServer`: In-process plugin server shared library.
  This has one `swift_inproc_plugins_handle_message` entry point that
  receives a message and return the response.
* In the compiler
  * Add `-in-process-plugin-server-path` front-end option, which specifies
    the `SwiftInProcPluginServer` shared library path.
  * Remove `LoadedLibraryPlugin`, because all library plugins are managed
    by `SwiftInProcPluginServer`
  * Introduce abstract `CompilerPlugin` class that has 2 subclasses:
    * `LoadedExecutablePlugin` existing class that represents an
      executable plugin
    * `InProcessPlugins` wraps `dlopen`ed `SwiftInProcPluginServer`
  * Unified the code path in `TypeCheckMacros.cpp` and `ASTGen`, the
    difference between executable plugins and library plugins are now
    abstracted by `CompilerPlugin`
2024-06-17 11:36:52 -07:00
Rintaro Ishizaki
f5aca556dd [Macros] Don't use 'ExportedSourceFile' for macro definition checking
`macro` declarations often appear in files that does not contain any
expansions (e.g. `.swiftinterface`). So invoking `SwiftParser` for the
entire file is a waste.
2024-04-24 22:05:15 -07:00
Apollo Zhu
ea35e1bac2 Use Swift Syntax for checking literals 2024-02-06 15:02:15 -08:00
Konrad `ktoso` Malawski
5acd366c98 [macros] allow forwarding generic arguments through macro declarations (#71271)
* [macros] allow forwarding generic arguments through macro declarations

[macros] add more tests for generic argument forwarding in macro declarations

* [macros] correct replacement picking logic
2024-02-06 03:56:20 -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
Rintaro Ishizaki
fb08a92f48 [ASTGen] Infrastructure to implment ASTGen Incrementally
* 'ASTGenVisitor' has a reference to a legacy C++ Parser configured for
  ASTGen.
* If 'ASTGenVisitor' encounters a AST node that hasn't been migrated,
  call parse(Decl|Stmt|Expr|Type) to parse the position using the legacy
  parser.
* The legacy parser calls ASTGen's
  'swift_ASTGen_build(Decl|Stmt|Expr|Type)' for each ASTNode "parsing"
  (unless the call is not directly from the ASTGen.)

rdar://117151886
2023-11-12 21:43:08 -08:00
Hamish Knight
6afde8a6d2 Remove CBasicBridging and CASTBridging
Merge with BasicBridging and ASTBridging
respectively. The changes here should be pretty
uncontroversial, I tried to keep it to just moving
code about.
2023-10-30 23:49:56 +00:00
Hamish Knight
356cf31d83 [ASTGen] Migrate onto some BasicBridging types
Migrate onto BridgedStringRef, and the
BasicBridging equivalents of BridgedSourceLoc
and BridgedArrayRef.
2023-10-30 23:49:53 +00:00
Rintaro Ishizaki
e01df929c2 [swift-parse-test] A parser performance check utility
```
% swift-parse-test -swift-parser -lib-parse -n 20 ../swift-syntax/Sources
files count: 228
total bytes: 5662399
total lines: 158428
iteration: 20
----
parser:  SwiftParser
wall clock time (ms): 3848
cpu time (ms): 3843
throughput (byte/sec): 355824
throughput (line/sec): 41225
----
parser:  libParse
wall clock time (ms): 296
cpu time (ms): 290
throughput (byte/sec): 4715281
throughput (line/sec): 546303
```
2023-10-28 20:23:26 -07:00