Commit Graph

393 Commits

Author SHA1 Message Date
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
Kavon Farvardin
148897ac1a [nfc] refactor ValueDecl::isMoveOnly
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
2023-10-18 13:45:50 -07:00
swift-ci
2e2e79810f Merge remote-tracking branch 'origin/main' into rebranch 2023-09-14 09:59:30 -07:00
Erik Eckstein
9cf0229824 IRGen: fix emission of constant single-case enums
Enums which have a single case with a payload were emitted with wrong field alignement into the data section.

Fixes a miscompile:
rdar://115251963
2023-09-14 12:17:06 +02:00
swift-ci
f52fc06ac7 Merge remote-tracking branch 'origin/main' into rebranch 2023-09-06 18:14:46 -07:00
zoecarver
349d37ab24 [embedded] Start fencing parts of IRGen that are not compatible with embedded Swift. 2023-09-06 10:48:17 -07:00
swift-ci
d4bb2bb86b Merge remote-tracking branch 'origin/main' into rebranch 2023-08-06 10:14:39 -07:00
Allan Shortlidge
ca8bf981a4 NFC: Hoist queries for unavailable decl optimizations into the AST library.
Moving the query implementation up to the AST library from SIL will allow
conveniences to be written on specific AST element classes. For instance, this
will allow `EnumDecl` to expose a convenience that enumerates element decls
that are available during lowering.

Also, improve naming and documentation for these queries.
2023-08-04 17:39:26 -07:00
Ben Barham
1d3b5f40a0 [rebranch] Finish off memory effects change
`ReadOnly`/`ArgMemOnly` were mostly moved over, but a few were missed.
Update them all. Also default to `unknown` for no memory effects rather
than none (ie. we should be conservative).
2023-08-01 15:29:40 -07:00
Evan Wilde
6e59c42201 more APInt renames 2023-07-17 10:55:57 -07:00