Commit Graph

402 Commits

Author SHA1 Message Date
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
Allan Shortlidge 31b5e3e0a7 IRGen: Skip reflection metadata for enum elements that don't exist at runtime.
The names of enum elements that are made unavailable at runtime via custom
availability conditions shouldn't leak through Swift's reflection metadata.
Don't emit the names into the metadata.  These enum elements should really be
skipped entirely for layout and tag generation, but that's a riskier change
that will need to come later.

Resolves rdar://175803941.
2026-05-02 06:45:27 -07:00
Gabor Horvath 75e2a0a33b [cxx-interop] Fix miscompilation of some single field structs
Swift has some optimizations in place to treat structs with a single
refcounted field as if it was only the field. This logic was not
correctly taken into account for foreign reference types when a struct
like this was stored in a single element enum like an Optional.

This patch fixes this logic by updating the TypeInfo hierarchy to
correctly emit strong retain/release calls during IRGen for structs with
one fields.

rdar://170990579
2026-02-23 17:18:57 +00:00
Jamie 7d3701925a [IRGen][NFC]: remove dead code in GenEnum.cpp
Deletes the seemingly-unused emitPayloadMetadataForLayout method
2026-01-01 10:14:16 -06:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Alexis Laferrière 9ec824c20b Parser: Rename the experimental attribute @cdecl to @c
There's no users of `@cdecl` yet so we can do a direct rename. The
legacy `@_cdecl` remains unaffected.
2025-09-19 11:55:07 -07:00
Alexis Laferrière a8cf1a477f IRGen: Use C compatible representation for @cdecl enums
https://github.com/swiftlang/swift/issues/83738
2025-08-19 13:40:09 -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
Dario Rexin 48ee212303 [IRGen] Use at least Int8 for extra tag bits
rdar://149985633

Using at least Int8 here allows LLVM to apply more optimizations, reducing code size, avoiding stack allocations and as a result often eliminating complete stack frames.
2025-04-30 15:55:17 -07:00
Nate Chandler 96a1c0c322 [BitwiseCopyable] Fix resilient enum type info.
Like other `EnumTypeInfo`s, the `TypeInfo` subclasses `EnumTypeInfoBase`
and store the `EnumImplStrategy`.
2024-12-11 17:54:17 -08:00
Kuba Mracek 6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Arnold Schwaighofer 35afefb08e IRGen: Prefer memcpy for initWithTake of single/mulipayload enums where
possible over an outlined copy function

rdar://83297558
https://github.com/swiftlang/swift/issues/57537
2024-10-07 16:49:41 -07:00
Hamish Knight 91ae5d6345 [AST] NFC: Rename getArgumentInterfaceType -> getPayloadInterfaceType
IMO this is a slightly clearer name, many of its
uses already use the term "payload".
2024-09-29 17:05:14 +01:00
Joe Groff 57a56e5804 IRGen: Set a "not bitwise borrowable" bit in value witnesses for @_rawLayout types.
For types like `Atomic` and `Mutex`, we want to know that even though they are
technically bitwise-takable, they differ from other bitwise-takable types until
this point because they are not also "bitwise-borrowable"; while borrowed,
they are pinned in memory, so they cannot be passed by value as a borrowed
parameter, unlike copyable bitwise-takable types. Add a bit to the value witness
table flags to record this.

Note that this patch does not include any accompanying runtime support for
propagating the flag into runtime-instantiated type metadata. There isn't yet
any runtime functionality that varies based on this flag, so that can
be implemented separately.

rdar://136396806
2024-09-24 19:08:50 -07:00
Arnold Schwaighofer 50156f2bb5 Address review comments 2024-08-22 12:35:26 -07:00
Arnold Schwaighofer c7b91a9a1b Address review comments 2024-08-22 07:50:52 -07:00
Arnold Schwaighofer ad6f6dec6e IRGen: We cannot call destroy through metadata of private types of non-copyable fields
So call the destroy on the closing type instead.

Amends the concepts areFieldsABIAccessible/isABIAccessible to take metadata
accessibility of non-copyable types into account.

rdar://133990500
2024-08-21 11:22:30 -07:00
Slava Pestov 375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Dario Rexin 90a9ffdf02 [IRGen] Properly compute bit mask for extra tag bits in CVW
rdar://132501359

PowerOf2Ceil is not the correct function to use, because we end up with an empty mask if there is only one value stored in the extra tag bits
2024-07-26 14:50:54 -07:00
Dario Rexin e3e06a79e4 [IRGen] Fix emitPrimitiveLoadPayloadAndExtraTag for CVW
rdar://129627898

When casting the projectedBits to Int8, we accidetnally passed the base addr instead of the projectedBits. This was causing the wrong bits to be read.
2024-07-16 10:35:01 -07:00
Slava Pestov 3fcda140bb AST: ModuleDecl::checkConformance() is a static method 2024-07-06 12:05:46 -04:00
Dario Rexin 5dcd163c42 [IRGen] Always load extra tag bits as full bytes in CVW to avoid elemination of masking
rdar://129627898

LLVM expects integer types of fractional byte sizes to have been written as those types as well, so it expects all unused bytes to be 0.
Since we are using the unused extra tag bits to store tags of outer enums, that assumption does not hold here. In regular witnesses,
the outer enum would mask out those bytes before checking the tag of the inner enum. In CVW we can't do that, so we have to apply the
mask ourselves. To guarantee the mask does not get optimized out, we have to use full bytes instead of fractionals.
2024-07-03 12:32:07 -07: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
Egor Zhdan 1078fd3bd5 Merge pull request #73366 from apple/egorzhdan/frt-release-nullptr
[cxx-interop][IRGen] Do not try to retain/release a null pointer
2024-05-08 19:39:16 +01:00
Doug Gregor 280f566568 Revert "IRGen: memcpy instead of the outlined copy with take" 2024-05-07 23:42:47 -07:00
Slava Pestov ca91d04968 Merge pull request #73457 from slavapestov/bitwise-copyable-lookup-conformance-irgen
IRGen: Fix incorrect BitwiseCopyable conformance lookups
2024-05-07 17:22:40 -04:00
Egor Zhdan bd6da5dc64 [cxx-interop][IRGen] Do not try to retain/release a null pointer
This teaches IRGen to only emit a lifetime operation (retain or release) for a C++ foreign reference type if the pointer is not `nullptr`.

Previously the compiler would in some cases emit a release call for `nullptr`, which breaks the assumption that the argument to a custom release function is `_Nonnull`. For instance:
```
var globalOptional: MyRefType? = nil
func foo() { globalOptional = MyRefType.create() }
```
When emitting IR for the assignment operation to `globalOptional`, the compiler would emit code to first retrieve the existing value of `globalOptional` and release it. If the value is `nil`, it does not need to be released.

rdar://97532642
2024-05-07 20:20:45 +01:00
Slava Pestov d5985158cb IRGen: Fix some more incorrect conformance checks 2024-05-07 10:37:49 -04:00
Arnold Schwaighofer 62dc98295c IRGen: memcpy instead of the outlined copy with take
The outlined copy with take would instantiate metadata to call the value
witness table's copy function.

rdar://126751753
2024-05-06 12:17:17 -07:00
Erik Eckstein 1b1d5ed020 IRGen: support the @sensitive attribute
Call `swift_clearSensitive` after destroying or taking "sensitive" struct types.

Also, support calling C-functions with "sensitive" parameters or return values. In SIL, sensitive types are address-only and so are sensitive parameters/return values.
Though, (small) sensitive C-structs are passed directly to/from C-functions. We need re-abstract such parameter and return values for C-functions.
2024-04-09 12:01:11 +02:00
Doug Gregor 72492aa75d Respect trivially-destructible and copyable for zero-sized enum payloads
Only the non-zero-sized associated values of a type were considered
when determining whether an enum is copyable or was
trivially-destructible, meaning that a zero-sized, noncopyable type
with a `deinit` wouldn't get destroyed. Treat these associated values
as if they were a payload, and centralize the logic for figuring out
these overall aspects of the enum (copyable, trivially-destructible,
bitwise-takable) since the same checks were repeated.

Fixes rdar://118449507.
2024-04-02 11:46:40 -07:00
Augusto Noronha 0e2c41cb8b Merge pull request #72338 from augusto2112/deb-specialized-types
[DebugInfo] Generate debug info for specialized types
2024-03-19 10:43:10 -07:00
Augusto Noronha ae5e341db4 [DebugInfo] Generate debug info for specialized types
Specialized types are generic types, or types whose parent is
specialized.

IRGenDebugInfo was previously mistankenly emitting debug info for
nominal specialized types as if they regular nominal types, which caused
problems as that code path does not handle references to generic
parameters.
2024-03-18 15:43:38 -07:00
Nate Chandler e507a6bcea [IRGen] Defer materializing metadata for outlining
Rather than materializing the metadata on demand during visitation, only
collect the types that may be required.  Finally, materialize everything
that's needed at the end.
2024-03-15 14:12:28 -07:00
Nate Chandler f638918be8 [IRGen] Multi payload enum consumes call deinits.
They include the necessary metadata.
2024-03-01 21:01:50 -08:00
Nate Chandler 0075682b4d [IRGen] Single payload enums consumes call deinits
The include the necessary metadata.
2024-03-01 21:01:50 -08:00
Nate Chandler 04d06806b2 [NFC] IRGen: Extracted method. 2024-03-01 21:01:50 -08:00
Nate Chandler a82140bc1c [NFC] IRGen: Renamed method.
Not all metadata that the OutliningMetdataCollector collects is for
layout anymore.
2024-03-01 21:01:49 -08:00
nate-chandler 40a0260c17 Merge pull request #71738 from nate-chandler/noncopyable-bugs/20240219/1/implement-single-payload-enum-deinit
[IRGen] Noncopyable enums dont forward.
2024-02-20 14:59:43 -08:00
Nate Chandler ca496e46ce [IRGen] Noncopyable enums dont forward.
If a payload is non-copyable, do not use the forward-to-payload strategy
for single-payload enums.
2024-02-19 19:02:06 -08:00
Nate Chandler d1bd039ebd [IRGen] Use BC TI for resilient conformers.
Resilient types conforming to BitwiseCopyable mostly shouldn't go
through the VWT for value operations, they should just use memcpy.
2024-02-16 11:14:26 -08:00
Augusto Noronha c10991a369 Merge pull request #71428 from augusto2112/nfc-sbm
[NFC] Move MultiPayloadEnum spare bits mask calculation into a function
2024-02-08 22:19:07 -08:00
Augusto Noronha 9c6dfd4c03 [NFC] Move MultiPayloadEnum spare bits mask calculation into a function
In preparation to emit the spare bits mask of a MultiPayloadEnum into
DWARF debug info, move the calculation of it into its own function, so
it can be reused later on.
2024-02-07 16:48:39 -08:00
Dario Rexin 747cbfcc24 [IRGen] Mask extra tag bits in getEnumTag function for CVW (#71421)
rdar://121868127

In compact value witnesses we need to mask the extra tag bits in case they are used to store tag bits of outer enums, so we only read the ones we are interested in.
2024-02-07 08:58:07 -08:00
Arnold Schwaighofer 01df0ca1ff Merge pull request #71092 from aschwaighofer/outline_enum_addr_insts
IRGen: Outline by-address SIL enum instructions
2024-01-29 07:10:25 -08:00
Kavon Farvardin b4985f7fde [NFC] replace canBeNoncopyable
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.

Also renames `TypeDecl::isEscapable` to match.
2024-01-23 22:42:38 -08:00
Arnold Schwaighofer 49e8ffb735 IRGen: Outline by-address SIL enum instructions
Use a heuristic to decide when to outline indirect enum operations.
2024-01-23 15:01:24 -08:00
Dario Rexin b238c16f51 [IRGen] Disable simple single payload enum in layout strings (#70528)
rdar://119792426

There are a few issues with wrong assumptions around extra inhabitants that cause tags to not be identified properly in some cases. Until a proper fix is identified, we emit tag functions instead.
2023-12-20 14:55:52 -08:00
Kavon Farvardin a9c64baaa3 [Sema] refactor TypeDecl::isNoncopyable
In preparation for reporting whether the inverse marking on a TypeDecl
was inferred instead of explicit.
2023-11-06 15:40:12 -08:00
Ben Barham 360c5d8465 Merge remote-tracking branch 'origin/main' into 20231019-merge-main
Conflicts:
  - `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
    a static_cast on rebranch because `Optional` is now a `std::optional`.
2023-10-19 16:16:23 -07:00