Commit Graph

493 Commits

Author SHA1 Message Date
Artem Chikin
73b01dccfc Remove incremental builds from the Legacy driver
The C++-based driver is deprecated and this will help reduce the code surface that requires maintenance as the legacy driver is fully sunset.
2024-01-16 16:34:51 -08:00
Alexis Laferrière
e431716e93 Merge pull request #70678 from xymus/write-no-verify
ModuleInterface: write down the -no-verify-emitted-module-interface flag in swiftinterfaces
2024-01-03 09:08:56 -08:00
Alexis Laferrière
1533894fed ModuleInterface: write down the -no-verify flag in the swiftinterface
The flag -no-verify-emitted-module-interface tells the driver to skip
verifying the swiftinterfaces emitted by the compiler. It used to be
passed only to the driver.

Let's pass it down to the frontend as well and write it in the
swiftinterfaces. This will help understand them from the reader side.
2024-01-02 16:40:19 -08:00
Doug Gregor
5909e75799 Teach the C++ driver not to add -enable-objc-interop for Embedded Swift
This mirrors a change to the Swift driver to do the same, for use with
legacy driver clients.
2023-12-21 14:29:16 -08:00
usama
3053fe01b5 [Sanitizers] Add new sanitize-stable-abi flag for libsanitizers.
This patch adds a new flag sanitize-stable-abi to support linking
against the Sanitizers stable ABI added recently in compiler-rt. The
patch also passes extra options for the ASan pass when using this flag
to outline instrumentation code and remove version check.

rdar://112915278
2023-12-16 14:13:00 -08:00
Ellie Shin
aba3b6c24e Introduce a package interface.
It has an extension .package.swiftinterface and contains package decls
as well as SPIs and public/inlinable decls. When a module is loaded
from interface, it now looks up the package-name in the interface
and checks if the importer is in the same package. If so, it uses
that package interface found to load the module. If not, uses the existing
logic to load modules.

Resolves rdar://104617854
2023-11-08 14:56:20 -08:00
Max Ovtsin
b0105e112d Introduce -application-extension-library (#63769)
The current implementation of `-application-extension` has a problem that affects the generation of ObjC headers for regular Swift modules.

The primary purpose of `-application-extension` is to prevent the use of unavailable APIs in app extensions. However, it has an impact on the generation of -Swift.h headers and exposes Swift's internal declarations to ObjC. This behavior is appropriate for mixed modules that are not consumed externally, such as app extensions, but it fails to address the situation when a module is not an extension itself but is consumed by the extension (c90cd11).

To resolve this issue while maintaining the desired behavior, we can introduce a new flag for this particular use-case.
2023-11-03 08:24:19 -07:00
Adrian Prantl
5d978b44ca Revert "Revert "Make the DWARF version emitted by the Swift compiler configurable."" 2023-10-26 12:29:18 -07:00
Adrian Prantl
2a32ca5944 Revert "Make the DWARF version emitted by the Swift compiler configurable." 2023-10-25 13:28:28 -07:00
Adrian Prantl
a26bbb0baf Make the DWARF version emitted by the Swift compiler configurable.
Previously it was hardcoded to version 4 on all platforms.
This patch introduces a driver and frontend option -dwarf-version to configure it if needed.
2023-10-24 12:30:16 -07:00
Adrian Prantl
d19fe381fa Use LLVM definitions for Swift section names (NFC) 2023-10-24 10:58:40 -07:00
Allan Shortlidge
e1f2e25ed5 Frontend: Introduce -emit-api-descriptor flag.
An "API descriptor" file is JSON describing the externally accessible symbols
of a module and metadata associated with those symbols like availability and
SPI status. This output was previously only generated by the
`swift-api-extract` alias of `swift-frontend`, which is desgined to take an
already built module as input. Post-processing a built module to extract this
information is inefficient because the module and the module's dependencies
need to be deserialized in order to visit the entire AST. We can generate this
output more efficiently as a supplementary output of the -emit-module job that
originally produced the module (since the AST is already available in-memory).
The -emit-api-descriptor flag can be used to request this output.

This change lays the groundwork by introducing frontend flags. Follow up
changes are needed to make API descriptor emission during -emit-module
functional.

Part of rdar://110916764.
2023-10-05 11:40:53 -07:00
Saleem Abdulrasool
fcd7b9e533 Driver: virtualise the plugin path handling
The plugin layouts are different across platforms.  Move this into a
virtual method and allow replacement.  On Windows, the plugins are
placed into the `bin` directory as the DLLs should always be co-located
to ensure that the proper DLLs are found (there is no concept of RPATH).
2023-09-04 15:21:39 -07:00
Allan Shortlidge
be70c568cb Frontend: Deprecate -warn-on-potentially-unavailable-enum-case option.
When `-warn-on-potentially-unavailable-enum-case` was introduced, the build
system was required to invoke `swift-frontend` at artificially low deployment
targets when emitting `.swiftinterface` files for legacy architectures. Because
the deployment target was low, some availability diagnostics needed to be
de-fanged in order to allow module interface emission to succeed. Today, the
build system is able to use the correct deployment target when emitting module
interfaces and the `-warn-on-potentially-unavailable-enum-case` is superfluous,
so deprecate it.

Resolves rdar://114092047
2023-08-18 10:02:39 -07:00
Finagolfin
30ba49e7fa [android][test] Fix a handful of tests and disable one CxxToSwiftToCxx bridging test
Also, make the analogous change to apple/swift-driver#1372, which gets the
sanitizer tests working on Android again, and remove the lld_lto feature in the
tests, which is now unused.
2023-08-12 16:36:35 +05:30
Doug Gregor
1ec900e2a0 [Macros] Add default plugin paths for Darwin SDKs and platforms.
Corresponding to https://github.com/apple/swift-driver/pull/1377, this
adds some default plugin paths for Darwin SDKs and platforms.
Fixes rdar://110819604.
2023-06-16 14:55:20 -07:00
Rintaro Ishizaki
457c55b93f Merge pull request #66650 from rintaro/macros-plugins-searchopts 2023-06-15 13:47:50 -07:00
Rintaro Ishizaki
5791a2cb37 [Macros] Plugin search options group
'load-plugin-library', 'load-plugin-executable', '-plugin-path' and
'-external-plugin-path' should be searched in the order they are
specified in the arguments.

Previously, for example '-plugin-path' used to precede
'-external-plugin-path' regardless of the position in the arguments.
2023-06-14 15:46:39 -07:00
Finagolfin
8f0c2d3ace [Driver] Remove unused runtime library path on non-Darwin platforms
Translation of apple/swift-driver#1374 to the legacy C++ Driver, with the
addition of a test.
2023-06-12 01:04:19 +05:30
Rintaro Ishizaki
64b353c5bd Revert "[Driver] Derive '-external-plugin-path'"
This reverts commit b0f5c3977f.

rdar://109851266
2023-05-25 13:39:40 -07:00
Rintaro Ishizaki
b0f5c3977f [Driver] Derive '-external-plugin-path'
When the current toolchain is not a Xcode toolchain, derive
'-external-plugin-path' poinintng Xcode plugins paths, so we can use
plugins in Xcode.

rdar://108624128
2023-05-04 16:41:45 -07:00
Steven Wu
c7d66b8845 Teach swift to compute cache key for compiler outputs
Teach swift how to serialize its input into CAS to create a cache key
for compiler outputs. To compute the cache key for the output, it first
needs to compute a base-key for the compiler invocation. The base key is
computed from: swift compiler version and the command-line arguments for
the invocation.

Each compiler output from swift will gets its own key. The key for the
output is computed from: the base key for the compiler invocation + the
primary input for the output + the output type.
2023-04-24 13:55:38 -07:00
Doug Gregor
74b12e8f23 [Driver] Implement inference of -plugin-path arguments.
This was previously implemented in the new driver; backport it to the
existing driver, which is still used by SourceKit.

Fixes rdar://106790436.
2023-03-21 21:23:49 -07:00
Rintaro Ishizaki
c4b3edd6df [Macros] Add swift-plugin-server executable
This executable is intended to be installed in the toolchain and act as
an executable compiler plugin just like other 'macro' plugins.

This plugin server has an optional method 'loadPluginLibrary' that
dynamically loads dylib plugins.
The compiler has a newly added option '-external-plugin-path'. This
option receives a pair of the plugin library search path (just like
'-plugin-path') and the corresponding "plugin server" path, separated
by '#'. i.e.

  -external-plugin-path
    <plugin library search path>#<plugin server executable path>

For exmaple, when there's a macro decl:

  @freestanding(expression)
  macro stringify<T>(T) -> (T, String) =
      #externalMacro(module: "BasicMacro", type: "StringifyMacro")

The compiler look for 'libBasicMacro.dylib' in '-plugin-path' paths,
if not found, it falls back to '-external-plugin-path' and tries to find
'libBasicMacro.dylib' in them. If it's found, the "plugin server" path
is launched just like an executable plugin, then 'loadPluginLibrary'
method is invoked via IPC, which 'dlopen' the library path in the plugin
server. At the actual macro expansion, the mangled name for
'BasicMacro.StringifyMacro' is used to resolve the macro  just like
dylib plugins in the compiler.

This is useful for
 * Isolating the plugin process, so the plugin crashes doesn't result
   the compiler crash
 * Being able to use library plugins linked with other `swift-syntax`
   versions

rdar://105104850
2023-03-16 14:00:45 -07:00
Saleem Abdulrasool
09ade25b31 Merge pull request #64151 from compnerd/control
Driver: introduce additional Windows controls
2023-03-08 13:24:19 -08:00
zoecarver
dcd83a807f [nfc][cxx-interop] Rename cxx-compatibility-mode -> cxx-interoperability-mode. 2023-03-07 10:23:19 -08:00
zoecarver
b64b52ae83 [cxx-interop] Add -cxx-compatibility-mode driver flag; deprecate -enable-experimental-cxx-interop. 2023-03-07 10:22:57 -08:00
Saleem Abdulrasool
73cafebaf5 Driver: introduce additional Windows controls
This adds the following four new options:
  - `-windows-sdk-root`
  - `-windows-sdk-version`
  - `-visualc-tools-root`
  - `-visualc-tools-version`

Together these options make one the master of Windows SDK selection for
the Swift compilation.  This is important as now that the injection is
no longer done by the user, we need to ensure that we have enough
control over the paths so that the synthesized overlay is going to map
the files to the proper location.
2023-03-06 13:29:31 -08:00
Alejandro Alonso
023c40c809 Add option to explicitly import Builtin 2023-02-16 15:23:45 -08:00
Rintaro Ishizaki
bf0a62f3ce [Option] Add compiler option to specify executable plugins
Add a compiler option `-load-plugin-executable <path>#<module names>`.
Where '<path>' is a path to a plugin executable, '<module-name>' is a
comma-separated module names the plugin provides.

Nothing is using it at this point. Actual plugin infratructure are
introduced in follow-up commits
2023-02-15 14:43:21 -08:00
Doug Gregor
4705183149 [Macros] Add plugin search paths to load plugin modules by name.
Introduce `-plugin-path <path>` to add a search path where we will look
for compiler plugins. When resolving an external macro definition, look
for libraries in these search paths whose names match the module name
of the macro.

Implements rdar://105095761.
2023-02-09 13:47:26 -08:00
Alexis Laferrière
39fb1c5f55 [ModuleInterface] Intro export-as for Swift modules
Introduce a new flag `-export-as` to specify a name used to identify the
target module in swiftinterfaces. This provides an analoguous feature
for Swift module as Clang's `export_as` feature.

In practice it should be used when a lower level module `MyKitCore` is
desired to be shown publicly as a downstream module `MyKit`. This should
be used in conjunction with `@_exported import MyKitCore` from `MyKit`
that allows clients to refer to all services as being part of `MyKit`,
while the new `-export-as MyKit` from `MyKitCore` will ensure that the
clients swiftinterfaces also use the `MyKit` name for all services.

In the current implementation, the export-as name is used in the
module's clients and not in the declarer's swiftinterface (e.g.
`MyKitCore`'s swiftinterface still uses the `MyKitCore` module name).
This way the module swiftinterface can be verified. In the future, we
may want a similar behavior for other modules in between `MyKitCore` and
`MyKit` as verifying a swiftinterface referencing `MyKit` without it
being imported would fail.

rdar://103888618
2023-01-26 14:27:31 -08:00
Ellie Shin
72ee150982 Add -package-name flag
De/serialize package name in module binary
Resoles rdar://103531218, rdar://103531208
2022-12-19 14:33:44 -08:00
Franklin Schrans
d3e96590d9 Merge pull request #61637 from theMomax/extension-block-symbols-deactivation-flag
Make emission of extension block symbols a formal feature
2022-12-01 08:18:24 +01:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Richard Wei
4ce1ebb120 [Macros] Support user-defined macros as compiler plugins (#61734)
Allow user-defined macros to be loaded from dynamic libraries and evaluated.

- Introduce a _CompilerPluginSupport module installed into the toolchain. Its `_CompilerPlugin` protocol acts as a stable interface between the compiler and user-defined macros.
- Introduce a `-load-plugin-library <path>` attribute which allows users to specify dynamic libraries to be loaded into the compiler.

A macro library must declare a public top-level computed property `public var allMacros: [Any.Type]` and be compiled to a dynamic library. The compiler will call the getter of this property to obtain and register all macros.

Known issues:
- We current do not have a way to strip out unnecessary symbols from the plugin dylib, i.e. produce a plugin library that does not contain SwiftSyntax symbols that will collide with the compiler itself.
- `MacroExpansionExpr`'s type is hard-coded as `(Int, String)`. It should instead be specified by the macro via protocol requirements such as `signature` and `genericSignature`. We need more protocol requirements in `_CompilerPlugin` to handle this.
- `dlopen` is not secure and is only for prototyping use here.

Friend PR: apple/swift-syntax#1022
2022-10-31 14:03:25 -07:00
Artem Chikin
c51efbed9c Add option to suppress emission of remarks ('-suppress-remarks')
And enforce it especially in downstream contexts such as building interfaces of SDK dependencies, where the remarks are not actionable by the user.
2022-10-28 10:49:27 -07:00
Max Obermeier
504fe3c3a4 Make emission of extension block symbols formal feature
- add name to lib/Option/features.json
 - add flag for explicitly disabling extension block symbols feature
2022-10-19 19:13:11 +02:00
Max Obermeier
453fd2231b Allow for emission of swift.extension symbols for extensions to external types in swiftSymbolGraphGen (#59047)
This includes:
 - bumping the SWIFT_SYMBOLGRAPH_FORMAT_MINOR version
 - introduction of the "swift.extension" symbol and "extensionTo" relationship
 - adding support for ExtensionDecl to the Symbol class
 - adding a "typeKind" field to the symbol's extension mixin which indicates what kind
   of symbol was extended
 - intoduction of the -emit-extension-block-symbols flag, which enables the behavior
   outlined below
 - adaptions to SymbolGraphASTWalker that ensure a swift.extension symbol is emitted
   for each extension to a type that does not exist in the local symbol graph
 - adaptions to SymbolGraph and SymbolGraphASTWalker that ensure member and conformance
   relationships are correctly associated with the swift.extension symbol instead of
   the original type declaration's (extended nominal's) symbol where applicable
 - adaptions to SymbolGraphASTWalker that ensure swift.extension symbols are connected
   to their respective extended nominal's symbol using an extensionTo relationship

Testing:
- adds SymbolGraph tests that test behavior only relevant in
  -emit-extension-block-symbols mode
- adapts some SymbolGraph tests to additionally test similar behavior for
  extensions to external types in -emit-extension-block-symbols mode
- adapts some SymbolGraph tests to (additionally or exclusively) test the
  behavior with -emit-extension-block-symbols mode enabled

Bugfixes:
- fixes a bug where some conformsTo relationships implicated by the conformances
  declared on an extension to an external type were not emitted
  (see test/SymbolGraph/Relationships/ConformsTo/Indirect.swift)

Further changes:
- documents the strategy for naming and associating children declared in extensions
  to typealiases (see test/SymbolGraph/Relationships/MemberOf/Typealias.swift,
  test/SymbolGraph/Symbols/Names.swift)
2022-09-16 12:02:40 -06:00
Alexis Laferrière
dcbef35982 [Sema] Intro flag to promote to an error missing explicit availability 2022-09-14 16:21:52 -07:00
Ben Barham
3ac580261e [Options] Move CXX interop back to a driver option
This flag is required in the driver to eg. choose `clang` vs `clang++`
for the linker. Move it back to a driver option and hide both it and the
stdlib flag from help.
2022-07-25 15:29:14 -07:00
Artem Chikin
85b767dea2 Merge pull request #60139 from artemcm/AddConstValueExtractionPathHandling
Add supplementary output path handling for extracted compile-time-known values
2022-07-21 13:19:42 -07:00
Doug Gregor
a317fad88d Add -enable-upcoming-feature X command-line argument.
Introduce the `-enable-upcoming-feature X` command-line argument to
allow one to opt into features that will be enabled in an upcoming language
mode. Stage in several features this way (`ConciseMagicFile`,
`ForwardTrailingClosures`, `BareSlashRegexLiterals`).
2022-07-19 21:20:12 -07:00
Artem Chikin
b1fee939f1 Add supplementary output path handling for extracted compile-time-known values 2022-07-19 16:24:26 -07:00
Tony Allevato
4d16c43d21 Add -index-include-locals flag.
When this flag is passed, index store data emitted during a build
will also contain definitions/references for local symbols.
2022-07-11 14:08:07 -07:00
Ben Barham
15c0ce3545 Merge pull request #58932 from DavidGoldman/ignoreclangmoduleindexing
Add `-index-ignore-clang-modules` flag to prevent indexing Clang modules
2022-06-03 09:42:56 -07:00
Doug Gregor
6d82448dc8 Add -enable-experimental-feature X for experimental features.
Experimental features can only be enabled in non-production (+Asserts)
builds. They can be detected with `hasFeature` in the same manner as
"future" features.

The `-enable-experimental-feature X` flag will also look for future
features by that name, so that when an experimental feature becomes an
accepted future feature, it will still be enabled in the same manner.

Switch variadic generics over to this approach, eliminating the
specific LangOption for it.
2022-05-26 11:50:39 -07:00
David Goldman
63c88b97f1 Add -index-ignore-clang-modules flag
This flag avoids indexing import clang modules (pcms), behaving
similar to `-index-ignore-system-modules` except for PCMs.
2022-05-17 19:41:26 -04:00
David Goldman
c232ed2913 Support hermetic indexing information
Swiftc port of https://github.com/apple/llvm-project/pull/4207.

This introduces a new flag, `-file-prefix-map` which can be used
instead of the existing `-debug-prefix-map` and `-coverage-prefix-map`
flags, and also remaps paths in index information currently.
2022-05-16 11:00:14 -04:00
Evan Wilde
94e30a817e Revert "Add -async-main flag to favor asynchronous main"
This reverts commit da0a3311a5.
2022-04-26 16:29:45 -07:00