Commit Graph

1544 Commits

Author SHA1 Message Date
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Dave Zarzycki
d8e39d106a Runtime: finish SwiftObject
<rdar://problem/12640667> Implement SwiftObject root class

Swift SVN r15706
2014-03-31 23:10:39 +00:00
Dave Zarzycki
bba63fa14d Runtime: Add LLVM_LIBRARY_VISIBILITY to a few APIs. NFC.
Swift SVN r15697
2014-03-31 22:50:22 +00:00
Dave Zarzycki
0e8de87f05 Runtime: more SwiftObject API completeness
Swift SVN r15696
2014-03-31 22:50:19 +00:00
John McCall
9490da8a1f Inform the runtime that metatype values have extra inhabitants.
Swift SVN r15665
2014-03-31 05:49:18 +00:00
Dave Zarzycki
c07ebee7b1 Runtime: make generic non-assembly entry points use atomics
Our conditional use of atomics goal will have to wait until 2.0.

Swift SVN r15305
2014-03-20 23:32:07 +00:00
Dave Zarzycki
2f4d679fd0 Runtime: Drop the "raw" label on normal memory. NFC.
DI defined away the need for zeroed memory.

Swift SVN r15293
2014-03-20 20:42:27 +00:00
Dave Zarzycki
bd9ce4d42c Runtime: remove dead code
Swift SVN r15291
2014-03-20 20:30:02 +00:00
Joe Groff
002701fd77 Reflection: Implement magic mirror destructuring for classes.
Destructure classes by counting their superclass instance, if any, as their first child, followed by their stored properties.

Swift SVN r15268
2014-03-20 17:43:16 +00:00
Joe Groff
a9c2a7d5b8 Reflection: Implement a magic mirror for structs.
Use the newly-minted field type vector accessors to provide magic mirror destructuring for all structs!

Swift SVN r15261
2014-03-20 02:41:07 +00:00
Joe Groff
4f2656cc7c Runtime: Prefab metadata for Builtin.Int128 (and for similar-sized Float* types).
Swift SVN r15259
2014-03-20 02:02:28 +00:00
John McCall
3135abc950 Make a stab at re-using ABI constant values across targets.
There's still a lot of manual intervention required, but
at least we don't have the constants written in two different
places.

Should be NFC.

Swift SVN r15242
2014-03-19 18:51:52 +00:00
John McCall
cb77899140 Use the same value for LeastValidPointerValue in the
runtime headers and IRGen.  Should fix a miscompile
involving nested optional types.

Swift SVN r15233
2014-03-19 09:42:40 +00:00
Joe Groff
c431509516 IRGen: Reserve a spot in the nominal type descriptor for the field type vector accessor.
Building the field type vector is potentially expensive and the vector isn't needed unless we do reflectiony things to a type, so let's use a lazy accessor. Make room for it, but don't populate it yet, so we can deal with fallout from the metadata layout change.

Swift SVN r15194
2014-03-18 17:30:31 +00:00
Dave Zarzycki
49bee35d1a Runtime: magic numbers are bad
Swift SVN r15012
2014-03-13 23:15:07 +00:00
Dave Zarzycki
8ef7f64619 Runtime: disable the assembly entry points for now
They aren't buying us anything until we thread through the custom ABI
work into Swift. I'm told this won't happen for a while. Until then,
they're just double the intermediate work in this area.

Swift SVN r15004
2014-03-13 21:21:12 +00:00
Dave Abrahams
6eee8e3205 Move HeapObject into the stdlib shim module
Now that we can read definitions directly from "C" headers, stop trying
to maintain a mirror of the HeapObject struct in Swift code in the
standard library.

Swift SVN r14982
2014-03-12 23:48:31 +00:00
Joe Groff
0c55845cc1 Replace Greg's r14771 with a slightly less outrageous hack.
Implicit conversions to and from an unsigned long long enum class give us the calling convention we want for swift_allocBox without totally destroying the API for C callers.

Swift SVN r14919
2014-03-11 16:01:13 +00:00
Greg Parker
338cb2b718 Add an outrageous hack to swift_allocBox() to fix arm (rdar://16257592).
Swift SVN r14771
2014-03-07 05:37:14 +00:00
Joe Groff
5af4e7255b Runtime: Start implementing a default Mirror for ObjC classes.
For ObjC classes, use class_copyIvarList to walk the ivars, and produce the summary string using -debugDescription. Still to come:

- visiting the base class as a child, and
- calling -debugQuickLookObject to get the quicklook object. Still waiting on a final design for the IDERepresentation API.

Swift SVN r14626
2014-03-04 01:42:19 +00:00
Dave Zarzycki
46d7fc8a46 Runtime: hardcode less about the OS implementation
This also fixes non-fast-path platforms.

Swift SVN r14481
2014-02-27 22:15:22 +00:00
Doug Gregor
904739cb03 Revert "Runtime: hardcode less about the OS implementation"
This reverts r14453, which seems to be breaking the build.

Swift SVN r14480
2014-02-27 21:43:56 +00:00
Dave Zarzycki
5946a56fa3 Runtime: hardcode less about the OS implementation
There is still more to do in this area before we GM.

Swift SVN r14453
2014-02-27 06:14:53 +00:00
Dave Zarzycki
6f6495b13f runtime: ALLOC_CACHE_COUNT should never have been less than 56/64
This change removes a broken simulator hack because we don't enable the
fast cache for the simulator anymore, and even if we did, ALLOC_CACHE_COUNT
must be 56 or 64, not 32 (for 32-bit and 64-bit respectively).

Swift SVN r14447
2014-02-27 03:52:54 +00:00
Dave Zarzycki
ab1efa6ec7 runtime: DI means we don't need heap APIs that take/return zero-initialized memory
Swift SVN r14404
2014-02-26 20:31:11 +00:00
Dave Zarzycki
22e30666bd Fix a build failure
Swift SVN r14402
2014-02-26 19:50:20 +00:00
Dave Zarzycki
8fd6b3a4ab runtime: disable the malloc cache entirely for the simulator
Swift SVN r14396
2014-02-26 17:18:31 +00:00
Dave Zarzycki
a85b2a3d78 Runtime: Rename Alloc.* to HeapObject.* (NFC)
Swift SVN r14228
2014-02-21 20:12:07 +00:00
Dave Zarzycki
b32a02a75f Runtime: wire up wrapper zone around the default zone
Swift SVN r14226
2014-02-21 20:11:48 +00:00
Joe Groff
3c15aff85b Expose unsafeReflect to the stdlib.
A useful unsafe optimization for potential implementations of Mirror that have existing heap storage to share from the value, like for Array or Dictionary.

Swift SVN r14186
2014-02-21 00:09:32 +00:00
Joe Groff
73e564428f stdlib/runtime: Stub out a mechanism for introspecting value structure.
Define a "Mirror" protocol with methods for querying the number of children a structured value has, getting the name and mirror for each of those children, and a string and "IDE representation" of the value, as needed by playgrounds and by our planned generic printing facility.

In the runtime, define a "reflect" function that can provide a Mirror for any object, either using a "Reflectable" protocol conformance if available, or falling back to a magic implementation in the runtime that grovels the type metadata. Stub out a bare minimum default implementation.

Swift SVN r14139
2014-02-20 08:26:27 +00:00
Jordan Rose
0b2541b58f Rename the standard library to "Swift" (instead of "swift")
This is more in line with all other modules currently on our system.
If/when we get our final name for the language, we're at least now set
up to rename the library without /too/ much trouble. (This is mostly just
a lot of searching for "import swift", "swift.", "'swift'", and '"swift"'.
The compiler itself is pretty much just using STDLIB_NAME consistently now,
per r13758.)

<rdar://problem/15972383>

Swift SVN r14001
2014-02-17 19:30:47 +00:00
Joe Groff
3fded63cac stdlib: Proof-of-concept 'print' implementation for an arbitrary Array.
Mock up a naive Printable protocol, and do some dirty tricks in the runtime to implement a 'printAny' function that uses swift_conformsToProtocol to look up a conformance to Printable if the type has one, or falls back to a dumb opaque printing if it doesn't. Use this to make Array<T> Printable in some way or another for all T.

Swift SVN r13902
2014-02-14 05:15:33 +00:00
Joe Groff
802df0bdf3 Runtime: Do awful things to implement "swift_conformsToProtocol" for Swift protocols.
Given our constraints for 1.0, we can actually sort-of look up protocol conformances just by dlsym'ing the symbol for their protocol witness table, since we won't be implementing runtime witness table instantiation or private conformances anytime soon. To make this work for generic types, distastefully regress our mangling for protocol conformances by assuming all generic conformances are completely general to the unbound generic type and leave the generic parameters out of the mangling.

Swift SVN r13901
2014-02-14 05:15:32 +00:00
Greg Parker
95c2fc43f8 Clena up some 32/64 mismatches. Remove some dead posix stubs.
Swift SVN r13144
2014-01-30 09:34:26 +00:00
Joe Groff
378f18c430 IRGen/Runtime: Provide getGenericMetadata[1-4] entry points.
This lets IRGen avoid emitting an alloca for common generic metadata instantiations. These entry points can also be marked "readnone", and the general getGenericMetadata entry point can be "readonly", giving LLVM's optimizer a fighting chance on unspecialized generic code.

Swift SVN r12789
2014-01-22 21:54:58 +00:00
Joe Groff
677576cffb IRGen: Use a shared bb for condfail instructions and kill the runtime call.
Swift SVN r12339
2014-01-15 19:33:01 +00:00
Connor Wakamo
c7c15d68b8 Added missing newlines to the end of a few files.
Swift SVN r10791
2013-12-04 21:37:17 +00:00
Dmitri Hrybenko
81dc5deee8 Change 'def' keyword back to 'func'
Swift SVN r10522
2013-11-17 07:45:28 +00:00
Joe Groff
562e2bfff6 Runtime: Add swift_once function.
For now, just shim over dispatch_once.

Swift SVN r10514
2013-11-16 03:11:17 +00:00
Joe Groff
7de9706403 IRGen/Runtime: Expose extra inhabitants of class protocol types.
This gives 'id?' and other optional class protocol types optimal representation consistent with class types.

Swift SVN r10346
2013-11-11 22:52:23 +00:00
Joe Groff
554abf2d7a IRGen/Runtime: Expose extra inhabitants of class types.
Start using null-page values as extra inhabitants when laying out single-payload enums that contain class pointers as their payload type. Don't use inhabitants that set the lowest bit, to avoid trampling potential ObjC tagged pointer representations. This means that 'T?' for class type T now has a null pointer representation. Enums with multiple empty cases, as well as nested enums like 'T??', should now have optimal representations for class type T as well.

Note that we don't yet expose extra inhabitants for aggregates that contain heap object references, such as structs with class fields, Swift function types, or class-bounded existentials (even when the existential has no witness tables).

Swift SVN r10061
2013-11-09 00:43:40 +00:00
Dmitri Hrybenko
91ce21666d Change 'func' keyword to 'def'
I tried hard find all references to 'func' in documentation, comments and
diagnostics, but I am sure that I missed a few.  If you find something, please
let me know.

rdar://15346654


Swift SVN r9886
2013-11-02 01:00:42 +00:00
Joe Groff
bbddf41693 IRGen: Instantiate existential metadata through the runtime.
When we need a reference to protocol or protocol composition type metadata, ask for it through the runtime, instead of referencing statically-emitted protocol metadata.

Swift SVN r9871
2013-11-01 17:13:49 +00:00
Joe Groff
fe7ecec60c Runtime: Provide value witness implementations for class existentials.
Same deal as for opaque existentials--pre-instantiate a static witness table for one-witness-table types (the zero-witness-tables case is nicely handled by Builtin.ObjCPointer's value witness), and generate a vwtable using dynamic witness implementations for each different-sized container on demand as necessary.

Swift SVN r9850
2013-10-31 18:38:54 +00:00
Joe Groff
eeed35909e Runtime: Add unknownRetain/unknownRelease entry points.
We can use these instead of objc_retain/objc_release for heap objects of unknown provenance, such as the references inside class existentials. We could use them in IRGen as well.

Swift SVN r9849
2013-10-31 18:36:01 +00:00
Joe Groff
c38ad6458e Runtime: Expose assignExistentialWithCopy entry points.
The assign-with-copy operation on existentials is complex enough to be emitted as a function call, which is currently generated on-demand by IRGen for every existential layout. We can instead use the implementation out of the runtime. Provide entry points for zero, one, and any number of witness tables.

Swift SVN r9815
2013-10-30 21:58:36 +00:00
Joe Groff
45d0ae05f8 Runtime: Add value witness forwarders to Metadata type.
Add member functions to Metadata that call into the value witness table and pass 'self' automatically.

Swift SVN r9758
2013-10-29 16:07:22 +00:00
Joe Groff
37e652b2ba Runtime: Add swift_getExistentialMetadata entry point.
Set up a metadata cache for existential type metadata. Instantiate existential metadata by first sorting the protocol list, so that it is order invariant, precomputing the overall witness table count and class constraint of the composition so it can be cached in the existential metadata.

We still need to implement value witnesses for existential containers in the runtime before this is complete. We can at least test the uniquing and flags computations at this point.

Swift SVN r9727
2013-10-28 20:53:20 +00:00
Joe Groff
65d443a158 runtime: Define structures for protocol descriptors and existential metadata.
We'll emit protocol descriptors with ObjC-compatible layout. Existential type metadata will be instantiated by the runtime and reference these descriptors to describe the type.

Swift SVN r9708
2013-10-28 16:56:09 +00:00