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.
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
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
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
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.
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.
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)
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
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.
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.
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.
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.
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.
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.
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.
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.
Conflicts:
- `lib/AST/TypeCheckRequests.cpp` renamed `isMoveOnly` which requires
a static_cast on rebranch because `Optional` is now a `std::optional`.
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.
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.
`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).