Commit Graph

540 Commits

Author SHA1 Message Date
Dmitri Hrybenko
1bc0053a6c Only emit used markers for witness tables on Darwin
The inline assembly we emit is only valid for Mach-O.

Swift SVN r22511
2014-10-03 23:53:30 +00:00
Doug Gregor
73fb0f74f0 Give PotentialArchetype::getType() access to the archetype builder. NFC
Swift SVN r22506
2014-10-03 22:39:24 +00:00
Doug Gregor
c9e0ed1e23 Archetype builder: move the "root" protocol into the potential archetype. NFC
Storing the root protocol outside the potential archetype meant we
could easily have forgotten to pass the right argument to
PotentialArchetype::getType(). Our current staging of archetype
construction means that nothing go it wrong today, but it's a minor
minefield for future improvements to the archetype builder.

Swift SVN r22504
2014-10-03 22:39:22 +00:00
Joe Groff
00fd417bd2 IRGen: Remove support for existential methods.
Eliminate support code for lowering protocol_method instructions, and eliminate ExtraDataKind::Metadata, which is no longer needed now that SIL provides all the necessary type information at the call site.

Swift SVN r22451
2014-10-02 00:11:54 +00:00
Joe Groff
7e1df225d7 IRGen: Remove dead code for lowering existential upcasts.
Swift SVN r22389
2014-09-30 16:11:55 +00:00
Joe Groff
c098645f34 SIL: Conformances relate to formal types, so change witness_method's lookup type to a CanType.
Should be NFC in practice, since only nominal types can currently conform to protocols anyway, but improves modeling of the system.

Swift SVN r22360
2014-09-29 20:44:00 +00:00
Joe Groff
f33d3a7abd Revert "IRGen: Remove dead code for lowering existential upcasts."
This reverts commit r22346.

Swift SVN r22352
2014-09-29 13:46:28 +00:00
Joe Groff
b9ccbb7f5d IRGen: Remove dead code for lowering existential upcasts.
Swift SVN r22346
2014-09-28 19:24:36 +00:00
Joe Groff
fd23404668 Revert "IRGen: Remove dead code for lowering existential upcasts."
This reverts commit r22334.

Swift SVN r22336
2014-09-28 18:40:56 +00:00
Joe Groff
9ae097e977 IRGen: Remove dead code for lowering existential upcasts.
Swift SVN r22334
2014-09-28 17:59:45 +00:00
Joe Groff
c8d0747ad9 IRGen: Don't attempt to lay out witness tables for @objc protocols.
This was a harmless bit of unnecessary work until John added "materializeForSet" witnesses for protocol requirements, which never exist in @objc protocols. Fixes rdar://problem/18428904.

Swift SVN r22244
2014-09-24 00:06:42 +00:00
Joe Groff
da26c54c06 IRGen: Preserve associated types and witness tables in NecessaryBindings.
Fixes crasher #003 (rdar://problem/18232605). This time, also increase the buffer size for the necessary bindings so we don't clobber memory.

Swift SVN r22118
2014-09-19 04:00:58 +00:00
Joe Pamer
ffc37729c8 Revert "IRGen: Preserve associated types and witness tables in NecessaryBindings."
This reverts commit r22108

Swift SVN r22115
2014-09-19 02:49:17 +00:00
Joe Groff
b0dea1625f IRGen: Preserve associated types and witness tables in NecessaryBindings.
Fixes crasher #003 (rdar://problem/18232605).

Swift SVN r22108
2014-09-19 00:06:18 +00:00
John McCall
bd218ea9d2 Add materializeForSet entries to vtables and protocol
witness tables.

Swift SVN r22017
2014-09-17 08:08:12 +00:00
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
Joe Groff
e004ad7df4 SIL: Carry AST types through init_existential instructions.
This is necessary to be able to properly stash values with nontrivial lowerings, such as metatypes and functions, inside existential containers. Modify SILGen to lower values to the proper abstraction level before storing them in an existential container. Part of the fix for rdar://problem/18189508, though runtime problems still remain when trying to actually dynamicCast out a metatype from an Any container.

Swift SVN r21830
2014-09-10 05:56:36 +00:00
Joe Groff
3cf9a13d68 IRGen: Fix some synchronization issues when skipping @objc protocols for witness emission.
We were stopping too early when binding witness tables for local archetypes, causing us to miss binding witness tables for native protocols if the number of total protocols was greater than the number of protocols with witness tables, and we failed to increment the local type data key to match the Archetype::getConformsTo() ordinal when binding polymorphic parameters. Together these fix rdar://problem/18232916 (though adding any methods to a class still crashes because of rdar://problem/17480006).

Swift SVN r21796
2014-09-09 03:22:49 +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
John McCall
0ddc7ee5b6 Resilience expansion is not an IR-generation concept.
If a type has to be passed or returned resiliently, it
will necessarily be passed indirectly, which is already
represented in SILFunctionType.  There is no need to
represent this as a separate channel of information.

NFC. Also fixes a problem where the signature cache
for ExtraData::Block was writing past the end of an
array (but into the storage for an adjacent array
which was fortunately never used).

ExtraData should also disappear as a concept, but we're
still relying on that for existential protocol witnesses.

Swift SVN r21548
2014-08-28 23:07:50 +00:00
Chris Lattner
50979a2ff4 implement SILGen and IRGen support for witness table generation of non-objc optional
protocol requirements.  Not testable because sema doesn't allow these to exist.


Swift SVN r21513
2014-08-28 04:20:02 +00:00
Joe Groff
8bb7f7b5fd IRGen: Fix codegen for weak class-constrained protocol types.
We were accidentally picking out the instance pointer for the witness table in the packed enum payload representation. Fixes <rdar://problem/17857154>.

Swift SVN r21026
2014-08-04 22:38:12 +00:00
John McCall
c367362f22 Properly flag opaque existential types as not being
bitwise-takable.

Swift SVN r20803
2014-07-31 02:03:56 +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
John McCall
584795e505 Replace the typeOf value witness with an
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
2014-07-30 08:24:12 +00:00
John McCall
934527a029 Eliminate all uses of the typeof value witness.
Swift SVN r20734
2014-07-30 04:40:58 +00:00
John McCall
6165da998c Rename some of the emitTypeMetadataFor... routines to make
it clear that they're requesting a dynamic type.

Some conceptual functional change; practical functionality
change should be limited.

Swift SVN r20733
2014-07-30 04:40:51 +00:00
John McCall
64aa0ea950 When instantiating a generic class, compensate for
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
2014-07-25 10:08:51 +00:00
Jordan Rose
b6818046a8 Eliminate optimization levels 0-3 in favor of -Onone/-O/-Ofast.
We were already effectively doing this everywhere /except/ when building
the standard library (which used -O2), so just use the model we want going
forward.

Swift SVN r20455
2014-07-24 01:12:59 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
Joe Groff
45eec9a2e9 Remove 'interface' from the method names of SILFunctionType.
SILFunctionTypes are always interface types now. NFC.

Swift SVN r19952
2014-07-14 22:03:46 +00:00
Jordan Rose
727a7eb77a Attributes: Use class names in the DAK_* enum instead of attribute spellings.
This allows for single attributes that can be spelled multiple ways.
No functionality change.

Swift SVN r18993
2014-06-18 23:28:28 +00:00
John McCall
6fb1dc2db1 Centralize more dynamic-casting code into GenCast.cpp. NFC.
Swift SVN r18818
2014-06-12 01:00:23 +00:00
Joe Groff
ac903bf943 IRGen: Make our use of spare bits in heap objects tagged-pointer-safe.
Don't use spare bits on platforms that use ObjC tagged pointers when an enum payload involves a class-constrained existential, archetype, or ObjC-defined class type. If a payload is of a Swift-defined class type, we can still assume it's a real pointer and use its spare bits. Add an @unsafe_no_objc_tagged_pointer attribute that can be applied to protocols to denote that existentials bounded by that protocol can use spare bits; this is necessary to preserve the layout of bridged Array and Dictionary types, which should not be bound to tagged pointer types in practice (fingers crossed). Fixes <rdar://problem/16270219>.

Swift SVN r18781
2014-06-10 17:07:47 +00:00
Chris Lattner
2dc1df52d1 Implement <rdar://problem/16954464> Cannot make a strong IBOutlet
This adds support for the "strong" ownership modifier, and specifically 
make it override the "implicit weak" behavior of @IBOutlet.



Swift SVN r18737
2014-06-08 20:49:21 +00:00
John McCall
bc3951761e Change the preserve-symbols hack for protocol witness tables to
survive through 'strip', which is apparently performed by the
app store.

All the hard work done by Greg Parker.

This hack is getting out of hand; we should add a proper
conformance registry for 1.0.

rdar://17033558

Swift SVN r18647
2014-05-27 02:39:54 +00:00
Joe Groff
464bce4b39 IRGen: Put witness tables into no_dead_strip sections.
Witness tables can't be dead-stripped without breaking the dynamic conformance queries printing now relies on. Fixes <rdar://problem/16993349>.

Swift SVN r18567
2014-05-22 19:30:45 +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
d6957d0328 Make existential-to-concrete metatype casts work.
This mostly falls out from the metatype cast infrastructure, but we need to generalize some Sema and SILGen code to accept AnyMetatypeType. Concrete-to-existential metatypes will need more runtime checking that isn't implemented, so raise a 'not implemented' error on those for now.

Swift SVN r17798
2014-05-09 20:57:55 +00:00
Joe Groff
1dce36edd2 Make 'T.self is U.Type' work.
Fix up all of type-checking, SILGen, IRGen, and the runtime to support checked casts of metatypes. <rdar://problem/16847453>

Swift SVN r17719
2014-05-08 22:55:14 +00:00
Michael Gottesman
67cb75ea94 [irgen] When emitting code for the JIT, do not emit available external witness tables.
Currently we have in a hack that available_external entries are emitted
shared. This does not jive well in the JIT when one is attempting to
merge an external witness table with the linkonce_odr internal
available_external witness table.

We are not doing any optimization at the JIT level so there is no reason
to emit available_external witness tables at all.

So lets not do that.

Swift SVN r17423
2014-05-05 04:21:24 +00:00
Joe Groff
71678b4bdf IRGen/Runtime: Expose the 'isBitwiseTakable' bit in the value witness flags.
Set a bit for types that are non-bitwise-takable, and calculate it as part of runtime struct and enum layout. Include 'bitwise takable' as part of the runtime 'is inline' calculation to be consistent with the compile-time policy change in r17008.

Swift SVN r17036
2014-04-29 15:23:14 +00:00
Joe Groff
caff7b62d9 IRGen: Expose the array value witnesses as builtins.
Add Builtin.destroyArray, .copyArray, .takeArrayFrontToBack, and .takeArrayBackToFront, which perform bulk destroy/copy/take operations using memcpy/memmove, a loop, or a generic value witness.

Swift SVN r17009
2014-04-29 03:46:58 +00:00
Joe Groff
1f6af41dc3 IRGen: Store non-bitwise-takable types out of line in existential containers.
Give non-bitwise-takable types the Allocate FixedPacking kind so that they get allocated out of line in fixed buffers. Small value types with @weak references seem rare enough to me that it's overall better to let existential containers be bitwise-takable than to pessimize their take operations for the few value types that aren't bitwise-takable.

While we're here, add an assertion to FixedTypeInfo::initializeWithTake to ensure that all non-bitwise-takable types override the default implementation.

Swift SVN r17008
2014-04-29 03:46:48 +00:00
Joe Groff
7a18f7231d IRGen: Emit array value witnesses.
Implement codegen for the destroyArray, initializeArrayWithCopy, and initializeArrayWithTake value witnesses.

Swift SVN r16999
2014-04-28 22:30:28 +00:00
Chris Lattner
a7012f23ef Remove swift::ArrayType. It is dead and vestigial code for supporting fixed size
arrays, which never got baked.  Remove it until we have time to do things right.


Swift SVN r16995
2014-04-28 21:18:27 +00:00
Joe Groff
809655d8d7 IRGen: Emit nontrivial initializeWithTake operations for types that aren't bitwise-takable.
Emit a real initializeWithTake value witness for types that aren't bitwise-takable. Drop the default 'initializeWithTake' implementation from NonFixedTypeInfo, so that leaf type infos are forced to properly override it for their own layout, and fill in the now-missing implementation in SequentialTypeInfo.

Swift SVN r16955
2014-04-27 23:45:28 +00:00
John McCall
285354fb5b Remove pointless code left over from a briefly
considered approach.

Swift SVN r16913
2014-04-27 04:55:12 +00:00
John McCall
7c742b4d32 Emit SILWitnessTables lazily if their linkage allows it.
Swift SVN r16911
2014-04-27 04:29:56 +00:00