5233 Commits

Author SHA1 Message Date
Alexis Laferrière
175d0ba8e6 Serialization: Minor improvements to the error on conformance mismatch
Clarify the sources of information when a conformance reference in a
swiftmodule doesn't match with the requirements seen by the reader.
2025-12-10 15:08:03 -08:00
Hamish Knight
302e803b2f [AST] Store original lazy VarDecl for backing storage
Store the original VarDecl in the same map we use for tracking the
original wrapper var for property wrappers. This will allow us to
use the same logic to determine the original var for both.
2025-12-08 23:22:35 +00:00
Anthony Latsis
153dd02cd8 Merge pull request #85833 from swiftlang/jepa-main
[NFC] "SwiftVersion" → "LanguageMode" in `DiagnosticEngine::warnUntilSwiftVersion`, etc.
2025-12-05 09:34:30 +00:00
Anthony Latsis
88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Doug Gregor
e888395a26 Fix typo in deserialization error name 2025-12-02 12:12:52 -08:00
Doug Gregor
e624915ed9 [Custom availability] Serialize custom domains described on the command line
When a custom domain is described on the command line, there is no
backing declaration for it. Serialize such custom domains by
identifier and look them up globally at the point of deserialization.
When that fails, warn and drop the annotation.

This is all a stopgap until we have a way to spell custom availability
domains in the Swift language itself.
2025-12-02 12:12:50 -08:00
Michael Gottesman
29229a9410 [sil] Add basic SIL support for alloc_stack [non_nested].
This means I just added the flag and added support for
cloning/printing/serializing the bit on alloc_stack.
2025-11-21 11:21:14 -08:00
Slava Pestov
27097430cc Serialization: Lazily deserialize OpaqueTypeDecl's underlying substitutions
We need to serialize the underlying type substitution map for an
inlinable function. However, there is no reason to deserialize it
eagerly, since doing so can lead to cycles. It is better for
correctness and performance to only deserialize it when needed.

Technically this fixes a regression from #84299, but the actual
problem was there all along, it was just exposed by my change
on a specific project.

Fixes rdar://163301203.
2025-11-20 18:13:50 -05:00
Adrian Prantl
5c3a26633a Merge pull request #85519 from adrian-prantl/unregister-api
[LLDB] Add an API for unregistering MemoryBuffer modules (NFC)
2025-11-18 08:27:05 -08:00
Adrian Prantl
addff767a6 [LLDB] Add an API for unregistering MemoryBuffer modules (NFC) 2025-11-14 13:51:30 -08:00
Anthony Latsis
dd5ac838e5 AST: Properly disallow isa/cast/dyn_cast on Type
We currently disallow these by deleting them in the `swift` namespace.
This approach has several loopholes, all of which ultimately work
because we happen to define specializations of `simplify_type` for
`swift::Type`:
* `llvm::isa/cast/dyn_cast`. The deleted partial specializations will
  not be selected because they are not defined in the `llvm` namespace.
* The argument is a non-const `Type`. The deleted function templates
  will not be selected because they all accept a `const Type &`, and
  there is a better `Y &Val` partial specialization in LLVM.
* Other casting function templates such as `isa_and_nonull` and
  `cast_if_present` are not deleted.

Eliminate these loopholes by instead triggering a static assertion
failure with a helpful message upon instantiation of `CastInfo` for
`swift::Type`.
2025-11-14 19:02:41 +00:00
Slava Pestov
64f2d1acce AST: Rename mapConformanceOutOfContext() => mapConformanceOutOfEnvironment(), mapReplacementTypesOutOfContext() => subs.mapReplacementTypesOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Alexis Laferrière
937e6c5241 Merge pull request #85446 from xymus/serial-xref-check
Serialization: Error on leaked cross-references to `@_implementationOnly` dependencies
2025-11-12 10:42:58 -08:00
Pavel Yaskevich
47805810be [AST/Serialization] Remove isCallerIsolated bit from ParamDecl
This was used primarily by the printer and doesn't work when
`nonisolated(nonsending)` is inferred, so let's remove it.
2025-11-11 16:07:19 -08:00
Alexis Laferrière
5a49e34426 Serialization: Error on xref to implementation-only dependencies
Introduce a last resort check reporting references to
implementation-only dependencies that would appear in the generated
swiftmodule. This check is applied at serialization, long after
exportability checking applied at typechecking. It should act as a back
stop to references missed by typechecking or @_implementationOnly decls
that should have been skipped.

This check is gated behind CheckImplementationOnlyStrict and should be
used with embedded only.

rdar://160697599
2025-11-11 13:03:16 -08:00
Alexis Laferrière
ac41fb60ff Serialization: Skip implementation-only witness tables 2025-11-11 13:03:16 -08:00
Alexis Laferrière
810c418829 Serialization: Option to skip writing decls marked @_implementationOnly 2025-11-11 13:03:15 -08:00
Alexis Laferrière
e2b0d53efe Serialization: Pass down the options to SILSerializer 2025-11-11 10:26:00 -08:00
Doug Gregor
020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08: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
38c23bcdda [Serialization] Allow near-misses when matching imported Clang declarations
Fixes the rest of rdar://137014448.
2025-11-02 07:21:15 -08:00
Doug Gregor
5d576470fd [IRGen] Detect duplicate definitions at the IR level 2025-10-31 10:32:54 -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
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
Hamish Knight
7f6a4da04e Merge pull request #85062 from hamishknight/not-the-bees 2025-10-23 22:39:58 +01:00
Meghana Gupta
1dc5c9611c Intoduce unchecked_ownership instruction in raw SIL
This instruction can be used to disable ownership verification on it's result and
will be allowed only in raw SIL.

Sometimes SILGen can produce invalid ownership SSA, that cannot be resolved until
mandatory passes run. We have a few ways to piecewise disable verification.
With unchecked_ownership instruction we can provide a uniform way to disable ownership
verification for a value.
2025-10-23 05:19:08 -07:00
Meghana Gupta
e116df3628 Introduce return_borrow instruction 2025-10-23 05:18:59 -07:00
Hamish Knight
169096c233 [AST] Rename mangleDeclAsUSR -> mangleDeclWithPrefix
This is used by other things that don't necessarily want an IDE
USR.
2025-10-23 09:11:17 +01:00
Adrian Prantl
a3529784a5 Merge pull request #84412 from adrian-prantl/159531233
Serialize module dependencies in swift module files
2025-10-22 16:25:57 -07:00
Allan Shortlidge
463bf91f68 AST: Rename Swift runtime availability domain to StandaloneSwiftRuntime.
This name will distinguish the standalone Swift runtime availability domain
from the domain for the built-in Swift runtime on supported targets.
2025-10-21 21:55:25 -07:00
Adrian Prantl
c91211a5d2 Serialize explicit module dependencies in swift module files
For clients, such as the debugger, who do not have access the full
output of the dependency scanner, it is a huger performance and
correctness improvement if each explicitly built Swift module not just
serialized all its Clang .pcm dependencies (via the serialized Clang
compiler invocation) but also its direct Swift module dependencies.

This patch changes the Swift module format to store the absolute path
or cas cache key for each dependency in the INPUT block, and makes
sure the deserialization makes these available to the ESML.

rdar://150969755
2025-10-21 09:08:58 -07:00
Alexis Laferrière
afcbd35868 Merge pull request #84958 from xymus/deser-witness
Serialization: Fix null dereference in witness deserialization
2025-10-20 15:11:23 -07:00
Meghana Gupta
a0c939bd3b Use @inout result convention for mutate accessors 2025-10-20 09:05:32 -07:00
Michael Gottesman
a9d409d526 Merge pull request #83346 from gottesmm/pr-df6aafa41c61b9a9a6ee4965a1564ec2946a0dc9
[concurrency] Change #isolated to mask out the TBI bits of the witness pointer of the implicit isolated any Actor pointer so we can do optimizations on TBI supporting platforms in the future.
2025-10-17 17:02:43 -07:00
Doug Gregor
39a36d9216 Merge pull request #84948 from DougGregor/extern-c-asmname
[SILGen] Map the @_extern(c) C function name over to the asmname of a SIL function
2025-10-16 18:27:00 -07:00
Michael Gottesman
fe9c21fd87 [sil] Add a new instruction cast_implicit_actor_to_optional_actor.
This instruction converts Builtin.ImplicitActor to Optional<any Actor>. In the
process of doing so, it masks out the bits we may have stolen from the witness
table pointer of Builtin.ImplicitActor. The bits that we mask out are the bottom
two bits of the top nibble of the TBI space on platforms that support TBI (that
is bit 60,61 on arm64). On platforms that do not support TBI, we just use the
bottom two tagged pointer bits (0,1).

By using an instruction, we avoid having to represent the bitmasking that we are
performing at the SIL level and can instead just make the emission of the
bitmasking an IRGen detail. It also allows us to move detection if we are
compiling for AArch64 to be an IRGen flag instead of a LangOpts flag.

The instruction is a guaranteed forwarding instruction since we want to treat
its result as a borrowed projection from the Builtin.ImplicitActor.
2025-10-16 10:52:04 -07:00
Hamish Knight
81e324efa6 Merge pull request #84916 from hamishknight/mac-n-cheese 2025-10-16 16:50:24 +01:00
Doug Gregor
1ca9235de6 [Serialization] Record the new SIL_EXTRA_STRING block
Also fix up a test
2025-10-16 08:00:40 -07:00
Hamish Knight
364eba482d [AST] Use CustomAttr's DeclContext for ResolveMacroRequest
Remove the DeclContext parameter from ResolveMacroRequest, we can now
retrieve the DeclContext either from the CustomAttr or macro expansion
expr/decl directly.
2025-10-16 11:21:54 +01:00
Hamish Knight
73710e3eef [AST] Introduce Decl::addAttribute
Introduce a convenience entrypoint that also calls `attachToDecl` on
the attribute, and migrate all existing uses of `getAttrs().add` onto
it.
2025-10-16 11:21:54 +01:00
Hamish Knight
0358e1eadd [AST] Consolidate attribute attachment logic
Introduce `DeclAttribute::attachToDecl` which is the now the main
entry point for associating an attribute with a decl. Different
attributes can implement `attachToDeclImpl` to add their custom logic.
Move DifferentiableAttr, DerivativeAttr, CustomAttr, and ABIAttr over
to this new logic.
2025-10-16 11:21:54 +01:00
Doug Gregor
4c33e7538d Merge pull request #84939 from DougGregor/sil-asmname-and-section
[SIL] Add asmname attribute to SIL functions and global variables
2025-10-16 02:09:48 -07:00
Artem Chikin
70341f4802 Merge pull request #84942 from artemcm/DowngradeIncompatBinModDepToWarning
[Dependency Scanning] Warn, instead of fail, when a Swift dependency query only finds modules built for incompatible target
2025-10-16 01:26:09 -04:00
Doug Gregor
081b5cd1e8 [SIL] Serialize section name correctly and model it on global variables
Fixes rdar://162549960.
2025-10-15 20:44:11 -07:00
Doug Gregor
3e1ea3c0f7 [SIL] Add asmname attribute to SIL functions and global variables
The asmname attribute allows one to specify the name that will be used
when lowering a given SIL declaration to LLVM IR. It is not currently
exposed in the surface language.

Make sure this attribute round-trips through the parser and
serialization.

Part of rdar://137014448O.
2025-10-15 20:44:09 -07:00
Artem Chikin
d699e2fc49 [Dependency Scanning] Warn, instead of fail, when a Swift dependency query only finds modules built for incompatible target
We have adopters who are relying on directly importing the underlying Clang module in the presence of incompatible Swift modules.

Resolves rdar://162549210
2025-10-15 16:58:50 -07:00
Alexis Laferrière
1db5ad0c4c Serialization: Fix null dereference in witness deserialization
Fix null dereference in deserialization logic for conformances. If
deserializing the witness itself failed, don't try to
get its actor isolation.

rdar://162158608
2025-10-14 16:39:54 -07:00
Hamish Knight
2b8a1cccfd [AST] Store owning Decl/DeclContext on CustomAttr
Introduce CustomAttrOwner that can store either a Decl for an
attached attribute, or a DeclContext for e.g a type or closure
attribute. Store this on CustomAttr such that we can query it from
the name lookup requests.
2025-10-13 13:37:29 +01: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