Commit Graph

268 Commits

Author SHA1 Message Date
Pavel Yaskevich
8977d80adc [Frontend] Rework -emit-supported-features mode into -emit-supported-arguments
The "featues" part was never actually implemented and Swift Driver
is replying on information about arguments, so instead of removing
this mode, let's scope it down to "arguments" to be deprecated in
the future.

(cherry picked from commit 18703d64d6)
2025-05-14 20:28:46 -07:00
Pavel Yaskevich
e477143d58 [Frontend] Add -print-supported-features option
This is a replacement for `-emit-supported-features` that prints
all of the upcoming/experimental features supported by the compiler
with some additional meta information in JSON format to stdout.

(cherry picked from commit 55bd906906)
2025-05-14 20:28:40 -07:00
Hamish Knight
54a6d75d15 [Frontend] Avoid storing StringRef values in ModuleAliasMap
Previously we would insert StringRefs that reference the keys in the
map, but that breaks if the invocation ever gets copied. Switch to
`std::string`.

rdar://148130166
2025-05-09 20:46:18 +01:00
Artem Chikin
88dec5199e [Dependency Scanning] Add support for placing explicitly-built SDK modules into a separate module cache
With '-sdk-module-cache-path', Swift textual interfaces found in the SDK will be built into a separate SDK-specific module cache.
Clang modules are not yet affected by this change, pending addition of the required API.
2025-03-19 09:17:04 -06:00
Tony Allevato
2b0f9aa765 Allow module aliases to use escaped identifiers as the alias name.
The original module names themselves must still be valid unescaped identifiers; most of the serialization logic in the compiler depends on the name of a module matching its name on the file system, and it would be very complex to turn escaped identifiers into file-safe names.
2025-03-11 17:18:43 -04:00
Steven Wu
c42268e7f1 Merge pull request #79301 from cachemeifyoucan/eng/PR-144623388
[BridgingHeader] Fix auto-chaining when only dependency has bridging header
2025-02-13 11:35:39 -08:00
Rintaro Ishizaki
71b24665fa [ASTDumper] Dump DeclContext
* Include `DeclContext` of the node where possible
* Add 'default-with-decl-contexts' dump style that dumps the dect context
  hierarchy in addition to the AST
* Support `-dump-parse` with `-dump-ast-format json`
2025-02-12 10:53:33 -08:00
Steven Wu
719edaf7e2 [BridgingHeader] Fix auto-chaining when only dependency has bridging header
When enable bridging header auto chaining, it is possible for the
compilation to have a PCH file input for the bridging header from a
binary swift module dependency. In this case, we should not report a
bridging header for current module as bridging header can be leaking out
through swiftinterface file.

To fully distinguish the PCH files passed in through different
situation, here are the situations:
* If no chaining is used, only `-import-objc-header` option is used and
  it can be used to pass either a header file or a PCH file depending if
  GeneratePCH job is requested or not.
* If chaining is enabled, `-import-objc-header` is only used to pass the
  header file and `-import-pch` is used to pass PCH file. Chaining mode
  requires PCH generation if bridging header is used.

rdar://144623388
2025-02-12 07:30:14 -08:00
Steven Wu
9d59044bb1 [BrdigingHeader] Auto bridging header chaining
Add ability to automatically chaining the bridging headers discovered from all
dependencies module when doing swift caching build. This will eliminate all
implicit bridging header imports from the build and make the bridging header
importing behavior much more reliable, while keep the compatibility at maximum.

For example, if the current module A depends on module B and C, and both B and
C are binary modules that uses bridging header, when building module A,
dependency scanner will construct a new header that chains three bridging
headers together with the option to build a PCH from it. This will make all
importing errors more obvious while improving the performance.
2025-02-05 09:41:04 -08:00
Artem Chikin
acb4e847f5 [Dependency Scanning] Add functionality to validate contents of a loaded scanner cache state
Checking each module dependency info if it is up-to-date with respect to when the cache contents were serialized in a prior scan.

- Add a timestamp field to the serialization format for the dependency scanner cache
- Add a flag "-validate-prior-dependency-scan-cache" which, when combined with "-load-dependency-scan-cache" will have the scanner prune dependencies from the deserialized cache which have inputs that are newer than the prior scan itself

With the above in-place, the scan otherwise proceeds as-is, getting cache hits for entries still valid since the prior scan.
2025-02-03 10:33:43 -08:00
Allan Shortlidge
f1156765b8 Frontend: Introduce options for defining availability domains. 2025-01-28 13:47:42 -08:00
Tony Allevato
a4c64b081d Address most of the simple review feedback. 2025-01-22 14:26:13 -05:00
Tony Allevato
71b0a5fae9 Restrict JSON AST dumps to when -dump-ast is used.
Specifically, this means `-dump-ast-format json` is
incompatible with `-dump-parse`. This is because the JSON
format is meant to export more details about the AST that
require type checking to have been performed.

I'm open to lifting this restriction in the future.
2025-01-22 14:26:13 -05:00
Tony Allevato
a57fb4dfa9 [AST] Add minimal JSON support to ASTDumper.
This only takes the existing AST information and writes it as JSON
instead of S-expressions. Since many of these fields are stringified,
they're not ideal for the kind of analysis clients of the JSON format
would want to do. A future commit will update these values to use a
more structured representation.
2025-01-22 14:26:13 -05:00
Xi Ge
c8fa52b96d FineModuleTracing/CAS: move the computation of whether fine module trace will be emitted to an early stage.
CAS needs to determine if an output is needed very early (when computing supplementary outputs) in the pipeline so we can do caching and replays.

Resolves: rdar://141850408
2024-12-20 19:09:35 -08:00
Xi Ge
c965343f54 Frontend: add a flag to disable fine-grained module tracing 2024-12-13 16:07:15 -08:00
Pavel Yaskevich
7c8000b3a5 [Frontend] Switch -interface-compiler-version to Version
`SWIFT_COMPILER_VERSION` has more than 4 components and it's
easier to use `Version` API over `VersionTuple` as well.
2024-11-18 15:11:36 -08:00
Allan Shortlidge
67c59279a4 Frontend: Rename -dump-type-refinement-contexts to -dump-availability-scopes. 2024-11-12 11:34:25 -08:00
Allan Shortlidge
239720897a AST: Rename TypeRefinementContext to AvailabilityScope. 2024-11-12 11:34:25 -08:00
Usama Hameed
305ac20716 Serialize and Deserialize Debug Scopes (#76934)
This patch adds support for serialization and deserialization of
debug scopes.

Debug scopes are serialized in post order and enablement is 
controlled through the experimental-serialize-debug-info flag which
is turned off by default. Functions only referred to by these debug
scopes are deserialized as zombie functions directly.
2024-11-05 11:01:35 -08:00
Artem Chikin
8e3a6207b9 Merge pull request #76915 from artemcm/AsyncScanExperiment
[Dependency Scanning] Parallelize Clang module queries
2024-11-05 10:04:31 -08:00
Michael Gottesman
4763251427 [sil] Add the ability for the frontend to dump LoweredSIL before IRGen.
This is something that I have wanted to add for a while and have never had the
need to. I need it now to fix a bug in the bots where I am forced to use IRGen
output to test ThunkLowering which causes platform level differences to show up
in the FileCheck output. With this, I can just emit the actual lowered SIL
output and just test it at that level. There are other cases like this where we
are unable to test lowered SIL so we use IRGen creating this brittleness.
Hopefully this stops this problem from showing up in the future.

rdar://138845396
2024-11-01 03:16:55 -07:00
Artem Chikin
0f50693aa5 [Dependency Scanning] Parallelize Clang module queries
This change refactors the top-level dependency scanning flow to follow the following procedure:

Scan():
1. From the source target under scan, query all imported module identifiers for a *Swift* module. Leave unresolved identifiers unresolved. Proceed transitively to build a *Swift* module dependency graph.
2. Take every unresolved import identifier in the graph from (1) and, assuming that it must be a Clang module, dispatch all of them to be queried in-parallel by the scanner's worker pool.
3. Resolve bridging header Clang module dpendencies
4. Resolve all Swift overlay dependencies, relying on all Clang modules collected in (2) and (3)
5. For the source target under scan, use all of the above discovered module dependencies to resolve all cross-import overlay dependencies
2024-10-30 11:10:10 -07:00
Pavel Yaskevich
84a62fc170 [Frontend/Serialization] Narrow -swift-compiler-version to -interface-compiler-version
It might be unexpected to future users that `-swift-compiler-version`
would produce a version aligned to .swiftinterface instead of one used
to build the .swiftmodule file. To avoid this possible confusion, let's
scope down the version to `-interface-compiler-version` flag and
`SWIFT_INTERFACE_COMPILER_VERSION` option in the module.
2024-10-28 13:45:27 -07:00
Pavel Yaskevich
83995f2ae0 [Frontend] Don't set "current" compiler version for modules built from swiftinterface
If swiftinterface doesn't have `-swift-compiler-version` flag
it means that it was generated with an older version of the
Swift compiler. In such cases it would be incorrect to use
"current" compiler version because the field is intended to
indicate the compiler the swiftinterface was built with.
2024-10-25 17:05:16 -07:00
Pavel Yaskevich
3bd4853626 [Frontend] Add -swift-compiler-version option to frontend, module interfaces
This option is going to be used to indicate what compiler was used
to build swift interface/module which is required for SE-0438.
2024-10-24 17:06:14 -07:00
Ryan Mansfield
1001f9eb41 Add -print-zero-stats option and use it in ensure_no_astgen.swift
to verify ExportedSourceFileRequest == 0.

In release mode only non-zero stats are printed by default now.

Fix diagnostic when compiler is built without statistics support.
2024-10-15 23:11:15 -04:00
Slava Pestov
c77fae3a2d Basic: Add -fine-grained-timers flag
By default, -stats-output-dir does not collect per-request timers and
counters, because of overhead.
2024-09-23 18:04:25 -04:00
Artem Chikin
6990b89ec2 Merge pull request #72854 from artemcm/DefaultParallelDepScan
[Dependency Scanning] Enable parallel dependency scanning by-default
2024-09-13 14:30:01 -07:00
Artem Chikin
1ce178bc11 Merge pull request #76372 from artemcm/PrebuiltModulesEnvVar
[Prebuilt Module Cache] Add an environment variable overload to specify location of the prebuilt module cache
2024-09-11 13:07:53 -07:00
Artem Chikin
12b7df87ee [Prebuilt Module Cache] Add an environment variable overload to specify location of the prebuilt module cache
Useful for allowing e.g. CI systems to share this parameter without needing to plumb through a new compiler flag everywhere

Resolves rdar://135033114
2024-09-11 09:36:45 -07:00
Alexis Laferrière
3fe97c2eb8 Frontend: Intro -public-module-name flag
Introduce the concept of public facing module name designed to hide support module from external clients. This name should be set on a support module that is an implementation detail of a public module, the public module name of the support module should be the name of the public module. For example, BigKitCore’s public module name can be set to BigKit for diagnostics to refer to both modules as BigKit.

This name is used to refer to the support module in diagnostics for external clients. We determine if a client is external if they also import the module identified by the public module name. If a client doesn’t import the public module, diagnostics will always use the real name of the module.

The public module name is set with the flag -public-module-name and it's preserved in textual swiftinterfaces and binary swiftmodules.

rdar://134527933
2024-09-04 16:20:06 -07:00
Artem Chikin
e7a76653aa [Dependency Scanning] Enable parallel dependency scanning by-default 2024-08-01 14:26:05 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Saleem Abdulrasool
dc131ee180 Frontend: share the module cache path with clang
Rather than trying to re-compute the cache path manually for the
default, use the clang provided interface to home the module cache. This
ensures that we do not write the files into a top-level directory on
Windows.
2024-06-11 08:58:53 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Allan Shortlidge
b11b64273b Frontend: Allow any experimental feature to be enabled when compiling a module.
When building a module from its interface, do not diagnose whether or not a
feature is available in production compilers. This is important since older
compilers may be expected to build .swiftinterfaces that were produced by newer
compilers where the feature has been enabled by default.

Resolves rdar://125500318
2024-03-27 11:43:48 -07:00
Ellie Shin
951e2abdea Create features mapped to package optimization flags to
allow a more standard way to pass experimental features
from build systems. Also moved other flags relevant to
diagnostics from Frontend options to Lang options.

Ref: rdar://124648653
2024-03-15 14:18:33 -07:00
Becca Royal-Gordon
fd9ae4c8ac Merge pull request #72023 from beccadax/lazy-objc-workaround
Add workaround flag for lazy import-as-member
2024-03-05 16:12:32 -08:00
Ellie Shin
30669fca65 Currently when checking if resilience check can be bypassed within a package,
we only check if the loaded module is built from a package interface. This is
not enough as a binary module could just contain exportable decls if built with
experimental-skip-non-exportable-decls, essentially resulting in content equivalent
to interface content. This might be made a default behavior so this PR requires
a module to opt in to allow non-resilient access by a participating client in the
same package.

Since it affects module format, SWIFTMODULE_VERSION_MINOR is updated.

rdar://123651270
2024-03-01 15:13:58 -08:00
Becca Royal-Gordon
1a97803c8c Add flag for dumping ClangImporter lookup tables
ClangImporter’s SwiftLookupTables map Swift names to their corresponding Clang declarations. These tables are built into a module’s clang .pcm file and missing or inaccurate entries can cause name lookup to fail to find an imported declaration.

Swift has always included a helper function that would dump these tables, and swift-ide-test has a command-line switch that would invoke it, but these tools are clumsy to use in many debugging scenarios. Add a frontend flag that dumps the tables at the end of the frontend job, making it a lot easier to get at this information in the context of a specific compilation.
2024-02-29 17:51:00 -08:00
Artem Chikin
8c53fe8b63 [Dependency Scannin] Fallback on system default cache directory when no explicit cache path is specified by the user 2024-02-29 11:40:50 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Steven Wu
3986937e03 [Caching][NFC] Restructure CASOption in swift. NFC
Clean up how CASOptions are kept and passed inside swift to make the
code more readable. Also avoid a copy of CAS configuration in
ClangImporter.
2024-02-11 14:08:09 -08:00
Allan Shortlidge
67661ccf93 Frontend: Ignore lazy typechecking flags when emitting non-resilient modules.
The `-experimental-lazy-typecheck` and `-experimental-skip-non-exportable-decls`
flags are not safe to use when emitting a non-resilient module because the
clients of non-resilient modules expect to have access to all the members of a
type in order to e.g. compute the size the type. The
`-experimental-skip-non-exportable-decls` flag skips serialization of
non-public members and would therefore cause mis-compilation. The
`-experimental-lazy-typecheck` is theoretically safe for non-resilient modules
but more requestification work is needed before it can be used successfully.

Resolves rdar://122272758
2024-02-04 09:10:46 -08:00
Steven Wu
b4e5e78bce [SupplementaryOutputs][NFC] Simplify boilerplate output checks.
Reduce some boilerplate code to check if supplementary outputs exist.
2024-02-01 13:43:40 -08:00
Steven Wu
f3c5e6a142 [Caching] Remove temporary caching test option
Remove `-allow-unstable-cache-key-for-testing` frontend flag. It is a
test only flag when the infrastructure is not ready to write tests for
fully cachable tasks. It is no longer needed after all the related tests
are rewritten to use dependency scanner.
2024-01-28 22:06:59 -08:00
Allan Shortlidge
5e5578aa0b Frontend: Ignore -experimental-lazy-typecheck when verifying module interfaces. 2023-11-29 10:51:24 -08:00
Allan Shortlidge
606bb391ff Frontend: Add -experimental-skip-non-inlinable-function-bodies-is-lazy.
This option causes the -experimental-lazy-typecheck and
-experimental-skip-non-exportable-decls options to be inferred from the
presense of -experimental-skip-non-inlinable-function-bodies. This new option
is meant to be a temporary testing aid that allows lazy typechecking to be
tested on projects without full build system support for passing the other
flags to the right jobs.

Resolves rdar://118938251
2023-11-29 10:51:24 -08:00
Rintaro Ishizaki
0c9f099d88 [Macros] Add option to disable sandbox for exectuable plugins
`-disable-sandbox` to disable sandboxing when invoking subprocess from
from the frontend. Since `sandbox(7)` in macOS doesn't support nested
sandbox, complation used to fail when the parent build process is sandboxed.
2023-11-27 13:44:40 -08:00