Commit Graph

350 Commits

Author SHA1 Message Date
Xi Ge 08776427a1 [AST] Introduce HiddenType for mangled-name placeholders
HiddenType is a new TypeBase subclass that carries a mangled name
without leaking the actual type definition. It serves as a type-slot
placeholder for stored-property types that have been elided from a
serialized binary module, so that the client side can either

(1) resolve this mangled name to the real type if the client has access to the owning module, or

(2) use the mangled name as a key to query abstract layout information also serialized in the binary module.

As an example — a library with a hidden field of a bridging-imported type:

```
    // Utility.h (internal bridging header)
    //   typedef struct { int value; } Wrapper;

    public struct S {
      private var w: Wrapper
      public var weight: Double
    }

  In the serialized module, the client's view reconstructs as:

    public struct S {
      private var w: @_hidden("$sSo7Wrappera")
      public var weight: Double
    }
```
2026-05-12 17:13:14 -07:00
Doug Gregor a5a1bcf1ac Merge pull request #88722 from DougGregor/embedded-dynamic-cast
[Embedded] Reimplement dynamic casting for Embedded Swift
2026-04-30 14:24:48 -07:00
Xi Ge 7f0562d9ae Merge pull request #87864 from beccadax/objcimpl-inaccessible-accessor
Fix objcImpl type metadata accessor issue
2026-04-29 15:56:52 -07:00
Pavel Yaskevich 77189ca314 Merge pull request #88335 from ktoso/wip-improve-callee-specific-diagnostics
[Concurrency] Better diagnostic on escaping to @concurrent context
2026-04-28 15:25:13 -07:00
Doug Gregor 29ea399833 [Embedded] Reimplement dynamic casting for Embedded Swift
The Embedded Swift dynamic casting logic was getting a bit tangled, and
used some heuristics for figuring out the existential representation
that didn't always work, e.g., with class-bound types.

Reimplement the entire thing using the same general approach that the
non-Embedded runtime uses, albeit simplified greatly because Embedded
Swift doesn't permit casting to existential types (only *from*
existential types). The new implementation correctly unwraps all levels
of existential, short-circuits where appropriate, and "takes" wherever
possible.

This change does require emitting some more metadata than we did
before, because it is necessary to handle the different existential
representations correctly. Previously, the compiler would pass a NULL
pointer as the "source" metadata to `swift_dynamicCast`, then try to
figure out what it was given by inspecting the source pointer. This is
insufficient for distinguishing the various existential representations
(opaque, class-bound, error) and relied on heuristics. Start passing
destination metadata to this function, just as we do in non-Embedded
Swift. This means we'll end up generating some more metadata for
existential types (like `any P`) that we wouldn't have before, but
it's still pay-per-use and they are relatively small. All of the other
metadata that can flow here will already have been created for other
reasons, e.g., because classes already have it in their vtable.

This also extends the metadata associated with existential types by one
more word (from 2 to 3). The new word is used to provide the
existential representation, which is needed for dynamic casting as
described above.
2026-04-28 15:07:56 -07:00
Konrad Malawski a6617f8801 rename isNonisolatedNonsendingCaller -> isNonisolatedNonsending 2026-04-28 09:21:46 -07:00
Konrad Malawski 2b8026dd94 rename isNonIsolatedCaller -> isNonisolatedNonsendingCaller 2026-04-28 09:21:46 -07:00
Doug Gregor 1be4208e4c [Embedded] Handle metatypes of metatypes 2026-04-27 14:02:03 -07:00
Doug Gregor 46389f7d7e [Embedded] Start allowing metatypes in Embedded Swift
Now that we have generalized existentials in Embedded Swift, we also
have all of the infrastructure for metatypes. They're lazily
constructed on an as-needed basis, but otherwise work the same way as
in non-Embedded Swift.

Fixes rdar://145706221.
2026-04-27 14:02:03 -07:00
Doug Gregor aad51cab01 [Embedded] Remove the ability to disable existentials in Embedded Swift
Support for existentials in Embedded Swift has been available for a
little while now and appears to be solid. Remove the ability to disable
them (via `-disable-experimental-feature EmbeddedExistentials`), both
because it simplifies the code and because it's an ABI break to
disable the feature.
2026-04-17 17:38:01 -07:00
Slava Pestov 3c2720b8bc AST: Introduce JoinType and MeetType singletons
These will be used internally by the type checker to represent bindings
that are the joins and meets of types involving type variables. They
will not appear anywhere outside of the bindings code---so you won't
see them in expressions, or matchTypes(), etc.
2026-03-21 08:48:47 -04:00
Becca Royal-Gordon c83cb66517 Fix objcImpl type metadata accessor issue
Classes that use `@objc @implementation` should be treated exactly like native Objective-C classes. Among other things, this means that rather than the defining module exposing a public type metadata accessor for them, each client should emit its own hidden accessor.

Unfortunately, Swift has not been doing this correctly—the defining module may expose an accessor and any clients which know the class is objcImpl will use it. (Clients using a swiftinterface module, or a swiftmodule built from a swiftinterface, won’t know the class is objcImpl, but clients using the original swiftmodule file will know.) Because existing binaries may be calling this symbol, we can’t remove it, but we *can* at least stop using it.
2026-03-16 15:43:36 -07:00
John McCall abb146fa0c Teach StackAddress to directly express the kind of allocation that was
performed, and simplify and improve the handling of allocation throughout
IRGen.

The improvements are that we used to use dynamic allocas in a few
places that clearly could and should use static allocas.
2026-03-06 03:15:28 -05:00
Michael Gottesman f118042e89 Merge pull request #86829 from gottesmm/pr-ff14cd21e6863ca70bf669d1677136eb30ea259e
[IRGen] Fix crash when getting nonisolated(nonsending) function metadata on older runtimes
2026-01-29 05:36:11 -08:00
Michael Gottesman 223acb337c [IRGen] Fix crash when getting nonisolated(nonsending) function metadata on older runtimes
When compiling for a triple that predates typed throws,
`swift_getFunctionMetadataExtended` is conditionally available and emitted as a
weak external symbol. Previously, when such code ran on a older runtime where
`swift_getFunctionMetadataExtended` was uanvailable, accessing function metadata
for a `nonisolated(nonsending)` function would crash by invoking the null
`swift_getFunctionMetadataExtended`.

This patch adds a runtime null check when emitting metadata accessors for simple
`nonisolated(nonsending)` functions (those without typed throws or other
extended flags) in such situations. If `swift_getFunctionMetadataExtended` is
unavailable at runtime, we fall back to `swift_getFunctionMetadata`, returning
`@concurrent` function metadata instead.

This trade-off is acceptable because:
- Function metadata is not required to call a `nonisolated(nonsending)` function
- This enables use of these functions in frameworks like SwiftUI on older OS versions

Known limitations of the fallback path:
- Dynamic casts between `nonisolated(nonsending)` and `@concurrent` will incorrectly succeed
- Reflection will report `nonisolated(nonsending)` functions as `@concurrent`
- Existential erasure will lose the `nonisolated(nonsending)` attribute

These edge cases will produce obvious crashes during testing if misused, since
`nonisolated(nonsending)` expects its first parameter to be an actor while
`@concurrent` does not. This makes the increased compatibility worth the
trade-off.

rdar://158970802
2026-01-29 00:30:33 -08:00
Alejandro Alonso 632d6f4257 WIP: Dependent borrow layout 2026-01-23 08:02:10 -08:00
Joe Groff bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Arnold Schwaighofer 4d879967a7 [embedded] Feature::EmbeddedExistentials requires Feature::Embedded 2025-12-09 10:21:51 -08:00
Arnold Schwaighofer 36a3c6e611 Merge pull request #85644 from aschwaighofer/wip_embedded_exits_with_eriks_changes_v1
[embedded] Fix associated type conformances for specialized witness tables
2025-12-01 16:40:31 -08:00
Arnold Schwaighofer b9f6454386 [embedded] Add support for storing/casting function types 2025-11-21 14:55:32 -08:00
Slava Pestov bfb6c826c4 Merge pull request #85560 from slavapestov/fix-ridiculous-irgen-thing
IRGen: Remove unsafe usage of static variable
2025-11-20 02:54:38 -05:00
Slava Pestov ca0f310242 IRGen: Remove unsafe usage of static variable
We cannot use 'static' linkage for something that points into the
ASTContext, because there might be more than one ASTContext in a
single process.

Also, fix the spelling mistake in a related function name.
2025-11-19 10:19:18 -05:00
Arnold Schwaighofer a725de5ba6 Address review comments 2025-11-17 15:52:00 -08:00
Arnold Schwaighofer 4285a2169d IRGen: Start support for embedded existentials
Allow storing struct, enum, and tuple types in an any.
2025-11-17 12:46:35 -08:00
Slava Pestov 41ff7383d9 IRGen: Clean up opaque type specialization wrappers 2025-10-23 15:36:54 -04:00
Michael Gottesman 2fa3908e94 [concurrency] Add a new type Builtin.ImplicitActor.
This is currently not wired up to anything. I am going to wire it up in
subsequent commits.

The reason why we are introducing this new Builtin type is to represent that we
are going to start stealing bits from the protocol witness table pointer of the
Optional<any Actor> that this type is bitwise compatible with. The type will
ensure that this value is only used in places where we know that it will be
properly masked out giving us certainty that this value will not be used in any
manner without it first being bit cleared and transformed back to Optional<any
Actor>.
2025-10-16 10:51:13 -07:00
Alejandro Alonso 89052a729a Merge pull request #84655 from Azoy/negative-nancy
[IRGen] Correctly sext instead of zext for negative integer types
2025-10-04 09:18:03 -07:00
Nate Chandler 8332b7c03f [VariadicGenerics] Fix memeffect of metadata accessor call.
Follow up to https://github.com/swiftlang/swift/pull/84635/.

The metadata accessor for a variadic generic type takes as arguments
packs of metadata records and witness tables, and each such pack is
passed in a buffer. So the call to any such accessor is not correctly
annotated memory(none).

rdar://161606892
2025-10-03 09:13:42 -07:00
Alejandro Alonso bb5dfd317c Always use sext 2025-10-02 11:18:56 -07:00
Alejandro Alonso 2b00d3f123 Correctly sext instead of zext for negative integer types 2025-10-02 10:27:44 -07:00
John McCall 64d020ec45 [NFC] Introduce a convenience specialization of CanTypeVisitor that
forwards the paired nominal type methods to common implementations.
2025-09-05 14:02:36 -04:00
Anthony Latsis f8577a2731 IRGen: Address llvm::Type::getPointerTo deprecation
See https://github.com/llvm/llvm-project/pull/113331.
2025-07-21 12:37:15 +01:00
Alejandro Alonso c165509147 Correctly emit inverse proto comps with extended shape symbolic refs 2025-04-30 13:43:01 -07:00
Slava Pestov 9148ae32bd Merge pull request #80482 from slavapestov/abstract-conformance-cleanup
AST: Simplify ProtocolConformanceRef operations a little bit
2025-04-04 10:37:49 -04:00
Slava Pestov a06a4213ef AST: Remove origType parameter from substOpaqueTypesWithUnderlyingTypes() 2025-04-03 17:35:34 -04:00
Augusto Noronha 6abbc0d754 [DebugInfo] Use underlying type of global variables with opaque type
rdar://144881938
2025-03-31 15:52:09 -07:00
Doug Gregor 731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Saleem Abdulrasool c7429f00c3 Merge pull request #79448 from compnerd/addressability
IRGen: adjust addressability of the generic metadata
2025-02-26 08:42:19 -08:00
Pavel Yaskevich 1067ead82c [Mangling] Mangle presence of @execution(caller) in a function type
If `@execution(caller)` attribute is present on a function type,
mark its presence in the mangling with `YC` suffix.
2025-02-19 16:48:41 -08:00
Saleem Abdulrasool c0b612c6b0 IRGen: adjust addressability of the generic metadata
When building on Windows, if the nominal base type is in a non-static
library, we cannot reference the type descriptor directly. As a load is
required, we cannot statically initialise the pattern metadata. Account
for this in the addressability computation.
2025-02-17 15:03:50 -08:00
Anthony Latsis a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Saleem Abdulrasool 5770d59e4d Merge pull request #78427 from compnerd/internals
IRGen: special case VWT emission linkage computation
2025-01-25 08:51:06 -08:00
John McCall 12bdfbf589 Fix a pair of IRGen bugs around materializing function type metadata
with sending results:

- The sending result mangling was added in the 6.0 runtime, so demangling
  cannot be used to produce this metadata when targeting an earlier
  runtime.

- The combination of a sending result with isolation requires the 6.1
  runtime to successfully demangle, due to a bug in the 6.0 demangler.
2025-01-23 02:24:51 -05:00
Saleem Abdulrasool 59e7c1b538 IRGen: special case VWT emission linkage computation
The well known builtin and structural types are strongly defined in the
runtime which is compacted into the standard library. Given that the VWT
is defined in the runtime, it is not visible to the Swift compilation
process and as we do not provide a Swift definition, we would previously
compute the linkage as being module external (`dllimport` for shared
library builds). This formed incorrect references to these variables and
would require thunking to adjust the references.

One special case that we add here is the "any function" type
representation (`@escaping () -> ()`) as we do use the VWT for this type
in the standard library but do not consider it part of the well known
builtin or structural type enumeration.

These errors were previously being swallowed by the build system and
thus escaped from being fixed when the other cases of incorrect DLL
storage were.
2025-01-07 10:45:13 -08:00
Saleem Abdulrasool c052d1b935 IRGen: simplify the stdlib special casing for Windows
Remove `IRGenModule::useDllStorage()` as there is a standalone version
that is available and the necessary information is public from the
`IRGenModule` type. Additionally, avoid the wrapped `isStandardLibrary`
preferring to use the same method off of the public accessors. This
works towards removing some of the standard library special casing so
that it is possible to support both static and dynamic standard
libraries on Windows.
2024-12-16 14:46:38 -08:00
Kuba Mracek 6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Slava Pestov 5190d98e1b Merge pull request #77178 from slavapestov/misc-solver-cleanups
Miscellaneous solver cleanups
2024-10-24 16:52:01 -04:00
Slava Pestov 5e1e18424b AST: Clean up ExistentialLayout for ParameterizedProtocolType 2024-10-22 20:14:44 -04:00
Joe Groff a184782a38 Introduce a Builtin.FixedArray type.
`Builtin.FixedArray<let N: Int, T: ~Copyable & ~Escapable>` has the layout of `N` elements of type `T` laid out
sequentially in memory (with the tail padding of every element occupied by the array). This provides a primitive
on which the standard library `Vector` type can be built.
2024-10-22 16:21:45 -07:00
Allan Shortlidge 02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00