There is a compatibility hack where fallback metadata access functions
used in field type metadata lie and say a field's type is the empty
tuple when it's noncopyable and the runtime doesn't advertise compatibility
with noncopyable types. Unfortunately, this hack applied to *all* fallback
metadata access functions, causing us to return wrong metadata in situations
we really need the correct metadata, such as in associated type substitutions.
Constrain the hack to only apply to reflection metadata. Fixes rdar://161562839.
rdar://159310652
This was causing the runtime to try to get types by mangled names for types of which the mangling was not supported by the target runtime, which led to runtime crashes.
We could encode local archetypes in reflection info by performing the
local archetype transform, to get an extended generic signature together
with substitutions for the added generic parameters.
However, for now, let's just not crash. This generalizes an earlier hack
for opened existential archetypes. Instead of replacing them with
nonsensical type parameters though, let's just not emit the whole
descriptor.
- Fixes https://github.com/swiftlang/swift/issues/83539.
- Fixes rdar://157554723.
If back-deploying prior to the introduction of name mangling and
runtime support for invertible constraints (~Copyable, ~Escapable),
don't use mangled names to access metadata. The code already existed
for this, but had a carve-out that still used mangled names for
standard library types that have always existed but got generalized to
support non-copyable & non-escapable types.
Tweak that carve-out to not apply to types like Span that come from a
back-deployment library. Fixes crashes when using metadata for Span et
al on older platforms.
Fixes rdar://155639204.
Raw identifiers are backtick-delimited identifiers that can contain any
non-identifier character other than the backtick itself, CR, LF, or other
non-printable ASCII code units, and which are also not composed entirely
of operator characters.
PR #78467 omitted certain fields from the FieldDescriptor list,
but did not update the count of fields that's emitted
just before that list.
Update the count so it matches the number of field descriptors
we actually emit.
Resolves rdar://143402921
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.
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
Some requirement machine work
Rename requirement to Value
Rename more things to Value
Fix integer checking for requirement
some docs and parser changes
Minor fixes
Missed a case when determining the strategy to use for obtaining the
metadata for a noncopyable existential metatype. Without this patch,
trying to use a metatype like `any ~Copyable.Type` can cause a crash at
runtime when setting a deployment target that predates Swift 6.0, due to
that runtime not knowing how to demangle inverses.
resolves rdar://134280902
We have had a heuristic that lets you reflect fields of types, where
the field's type is conditionally Copyable, despite the reflection
infrastructure always copying a field. That heuristic was added to allow
ubiquitous types like Optional in the stdlib to continue to be
reflected, even if the Optional at runtime really isn't Copyable.
As a consequence, we were also allowing reflection of fields containing
user-defined conditionally copyable types, when that's unsafe for no
real benefit, yielding runtime crashes!
I think in that case it's better to fall-back on the non-crashy case of
reflection seeing it as the EmptyTupleType, which isn't inhabited, so it
won't try to copy the field and instead basically skip-over it until a
future runtime supports the reflection safely.
So, this patch limits the dangerous reflection to only stdlib-defined
types, until Mirror and friends are updated.
We generally should use the open-coded, metadata function "accessor"
strategy when targeting older runtimes, but if the type is part of
the stdlib, assume the runtime demangler will produce correct
metadata, as the retrofitting of Optional, etc, was done Carefully.
resolves rdar://131337585
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)
When emitting reflection metadata for fields that have noncopyable
type with deployment targets that predate support for noncopyable
types, we introduce some indirection to make sure that these fields
are only visible to reflection clients (e.g., mirrors) when running on
a sufficiently-new Swift runtime. However, this indirection has the
downside that out-of-process clients (such as LLDB) can no longer
reflect the fields.
Tweak the heuristic to only introduce the indirection if the field is
*guaranteed* to have noncopyable type. If it somehow could be
copyable, e.g., based on the properties of its generic arguments, then
still emit the normal metadata. This eliminates regressions when
existing generic types like Optional become conditionally Copyable
(based on their Wrapped functions).
and implement it for @isolated(any) function types.
The existing testing was pretty broken: we were diagnosing all sorts
of things that don't require type metadata (like using a tuple with
an extended existential in a value position in an API signature)
and not diagnosing several things that do (like covariant function
conversions that erase types). There's therefore some risk to this
patch, but I'm not too worried because needing metadata like this is
pretty uncommon, and it's likely that programs won't build correctly
anyway --- it'll just get caught by the linker instead of the compiler.
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.
In preparation for future patches where debug info generation will need
to access the special builtin types, lazily emit them into a separate
lazily initialized vector.
Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.
Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.
Introduce all of the runtime mangling/demangling support needed for
thrown error types.
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.
Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
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.
`std::optional` implicitly converts the underlying type to an optional,
unlike `llvm::Optional`, so the overload that did the conversion
manually was causing ambiguity issues. It's no longer needed, so
removing it now.
This attribute can be attached to a noncopyable struct to specify that its
storage is raw, meaning the type definition is (with some limitations)
able to do as it pleases with the storage. This provides a basis for
implementing types for things like atomics, locks, and data structures
that use inline storage to store conditionally-initialized values.
The example in `test/Prototypes/UnfairLock.swift` demonstrates the use
of a raw layout type to wrap Darwin's `os_unfair_lock` APIs, allowing
a lock value to be stored inside of classes or other types without
needing a separate allocation, and using the borrow model to enforce
safe access to lock-guarded storage.