Commit Graph

2173 Commits

Author SHA1 Message Date
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
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
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
Hamish Knight
7f6a4da04e Merge pull request #85062 from hamishknight/not-the-bees 2025-10-23 22:39:58 +01: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
Meghana Gupta
a0c939bd3b Use @inout result convention for mutate accessors 2025-10-20 09:05:32 -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
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
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
Allan Shortlidge
4e9a883824 AST: Rename SwiftLanguage availability domain kind to SwiftLanguageMode. 2025-10-08 15:46:34 -07:00
Slava Pestov
0d90b62491 AST: Clean up in preparation for non-canonical archetypes 2025-10-08 15:15:43 -04:00
Hamish Knight
954b08cae5 [AST] Remove UnresolvedType
We have now removed all uses of this type.
2025-10-03 09:50:42 +01:00
Mishal Shah
03a599c5be Merge pull request #84606 from swiftlang/rebranch
Merge clang 21.x rebranch into main
2025-10-02 20:17:05 -07:00
Alejandro Alonso
dd006e073a Serialize isAddressable on param decls 2025-10-01 11:07:48 -07:00
Gábor Horváth
e8784b8c10 Merge pull request #83827 from Xazax-hun/const-ref-crash-take-4
[SILGen] Fix the type of closure thunks that are passed const references
2025-10-01 09:56:06 +01:00
swift-ci
d5a03fa0e4 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-26 22:36:42 -07:00
Erik Eckstein
a322fd9209 Serialization: remove the IS_OSSA flag from the module file header 2025-09-26 08:01:08 +02:00
swift-ci
0d2c4ca9be Merge remote-tracking branch 'origin/main' into rebranch 2025-09-15 10:29:21 -07:00
Meghana Gupta
1cff471c57 Introduce ResultConvention::Guaranteed and ResultConvention::GuaranteedAddress
ResultConvention::Guaranteed will be used by borrow accessors when the storage type can be returned by value.

ResultConvention::GuaranteedAddress will be used by mutate accessors and borrow accessors when the storage type
cannot be returned by value.
2025-09-09 14:45:40 -07:00
Meghana Gupta
9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
Gabor Horvath
f26749245b [SILGen] Fix the type of closure thunks that are passed const reference structs
This PR is another attempt at landing #76903. The changes compared to
the original PR:
* Instead of increasing the size of SILDeclRef, store the necessary type
  information in a side channel using withClosureTypeInfo.
* Rely on SGFContext to get the right ClangType
* Extend BridgingConversion with an AbstractionPattern to store the
  original clang type.
* The PR above introduced a crash during indexing system modules that
  references foreign types coming from modules imported as
  implementation only. These entities are implementation details so they
  do not need to be included during serialization. This PR adds a test
  and adds logic to exclude such clang types in the serialization
  process.

rdar://131321096&141786724
2025-09-09 12:07:52 +01:00
swift-ci
a99470e579 Merge remote-tracking branch 'origin/main' into rebranch 2025-09-08 07:13:18 -07:00
Richard Howell
7296b28b08 Debug prefix macro search paths
Macro search paths are generally absolute paths which will cause
non-deterministic output for build systems that build remotely.
When the -prefix-serialized-debugging-options flag is set remap
the macro search paths as well as the other debug paths.
2025-09-05 14:09:23 -07:00
swift-ci
07b17d605e Merge remote-tracking branch 'origin/main' into rebranch 2025-09-04 06:17:38 -07:00
Doug Gregor
ed93b46fa6 [Embedded] Introduce DeferredCodeGen feature.
Introduce an experimental feature DeferredCodeGen, that defers the
generation of LLVM IR (and therefore object code) for all entities
within an Embedded Swift module unless they have explicitly requested
to not be emitted into the client (e.g., with
`@_neverEmitIntoClient`).

This feature is meant to generalize and subsume
-emit-empty-object-file, relying on lazy emission of entities rather
than abruptly ending the compilation pipeline before emitting any IR.

Part of rdar://158363967.
2025-09-03 15:55:47 -07:00
swift-ci
38dbbf0747 Merge remote-tracking branch 'origin/main' into rebranch 2025-08-08 12:54:14 -07:00
Pavel Yaskevich
4e445d1483 Merge pull request #83556 from xedin/rename-nonisolated-caller-to-nonsending
[AST] NFC: Rename function type isolation `NonisolatedCaller` to `Non…
2025-08-08 09:37:17 -07:00
Anthony Latsis
ece73d8004 Manually merge remote-tracking branch 'origin/main' into rebranch
Conflicts:
-	include/swift/AST/Decl.h
2025-08-07 15:31:16 +01:00
Allan Shortlidge
78f50ba741 AST: Refactor ConditionallyAvailableSubstitutions to use AvailabilityQuery.
Conditionally available opaque return types should support availability
conditions that are evaluated in any availability domain. Update
`ConditionallyAvailableSubstitutions` to model its conditions with
`AvailabilityQuery` instead of assuming that conditions are always a single
version query for the current platform.
2025-08-06 18:01:10 -07:00
Pavel Yaskevich
53ef38e31b [AST] NFC: Rename function type isolation NonisolatedCaller to NonisolatedNonsending
This reduces the number of ways we refer to caller isolated async
functions and matches the name to the attribute spelling.
2025-08-05 17:22:10 -07:00
swift-ci
3998a187f9 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-30 09:36:41 -07:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
swift-ci
3787a312d7 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-15 17:17:19 -07:00
Allan Shortlidge
d09e117dc0 AST: Canonicalize platform versions for @backDeployed attrs.
Also, diagnose invalid platform versions.

Part of rdar://155558161.
2025-07-14 16:40:16 -07:00
Allan Shortlidge
910989c2c2 AST: Store parsed version in OriginallyDefinedInAttr instead of canonical.
Canonicalize the version on-demand instead.

NFC, part of rdar://155558161.
2025-07-14 16:04:04 -07:00
swift-ci
2b8612c203 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-08 00:16:43 -07:00
Pavel Yaskevich
43eec8fede [AST/Sema] SE-0487: Expand @nonexhaustive attribute to support warn argument
The spelling `@nonexhaustive(warn)` replaces `@preEnumExtensibility`
attriubte.
2025-07-04 10:20:25 -07:00
swift-ci
d5a8982db5 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-01 00:37:27 -07:00