Commit Graph

71 Commits

Author SHA1 Message Date
Rintaro Ishizaki
d480761a9c [CMake] Sink add_pure_swift_host_library call into actual source dirs
Instead of doing everything in lib/ASTGen/CMakeLists.txt
2024-10-02 19:35:45 -07:00
Rintaro Ishizaki
fdacd9dabb [CMake] Add 'CXX_INTEROP' option to add_pure_swift_host_library 2024-10-02 19:34:59 -07:00
Rintaro Ishizaki
58ba27b34e [ASTGen/CMake] Remove redundant -Xcc -I options
Include directories are already specified in parent directories or
dependencies, and `-I` for swiftc are propagated to ClangImporter. We
don't need to specify them manually.
2024-10-02 19:34:57 -07:00
Rintaro Ishizaki
134c0a1bdc [ASTGen] Move macros related code to a new dedicated module
Introduce 'swiftMacros' module.
2024-10-02 15:22:16 -07:00
Rintaro Ishizaki
efe38a0bcf [Windows] Enable "INLINE" bridging mode
* Workaround for https://github.com/swiftlang/llvm-project/issues/7172
* `-D_CRT_USE_BUILTIN_OFFSETOF` to make `offsetof()` a constant
* Pass correct 'swift/shims' search path
2024-09-27 13:50:18 -07:00
Doug Gregor
0f2cedb92b [ASTGen] Implement #if config handling using the SwiftIfConfig library
Wherever there is a syntax collection in the syntax tree that can involve
an `#if` clause, evaluate the `#if` conditions to find the active clause,
then recurse into the active clause (if one exists) to "flatten" the
translated collection to only contain active elements.

Note that this does not yet handle #if for postfix expressions.
2024-08-17 22:48:18 -07:00
Doug Gregor
5c3b7777e7 Implement a SwiftIfConfig.BuildConfiguration that queries the ASTContext
This concrete implementation of the BuildConfiguration allows the use of
the SwiftIfConfig library's APIs where the build configuration comes from
the compiler itself.
2024-08-02 10:04:26 -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
cd54cc1c31 [Macros] Use SwiftCompilerPluginMessageHandling JSON encoder/decoder
Replacing swiftLLVMSJON with SwiftCompilerPluginMessageHandling.JSON
2024-04-25 14:42:20 -07:00
Adrian Prantl
40f8cfd5a8 Prefix experimental interop flag with -Xfrontend 2024-04-17 12:51:07 -07:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Allan Shortlidge
002277d2c3 ASTGen: Suppress warnings about handling unknown enum cases.
When built as part of the compiler toolchain SwiftSyntax is built with library
evolution enabled. This means that switches over enums from SwiftSyntax must
include a default case to be considered exhaustive, or a warning will be
emitted. This change suppresses those warnings by adding `@unknown default`
cases wherever they are expected. As a compromise, these `@unknown default`
cases are wrapped with a `#if` to ensure they are only included in the CMake
build of ASTGen, but continue to be omitted from the SPM build which compiler
engineers use to iterate on ASTGen's implementation. This is needed to avoid
generating the opposite warning during the SPM build, since the compiler thinks
the `@unknown default` case is superfluous when SwiftSyntax is built
non-resiliently. As an aside, this catch-22 is a bummer and I think we should
change the compiler to suppress the unreachable default warning when the
default is annotated `@unknown`.
2024-02-02 09:42:10 -08:00
Rintaro Ishizaki
cd7a31cddc [ASTGen] Cleanup type attribute generation
Use similar scheme as DeclAttribute.
* Create `BridgedTypeAttribute.createSimple()` and
  `BridgedTypeAttributes.add()`, instead of
  `BridgedTypeAttributes.addSimple()`
* Create `DeclAttributes::createSimple()` to align with `TypeAttribute`
2024-02-01 15:45:50 -08:00
Rintaro Ishizaki
a0120ad884 [ASTGen] Decl attributes 2024-01-31 12:58:41 -08:00
Ben Barham
cb29ec8837 [CMake] Ignore None and NoneType deprecations
`llvm::None` is deprecated, but still being used in Swift until we have
fewer 5.10 cherry-picks. Add the `SWIFT_TARGET` definition to ignore the
deprecation.
2023-12-06 10:47:02 -08:00
Alex Hoppen
fc08a24e95 [build] Set CRT_USE_BUILTIN_OFFSETOF when building with C++ interop on Windows
Without this, header fail to compile when they are used from Swift with C++ interop.
2023-11-22 21:36:55 -08:00
Alex Hoppen
d224549030 [SourceKit] Don’t use C++ to Swift interop to run NameMatcher 2023-11-20 11:30:18 -08:00
Alex Hoppen
8fd025625b [SourceKit] Use NameMatcher that is rewritten in Swift for syntactic rename 2023-11-17 09:30:04 -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
038597c80f [ASTGen] Use kind specific SyntaxEnum 2023-11-14 10:47:16 -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
32ee2ccf68 [ASTGen] Build with -disable-target-os-checking
Temporarily workaround an availability issue with
CxxStdlib.
2023-11-01 17:39:55 +00:00
Saleem Abdulrasool
8354c864b0 build: guard against builds where SwiftSyntax may not be enabled
Fix the build after #69440
2023-10-31 07:53:12 -07:00
Hamish Knight
e5442fea50 [ASTGen] Enable C++ interop 2023-10-30 23:49:52 +00:00
Ben Barham
041691184c [CMake] Replace early swift-syntax with FetchContent
Use FetchContent to include swift-syntax directly in swift. This can be
thought of as an `add_subdirectory` for a directory outside the root.

The default build directory will be `_deps/swiftsyntax-subbuild/`, though
the modules and shared libraries will be built in `lib/swift/host` by
passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we
were doing previously.
2023-09-18 14:44:10 -07:00
Anthony Latsis
808ab1b064 [NFC] ASTGen: Extract ParamDecl and ParameterList translation into a new file 2023-09-12 20:37:50 +03:00
Anthony Latsis
4b2cdedc48 ASTGen: Start diagnosing instances of an invalid syntax tree 2023-09-12 20:37:50 +03:00
Anthony Latsis
e72b421fa4 [NFC] ASTGen: Rename "Diagnostics.swift" → "DiagnosticsBridge.swift"
This file deals with emitting SwiftSyntax diagnostics via the C++ engine and
rendering C++ diagnostics via SwiftSyntax rather than ASTGen diagnostics.
2023-09-12 20:37:50 +03:00
Anthony Latsis
3e0c368022 [NFC] ASTGen: Rename "Misc.swift" → "Bridge.swift" 2023-09-12 13:33:47 +03:00
Rintaro Ishizaki
3e9c2536f6 [Macros] Unify PluginMessages.swift
Use PluginMessages.swift in swift-syntax consistently.
2023-06-29 13:04:10 -07:00
Rintaro Ishizaki
5fe2ead4e2 [Madros] Update for SwiftSyntaxMacroExpansion module
Share the same expansion logic between ASTGen and
SwiftCompilerMessageHandling
2023-05-11 19:45:14 -07:00
Ben Barham
fe2104ca99 [Macros] Automatically format expanded macros
Rather than requiring macro implementations to add required whitespace
and indentation, basic format all macro expansions. Right now this uses
the default four space indentation, we can consider having that inferred
later. Macros can opt-out of automatic formatting by implementing
`formatMode` and setting it to `.disabled`.

Also moves the extra newlines before/after expansions to a new "Inline
Macro" refactoring.

Resolves rdar://107731047.
2023-04-27 21:24:46 -07:00
Rintaro Ishizaki
f9fba6ce3e [CMake] Move add_pure_swift_host_library to a file
* Move `add_pure_swift_host_library()` from lib/CMakeLists.txt to
  AddPureSwift.cmake so that code outside `lib` can use it
* Add `add_pure_swift_host_tool()` function to make a pure Swift
  host executable target (for future usages)
* Specify depending `SwiftSyntax` modules explicitly because not all
  Swift libraries uses all SwiftSyntax libraries
2023-03-13 19:28:13 -07:00
Rintaro Ishizaki
9004fd24d4 [ASTGen] Separate JSON serialization module from ASTGen
For future usage from other host libraries written in Swift

For CMake:
 * Explicitly specify LINKER_LANGAGE to CXX in existing components so
   that 'swiftc' is not used when linking with 'swiftASTGen'
 * Add 'EMIT_MODULE' argument to 'add_pure_swift_host_library' to emit
   .swiftmodule usable from other Swift libraries.
2023-03-09 19:15:45 -08:00
Doug Gregor
6b0a0b6555 [CMake] Rework build of ASTGen and ObservationMacros
Refactor the build support for ASTGen and ObservationMacros. Both have
nearly-identical copies of a bunch of messy, workaround-laden CMake
code to build "pure" Swift host libraries using CMake's Swift support.

Instead, introduce `add_pure_swift_host_library` to centralize all of
the hacks to build a host library that's all Swift, using CMake's
support directly (rather than custom commands), and link against the
swift-syntax stack. Switch ASTGen directly over to this.

Add `add_swift_macro_library` on top of this, to make it easy to
create a macro library and install it into the appopriate plugin
directory. Switch ObservationMacros over to this.
2023-03-03 14:01:30 -08:00
Ben Barham
50fb165d61 [CMake] Workaround stale object files causing rebuilds
Consider the case of A -> B. The previous workaround will add a
forced-B-dep.swift to A that is touched if B rebuilds. So if B is
rebuilt, A is also rebuilt. But A itself has no real changes, and so
none of its object files are built and none of the mtimes are updated.

Thus, A is then rebuilt again on the next run because its input
(forced-B-dep.swift) is newer than the corresponding object file. To
prevent this, update the mtime for the library and object files after the
build (which is actually a link step that both compiles and links).
2023-02-27 19:29:02 -08:00
Rintaro Ishizaki
0e31393024 [Macros] Add executable plugin support
Executable compiler plugins are programs invoked by the host compiler
and communicate with the host with IPC via standard IO (stdin/stdout.)
Each message is serialized in JSON, prefixed with a header which is a
64bit little-endian integer indicating the size of the message.

* Basic/ExecuteWithPipe: External program invocation. Lik
  llvm::sys::ExecuteNoWait() but establishing pipes to the child's
  stdin/stdout
* Basic/Sandbox: Sandboxed execution helper. Create command line
  arguments to be executed in sandbox environment (similar to SwiftPM's
  pluging sandbox)
* AST/PluginRepository: ASTContext independent plugin manager
* ASTGen/PluginHost: Communication with the plugin. Messages are
  serialized by ASTGen/LLVMJSON

rdar://101508815
2023-02-22 10:22:14 -08:00
Rintaro Ishizaki
66aba1bc67 [ASTGen] Add Encoder/Decoder implementation backed by llvm::json::Value
Preparation for a future use.
2023-02-15 11:55:16 -08:00
Evan Wilde
c67e22e6aa Merge pull request #63192 from etcwilde/ewilde/fix-backdeploy-compat56-crash
Fixes for the compat56 library
2023-02-07 10:22:50 -08:00
Evan Wilde
c1ef992d2d Disable ASTGen runtime-compat libs
The runtime compat 5.6 library is not available in current toolchains.
The stage-0 compiler builds fine since the builder compiler is not aware
of the 5.6 library, but the stage-1 compiler will not link since the
builder libraries don't have the compat 5.6 library, while the stage-0
compiler is aware of the library and attempts to link it into the built
products. The issue is that the bootstrap goes and uses the libraries
off of the builder instead of the things that actually match the
compiler.

This is currently safe because the 5.6 compat library only contains
concurrency runtime fixes and the compiler frontend does not use
concurrency yet. If this changes, we will need to re-enable this and
make the bootstrap use the libraries correctly.
2023-02-06 21:12:25 -08:00
Doug Gregor
8ad7601ade [Macros] Create macro expansion contexts based on the SourceManager
Rather than trying to patch up the "basic" macro expansion context
that comes from the swift-syntax package, implement our own based
on the new SourceManager. Fixes the `location(of:)` operation.
2023-02-02 23:24:56 -08:00
Doug Gregor
28f0eadaf9 Revert "[ASTGen] Move source manager diagnostics code into its own file"
This reverts commit 83012a586a.
2023-01-29 08:29:58 -08:00
Doug Gregor
83012a586a [ASTGen] Move source manager diagnostics code into its own file 2023-01-28 22:43:11 -08:00
Doug Gregor
027ce8d21c [ASTGen/Macros] Introduce a Swift-side SourceManager into ASTGen.
Add SourceManager that can keep track of multiple source file syntax
nodes along with their external representations. The source manager can
emit diagnostics into any of those files, including tracking any
explicitly "detached" syntax nodes used for macro expansion.

Make sure we detach syntax nodes before passing them to macro
implementations, so they cannot see more of the source file than they
are permitted. We hadn't been doing this before (by accident), and
doing so motivated the introduction of the SourceManager.

Additionally, perform operator folding on macro arguments as part of
detaching them. Macro clients shouldn't have to do this, and moreover,
when clients do this, they lose the ability to easily emit diagnostics
on the now-folded nodes.
2023-01-28 22:23:52 -08:00
Doug Gregor
182950bacb Update to account for SwiftSyntaxMacros module rename and overhaul 2023-01-28 09:00:54 -08:00
Doug Gregor
1a3c6d721f [ASTGen] Handle new parser validation in ASTGen.
Replace the use of the "consistency check" vended by swift-syntax with
an ASTGen-implemented operation that emits diagnostics from the new parser
via the normal diagnostic engine. This eliminates our last dependency
on SwiftCompilerSupport, so stop linking it.
2022-12-15 21:24:44 -08:00
Doug Gregor
f0fc1c51bb Remove compiler plugin support library
The functionality of the compiler plugin support library has been
subsumed into parts of the compiler. Remove the functionality and its
last test.
2022-12-05 12:54:36 -08:00
Doug Gregor
14aebcab1b Bridge swift-syntax diagnostics to the C++ diagnostic engine's diagnostics.
Implement an ASTGen operation to bridge swift-syntax diagnostics, as
produced by the parser, operator folding, and macros, over to the C++
diagnostic engine infrastructure. Use this to wire up macro expansion
diagnostics.
2022-12-05 11:49:42 -08:00
Doug Gregor
811595394f [Macros] Build and test a macro plugin based on SwiftSyntax 2022-12-01 23:20:56 -08:00
Doug Gregor
1c00e1cafe Copy all of the swift-syntax Swift modules.
Make the build directory for lib/swift/host look like the eventually
toolchain directory by copying in all of the Swift module files. This
makes it easier to correctly build anything requiring these libraries
against either the build or the install directories.
2022-11-30 15:57:10 -08:00