Added a new flag to the GenericMetadataPatternFlags flagset for whether
the metadata has a set of flags at its tail. When that flag is set,
there will be an extra uint64_t flagset at the end of the metadata. For
struct metadata, the type of that flagset will be
StructMetadataTrailingFlags. The first flag in that trailing flagset
indicates whether the metadata was statically specialized. The second
flag in that trailing flagset indicates whether the metadata is
statically canonical.
When verifying the metadata cache, a check is done for whether the
metadata was statically specialized and whether it was known to be
canonical statically. If so, verification is skipped. Skipping it is
necessary because the known-canonical statically specialized metadata
will not be in the cache. In that case, the canonical statically
specialized metadata will be returned from the metadata accessor and
never be cached.
SR-5289: Teach Mirror how to inspect weak, unowned, and unmanaged refs
Correctly reflect weak, unowned, and unmanaged references
to both Swift and Obj-C types (including existential references to
such types) that occur in both Swift class objects and in Swift
structs.
This includes the specific reported case (unowned reference to an
Obj-C object) and several related ones.
Related changes in this PR:
* Tweak internal bitmap used for tracking ownership modifiers
to reject unsupported combinations.
* Move FieldType into ReflectionMirror.mm
FieldType is really just an internal implementation detail
of this one source file, so it does not belong in an ABI header.
* Use TypeReferenceOwnership directly to track field ownership
This avoids bitwise copying of properties and localizes some
of the knowledge about reference ownership
* Generate a top-level "copyFieldContents" from ReferenceStorage.def
Adding new ownership types to ReferenceStorage.def will now
automatically produce calls to `copy*FieldContents` - failure
to provide a suitable implementation will fail the build.
* Add `deallocateBoxForExistentialIn` to match `allocateBoxForExistentialIn`
Caveat: The unit tests are not as strict as I'd like. Attempting to make them
so ran afoul of otherwise-unrelated bugs in dynamic casting.
* SR-5289: Support reflecting weak, unowned, and unmanaged refs
This refactors how we handle reference ownership
when reflecting fields of struct and class objects.
There are now explicit paths for each type of reference
and some simple exhaustiveness checks to fail the build
if a new reference type is added in the future without
updating this logic.
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:
- Reflection still uses the notion of "unknown object" to mean an
object with unknown refcounting. There's no real reason to make
this different from AnyObject (an existential containing a
single object with unknown refcounting), but this way nothing
changes for clients of Reflection, and it's consistent with how
native objects are represented.
- The value witness table and reflection descriptor for AnyObject
use the mangling "BO" instead of "yXl".
- The demangler and remangler continue to support "BO" because it's
still in use as a type encoding, even if it's not an AST-level
Type anymore.
- Type-based alias analysis for Builtin.UnknownObject was incorrect,
so it's a good thing we weren't using it.
- Same with enum layout. (This one assumed UnknownObject never
referred to an Objective-C tagged pointer. That certainly wasn't how
we were using it!)
This makes for a cleaner and less implicit-context-heavy API, and makes it easier for symbolic
reference resolvers to do context-dependent things (like map the in-memory base address back to a
remote address in MetadataReader).
The memcpy in the type layout verifier was not correct for big-
endian systems. While we are here change 'long long' to a fixed
width unsigned type (uint64_t). It doesn't really make sense to
print the value as a signed number since we have zero extended
it from its original bit width using the memcpy.
Unfortunately, `std::atomic` in msvcprt as of 14.21.27702 is broken for
double-width atomics on ARM64. This has been reported to Microsoft and
is going to be fixed in VC++ 2019u3. For the time being, add a partial
template specialisation for the two double-word sized types temporarily
as a workaround. This allows the standard library build to get further.
When building without assertions, the variable will be unreferenced on
non-ObjC runtimes. Sink the evaluation into the assertion and move the
declaration into the ObjC runtime case.
Build a static archive that can be linked into executables and take advantage of the Swift runtime's
hooking mechanism to work around the issue Doug fixed in https://github.com/apple/swift/pull/24759.
The Swift 5.0 version of swift_conformsToProtocol would return a false negative in some cases where
a subclass conforms using an inherited conformance, so work around this by successively retrying
the original implementation up the superclass chain to try to find a match.
This will allow us to emit class stubs unconditionally, rather than
checking the -enable-resilient-objc-class-stubs flag.
Part of <rdar://problem/49090631>.
This adds a new tail-allocated field to class context descriptors storing
a pointer to an Objective-C class stub.
When the stub is present, we use the new _objc_realizeClassFromSwift()
entry point to realize the class instead of calling objc_readClassPair().
This should attach categories to the realized class, if they were emitted
to reference the stub.
Extract common code from the old and new remangler into a common base class.
This lets the old remangler benefit from the changes I did recently in the new remangler.
This is needed for Windows which does not support cross-module data
references without indirection. By lazy initializing the data, we can
indirect through the IAT for the data pointer and fill in the parent
pointer.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
Instead of capturing SubstGenericParametersFromMetadata and SubstGenericParametersFromWrittenArgs by value, capture by reference.
This avoids those instances to be copied and thus avoids a lot of mallocs.
SR-10028
rdar://problem/48575729
This initialization pattern can only be used if there is a backward deployment
layout (IRGen calls this ClassMetadataStrategy::FixedOrUpdate) or if we are
running on a newer Objective-C runtime that supports class metadata update
hooks (IRGen calls this ClassMetadataStrategy::Update).
If neither condition holds, we must trap here to avoid undefined behavior.
Note that I've called out a couple of suspicious places where we
are requesting abstract metadata for superclasses but probably
need to be requesting something more complete.
The Name field of a type descriptor is not the appropriate
way to compare types for uniquing. Instead, use TypeContextIdentity.
Fixes rdar://problem/46685973.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.
The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change. Also, being able to access the XI count directly
should be a nice win.
* cmake: Propagate SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT to overlay builds.
* runtime: Clear the correct bit in getROData()
* test/IRGen/objc_class_export.swift: Allow either is-Swift bit.
* test/stdlib/SwiftObjectNSObject.swift: Allow either name for SwiftObject.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
Resilient conformances now put all witnesses into the resilient witness
table, so optimize away the witness table pattern for such cases. Teach
the runtime to fill in the protocol conformance descriptor, because that’s
the only bit of real information that would be in the pattern.
This is a minor optimization enabled by rdar://problem/46282080.