Commit Graph

47728 Commits

Author SHA1 Message Date
John McCall
7a6ee1134c [NFC] Add a utility function for testing for a specific BuiltinInst 2025-11-03 13:44:18 -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
John McCall
8d231d20c6 Rewrite StackNesting to be a non-iterative single-pass algorithm.
The previous algorithm was doing an iterative forward data flow analysis
followed by a reverse data flow analysis. I suspect the history here is that
it was a reverse analysis, and that didn't really work for infinite loops,
and so complexity accumulated.

The new algorithm is quite straightforward and relies on the allocations
being properly jointly post-dominated, just not nested. We simply walk
forward through the blocks in consistent-with-dominance order, maintaining
the stack of active allocations and deferring deallocations that are
improperly nested until we deallocate the allocations above it. The only
real subtlety is that we have to delay walking into dead-end regions until
we've seen all of the edges into them, so that we can know whether we have
a coherent stack state in them. If the state is incoherent, we need to
remove any deallocations of previous allocations because we cannot talk
correctly about what's on top of the stack.

The reason I'm doing this, besides it just being a simpler and hopefully
faster algorithm, is that modeling some of the uses of the async stack
allocator properly requires builtins that cannot just be semantically
reordered. That should be somewhat easier to handle with the new approach,
although really (1) we should not have runtime functions that need this and
(2) we're going to need a conservatively-correct solution that's different
from this anyway because hoisting allocations is *also* limited in its own
way.

I've attached a rather pedantic proof of the correctness of the algorithm.

The thing that concerns me most about the rewritten pass is that it isn't
actually validating joint post-dominance on input, so if you give it bad
input, it might be a little mystifying to debug the verifier failures.
2025-11-03 11:51:17 -08:00
Aidan Hall
0b342ded1c Merge pull request #85237 from aidan-hall/dedup-erase
DebugUtils: Remove eraseFromParentWithDebugInsts
2025-11-03 14:46:18 +00:00
Hamish Knight
6a0278c59f [Sema] NFC: Remove GetDistributedMethodWitnessedProtocolRequirements (#85274)
This has been unused for over a year now (since #71801), let's just
remove it.
2025-11-03 06:10:23 -08:00
Jamie
c2a42e28f7 [NFC][Diagnostics]: remove a number of unused diagnostics 2025-11-03 07:39:12 -06:00
Doug Gregor
1bae4da121 [Deserialization] Require labels to match when looking for closely-matching clang declarations 2025-11-02 08:32:50 -08:00
Doug Gregor
ba507ab822 Merge pull request #85203 from DougGregor/clang-decl-asmname 2025-11-01 20:46:50 -07:00
Allan Shortlidge
1bf2e8ffb6 Merge pull request #85256 from tshortli/any-apple-os-availability
AST: Introduce experimental support for an `anyAppleOS` availability domain
2025-11-01 11:10:09 -07: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
Steven Wu
a0553cf007 Merge pull request #85254 from cachemeifyoucan/eng/PR-fix-swift-driver-flag
[Options] Add missing `-sil-output-dir` and `ir-output-dir` flag
2025-10-31 18:20:40 -07: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
0b344f8c9c Merge pull request #85250 from cachemeifyoucan/eng/PR-162547707
[CAS] Add `-no-cache-compile-job` frontend option
2025-10-31 16:47:34 -07:00
Allan Shortlidge
3b77e2e64a AST: Introduce experimental support for an anyAppleOS availability domain.
`anyAppleOS` represents a meta-platform for availability checks that can be
used to check availability across all of Apple's operating systems. It
supports versions 26.0 and up since version 26.0 is the first OS version number
that is aligned accross macOS, iOS, watchOS, tvOS, and visionOS.

Apple platform-specific availability specification take precedence over
`anyAppleOS` availability specifications when specified simultaneously.

Resolves rdar://153834380.
2025-10-31 15:21:30 -07:00
Henrik G. Olsson
87af5538d3 Merge pull request #84871 from hnrklssn/inherit-literal-std
[ImportResolution] Only disallow explicit `std` imports (allow implicit)
2025-10-31 14:22:16 -07:00
Steven Wu
8d0fd383a0 [Options] Add missing -sil-output-dir and ir-output-dir flag
The swift-driver flags need to be declared in Options.td. Add the
missing driver flags in swift-driver#1995
2025-10-31 12:57:47 -07:00
Joe Groff
e002d96ac9 Merge pull request #85169 from jckarter/builtin-generic-base-class
Add a BuiltinGenericType base class.
2025-10-31 12:45:58 -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
Doug Gregor
5d576470fd [IRGen] Detect duplicate definitions at the IR level 2025-10-31 10:32:54 -07:00
Aidan Hall
b353bb302f DebugUtils: Remove eraseFromParentWithDebugInsts
There is another near-identical function in DebugOptUtils.h that can be used
everywhere this function is used, and offers more flexibility in its callback
interface.
2025-10-31 13:47:22 +00:00
Aidan Hall
a8cef4451a Merge pull request #84513 from aidan-hall/pack-opt
Optimize Specializations of Variadic Generics by Eliminating Parameter Packs
2025-10-31 11:24:04 +00:00
Alexis Laferrière
048c9276a9 Merge pull request #85122 from xymus/official-c-attr
SE-495: Make `@c` an official feature
2025-10-30 16:06:25 -07:00
Susana Monteiro
a6f4e415cb Merge pull request #84646 from susmonteiro/susmonteiro/implicit-copy-constructors
[cxx-interop] Implicitly defined copy constructors
2025-10-30 19:36:43 +00:00
Aidan Hall
8632e58825 Create Pack Specialisation pass 2025-10-30 14:28:16 +00:00
susmonteiro
1c5bbe0290 [cxx-interop] Implicitly defined copy constructors 2025-10-30 14:17:19 +00:00
Nate Chandler
e0ead75622 [CoroutineAccessors] Use typed-malloc. 2025-10-30 03:59:18 -07:00
Nate Chandler
7bf535c546 [Gardening] IRGen: Delete this xmacro entry.
The swift_coroFrameAllocStub function isn't in the runtime.
2025-10-30 03:59:17 -07:00
Doug Gregor
f267f62f65 [SILGen] Consistently use SIL asmname for foreign function/variable references
Whenever we have a reference to a foreign function/variable in SIL, use
a mangled name at the SIL level with the C name in the asmname
attribute. The expands the use of asmname to three kinds of cases that
it hadn't been used in yet:

* Declarations imported from C headers/modules
* @_cdecl @implementation of C headers/modules
* @_cdecl functions in general

Some code within the SIL pipeline makes assumptions that the C names of
various runtime functions are reflected at the SIL level. For example,
the linking of Embedded Swift runtime functions is done by-name, and
some of those names refer to C functions (like `swift_retain`) and
others refer to Swift functions that use `@_silgen_name` (like
`swift_getDefaultExecutor`). Extend the serialized module format to
include a table that maps from the asmname of functions/variables over
to their mangled names, so we can look up functions by asmname if we
want. These tables could also be used for checking for declarations
that conflict on their asmname in the future. Right now, we leave it
up to LLVM or the linker to do the checking.

`@_silgen_name` is not affected by these changes, nor should it be:
that hidden feature is specifically meant to affect the name at the
SIL level.

The vast majority of test changes are SIL tests where we had expected
to see the C/C++/Objective-C names in the tests for references to
foreign entities, and now we see Swift mangled names (ending in To).
The SIL declarations themselves will have a corresponding asmname.

Notably, the IRGen tests have *not* changed, because we generally the
same IR as before. It's only the modeling at the SIL lever that has
changed.

Another part of rdar://137014448.
2025-10-29 19:35:55 -07:00
Alexis Laferrière
94113f4a83 SE-496: Remove references to features CDecl and CImplementation 2025-10-29 17:31:20 -07:00
Hamish Knight
6a7bf6fef5 Merge pull request #85188 from hamishknight/tuple-trouble
[CS] Upgrade a couple of tuple warnings to error for future lang mode
2025-10-29 23:34:22 +00:00
Becca Royal-Gordon
89ecc5ab2a [NFC] Pipe PrintDiagnosticNames through swiftinterface loader 2025-10-29 15:19:51 -07:00
Artem Chikin
1b38c919c7 Merge pull request #85098 from artemcm/DefaultIgnoreDiagnosticGroups
[Diagnostics] Replace diagnostics' `DefaultIgnore` option with a corresponding option on diagnostic groups
2025-10-29 18:10:32 -04:00
Alexis Laferrière
bce585c133 SE-495: Make CImplementation an official feature 2025-10-29 11:55:51 -07:00
Alexis Laferrière
000c2604b0 SE-495: Make @c an official feature 2025-10-29 11:55:41 -07:00
Artem Chikin
9e35f82b2c [Diagnostics] Replace diagnostics' 'DefaultIgnore' option with a corresponding option on diagnostic groups
This brings this control in line with other diagnostic controls we have which operate on a per-group level.
'DefaultIgnoreWarnings' diagnostic group option applies to all warnings belonging to a certain diagnostic group.

The inheritance rules are:
- Marking a diagnostic group as 'DefaultIgnoreWarnings' means warnings belonging to this group will not be emitted by-default
  - Warnings belonging to sub-groups of this group will also not be emitted by-default
- Enabling a 'DefaultIgnoreWarnings' group (with '-Werror','-Wwarning', etc.) means warnings belonging to this group will be emitted.
  - Warnings belonging to sub-groups of this group will also be emitted.
  - Warnings belonging to super-groups of this group will not be affected.
2025-10-29 09:42:03 -07:00
Hamish Knight
00d8774032 [Sema] Upgrade tuple shuffle warning to error in future lang mode
This has been deprecated for a while now, flip it to an error for a
future language mode.
2025-10-29 15:14:23 +00:00
Hamish Knight
24347812f5 [Diag] Reword the tuple shuffle diagnostic
"reorder" seems a bit less jargony than "shuffle", and include the 
labels that are being reordered.
2025-10-29 15:14:23 +00:00
Hamish Knight
1781faba1a [CS] Upgrade tuple label mismatch warning to error for future lang mode
I missed upgrading this to an error for Swift 6 mode, let's upgrade it
to an error for a future language mode. It's important we reject these
cases since we're otherwise allowing subtyping to be a weaker constraint
than conversion.
2025-10-29 15:14:23 +00:00
Yuta Saito
3e834ccf9f Merge pull request #85106 from kateinoigakukun/yt/fix-dead-stub-comdat-wasm
[wasm][IRGen] Stop attaching COMDATs to dead stub methods
2025-10-29 15:29:48 +09:00
Yuta Saito
50298bd8e5 [wasm][IRGen] Stop attaching COMDATs to dead stub methods
When generating dead stub methods for vtable entries, we should not
attach COMDATs to their definitions. This is because such stubs may be
referenced only through aliases, and the presence of a COMDAT on the
stub definition would cause the aliased symbol, we want to keep, to be
discarded from the symbol table when other object files also have a
dead stub method.

Given the following two object files generated:

```mermaid
graph TD
    subgraph O0[A.swift.o]
        subgraph C0[COMDAT Group swift_dead_method_stub]
            D0_0["[Def] swift_dead_method_stub"]
        end
        S0_0["[Symbol] swift_dead_method_stub"] --> D0_0
        S1["[Symbol] C1.dead"] --alias--> D0_0
    end

    subgraph O1[B.swift.o]
        subgraph C1[COMDAT Group swift_dead_method_stub]
            D0_1["[Def] swift_dead_method_stub"]
        end
        S0_1["[Symbol] swift_dead_method_stub"] --> D0_1
        S2["[Symbol] C2.beef"] --alias--> D0_1
    end
```

When linking these two object files, the linker will pick one of the
COMDAT groups of `swift_dead_method_stub`. The other COMDAT group will be
discarded, along with all symbols aliased to the discarded definition,
even though those aliased symbols (`C1.dead` and `C2.beef`) are the
ones we want to keep to construct vtables.

This change stops attaching COMDATs to dead stub method definitions.
This effectively only affects WebAssembly targets because MachO's
`supportsCOMDAT` returns false, and COFF targets don't use
`linkonce_odr` for dead stub methods.

The COMDAT was added in 7e8f782457
2025-10-29 01:17:38 +00:00
Becca Royal-Gordon
393965090e Merge pull request #34556 from beccadax/mod-squad-2
[SE-0491] Implement lookup and diagnostics for module selectors (MyMod::someName)
2025-10-28 16:00:26 -07:00
Joe Groff
cf5f7c8637 Add a BuiltinGenericType base class.
Builtin.FixedArray was introduced as the first generic builtin type, with
special case handling in all the various recursive visitors. Introduce
a base class, and move the handling to that base class, so it is easier
to introduce other generic builtins in the future.
2025-10-28 12:48:18 -07:00
Allan Shortlidge
2887334ffb Merge pull request #85167 from tshortli/new-platform-kinds
AST: Introduce the `Swift`, `anyAppleOS`, and `DriverKit` platform kinds
2025-10-28 11:21:38 -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
Allan Shortlidge
92227ad1cf AST: Introduce the Swift, anyAppleOS, and DriverKit platform kinds.
This change just stages in a few new platform kinds, without fully adding
support for them yet.

- The `Swift` platform represents availability of the Swift runtime across all
  platforms that support an ABI stable Swift runtime (see the pitch at
  https://forums.swift.org/t/pitch-swift-runtime-availability/82742).
- The `anyAppleOS` platform is an experimental platform that represents all of
  Apple's operating systems. This is intended to simplify writing availability
  for Apple's platforms by taking advantage of the new unified OS versioning
  system announced at WWDC 2025.
- The `DriverKit` platform corresponds to Apple DriverKit which is already
  supported by LLVM.
2025-10-27 19:15:04 -07:00
Slava Pestov
233b334a47 Sema: Enable prepared overloads by default
This can be turned off with -solver-disable-prepared-overloads.
2025-10-27 21:42:11 -04:00
Hamish Knight
b47ab91547 Merge pull request #85149 from hamishknight/fail-n-bail
[CS] Propagate CSApply failures in a few more places
2025-10-27 16:58:03 +00: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
Augusto Noronha
d7a42a05b7 Merge pull request #85091 from augusto2112/remote-mirr-indirect-addr
[RemoteMirrors] Add hook for resolving indirect addresses
2025-10-27 08:02:02 -07:00
Hamish Knight
05e3d15955 [CS] Propagate CSApply failures in a few more places
We had some cases where we weren't propagating failures to apply the
solution, and as such weren't invalidating the resulting AST. Fix up
these cases.
2025-10-26 14:49:17 +00:00