Commit Graph

272 Commits

Author SHA1 Message Date
Doug Gregor 14bc0baecf Introduce the notion of an "effective" code generation model
The code generation model for a particular declaration or conformance
can be defined explicitly with `@export(interface)`,
`@export(implementation)`, or `@inlinable` (for declarations),
indicating where the definition will occur.

Embedded Swift also has some limitations on what can be emitted into
IR. For example, a generic function cannot be `@export(interface)`
because Embedded Swift does not support unspecialized generics.

Compute the effective code generation model based on what was
explicitly specified, the limitations of the model, and the default
code generation model for the given module, which defaults to
"inlinable" but can be made "implementation" by the DeferredCodeGen
feature. Use the effective code generation model for IR- and SIL-level
determinations of linkage and where to emit symbols.
[WIP] Start computing and using the "effective" code generation model

FIXUP linkage of the alias symbol
2026-05-20 08:35:11 -07:00
Doug Gregor f6f379daab [Embedded] Extend @export(interface) to protocol conformances
Protocol conformances normally have shared linkage in Embedded Swift.
However, allow the use of @export(interface) on conformances (by way
of their enclosing nominal type or extension), which will emit the
witness tables for those conformances as strong symbols in the owning
module, and references to these symbols from other modules.
2026-05-08 16:25:46 -07:00
Doug Gregor 09dd9db3e1 [Embedded] Extend @export(interface) to non-generic types
@export(interface) makes it so that Embedded Swift will emit a strong
definition of a symbol in its defining module, and use that symbol in
other modules. Extend this notion to non-generic types, where we will
emit a strong definition for the full type metadata, and let it be
referenced from other modules rather than the lazy, shared emission.

Implements rdar://176392354.
2026-05-08 14:23:21 -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
Kavon Farvardin aba9338a85 Reparenting: handle unavailable base conformance descriptor
It's now possible to have a base protocol that's less available
than one inheriting from it:

```
@available(macOS 200)
@reparentable public protocol P {}

public protocol Q: P {}
```

In this case, the protocol conformance descriptor for a client type
conforming to Q would contain in its resilient witnesses a base conformance
descriptor for Q conforming to P. That symbol (ending in 'Tb') won't be
available on older versions of the library. So, we choose to weak-link
that symbol (i.e., expect it to be extern_weak) in order to allow the client
targeting an older deployment target to still work.
2026-02-13 16:37:19 -08:00
Kavon Farvardin 9850988b6e Reparenting: fix linking of Self associated conformance descriptor
It should check the weak imported status of the type requirement decl.
We already checked the status of `getDecl()` earlier.
2026-02-13 14:20:41 -08:00
Kavon Farvardin 006a0a494a Reparenting: require an extension
This change forces you to write ``@reparented` relationships
on an extension of a protocol, rather than on the protocol
itself.

The ProtocolConformance needs to be associated with some
GenericContext and IRGen expects it to be an ExtensionDecl.
That environment defines under what conditions the conformance
exists. We also need to define witnesses for the new parent's
requirements in an extension anyway, so it's a natural fit.

The previous workaround for this was kind of awful, as it'd
require searching all the protocol's extensions and "guess"
which extension they want to represent the conformance. While
we could try to synthesize an extension, there's two
challenges there:

1. Due to SuppressedAssociatedTypes, it's not so simple to
synthesize an unconstrained ExtensionDecl.
2. We currently rely on same-type requirements to pin the
associated types to particular witnesses of those requirements
in the extension. So it's not purely unconstrained! For example,

```
extension Seq: @reparented BorrowSeq where Iter == MyIter {}
```

The constraints that are disallowed (but not yet diagnosed)
are conditional conformance requirements, as the default
conformance for a reparenting cannot depend on those.

Thus, it's better that programmers to specify the extension.
2026-02-03 16:40:21 -08:00
Kavon Farvardin eb7fe3c8a3 Reparenting: initial functionality 2026-02-03 16:39:19 -08:00
Arnold Schwaighofer 4d879967a7 [embedded] Feature::EmbeddedExistentials requires Feature::Embedded 2025-12-09 10:21:51 -08:00
Arnold Schwaighofer 81dfb754ba [embedded] Apply shared linkage to metadata of public types in embedded with existential mode
We generate public metadata lazily which implies it could be emitted into a
different module. If we emit metadata for a public type into a module
other than its "home module" apply "shared" linkage.
2025-12-05 13:03:34 -08:00
Arnold Schwaighofer 729cc1e08f [embedded] When using existentials in embedded value witness tables can also have non unique definitions 2025-12-04 09:11:50 -08:00
Arnold Schwaighofer b9f6454386 [embedded] Add support for storing/casting function types 2025-11-21 14:55:32 -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
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
Nate Chandler e0ead75622 [CoroutineAccessors] Use typed-malloc. 2025-10-30 03:59:18 -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
Doug Gregor 17a6e72a3e [Embeddedd] Protocol conformance tables have nonunique definitions
Fixes rdar://162071487.
2025-10-06 18:07:34 -07:00
Doug Gregor 66a730b638 [Embedded] Remove -mergeable-symbols
This option is no longer necessary, because we emit weak definitions
for any imported modules. Fixes rdar://158364032.
2025-09-08 17:44:51 -07:00
Doug Gregor 9a20ebac5b [Embedded] Emit weak definitions for imported symbols
When Embedded Swift emits a symbol that was imported from another
module, ensure that the symbol is emitted as a weak definition. This
way, importing the same module (and using its symbol) into several
different modules doesn't cause duplicate-symbol errors at link time.
Rather, the linker will merge the different symbol definitions. This
makes Embedded Swift libraries work without resorting to
`-mergeable-symbols` or `-emit-empty-object-file`.
2025-08-17 15:26:08 -07: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
Nate Chandler 0c2a38b10b [CoroutineAccessors] Directly reference allocators
Replace the call to a runtime function that looks up the allocator with
a direct reference to a just-emittedd sought-after global allocator.
2025-03-26 08:35:35 -07:00
Nate Chandler 35d06c325d [CoroutineAccessors] Witness and vtable dispatch.
And thunking.
2025-03-07 11:46:50 -08:00
Nate Chandler a50a3f022b [CoroutineAccessors] Mangling.
Change the suffix to Twc and demangle.
2025-03-07 11:40:38 -08:00
Nate Chandler dd8cbe3e0a [CoroutineAccessors] Use retcon.once variant.
Allocate a coroutine frame in the caller based on the size in the
corresponding "function pointer" and pass it along with an allocator to
the callee.
2025-02-27 07:53:58 -08:00
Nate Chandler 3d655f58a2 [IRGen] Add coroutine fp link entities.
Duplicative boilerplate copying what was done for async function
pointers which these have the same characteristics as.
2025-02-27 07:53:13 -08:00
Kuba Mracek b2f87e7614 [embedded] Add an experimental -Xfrontend -mergeable-symbols to allow linking multiple .o modules in Embedded Swift 2025-02-08 11:56:09 -08:00
Kuba Mracek 6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Amritpan Kaur 6066418340 Merge pull request #73242 from amritpan/metatype-kp-implementation 2024-09-28 02:46:15 -07:00
Amritpan Kaur 2d70cd74e7 [IRGen] Weak link static keypath component property descriptors. 2024-09-25 12:54:52 -07:00
Erik Eckstein 2950e4521e SIL: representation for specialized witness tables
The main change here is to associate a witness table with a `ProtocolConformance` instead of a `RootProtocolConformance`.
A `ProtocolConformance` is the base class and can be a `RootProtocolConformance` or a `SpecializedProtocolConformance`.
2024-09-25 19:32:08 +02: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
Konrad `ktoso` Malawski eb675c222e [Distributed] Correct tbd handling for distributed thunks (#74935) 2024-07-26 16:52:18 +09:00
Tim Kientzle 1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Erik Eckstein 09d2e8f685 IRGen: add forceShared flag to LinkeEntity for type metadata 2024-05-21 18:04:10 +02:00
Pavel Yaskevich 89e4fb25d6 [IRGen] Distributed/NFC: Switch from ASTMangler to IRGenMangler 2024-03-04 15:59:57 -08:00
Pavel Yaskevich 0f41071fe6 [IRGen] Distributed: Switch DistributedAccessor linking to reference underlying thunks
Preparing to start emitting distributed requirement accessors
that don't have `SILFunction *` because they are associated with
protocol requirements.
2024-03-01 17:12:23 -08:00
Konrad `ktoso` Malawski c56a1e8be7 [Distributed] Handle mangling thunks in extensions with generic AS and $Stubs (#71914) 2024-02-29 04:22:00 -08:00
Konrad `ktoso` Malawski e9c7f3c382 [Distributed] Target identifiers for protocol calls (#70928) 2024-02-16 07:19:20 -08:00
Ellie Shin 72a7760027 Support package SIL linkage.
Decls with a package access level are currently set to public SIL
linkages. This limits the ability to have more fine-grained control
and optimize around resilience and serialization.
This PR introduces a separate SIL linkage and FormalLinkage for
package decls, pipes them down to IRGen, and updates linkage checks
at call sites to include package linkage.

Resolves rdar://121409846
2024-02-06 01:23:14 -08:00
Erik Eckstein eaabcfd933 IRGen: restrict generation of read-only static objects to Array buffers
Currently only arrays can be put into a read-only data section.
"Regular" classes have dynamically initialized metadata, which needs to be stored into the isa field at runtime.
2024-01-10 09:33:17 +01:00
Cyndy Ishida 331b11f39c [TBDGen] Determine whether symbols belong in TEXT/DATA to record in tbd
files
2023-11-10 08:48:28 -08:00
swift-ci d253b717d2 Merge remote-tracking branch 'origin/main' into rebranch 2023-10-07 19:35:15 -07:00
Kuba Mracek 5d8c55eacb [embedded] Initial Swift Concurrency for embedded Swift 2023-10-06 20:04:03 -07:00
swift-ci 174b6bc00c Merge remote-tracking branch 'origin/main' into rebranch 2023-08-18 19:34:12 -07:00
Slava Pestov c2f1193ae3 Merge pull request #67952 from slavapestov/tuple-conformance-tbd-etc
A pile of mostly unrelated one-liners
2023-08-18 15:31:26 -04:00
Slava Pestov 90562a0fe9 IRGen: Fix linkage of opaque type descriptor with @_alwaysEmitIntoClient owner decl 2023-08-18 12:12:50 -04:00
Slava Pestov 99d68ba14c IRGen: Some progress toward tuple conformances 2023-08-18 12:12:50 -04:00
swift-ci 73cf37d597 Merge remote-tracking branch 'origin/main' into rebranch 2023-08-16 17:33:42 -07:00
Pavel Yaskevich eee923bc42 [IRGen] [AST] NFC: Remove @runtimeMetadata related code and metadata records 2023-08-15 12:17:31 -07:00
Evan Wilde 41d59b215a Update Triple.h location
Triple moved from ADT to TargetParser. Updating includes to reflect
that.
2023-07-17 10:53:42 -07:00