Commit Graph

2231 Commits

Author SHA1 Message Date
Steven Wu
23b42cf6c9 [CAS] Support legacy prefix map option
Bring back legacy prefix map option to allow an older swift-driver to
work with newer swift-frontend. For old swift-driver, it will always
send the old style prefix map option, so the new compiler needs to
support that.

rdar://164208526
2025-11-06 20:35:10 -08:00
Dylan Sturgeon
4b4f9f18fc Add an option for symbol graph to support long module names. (#83782)
Currently symbol graphs are always written in files that contain 1 to 2
module names. It's possible for Swift module names to be very long, so
combining 2 of them in file name like `module1@module2...` in the same
path component means the name can be too long for some file systems. The
new option `-symbol-graph-shorten-output-names` changes the symbol graph
output files to use a MD5 hash of the module name(s) as the filename and
outputs an additional JSON file with the original names mapped to the
real filename. The module names JSON can be used to construct a VFS
overlay with the original naming scheme.

fix #83723

I considered using vfsoverlay, which seems like a viable solution, but
the vfsoverlay options don't seem to apply to any of the outputs from
the compiler. When I set an overlay to remap the symbol graph file
outputs, the remapped external paths aren't used so the root problem of
too long file names remains.
2025-11-06 19:30:44 -08:00
Pavel Yaskevich
123198b4ac [Frontend] Change -require-explicit-sendable argument to mean -Wwarning ExplicitSendable 2025-11-04 17:53:38 -08:00
Becca Royal-Gordon
2504beeccc Merge pull request #85043 from beccadax/mod-squad-interface
[SE-0491] Conditionally emit module selectors into swiftinterfaces
2025-11-03 19:08:09 -08:00
Adrian Prantl
457a2d3325 Merge pull request #85100 from adrian-prantl/163302154
Add a -debug-module-path frontend option
2025-11-03 12:30:55 -08:00
Artem Chikin
164d3ae5a8 Merge pull request #85010 from artemcm/AlwaysRebuildExplicitInterface
[Explicit Module Builds] Always rebuild the target module in explicit `-compile-module-from-interface` builds.
2025-10-31 21:24:18 -04:00
Becca Royal-Gordon
9454c0aaa4 Emit module selectors in swiftinterfaces
This support is currently opt-in and can be disabled by a blocklist.
2025-10-31 16:48:06 -07:00
Steven Wu
eae4555213 [CAS] Add -no-cache-compile-job frontend option
Add a negative frontend to turn off compilation caching. This allows
turn off compilation caching by just appending argument.

rdar://162547707
2025-10-31 11:03:05 -07:00
Mike Ash
3a0b3924df Merge pull request #85044 from mikeash/emit-into-client-retain-release
[IRGen][Runtime] Add emit-into-client retain/release calls for Darwin ARM64.
2025-10-28 12:09:01 -04:00
Mike Ash
93fae78e04 [IRGen][Runtime] Add emit-into-client retain/release calls for Darwin ARM64.
This is currently disabled by default. Building the client library can be enabled with the CMake option SWIFT_BUILD_CLIENT_RETAIN_RELEASE, and using the library can be enabled with the flags -Xfrontend -enable-client-retain-release.

To improve retain/release performance, we build a static library containing optimized implementations of the fast paths of swift_retain, swift_release, and the corresponding bridgeObject functions. This avoids going through a stub to make a cross-library call.

IRGen gains awareness of these new functions and emits calls to them when the functionality is enabled and the target supports them. Two options are added to force use of them on or off: -enable-client-retain-release and -disable-client-retain-release. When enabled, the compiler auto-links the static library containing the implementations.

The new calls also use LLVM's preserve_most calling convention. Since retain/release doesn't need a large number of scratch registers, this is mostly harmless for the implementation, while allowing callers to improve code size and performance by spilling fewer registers around refcounting calls. (Experiments with an even more aggressive calling convention preserving x2 and up showed an insignificant savings in code size, so preserve_most seems to be a good middle ground.)

Since the implementations are embedded into client binaries, any change in the runtime's refcounting implementation needs to stay compatible with this new fast path implementation. This is ensured by having the implementation use a runtime-provided mask to check whether it can proceed into its fast path. The mask is provided as the address of the absolute symbol _swift_retainRelease_slowpath_mask_v1. If that mask ANDed with the object's current refcount field is non-zero, then we take the slow path. A future runtime that changes the refcounting implementation can adjust this mask to match, or set the mask to all 1s to disable the old embedded fast path entirely (as long as the new representation never uses 0 as a valid refcount field value).

As part of this work, the overall approach for bridgeObjectRetain is changed slightly. Previously, it would mask off the spare bits from the native pointer and then call through to swift_retain. This either lost the spare bits in the return value (when tail calling swift_retain) which is problematic since it's supposed to return its parameter, or it required pushing a stack frame which is inefficient. Now, swift_retain takes on the responsibility of masking off spare bits from the parameter and preserving them in the return value. This is a trivial addition to the fast path (just a quick mask and an extra register for saving the original value) and makes bridgeObjectRetain quite a bit more efficient when implemented correctly to return the exact value it was passed.

The runtime's implementations of swift_retain/release are now also marked as preserve_most so that they can be tail called from the client library. preserve_most is compatible with callers expecting the standard calling convention so this doesn't break any existing clients. Some ugly tricks were needed to prevent the compiler from creating unnecessary stack frames with the new calling convention. Avert your eyes.

To allow back deployment, the runtime now has aliases for these functions called swift_retain_preservemost and swift_release_preservemost. The client library brings weak definitions of these functions that save the extra registers and call through to swift_retain/release. This allows them to work correctly on older runtimes, with a small performance penalty, while still running at full speed on runtimes that have the new preservemost symbols.

Although this is only supported on Darwin at the moment, it shouldn't be too much work to adapt it to other ARM64 targets. We need to ensure the assembly plays nice with the other platforms' assemblers, and make sure the implementation is correct for the non-ObjC-interop case.

rdar://122595871
2025-10-27 12:00:28 -04:00
Adrian Prantl
cb4efa0839 Add a -debug-module-path frontend option
This new option allows the Driver to pass the path to a compilation
job's own binary swiftmodule artifact to the frontend. The compiler
then stores this path in the debug info, to allow clients like LLDB to
unambiguously know which binary Swift module belongs to which compile
unit.

rdar://163302154
2025-10-23 17:10:50 -07:00
Allan Shortlidge
16dee385bf AST/Basic: Introduce the StandaloneSwiftAvailability experimental feature.
This experimental feature will be used to force the compiler to treat `Swift`
runtime availability as separate from platform availability when compiling for
targets that have the Swift runtime built-in.
2025-10-21 21:55:24 -07:00
Artem Chikin
4cdbcb8645 [Explicit Module Builds] Always rebuild the target module in explicit -compile-module-from-interface builds.
We have long switched to delegate the checking of whether a module is up-to-date to the build system (SwiftDriver) and stopped serializing file dependencies for interface-built binary modules.

Resolves rdar://162881032
2025-10-20 14:13:37 -07:00
Steven Wu
4f059033bb [Caching][NFC] Using llvm::cas::CASConfiguration
Prefer llvm::cas::CASConfiguration where it used to clang::CASOption.
2025-10-17 16:42:35 -07:00
Ryan Mansfield
c314fc1582 Merge pull request #84296 from rjmansfield/emit-verbose-asm
Add frontend option -verbose-asm to emit verbose assembly.
2025-10-17 12:40:42 -04:00
Henrik G. Olsson
f83752dd14 Merge pull request #84870 from hnrklssn/verify-ignore-macro-note
[DiagnosticVerifier] Add -verify-ignore-macro-note
2025-10-14 19:41:31 -07:00
Henrik G. Olsson
89b31cfcf9 Merge pull request #84872 from hnrklssn/disable-safe-wrappers-in-stdlib
[Swiftify] Always skip safe wrappers when building the stdlib
2025-10-14 09:36:20 -07:00
Henrik G. Olsson
a8fec6f39b [Swiftify] Always skip safe wrappers when building the stdlib
_SwiftifyImport assumes types like Swift.Int, Swift.UnsafePointer<T> and
Swift.Span<T> are available. This is not the case when building the
stdlib itself. Disable safe interop in the stdlib to prevent errors.
This currently has no effect, but will when this feature is enabled by
default, which I have manually tested.
2025-10-13 19:11:57 -07:00
Henrik G. Olsson
da55801862 [DiagnosticVerifier] Add -verify-ignore-macro-note
The _SwiftifyImport macro is emitted into an unnamed buffer and then
parsed, pretending it was in the header all along. This makes it hard to
add `expected-note` comments for `diag::in_macro_expansion` when they
point here. That's okay, because the macro expansion has already been
pointed out by `expected-expansion` directives. But
-verify-ignore-unrelated is too blunt of a tool, so this adds
-verify-ignore-macro-note to ignore these specific diagnostics.
2025-10-13 18:35:46 -07:00
Erik Eckstein
65e4c10113 Optimizer: remove the obsolete SpeculativeDevirtualization pass
This pass has been disabled since a very long time (because it's terrible for code size).
It does not work for OSSA. Therefore it cannot be enabled anymore (as is) once we have OSSA throughout the pipeline.
So it's time to completely remove it.
2025-10-13 10:49:17 +02:00
Doug Gregor
367e02703d Temporarily suppress embedded-restrictions diagnostic in Swift and _Concurrency
These are really noisy and are masking other issues. While we still
have tons of cleanup to do, suppress these warnings.
2025-10-11 07:15:14 -07:00
Chirag Ramani
5179bc9609 Add IRPGO and CSIRPGO options to Swift (#84335)
This PR introduces three new instrumentation flags and plumbs them
through to IRGen:

1. `-ir-profile-generate` - enable IR-level instrumentation.
2. `-cs-profile-generate` - enable context-sensitive IR-level
instrumentation.
3. `-ir-profile-use` - IR-level PGO input profdata file to enable
profile-guided optimization (both IRPGO and CSIRPGO)

**Context:**
https://forums.swift.org/t/ir-level-pgo-instrumentation-in-swift/82123

**Swift-driver PR:** https://github.com/swiftlang/swift-driver/pull/1992

**Tests and validation:**
This PR includes ir level verification tests, also checks few edge-cases
when `-ir-profile-use` supplied profile is either missing or is an
invalid IR profile.

However, for argument validation, linking, and generating IR profiles
that can later be consumed by -cs-profile-generate, I’ll need
corresponding swift-driver changes. Those changes are being tracked in
https://github.com/swiftlang/swift-driver/pull/1992
2025-10-09 17:41:47 -07:00
Allan Shortlidge
b9fd3e4604 Merge pull request #84778 from tshortli/swift-runtime-availability-domain
AST: Introduce a Swift runtime availability domain
2025-10-09 08:53:20 -07:00
Allan Shortlidge
1a86cd9c26 AST: Introduce a Swift runtime availability domain.
Add support for the `Swift` availability domain, which represents availability
with respect to the Swift runtime. Use of this domain is restricted by the
experimental feature `SwiftRuntimeAvailability`.
2025-10-08 17:31:57 -07:00
Ryan Mansfield
4cc2940619 Add frontend option -verbose-asm to emit verbose assembly.
This enables the option by default to aid readability with
-emit-assembly.
2025-10-08 16:01:13 -04:00
Doug Gregor
151415b550 [Frontend] Don't enable EmbeddedRestrictions warnings under -suppress-warnings
Fixes #84697.
2025-10-07 16:21:42 -07:00
John Hui
312caa3a82 Merge pull request #84723 from j-hui/suppress-notes
[Diagnostics] Add -suppress-notes flag
2025-10-07 11:18:22 -07:00
eeckstein
401a2ac2bc Merge pull request #84704 from eeckstein/closure-specialization
ClosureSpecialization: support for OSSA and a big overhaul
2025-10-07 06:59:08 +02:00
John Hui
d68ca8de1e [Diagnostics] Add -suppress-notes flag
We already have -suppress-warnings and -suppress-remarks; this patch
adds support for suppressing notes too. Doing so is useful for -verify
tests where we don't really care about the emitted notes.
2025-10-06 17:05:57 -07:00
Erik Eckstein
8efafc7e3b Optimizer: remove the -experimental-swift-based-closure-specialization option 2025-10-06 12:02:48 +02:00
Henrik G. Olsson
e0c65b7c44 [DiagnosticVerifier] Add -verify-ignore-unrelated flag
This adds the implementation required for later changing the default
behaviour of the -verify flag to error when diagnostics are emitted
in buffers other than the main file and files added with
-verify-additional-file. To keep the current behaviour, use the flag
-verify-ignore-unrelated. This flag is added as a no-op so that tests
can start using it before the new behaviour is enabled by default.
2025-10-04 12:40:59 -07:00
Michael Gottesman
52a163fa5e Merge pull request #84555 from gottesmm/pr-4f37ab5228b75850c247af4f8dd913996a0390bd
[irgen] Make HasAArch64TBI an IRGen option instead of a LangOpts.
2025-09-27 18:09:12 -07:00
Michael Gottesman
361e63c815 [irgen] Make HasAArch64TBI an IRGen option instead of a LangOpts.
With some changes that I am making, we will no longer need this flag at the SIL
level, so we can just make it an IRGen flag (which it really should have been
in the first place).
2025-09-27 14:44:36 -05:00
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Allan Shortlidge
fba664c082 Revert "Frontend: Require explicit language mode when emitting swiftinterfaces."
This reverts commit 9067051c29.
2025-09-25 08:02:18 -07:00
Kavon Farvardin
a44bf30141 Merge pull request #84476 from kavon/manual-ownership/usability-fixes-1
Usability improvements for ManualOwnership (aka "explicit copies mode")
2025-09-23 22:47:22 -07:00
Kavon Farvardin
c20ed75d19 ManualOwnership: imply MandatoryCopyPropagation
The usability of the feature depends on running
MandatoryCopyProp, which is in development.
2025-09-23 16:35:08 -07:00
Artem Chikin
391a18d56a Merge pull request #84443 from artemcm/RestrictEmbeddedToBinarySwift
[Dependency Scanning] Avoid querying Swift Overlay for underlying module
2025-09-23 18:41:47 -04:00
Doug Gregor
0737723c5c Merge pull request #84465 from DougGregor/has-feature-library-evolution
Add an optional language feature for Library Evolution
2025-09-23 15:18:48 -07:00
Doug Gregor
90a5a0f87d Merge pull request #84410 from DougGregor/internal-import-bridging-header 2025-09-22 23:09:07 -07:00
Doug Gregor
c68ef1cf71 Add an optional language feature for Library Evolution
Replace the one-off compiler flag for Library Evolution with an
optional language feature. This makes the
`hasFeature(LibraryEvolution)` check work in an `#if`, and is
otherwise just cleanup.

Tracked by rdar://161125572.
2025-09-22 17:45:34 -07:00
Artem Chikin
7803fe2eef [Embedded] Restrict embedded compilation mode to load serialized binary modules only 2025-09-22 14:14:05 -07:00
Kavon Farvardin
889baf7f2c Merge pull request #84411 from kavon/copyprop-onone
sil: provide ability to run CopyPropagation in -Onone
2025-09-19 22:09:59 -07:00
Henrik G. Olsson
7fcc72f108 Merge pull request #81859 from swiftlang/swiftify-inherit-imports
[MacrosOnImports][Swiftify] Copy module imports from clang node's module to its Swift macro SourceFile
2025-09-19 21:21:09 -07:00
Doug Gregor
b9f00ef923 Warn about the use of internal bridging headers without library evolution
It's very, very easy to make a mistake that will cause broken
serialized modules. Until that's no longer true, at least tell folks
that they are heading into uncharted waters, as we do with
`@_implementationOnly` imports.
2025-09-19 16:49:22 -07:00
Doug Gregor
2383d7ab2d Introduce "-internal" variant of bridging header import flags
The flags "-import-bridging-header" and "-import-pch" import a bridging
header, treating the contents as a public import. Introduce
"internal-" variants of both flags that provide the same semantics,
but are intended to treat the imported contents as if they came in
through an internal import. This is just plumbing of the options for
the moment.
2025-09-19 16:49:11 -07:00
Doug Gregor
ffa6d65f12 [Options] Make -import-bridging-header the canonical spelling instead of -import-objc-header
This command-line option hasn't been Objective-C specific ever, really.
Make the language-independent spelling the primary one to make that
more obvious.
2025-09-19 16:49:11 -07:00
Kavon Farvardin
4a943d464d sil: provide ability to run CopyPropagation in -Onone
This does not enable it by default. Use either of the flags:

```
-enable-copy-propagation
-enable-copy-propagation=always
```

to enable it in -Onone. The previous frontend flag
`-enable-copy-propagation=true` has been renamed to
`-enable-copy-propagation=optimizing`, which is currently default.

rdar://107610971
2025-09-19 16:23:19 -07:00
Slava Pestov
2deb5ff0a5 Sema: Add -solver-{enable,disable}-prepared-overloads frontend flags 2025-09-18 15:05:43 -04:00
Doug Gregor
5a46664954 Merge pull request #84359 from DougGregor/diagnose-untyped-throws-in-embedded 2025-09-18 06:11:55 -07:00