Commit Graph

284 Commits

Author SHA1 Message Date
Joe Groff
1c4e08a9c8 Fix up a tangle of issues related to reabstraction.
- A spot fix in SILGen for reabstracting the result of a downcast, which fixes checked casts to function types.
- Associate the layout information in type metadata records with the most abstract representation of the type. This is the correct thing to do in cases where we need the metadata as a tag for an opaque value--if we store a value in an Any, or pass it as an unconstrained generic parameter, we must maximally reabstract it. This fixes the value semantics of existentials containing trivial metatypes.
- To ensure that we get runtime layout of structs and enums correct when they contain reabstractable types, introduce a "metadata for layout" concept, which doesn't need to describe the canonical metadata for the type, but only needs to describe a type with equivalent layout and value semantics. This is a correctness fix that allows us to correctly lay out generic types containing dependent tuples and functions, and although we don't really take advantage of it here, it's also a potential runtime performance win down the road, because we could potentially produce direct metadata for a primitive type that's layout-equivalent with a runtime-instantiated type. To aid in type safety here, push SILType deeper into IRGen in places where we potentially care about specific representations of types.
- Finally, fix an inconsistency between the runtime and IRGen's concept of what spare bits unmanaged references and thick metatypes have.

Together, these fixes address rdar://problem/16406907, rdar://problem/17822208, rdar://problem/18189508, and likely many other related issues, and also fixes crash suite cases 012 and 024.

Swift SVN r21963
2014-09-16 01:44:34 +00:00
Michael Gottesman
af52f7c4f9 [irgen] Now that swift_unknown{Retain,Release} are implemented, have IRGen emit them.
This gives us some nice speedups on the perf test suite.

Phonebook     19508  15378  26.86%
Dictionary    31664  1384   20.23%
LinkedList    1902   1583   20.15%
SortStrings   1402   1168   20.03%
StrToInt      1014   861    17.77%
EditDistance  703    633    11.06%
Dictionary    21206  1088   10.85%
Dictionary    1354   1225   10.53%
StringWalk    1361   1246   9.23%

rdar://18314006

Swift SVN r21959
2014-09-15 22:56:01 +00:00
Michael Gottesman
9514ba5a7d [irgen] Lower fix_lifetime => swift_keepAlive().
I introduced a function swift_keepAlive2() which has a different signature from
swift_keepAlive() until I can verify that the stdlib is using the new
infrastructure.

The difference in signature is that swift_keepAlive2 takes just a pointer while
swift_keepAlive also takes a metadata value that is not necessary for our
purposes anymore.

Swift SVN r21718
2014-09-04 21:53:18 +00:00
Joe Groff
ceb05a7e2f IRGen: Fix weak reference operations for @objc types.
Now that weak is represented as an optional type, these need the same ptrtoint/inttoptr hacks that Chris added to the pure Swift versions.

Swift SVN r18586
2014-05-23 04:44:52 +00:00
John McCall
329abe543d Pass an alignment mask during heap array allocation,
not an alignment value.

Assert that various entrypoints get an alignment mask.

Get everything uniformly passing an assertion about
dealloating an object with the correct allocation
size; don't actually enable the assertion yet, though.

rdar://16989632

Swift SVN r18550
2014-05-22 01:58:05 +00:00
John McCall
cc1d8b606f Look through reference storage types when generating
@encodings for property getter/setters.

rdar://16909436

Swift SVN r18399
2014-05-19 08:00:07 +00:00
Chris Lattner
6d84785e52 Substantially rework how weak pointers are represented in the AST and
at the SIL level.  Now, the referent type of a WeakStorageType is always
an optional type, instead of always being the underlying reference.  This
allows us to represent both optional types.  Before, both of these had the
same AST representation of WeakStorageType(T):

  weak var x : T?
  weak var x : T!

which doesn't work.  Now we represent the optional type explicitly in the
AST and at SIL level.  This also significantly simplifies a bunch of code
that was ripping off the optional type and resynthesizing it in other places,
and makes SILGen of weak pointers much more straight-forward by eliminating
the need for emitRefToOptional and emitOptionalToRef entirely (see the diffs
in test/SILGen/weak).

Weak pointers still have problems, but this is a big step forward.


Swift SVN r18312
2014-05-18 04:53:35 +00:00
John McCall
059ed4cd10 Propagate alignment arguments around through the
slow allocation/deallocation APIs.

Swift SVN r18160
2014-05-16 01:40:36 +00:00
Joe Groff
f1fa77e140 IRGen: Fix heap array destructor for types where size != stride.
Use TypeInfo::indexArray to get the bounds of the array instead of duplicating its logic incorrectly. Fixes <rdar://problem/16916422>.

Swift SVN r18115
2014-05-15 18:15:04 +00:00
John McCall
b38a63950d Implement @unowned(unsafe).
This was part of the original weak design that
there was never any particular reason to rush the
implementation for.  It's convenient to do this now
so that we can use it to implement Unmanaged<T> for
importing CF types.

Swift SVN r16693
2014-04-23 08:51:23 +00:00
John McCall
8bd79535a1 Track spare bits in @unowned types.
Swift SVN r16692
2014-04-23 08:51:18 +00:00
John McCall
8681963bcb A couple of long-overdue renames.
Builtin.ObjectPointer -> Builtin.NativeObject
Builtin.ObjCPointer -> Builtin.UnknownObject

Swift SVN r16634
2014-04-22 00:17:08 +00:00
Joe Groff
9c198cd1cc IRGen: In heap array destructors, iterate by the stride, not by the size of the LLVM type.
Fixes more crashes with array literals when using them with generic types or types with a size/stride difference.

Swift SVN r16144
2014-04-10 00:24:58 +00:00
Joe Groff
a51636ccc9 IRGen: Fix broken destructors for heap arrays.
There were two problems here:

- We weren't storing the length of the array in the heap object, so the destructor never attempted to destroy any elements, and
- In the destructor loop, we were iterating backward but comparing the loop pointer against 'end', so if we actually initialized the length, the destructor would run forever destroying elements until it crashed on an invalid object.

Fixes <rdar://problem/16536439>.

Swift SVN r16138
2014-04-10 00:01:10 +00:00
Joe Groff
def2f97944 IRGen: Generalize 'hasSwiftRefcount' into an enum of reference counting mechanisms.
Replace HeapTypeInfo::hasSwiftRefcount with a "getSwiftRefcounting" method, returning an enum indicating whether a heap object has native/ObjC/block/unknown refcounting semantics. Use _Block_copy and _Block_release for block refcounting.

Swift SVN r16041
2014-04-08 02:43:16 +00:00
Joe Groff
5e5f31d5e3 IRGen: Share TypeInfo among equivalent generic instantiations, take 2.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

In this revision, we profile the nested archetypes of each recursively, which I neglected to take into account originally in r12112, causing failures when archetypes that differed by associated type constraints were incorrectly collapsed.

Swift SVN r12116
2014-01-10 05:25:45 +00:00
Joe Groff
97ff9e47a8 Revert "IRGen: Share TypeInfo among equivalent generic instantiations."
This reverts commit r12112. It gives the buildbot indigestion.

Swift SVN r12113
2014-01-10 03:22:53 +00:00
Joe Groff
57cacbfe38 IRGen: Share TypeInfo among equivalent generic instantiations.
IRGen type conversion is invariant with respect to archetypes with the same set of constraints, so instead of redundantly generating a TypeInfo object and IR type for Optional<T> for every T everywhere, key TypeInfo objects using an "exemplar type" that we form using a folding set to collapse together archetypes with the same class-ness, superclass constraint, and protocol constraints.

This is a nice memory and IR size optimization, but will be essential for correctness when lowering interface types, because there is no unique context to ground a dependent type, and we need to lower the same generic parameter with the same context requirements to the same type whenever we instantiate it in order for the IR to type-check.

Swift SVN r12112
2014-01-10 02:02:58 +00:00
Adrian Prantl
d40c6e15a8 Debug info: Assign the location of the terminator to cleanups.
Yay! Less hacky.
<rdar://problem/15510646> Current line seems incorrect after single stepping from breakpoint

Swift SVN r10664
2013-11-22 19:39:14 +00:00
John McCall
20e58dcf93 Change the type of function values in SIL to SILFunctionType.
Perform major abstraction remappings in SILGen.  Introduce
thunking functions as necessary to map between abstraction
patterns.

Swift SVN r10562
2013-11-19 22:55:09 +00:00
John McCall
93dfaa6bf4 Make everything getting a TypeInfo declare whether it's
working with a SIL-lowered or SIL-unlowered type.

Swift SVN r10067
2013-11-09 01:41:16 +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
dc24cb2732 Portability: APInt is not implicitly convertible to bool, call getBoolValue
explicitly

(I have no idea why this compiles on Darwin.)


Swift SVN r9612
2013-10-23 05:21:43 +00:00
Joe Groff
4ff3c62ef6 IRGen: Include instance size and alignment mask in class metadata.
We need these for dependent-layout generic classes so we know the allocation/deallocation size and alignment. When I figure out ObjC interop with generic subclasses these should move to the rodata so they get handled resiliently by the ObjC runtime, but for generic class bringup this is convenient.

Swift SVN r9249
2013-10-12 01:51:18 +00:00
Adrian Prantl
88e5426c71 Debug info: Line table: Calls to swift_releases should not jump to the
point where that memory was retained/allocated.
rdar://problem/15204469

Swift SVN r9235
2013-10-11 23:37:40 +00:00
John McCall
eaa6228124 getFragileTypeInfo -> getTypeInfo
I didn't end up going the same way with fragility that I
thought I would at start, and this method name has become a
legacy.

Swift SVN r7340
2013-08-19 23:01:44 +00:00
Dmitri Hrybenko
d0455ca1c6 Remove unneeded llvm:: qualifier for llvm::ArrayRef
Swift SVN r7093
2013-08-09 20:05:02 +00:00
Dmitri Hrybenko
de59d8dcd4 Remove unneeded llvm:: qualifier for llvm::StringRef and llvm::SmallVector
Swift SVN r7089
2013-08-09 18:41:46 +00:00
Adrian Prantl
5e98accde4 Debug info: Rename createFunction -> emitFunction for consistency.
Swift SVN r7054
2013-08-08 21:20:07 +00:00
John McCall
14cb7001b3 Implement basic support for [weak].
Swift SVN r7041
2013-08-08 04:04:51 +00:00
John McCall
b77c430848 Add SIL-gen and some missing runtime support for [unowned].
Swift SVN r6881
2013-08-03 08:46:54 +00:00
John McCall
00a940ac1b Rename weak_retain to unowned_retain and change it to
require the correct [unowned] type as an argument.

Swift SVN r6825
2013-08-02 00:02:09 +00:00
John McCall
0d0e0d1939 Abstract out sub-interfaces for [unowned] and [weak] TypeInfos.
Swift SVN r6325
2013-07-17 09:20:30 +00:00
John McCall
7b86817b3c Basic value structure for [weak] and [unowned] references.
Add a bunch of new entrypoints and give them terrible
implementations.

Swift SVN r6322
2013-07-17 09:20:20 +00:00
Adrian Prantl
ae9bd9397b Debug Info: Generate scope information for many more builtin/artificial functions.
Swift SVN r5876
2013-06-28 20:05:41 +00:00
Joe Groff
4ff8cd27dd IRGen: Abstract out an "unknown refcounted" concept.
In the implementation of class-bounded archetypes and existentials, instead of referring to ObjC pointer types and retain/release operations directly, use an 'UnknownRefCountedPtrTy' and 'emitUnknownRetain/Release' functions.

Swift SVN r5619
2013-06-17 18:31:49 +00:00
Joe Groff
197c3e6d02 IRGen: Strip unneeded parameters from IRGenFunction constructor.
Swift SVN r5146
2013-05-10 18:18:14 +00:00
Joe Groff
223d0251bd IRGen: Add getFragileTypeInfo and getFunctionType for SIL types.
Add overloads of getFragileTypeInfo and getFunctionType that take a SILType instead of a Swift CanType, and use them where it's easy to do so. Right now they just forward to the CanType versions, but we'll want to do SILType-specific type conversion soon. Clean up some IRGenSILFunction interfaces now that SILFunction carries most of the information IRGen needs intrinsically. No functionality change.

Swift SVN r5141
2013-05-10 16:28:25 +00:00
John McCall
d8cdb0160f Switch IR-generation to generally traffic in alignment
masks rather than raw alignments.

Swift SVN r5136
2013-05-10 06:16:28 +00:00
Joe Groff
2be26b31a5 Make the deallocating destructor actually deallocate.
Emit the deallocObject runtime call inside the deallocating destructor for a heap object, instead of inside swift_release. This will allow for heap objects with known size to directly call fast deallocator entry points and potentially custom deallocators in the future.

Swift SVN r5027
2013-05-02 20:37:12 +00:00
John McCall
65fc2b74f8 Basics of dynamic struct layout.
Swift SVN r4902
2013-04-25 01:39:58 +00:00
John McCall
80a82b6849 Abstract ElementLayout to work with non-fixed layouts.
Swift SVN r4899
2013-04-25 01:39:40 +00:00
Chris Lattner
2b6902b232 eliminate the "manage" operation on TypeInfo, which is now a (complicated!) noop.
Swift SVN r4850
2013-04-21 16:27:43 +00:00
Chris Lattner
5664431c9a remove Cleanup.h and references to the Cleanup class, along with
some dead logic in IRGenFunction.



Swift SVN r4847
2013-04-21 06:36:22 +00:00
Chris Lattner
85663f6df2 simplify Explosion by eliminating (now) copies of existing methods.
This removes addUnmanaged, ignoreAndDestroy, ignoreUnmanaged, claimUnmanagedNext,
claimUnmanaged, forwardNext, and forward


Swift SVN r4846
2013-04-21 06:29:50 +00:00
Chris Lattner
0be7bbdddf remove ManagedValue.
Swift SVN r4843
2013-04-21 05:56:02 +00:00
Chris Lattner
e8686c9560 remove Cleanups from IGF, simplify Initialization a bit.
Swift SVN r4841
2013-04-21 05:28:04 +00:00
Chris Lattner
e3d6a489af remove the Cleanup subclasses.
Swift SVN r4839
2013-04-21 05:06:52 +00:00
Chris Lattner
abee79b26e remove some Expr stuff.
Swift SVN r4810
2013-04-18 22:32:37 +00:00
John McCall
38b34b7307 Pass #1 at localizing assumptions about fixed layout and
handling non-fixed layouts.

This uncovered a bug where we weren't rounding up the header
size to the element alignment when allocating an array of archetypes.

Writing up a detailed test case for *that* revealed that we were
never initializing the length field of heap arrays.  Fixing that
caused a bunch of tests to crash trying to release stuff.  So...
I've left this in a workaround state right now because I have to
catch a plane.

Swift SVN r4804
2013-04-18 07:58:21 +00:00