Commit Graph

198 Commits

Author SHA1 Message Date
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
dfac9181dd Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

This can be reapplied now that we properly call objc_destructInstance on deallocation.

Swift SVN r23070
2014-11-02 21:03:21 +00:00
Joe Groff
0885c5617e Runtime: Invoke objc_destructInstance before deallocating class instances.
This is necessary to clean up associated objects and ObjC weak references to the object. rdar://problem/18637774

Swift SVN r23068
2014-11-02 21:03:18 +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
Graham Batty
eba89b15fe Implemented swift_once with C++11 call_once.
Swift SVN r22972
2014-10-27 17:16:26 +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
Joe Groff
c98ce540d4 IRGen: Emit protocol conformance records.
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
2014-10-25 01:50:49 +00:00
Joe Groff
df42e26d5f Runtime: Define a type for protocol conformance records.
Swift SVN r22918
2014-10-24 18:24:00 +00:00
Joe Groff
1a24b1b56b IRGen/Runtime: Expand the private data area in metadata caches.
And move the new size into an ABI constant so we can change it in one place in the future if need be.

Swift SVN r22899
2014-10-23 22:16:32 +00:00
Joe Groff
f761fc03e6 IRGen/Runtime: Put a reference to the metadata pattern in the nominal type descriptor.
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
2014-10-23 21:33:38 +00:00
Greg Parker
aa7aa29287 [stdlib] Delete the FastEntryPoint files for real this time.
Swift SVN r22888
2014-10-23 08:39:17 +00:00
Greg Parker
c6a88262cf [stdlib] Scrap bit-rotted FastEntryPoints.s. Rewrite refcounts using __atomic.
Generated code on x86_64 for swift_retain and swift_release and 
swift_allocObject are unchanged. arm64 is improved by using weaker 
memory barriers, fixing rdar://17423624.


Swift SVN r22887
2014-10-23 08:22:48 +00:00
Joe Groff
fc369ce734 Give Builtin.BridgeObject nil as an extra inhabitant.
Reserve the other low pointer values for potential internal use.

Swift SVN r22881
2014-10-23 00:49:14 +00:00
Joe Groff
5a2f48e3be Add a Builtin.BridgeObject type.
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
2014-10-23 00:09:23 +00:00
Greg Parker
330752b749 Revert r22710 and r22711 implementing ObjC weak ref methods on SwiftObject.
This is still incomplete and needs more work. rdar://18637774.


Swift SVN r22717
2014-10-14 01:33:29 +00:00
Joe Groff
82f6260c64 Runtime: Add ObjC weak referencing support to SwiftObject.
We were missing -_tryRetain, -_isDeallocating, -allowsWeakReference and -retainWeakReference implementations on SwiftObject, so forming an ObjC weak reference to a pure Swift object always failed and produced a nil reference. Fixes rdar://problem/18637774.

Swift SVN r22710
2014-10-13 22:12:39 +00:00
John McCall
89e60f31aa Add protocol witness tables to existential metatype
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
2014-10-08 01:20:13 +00:00
Dmitri Hrybenko
872a02f205 Runtime: don't use metadata for Builtin.UnknownObject when
!SWIFT_OBJC_INTEROP

Swift SVN r22510
2014-10-03 23:43:01 +00:00
Graham Batty
ed46e650f3 runtime: Simple wrappers to skip objc refcounts
Swift SVN r22410
2014-09-30 22:31:59 +00:00
Dmitri Hrybenko
c2d80c2589 Change swift_once_t to be actually pointer-sized on non-Darwin
Swift SVN r22384
2014-09-30 13:19:16 +00:00
Dmitri Hrybenko
0197e15a0e Runtime: untie swift_once from libdispatch
<rdar://problem/18499385> [Linux] Implement swift_once

Swift SVN r22383
2014-09-30 12:02:15 +00:00
Dmitri Hrybenko
b9ccc2d72b Don't try to include TargetConditionals.h on non-Apple platforms
Swift SVN r22329
2014-09-28 02:21:18 +00:00
Dmitri Hrybenko
b246c6cf10 Remove traces of the custom Swift zone
Swift SVN r22320
2014-09-28 00:10:49 +00:00
Joe Groff
93cb4dd83e Runtime: Remove dead HeapArrayMetadata kind.
Swift SVN r22294
2014-09-26 03:12:21 +00:00
Joe Groff
7a08716de3 Runtime: Factor out a helper function on Metadata to say when metadata refers to a class type.
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
2014-09-21 00:18:16 +00:00
Joe Groff
7d1e60e253 IRGen/Runtime: Agree on which flag bit means "isNotBitwiseTakable" again.
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
2014-09-09 05:07:17 +00:00
John McCall
590c25479d Use isa-masking to read the class object pointer from
instances of Swift subclasses of ObjC classes.

We were already doing this in the runtime.  This patch
unhides the runtime's mask word (swift_isaMask) and makes
IR-gen take advantage of it when it can.

Swift SVN r21592
2014-08-29 21:36:53 +00:00
John McCall
c1b03784df Instead of passing type metadata to swift_initClassMetadata,
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
2014-08-28 01:27:53 +00:00
Doug Gregor
e00aaadf48 Allow dynamic casting of foreign metatypes.
Another part of CF casting support, <rdar://problem/18088474>.


Swift SVN r21402
2014-08-22 04:47:11 +00:00
Doug Gregor
61ee5f7529 Allow dynamic casts between foreign classes and other classes.
These casts always succeed, because we don't have any way to check
them (yet). Part of <rdar://problem/18088474>.

Swift SVN r21386
2014-08-21 22:54:10 +00:00
Joe Groff
dc926bc649 Runtime: Intercept -_tryRetain on the magic base classes of bridged containers.
Strings that get used to name SpriteKit nodes on Mavericks end up weakly referenced by NSMapTables using the legacy GC-compatible weak pointer personality, which for our bridged objects ended up falling into the default NSObject implementation of reference counting via the "_tryRetain" SPI, causing heap corruption. I tried really hard to isolate a test case and failed, but this fixes the Adventure crasher in <rdar://problem/17887502>.

Swift SVN r20966
2014-08-03 05:33:09 +00:00
Greg Parker
fe8618a3d2 Scrap the custom allocator until we have time to fix it.
The allocator's crimes include:
* It uses OS SPI that must not be used by non-OS apps.
* It does not play well with memory debugging tools like Instruments.
* It does not return memory to the OS in response to memory pressure.
* It is less tested than we would like because many configurations 
  inadvertently turn it off (such as running from Xcode).
* Its per-thread magazine implementation does not actually work.
* Its "try alloc" flag is incompletely implemented and never used.
* Its "zero fill" flag is unimplemented and inconsistently used.



Swift SVN r20757
2014-07-30 14:11:40 +00:00
John McCall
80dd63b38d Don't allocate values out-of-line just because they're
not bitwise takable.

Finishes rdar://16755731

Swift SVN r20742
2014-07-30 08:24:18 +00:00