Teach ExistentialTypeMetadata how to project out the value pointer, type metadata, and protocol witness table from ErrorType containers. NFC yet; the dynamic casting and reflection machinery needs further work to correctly handle ErrorType boxes.
Swift SVN r26509
We need to be able to easily recognize ErrorType in the runtime (and AnyObject, which we recognize by strcmp'ing in a few places currently, which is terrible). Carve out a byte in the protocol descriptor and existential type metadata flags where we can store an enumerator to identify interesting protocols and their existential types. While we're here, move the ProtocolDescriptorFlags and ExistentialTypeFlags up to swift/ABI/MetadataValues.h so their layout can be shared easily from IRGen and the runtime. NFC yet (except you're now arbitrarily limited to 16M protocols in a composition instead of 2G, but hopefully nobody will notice).
Swift SVN r26361
correct preconditions for ObjC layout, and write the
computed offsets back to global ivar offset variables
when present.
Swift will use the global variables for accesses to
ivars when it can show that their offsets are
non-dependent.
Fixes a major problem with generic subclasses of ObjC
classes whose dynamic layout does not match the layout
in their @interface.
rdar://19583881
Swift SVN r25536
use a thin function type.
We still need thin-function-to-RawPointer conversions
for generic code, but that's fixable with some sort of
partial_apply_thin_recoverable instruction.
Swift SVN r24364
Teach IRGen and the runtime about the extra inhabitants
of function pointers, and take advantage of that in
thin and thick function types.
Also add runtime entrypoints for thin function type
metadata.
Swift SVN r24346
swift_retain and objc_retain both handle nil already, so we can bypass the generic Optional value witnesses when instantiating Optional on a class type, which happens kind of a lot.
Swift SVN r23613
If, after layout, we recognize that a generic struct or enum instance is POD, we can replace the generic value witnesses in the image with POD ones.
Swift SVN r23609
References to functions that take inout parameters crash the compiler
because InOutType isn't a "real" type in itself and has no special type
metadata to emit. It merely further qualifies the function's input
types.
For example, we would like to have a unique entry in the cache for:
var f: (T, T) -> ()
and
var f2: (inout T, T) -> ()
For each argument type metadata pointer in the function's input, take
advantage of pointer alignment and mark the lowest bit if it is inout.
Since the metadata cache uses pointers to create the key, this creates a
unique entry while still being able to extract the actual pointer.
This fixes <rdar://problem/17655125>, and a couple of other similar
crashes.
Swift SVN r23557
We used to reserve a specific spare bit to say "this is a native
object." Now, we're going to say, "if *any* spare bit is set, this is a
native object." At the cost of having no spare bits to work with in the
non-native case, this allows us to store a number in 1..<4 (actually
0..<4, at some cost in speed for the 0 case) along with any native
object on all platforms.
This half bit advantage is important on 32-bit platforms, we have only
spare 2 bits to work with.
Given that on the 64-bit platforms there are *no* spare bits in the case
where the object is a non-native tagged pointer, we have no guarantee of
being able to store extra information along with an arbitrary non-native
object. Giving up the ability to store bits for *all* non-native
objects (even non-tagged ones) is therefore not much of a sacrifice.
Fixes <rdar://problem/18920415> More useful spare bits in Builtin.BridgeObject
Swift SVN r23345
Handle a null conformances pointer in _conformsToProtocol, and when we want to overwrite a metatype, pass a correct conformances pointer for the existential metatype value.
Swift SVN r23304
These always fail, and it doesn't make sense to inline this check into the cast site, so provide additional runtime functions for metatype-to-objc-existential casts.
Swift SVN r23237
When there's no init function, we can do relaxed loads and stores, because the metadata record will not change in the course of canonicalization. However, if there is initialization, we need to do a release-consume in order to ensure the initialization is visible to readers.
Swift SVN r23119
Per review from Dmitri and Greg. We can do relaxed loads (if we miss the store, we'll lock the global hashtable and find the metadata that way), but we need a seq_cst barrier when we store.
Swift SVN r23101
The race here was benign--we just end up writing the same uniqued value twice to the invasive cache. Relax the assertion that this used to trip.
Swift SVN r23098
Move the uniquing information for ForeignTypeMetadata behind the address point so we can share the layout between foreign classes and the existing layout for struct and enum metadata. Emit metadata records for imported structs and enums as foreign metadata candidates, and dynamically unique references to the metadata by calling swift_getForeignTypeMetadata.
Swift SVN r23081
As a stopgap till IRGen properly emits indirected class references, support direct class reference protocol conformance records. This should get us to the point we can replace the dlsym hack with the new implementation.
Swift SVN r23073
We can share a lookup cache entry under the generic metadata pattern when the witness table for a protocol conformance is shared among all instances of the type. (This happens to always be the case currently.)
Swift SVN r23062
Set up the basic logic for first looking into a cache then pulling in conformances from enqueued images and trying again for exact-matchable types (pretty much just nongeneric native value types).
Swift SVN r23053
Set up lazy registration of a dyld add image callback that looks up the "__DATA,__swift1_proto" section in the loaded image. As a first-pass sanity check, just walk the section and dump the records.
Swift SVN r23025
Per Joe, a low level retained-pointer-with-user-controlled-spare-bits
type would still be useful for space efficiency even on platforms that
don't need ObjC interop.
Swift SVN r22943
When we emit a witness table, build a protocol conformance record for it, and emit the list of all conformance records into a "__swift1_proto" section of the data segment.
Swift SVN r22939
We want to use the reserved space in the metadata pattern for protocol conformance caching, and this link lets us find the metadata pattern from an instance of the generic type.
Swift SVN r22898
This is a type that has ownership of a reference while allowing access to the
spare bits inside the pointer, but which can also safely hold an ObjC tagged pointer
reference (with no spare bits of course). It additionally blesses one
Foundation-coordinated bit with the meaning of "has swift refcounting" in order
to get a faster short-circuit to native refcounting. It supports the following
builtin operations:
- Builtin.castToBridgeObject<T>(ref: T, bits: Builtin.Word) ->
Builtin.BridgeObject
Creates a BridgeObject that contains the bitwise-OR of the bit patterns of
"ref" and "bits". It is the user's responsibility to ensure "bits" doesn't
interfere with the reference identity of the resulting value. In other words,
it is undefined behavior unless:
castReferenceFromBridgeObject(castToBridgeObject(ref, bits)) === ref
This means "bits" must be zero if "ref" is a tagged pointer. If "ref" is a real
object pointer, "bits" must not have any non-spare bits set (unless they're
already set in the pointer value). The native discriminator bit may only be set
if the object is Swift-refcounted.
- Builtin.castReferenceFromBridgeObject<T>(bo: Builtin.BridgeObject) -> T
Extracts the reference from a BridgeObject.
- Builtin.castBitPatternFromBridgeObject(bo: Builtin.BridgeObject) -> Builtin.Word
Presents the bit pattern of a BridgeObject as a Word.
BridgeObject's bits are set up as follows on the various platforms:
i386, armv7:
No ObjC tagged pointers
Swift native refcounting flag bit: 0x0000_0001
Other available spare bits: 0x0000_0002
x86_64:
Reserved for ObjC tagged pointers: 0x8000_0000_0000_0001
Swift native refcounting flag bit: 0x0000_0000_0000_0002
Other available spare bits: 0x7F00_0000_0000_0004
arm64:
Reserved for ObjC tagged pointers: 0x8000_0000_0000_0000
Swift native refcounting flag bit: 0x4000_0000_0000_0000
Other available spare bits: 0x3F00_0000_0000_0007
TODO: BridgeObject doesn't present any extra inhabitants. It ought to at least provide null as an extra inhabitant for Optional.
Swift SVN r22880
layouts. Introduce new SIL instructions to initialize
and open existential metatype values.
Don't actually, y'know, lift any of the restriction on
existential metatypes; just pointlessly burn extra
memory storing them.
Swift SVN r22592
Rename the existing misleadingly-named "isClassType" to "isClassObject", and document that it refers to (swift or ObjC) class objects, the latter of which aren't always type metadata.
Swift SVN r22153
Somehow this got out of sync, and IRGen's idea of which flag it was collided with "hasExtraInhabitants", causing hilarity to ensue whenever weak or protocol types were packed in optionals. Fixes rdar://problem/17814752.
Swift SVN r21803
pass the size and alignment of each field. Take advantage
of this to pass a constant size and alignment when
possible.
This avoids the need to recursively find type metadata for
every field type, allowing generic recursively-structured
classes to be built. There are a number of more complicated
cases that this approach isn't good enough for, but this
is good enough for now to fix rdar://18067671.
Also make an effort to properly support generic subclasses
of Objective-C classes.
Swift SVN r21506
initializeBufferWithTakeOfBuffer value witness.
Attempt to use initializeBufferWithTakeOfBuffer in
some appropriate places.
There are some changes enabled by this which are
coming in a follow-up patch.
Swift SVN r20741
constructs generic class metadata properly when the
superclass has an unexpected prefix.
Also fix a bug in the constructor for ClassMetadata (which is
only actually constructed this way in unit tests).
Swift SVN r20586
unexpected forematter from the superclass.
This requires a pretty substantial shift in the
generic-metadata allocation/initialization dance
because (1) we can't allocate class metadata without
knowing what the superclass is and (2) the offset
from the metadata cache entry to the address point is
no longer determined solely by the metadata pattern.
While I'm making invasive changes to metadata, fix
two race conditions in metadata creation. The first
is that we need to ensure that only one thread succeeds
at lazily creating a generic-metadata cache. The second
is that we need to ensure that only one thread actually
attempts to create a particular metadata; any others
should block until the metadata is successfully built.
This commit finishes rdar://17776354. LLDB will
need to adjust to the runtime-private metadata layout
changes.
Swift SVN r20537
a flags field, add an instance address point field, and reserve
some additional space.
This change must be coordinated with a corresponding change
to ObjC runtime bits in libarclite; without this, dynamic
subclassing features like KVO will break.
The actual contents of the new fields can change without
bothering the ObjC runtime.
Swift SVN r20183