Commit Graph

685 Commits

Author SHA1 Message Date
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
Ben Langmuir
e7c37655e4 [CAS] Cache symbol graph outputs
The symbol graph output from a module can contain an arbitrary number of
files, depending on what extensions it contains, so cache a list of
symbol graph files with their base name and contents so that they can be
replayed.

rdar://140286819
2024-12-03 13:11:19 -08:00
Xi Ge
4a5d041932 FineModuleTrace: reposition the currently ObjC message specific trace files to be a more general purposed file for tracing fine-grained dependencies. NFC 2024-11-20 12:41:21 -08:00
Xi Ge
51a68ecdd1 ModuleObjCTrace/CAS: compute objc trace file paths via the canoical supplementary output paths computation
CAS support in compiler relies on supplementary paths to decide the mapping between input and output files. Therefore, we
have to compute the paths of the module ObjC trace files in this canonical place to have CAS support for
this newly added ObjC message trace files.
2024-11-20 08:52:15 -08:00
Allan Shortlidge
67c59279a4 Frontend: Rename -dump-type-refinement-contexts to -dump-availability-scopes. 2024-11-12 11:34:25 -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
Tony Allevato
bd4cfee965 Merge pull request #76872 from allevato/swift-synthesize-interface-tool
Add a new driver tool/mode to print the synthesized Swift interface for a module.
2024-10-18 13:26:22 -04: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
Tony Allevato
2cfcdd8ed1 Add a new driver tool/mode to print the synthesized Swift interface for a module.
This mode is similar to `swift-symbolgraph-extract`; it takes a subset of compiler
flags to configure the invocation for module loading, as well as a module name
whose contents should be extracted. It does not take any other input files. The
output is a single text file specified by `-o` (or `stdout` if not specified).

While the most common use case for this would be viewing the synthesized Swift
interface for a Clang module, since the implementation simply calls
`swift::ide::printModuleInterface` under the hood, it's usable for any module
that Swift can import. Thus, it could also be used to view a synthesized textual
representation of, say, a compiled `.swiftmodule`.

One could imagine that in the future, we might add more flags to
`swift-synthesize-interface` to modify various `PrintOptions` used when
generating the output, if we think those would be useful.
2024-10-10 15:30:41 -04:00
Nate Chandler
9718aa5b29 [Driver] Pass -emit-irgen thru to frontend.
Add a new filetype for this mode option: "Raw LLVM IR". When the mode
option is emit-irgen, the new filetype will be the output kind;
conversely when determining the mode option to use, if the output kind
is the new filetype, the mode option will be emit-irgen.
2024-10-02 08:25:30 -07: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
Saleem Abdulrasool
6443619126 Remove swift-indent tool
This removes the implementation of the `swift-indent` tool, its
associated documentation, and utilities. This tool was never completed
and has much better alternatives with `swift-format` which is more
flexible and actually maintained.
2024-09-19 11:21:59 -07:00
Dmitrii Galimzianov
070c77ebcf fixup! [Diagnostics] Add -[no-]warning-as-error flags for precise control over warning behavior 2024-09-07 07:55:27 +02:00
Ben Barham
d8f381e660 Merge pull request #74804 from bnbarham/rename-equals
Update `StringRef::equals` references to `operator==`
2024-06-28 11:22:20 -07:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Allan Shortlidge
470baff865 Driver: Remove swift-api-extract.
Now that API descriptions are emitted during module build jobs when
`-emit-api-descriptor-path` is specified and the build system has been updated
to pass that flag when the output is needed, the `swift-api-extract` frontend
alias is no longer used. Delete it and the tests that were specific to invoking
`swift-api-extract`.

Resolves rdar://116537394.
2024-06-27 17:05:32 -07:00
Tim Kientzle
5b49a04ddc New assertions support
This adds three new assertion macros:
* `ASSERT` - always compiled in, always checked
* `CONDITIONAL_ASSERT` - always compiled in, checked whenever the `-compiler-assertions` flag is provided
* `DEBUG_ASSERT` - only compiled into debug builds, always checked when compiled in  (functionally the same as Standard C `assert`)

The new `-compiler-assertions` flag is recognized by both `swift-frontend` and
`swiftc`.

The goal is to eventually replace every use of `assert` in the compiler with one of the above:
* Most assertions will use `ASSERT` (most assertions should always be present and checked, even in release builds)
* Expensive assertions can use `CONDITIONAL_ASSERT` to be suppressed by default
* A few very expensive and/or brittle assertions can use `DEBUG_ASSERT` to be compiled out of release builds

This should:
* Improve quality by catching errors earlier,
* Accelerate compiler triage and debugging by providing more accurate crash dumps by default, and
* Allow compiler engineers and end users alike to add `-compiler-assertions` to get more accurate failure diagnostics with any compiler
2024-05-16 11:38:00 -07:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Ben Barham
1fdda023b3 Rename StringRef::endswith references to StringRef::ends_with
Missed this when doing the `startswith` renaming. `endswith` has also
been deprecated upstream (and presumably soon to be removed).
2024-04-01 10:59:16 -07:00
Ben Barham
9779c18da3 Rename startswith to starts_with
LLVM is presumably moving towards `std::string_view` -
`StringRef::startswith` is deprecated on tip. `SmallString::startswith`
was just renamed there (maybe with some small deprecation inbetween, but
if so, we've missed it).

The `SmallString::startswith` references were moved to
`.str().starts_with()`, rather than adding the `starts_with` on
`stable/20230725` as we only had a few of them. Open to switching that
over if anyone feels strongly though.
2024-03-13 22:25:47 -07: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
Allan Shortlidge
07a67437be Merge pull request #64656 from artemcm/LegacyDeathBed
Deprecate Legacy driver by removing incremental builds and adding warnings
2024-01-18 08:55:59 -08:00
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
Allan Shortlidge
35fd79af57 NFC: Import llvm/TargetParser/Host.h instead of llvm/Support/Host.h. 2024-01-16 13:27:54 -08:00
Artem Chikin
6a181fb04c Add symlinks for the legacy driver invocation (for emergency fallback invoked from 'swift-driver') 2024-01-03 14:12:22 -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
3f71ebb5a6 Update Driver to generate package interface only if package-name is passed
Resolves rdar://119275771
2023-12-06 14:27:33 -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
Rintaro Ishizaki
22592d22fc Merge pull request #69470 from rintaro/swift-parse-test
[swift-parse-test] A parser performance check utility
2023-10-30 15:35:57 -07: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
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
swift-ci
4a749b3e3d Merge remote-tracking branch 'origin/main' into rebranch 2023-10-05 16:59:34 -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
swift-ci
099ba55cfa Merge remote-tracking branch 'origin/main' into rebranch 2023-08-19 09:33:55 -07:00
Allan Shortlidge
54435aca4f Frontend: Introduce -experimental-lazy-typecheck action.
This action is currently just an alias of the `-resolve-imports` action.
However, it's named to more clearly reflect the purpose which is to do the
minimal typechecking needed in order to emit the requested outputs. This mode
is intended to improve performance when emitting `.swiftinterface` and `.tbd`
files.
2023-08-18 16:15:33 -07:00
Jan Svoboda
ed6f2bdba6 [driver] Fix build after LLVM options change 2023-08-15 15:26:26 -07:00
Jan Svoboda
57e52214de [driver] Fix build after LLVM options change 2023-08-15 15:09:24 -07:00
Evan Wilde
8ce6ee8dd1 Updating API usages
LLVM deprecated, renamed, and removed a bunch of APIs. This patch
contains a lot of the changes needed to deal with that.

The SetVector type changed the template parameters.

APInt updated multiple names, countPopulation became popcount,
getAllOnesValue became getAllOnes, getNullValue became getZero, etc...

Clang type nullability check stopped taking a clang AST context.

The LLVM IRGen Function type stopped exposing basic block list directly,
but gained enough API surface that the translation isn't too bad.
(GenControl.cpp, LLVMMergeFunctions.cpp)

llvm::Optional had a transform function. That was being used in a couple
of places, so I've added a new implementation under STLExtras that
transforms valid optionals, otherwise it returns nullopt.
2023-07-17 10:53:42 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Yuta Saito
c994500d82 [Driver] Use WebAssembly toolchain for WASI target
The toolchain was introduced in 710816d3e0
but was not used. Test cases now use fake resource dir to lookup
static-executable-args.lnk file, which is required by the toolchain but
is not present when not building stdlib for WASI.
2023-06-08 11:40:10 +00:00
Steven Wu
86927ef39c Merge pull request #65288 from cachemeifyoucan/eng/PR-swift-cache-backend
[CAS] Teach swift compiler to compute cache key and store outputs into CAS
2023-04-25 09:23:15 -07:00
Steven Wu
c153210505 [CAS] Add test case for cache key computation
Add tool swift-cache-tool for caching related testing and inspection.
2023-04-24 13:56:33 -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
Erik Eckstein
e7af73e2de Replace the swift-llvm-opt binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:53:12 +02:00
Erik Eckstein
2b2bc45e08 Replace the swift-dependency-tool binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:51:04 +02:00
Erik Eckstein
8ce6038a42 Replace the sil-passpipeline-dumper binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:49:33 +02:00
Erik Eckstein
e3a174b85e Replace the sil-llvm-gen binary with a symlink to swift-frontend
rdar://76551283
2023-04-24 13:48:23 +02:00