IRGen always just emits a simple implementation that immediately
calls swift_relocateClassMetadata(); so allow the function to be
null in this case to save on code size.
This is in preparation to make the code here more target agnostic for
porting to the Windows threading primitives. This is used pretty
extensively in the tests, so disabling tests would lose a chunk of
coverage.
Rather than scanning through the generic parameters and generic requirements
each time we form a key for the generic metadata cache, compute these
values once, when the cache itself is first initialized.
Rather than scanning the type descriptor each time we perform a comparison
or hash of a metadata cache entry, do so only once to establish the number
of key parameters and the number of witness tables. Use those values to
more efficiently compare keys.
Metadata uniquing might encounter witness tables that were distinctly
generated but come from identical descriptors. Handle this case in metadata
uniquing be looking into the protocol conformance descriptors themselves.
Ensure that UnsafeMutablePointer.deallocate has the alignment that was
used when invoking UnsafeMutablePointer.allocate. This is required to
ensure that the appropriate `free` function is invoked. We would
previously fail on Windows as the allocation would use `malloc` and due
to the value being `-1`, use `_aligned_free` instead when deallocating.
The conformance cache was caching the witness table for a conformance
`T: P`, where `T` is a concrete type and `P` is a protocol. However, it
essentially picked one of potentially many witness tables for that
conformance, because retroactive conformances might produce different results
from different modules.
Make the conformance cache what is says it is: a cache of the conformance
descriptor for a given `T: P`, potentially filtered by a module (when
requested). Clients of the conformance cache can choose how to interpret
the protocol conformance descriptor, e.g., by instantiating a witness table.
We can bring back a specific conformance cache for swift_conformsToProtocol()
if it is profitable.
(cherry picked from commit 0af2af00a739a4d912d2a9c3b196449e4164484f)
Add a use an unchecked subscript on UnsafeBufferPointer, which skips
debugPrecondition checks (in case we're not inlined) as well as a
force-unwrap check.
We now have plenty of extra inhabitants in the variant enum, so we can get rid of the 7-bit hack.
It’d also be possible now to increase small string capacity to a spacious 11 bytes; however this needs a full overhaul of the 32-bit representation, so it needs a little bit more time in the oven.