Commit Graph

562 Commits

Author SHA1 Message Date
Joe Groff
feebd56bf4 IRGen: Reorder the extra inhabitant value witnesses so that the count and flags go first.
This nicely gathers all the layout information together in one contiguous bundle we can potentially emit independently for use in generic type layout. A step on the way to rdar://problem/19898165.

Swift SVN r30128
2015-07-12 01:06:15 +00:00
Joe Groff
16c8a3b6c0 Runtime: Fix crash when first allocation for a metadata cache is page-sized or greater.
We incorrectly tested the uninitialized "next" pointer against MAP_FAILED, instead of the real result of mmap. Fixes rdar://problem/21659505.

Swift SVN r30030
2015-07-09 18:19:59 +00:00
Joe Groff
ab1f459a40 Runtime/stdlib: Non-verbatim bridging of metatypes.
Metatypes can't directly conform to _ObjectiveCBridgeable, but we can pretend they do by making a struct with the same ABI conform and returning that conformance when we call findBridgeWitness on a metatype. Fixes rdar://problem/16238475.

Swift SVN r29999
2015-07-08 23:23:55 +00:00
Joe Groff
6c3efc0d8f IRGen: Use opaque Builtin.IntNN metadata for Builtin.Vec types.
Builtin.Int128 and Builtin.Int256 already have the proper size and alignment for common vector types on our platform, and since they're opaque builtins, they only need placeholder metadata.

Swift SVN r29890
2015-07-02 17:05:27 +00:00
Joe Groff
a9e69dda79 IRGen/Runtime: Mark indirect cases in an enum's field type infos.
And use this information in EnumMirror to project boxed payloads when we encounter them.

Swift SVN r29866
2015-07-02 00:00:42 +00:00
Joe Groff
8ec59e5c11 Runtime: Implementation for generic typed boxes.
Provide new swift_{alloc,dealloc,project}Box2 entry points that allocate, project, and deallocate typed boxes using runtime-instantiated metadata. Give these a new metadata kind, so that external tools recognize the difference and can interpret the metadata appropriately.

Swift SVN r29714
2015-06-26 00:06:17 +00:00
Joe Groff
9a33c50f04 Runtime: Look through artificial subclasses when generating metatype names.
Fixes rdar://problem/20307995.

Swift SVN r29325
2015-06-05 23:37:33 +00:00
Joe Groff
9b4dc24721 Runtime: (Almost) cleanse of global constructors and destructors.
Configure the runtime to build with -Wglobal-constructors, and Lazy-fy almost everything that gets flagged. (I gave "swift_isaMask" a pass since that's almost definitely hot enough to warrant a static initialization.) Make some improvements to the Lazy wrapper, using aligned_storage to ensure that it's trivially constructed and destructed.

Swift SVN r28199
2015-05-06 04:59:56 +00:00
Joe Groff
4afbe78d59 Runtime: Entry points for dynamic multi-payload enums.
Swift SVN r27791
2015-04-27 00:35:10 +00:00
Joe Groff
0b339b9a46 IRGen: Populate nominal type descriptor metadata for enums.
Store the number of payload and no-payload cases, the case names, and a lazy case type accessor function for enums, like we do for stored properties of structs and classes. This will be useful for multi-payload runtime support, and should also be enough info to hack together a reflection implementation for enums.

For dynamic multi-payload enums to not be ridiculously inefficient, we'll need to track the size of the payload area in the enum, like we do the field offsets of generic structs and classes, so hack off a byte in the payload case count to track the offset of that field in metadata records. 16 million payloads ought to be enough for anyone, right? (and 256 words between the enum metadata's address point and the payload size offset)

Swift SVN r27789
2015-04-27 00:35:04 +00:00
Michael Gottesman
e43570f1f0 Add MetadataKind.def, a header for metaprogramming with MetadataKinds
and use it to update LeaksChecker in a robust way to handle new metadata
kinds.

I also fixed a small typo where the native ErrorType was not included in
the range of non-ObjC isa metadata kinds.

Swift SVN r27718
2015-04-25 19:04:55 +00:00
Joe Groff
00f7520888 IRGen/Runtime: Combine the separate per-convention function metadata caches into one.
We have enough flag bits on function types now to warrant stashing an extra word in the metadata key alongside the arguments and results, so add one, and pack the number of arguments, function convention, and 'throws' bit in there. This lets us merge the separate metadata caches for thick/thin/block/C functions into one, saving a bit of runtime memory, and simplifying a bunch of repetitive code in the runtime and IRGen.

This also fixes a subtle bug we had where the runtime getFunctionTypeMetadata function expected the result argument to be passed in the arguments array, but IRGen was passing it as a separate argument, which would have caused function type metadata to fail to be uniqued by result type.

Swift SVN r27651
2015-04-23 22:58:11 +00:00
Joe Groff
c4ec47ddea IRGen/Runtime: Metadata for @convention(c) function types.
For now, C&P a new metadata cache for C function pointers, like we do for blocks and thin types.

Swift SVN r27595
2015-04-22 18:06:23 +00:00
Joe Groff
fcf535d682 Runtime: Implement ObjC-free metatype dynamic casts.
Swift SVN r27414
2015-04-17 05:30:35 +00:00
Joe Groff
225a0ebd70 Runtime: Non-ObjC-interoperable version of ErrorObject implementation.
This gets the runtime building again with ObjC interop disabled, though the standard library still has issues.

Swift SVN r27326
2015-04-15 20:27:24 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Joe Groff
41f73d43ae Runtime: Try to make lazy ErrorType-to-NSError bridging thread-safe.
Atomically initialize and load the NSError bridging fields within an ErrorType box so that we do the right thing when two threads concurrently coerce the box to NSError.

Swift SVN r26996
2015-04-05 00:17:34 +00:00
Joe Pamer
980bd819a2 Propagate 'throws' information into function type metadata.
Swift SVN r26956
2015-04-03 21:45:33 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Joe Groff
ff5f87f56b Runtime: Add ExistentialTypeMetadata helpers for taking values.
Add a 'mayTakeValue' function, which returns true if we're allowed to take the value from an existential container (assuming we own the existential container value). This is true for class and opaque existential containers, but not for boxed existentials, where multiple owners may share references to the boxed value. Also add a 'deinitExistentialContainer' function to do any cleanup that must happen after the value has been consumed out of an existential container. Fix up an off-by-one indirection level in the SwiftError implementations of the existing existential container methods.

Swift SVN r26561
2015-03-25 23:02:56 +00:00
Joe Groff
668928cc83 Runtime: Handle ErrorType's layout in ExistentialTypeMetadata accessors.
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
2015-03-25 00:56:16 +00:00
Joe Groff
c0712e8cb0 Runtime: Reserve some protocol descriptor bits to identify special protocols.
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
2015-03-20 21:06:18 +00:00
John McCall
b6bafa5d74 When instantiating a generic class, set up the
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
2015-02-25 23:35:25 +00:00
John McCall
f3dc58667d Improve the typing of materializeForSet callbacks to
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
2015-01-11 21:13:35 +00:00
John McCall
6a91f7a172 Various improvements to the function-type ABI.
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
2015-01-10 01:45:37 +00:00
Joe Groff
27f49cd19d Runtime: Optional-like enums with single-refcounted payloads can share the refcounted value witnesses.
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
2014-12-02 17:34:36 +00:00
Joe Groff
d752636387 Runtime: Drop in POD value witnesses when generic structs or enums are instantiated.
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
2014-12-02 03:33:40 +00:00
David Farler
3c4428dd78 Emit unique metadata for functions with inout
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
2014-11-22 22:01:23 +00:00
Dave Abrahams
b297c1f51b Make better use of Builtin.BridgeObject bits
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
2014-11-15 00:53:39 +00:00
Joe Groff
412b1332f9 Runtime: Fix crash in cast to existential metatype.
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
2014-11-13 17:36:07 +00:00
Joe Groff
08fe138808 Runtime: Generate a human-understandable name for Any.Type.
Expose this in the stdlib as _typeName(Any.Type) -> String, pending API review.

Swift SVN r23254
2014-11-11 23:38:24 +00:00
Joe Groff
7ce4ea860c IRGen/Runtime: Handle non-class-metatype to ObjC existential casts.
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
2014-11-11 18:51:09 +00:00
Joe Groff
2475bd1e4f Clean up platform conditionals.
Thanks Jordan!

Swift SVN r23235
2014-11-11 17:05:56 +00:00
Joe Groff
7ee99eb9d3 Runtime: Workaround for rdar://problem/18889711.
LLVM treats 'consume' as 'acquire' on ARM64, emitting an unnecessary barrier.

Swift SVN r23180
2014-11-08 17:17:49 +00:00
Joe Groff
32d148c807 Runtime: Improve type safety when working with witness tables.
Declare an opaque WitnessTable type instead of throwing void* around everywhere.

Swift SVN r23149
2014-11-07 01:17:51 +00:00
Joe Groff
e2cd398caf Runtime: Remove dead casting entry points.
Swift SVN r23138
2014-11-06 22:19:29 +00:00
Joe Groff
8ba1f42c63 Remove stray "#if 0 ||" and add missing else.
Swift SVN r23125
2014-11-06 01:32:11 +00:00
Graham Batty
d15c24e25b Changes to runtime library to support non-objc targets
Swift SVN r23122
2014-11-05 23:17:07 +00:00
Joe Groff
763ce97193 Runtime: Tighten up barriers in foreign type metadata.
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
2014-11-05 19:16:10 +00:00
Joe Groff
58273118e2 Runtime: Make the invasive cache pointer in ForeignTypeMetadata atomic.
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
2014-11-04 17:43:29 +00:00
Joe Groff
914f47ff47 Runtime: Take the lock off the hot path of getForeignTypeMetadata again.
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
2014-11-04 06:16:00 +00:00
Joe Groff
90cb504b75 Runtime: Switch swift_conformsToProtocol over to the new implementation.
Swift SVN r23083
2014-11-03 06:12:18 +00:00
Joe Groff
e773d9a1aa IRGen: Unique the metadata for imported structs and enums at runtime.
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
2014-11-03 06:12:13 +00:00
Joe Groff
ef82526795 Runtime: Hack up support for conformance lookup on ObjC classes.
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
2014-11-03 00:17:55 +00:00
Joe Groff
01554448fc Runtime: Walk up superclass chains to find class conformances.
Swift SVN r23065
2014-11-02 15:41:00 +00:00
Joe Groff
139bf0323d Runtime: Cache nondependent generic witnesses for lookup.
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
2014-11-02 01:17:14 +00:00
Joe Groff
f205082b6d IRGen: Register JITed conformances with the runtime.
dyld won't help us with JIT code, so we need to inject a runtime call to add the conformances ourselves in JIT mode.

Swift SVN r23058
2014-11-01 22:20:10 +00:00
Joe Groff
2dc7678253 Runtime: Handle the easy cases for protocol lookup.
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
2014-11-01 02:46:52 +00:00
Joe Groff
81568bf895 Runtime: Beginnings of protocol conformance lookup.
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
2014-10-31 02:57:57 +00:00
Dmitri Hrybenko
fd7ce02a51 Runtime: emit BridgeObject metadata on all platforms
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
2014-10-25 21:37:41 +00:00