Commit Graph

315 Commits

Author SHA1 Message Date
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
b56c31dc5f [sil-combine] convert_function simplification.
convert_function works essentially as a bitcast on functions that
enables you to change address/ref type parameters. This commit enforces
that invariant in the verifier and teaches SILCombine how to simplify it
so we can use it in the devirtualizer.

Swift SVN r17516
2014-05-06 01:16:14 +00:00
Joe Groff
bf858cc8a1 SILGen: Handle inner pointer returns through currying and dynamic lookup.
When we partially apply an inner-pointer method or property, the thunk or partial_apply that applies "self" needs to be the one that handles lifetime-extending "self". Verify that a partial_apply-ed inner pointer method is not inner pointer and implement lifetime extension in the partial apply thunk. Fixes <rdar://problem/16803701>.

Swift SVN r17321
2014-05-03 18:37:42 +00:00
Michael Gottesman
a7bb61265c [deserialization] Tighten up deserialization of witness tables.
We now enforce via an assert that each witness table is unique and that
every protocol conformance that is referenceable from SIL must have a
witness table matched to it.

Also, I taught the linker that it should deserialize witness tables for
InitExistentialRefInst instructions, something that was missed before.

Swift SVN r17283
2014-05-02 22:28:13 +00:00
Michael Gottesman
4ff2e7b7f1 Re-enable the verifier always. XFAIL remaining problem tests so we get verifier converage.
Swift SVN r17213
2014-05-02 00:53:58 +00:00
Michael Gottesman
e1385e7c9c Re-enable the verifier when processing SILGen and the gauranteed diagnostic passes.
Swift SVN r17212
2014-05-02 00:39:08 +00:00
Joe Groff
a3a54545e5 SIL: Fix up ownership and bridging when emitting dynamic method calls.
There were a bunch of things broken here--it's amazing this ever appeared to work.

- Retain 'self' before partial_applying it to the method, so we don't overrelease it.
- Correctly lower the ownership conventions of the dynamic method against the SILDeclRef, so we don't overrelease arguments or over-over-release self, and we handle ObjC methods with weird conventions correctly.
- Thunk when there are bridging type differences between the partially-applied ObjC method and a Swift method, so we don't crash if the method takes NSStrings or other bridged types.

Add verifier checks that the result of 'dynamic_method' and BB arg of 'dynamic_method_br' actually match the method they're dispatching.

Swift SVN r17198
2014-05-01 22:46:11 +00:00
Joe Groff
aeb607ad5b Fix latent SIL verification errors.
r15824 overrode SILVerifier::visitSILBasicBlock without calling up to the super definition, causing us to never actually verify any instructions for the past three weeks. Awesome. Patch up the latent bugs that have crept in, except for three devirtualizer tests that fail. This doesn't reenable the verifier because I don't want to cause crashes until all the regressions have been cleared up.

Swift SVN r17121
2014-04-30 22:33:46 +00:00
Michael Gottesman
888f72cbbf [specializer] Teach the specializer how to specialize partial apply insts.
<rdar://problem/16696421>

Swift SVN r16871
2014-04-26 04:39:39 +00:00
Joe Groff
7d274e28a7 SIL: Add an unchecked_addr_cast instruction.
Cast an address to another address type without the silly address_to_pointer/pointer_to_address round trip.

Swift SVN r16743
2014-04-24 04:14:48 +00:00
Joe Groff
68f942117a SIL: Squash 'ref_to_native_object' and 'native_object_to_ref' into one 'unchecked_ref_cast' insn.
An unsafe cast from a base to a derived class isn't really all that different from one from Builtin.NativeObject to an arbitrary class, so relax this pair of instructions to allow an arbitrary bitcast. This only combines the instructions; it doesn't attempt to simplify any codegen that was emitting round-trip casts before yet.

Swift SVN r16736
2014-04-24 03:10:53 +00:00
Joe Groff
285ec1e2dd SIL: Add an unchecked_enum_data instruction.
This allows the payload for a loadable enum to be unsafely projected without branching, enabling more enum optimizations when switch branches can be culled or when indirect enum code can be promoted.

Swift SVN r16729
2014-04-24 00:41:08 +00:00
Joe Groff
55f6b925de SIL: Rename 'take_enum_data_addr' to 'unchecked_take_enum_data_addr'.
In preparation for adding an 'unchecked_enum_data' equivalent for loadable enums.

Swift SVN r16728
2014-04-24 00:40:47 +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
Chris Lattner
a3916614ef respond to mainline API changes in the Debug.h header, by defining the
DEBUG_TYPE macro in all .cpp files that use the DEBUG macro.  Hopefully
this will unbreak the build.


Swift SVN r16638
2014-04-22 02:54:55 +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
dcad7fb248 SIL: Add an autorelease_value instruction.
Give us a way to formally represent autoreleases in SIL separate from autoreleased returns, allowing us to lifetime-extend inner pointer parameters the lazy way and hopefully clean up some asmname hacks in the stdlib implementation too.

Swift SVN r16632
2014-04-21 23:11:38 +00:00
Joe Groff
eaa6088102 SIL: Remove the now-obsolete bridge_to_block instruction.
Swift SVN r16487
2014-04-18 02:26:10 +00:00
Joe Groff
1e75561807 SIL: Type-check block storage instructions in the verifier.
Swift SVN r16371
2014-04-15 17:16:58 +00:00
Joe Groff
3bad92b342 AST: Remove the stopgap BridgeToBlockExpr and handle block <-> non-block conversions freely as function conversions.
Teach SILGen to handle function representation changes as part of function conversion instead of needing to be spoonfed a special expr for the purpose. Handle representation changes in both directions to and from blocks using the same logic as the bridging conversions.

Swift SVN r16318
2014-04-14 15:00:34 +00:00
John McCall
8a85750c4c Plumb a lot of querying for different kinds of existential
type.

Swift SVN r16232
2014-04-11 22:30:14 +00:00
Joe Groff
dccf84bc46 Remove a dirty development hack.
Swift SVN r16178
2014-04-10 22:38:40 +00:00
Joe Groff
7e97b48e60 SIL: Allow copy_block to apply to optional block types.
Unprincipled, but expedient, and precedented by a similar hack for return_autoreleased.

Swift SVN r16173
2014-04-10 22:35:39 +00:00
Joe Groff
8adaab0233 Fold ExtInfo::isThin and ::isBlock into a "Representation" enum.
These bits are orthogonal to each other, so combine them into one, and diagnose attempts to produce a type that's both. Spot-fix a bunch of places this revealed by inspection that we would have crashed in SILGen or IRGen if blocks were be handled.

Swift SVN r16088
2014-04-09 00:37:26 +00:00
Joe Groff
fd9a9b5881 SIL: Add a CopyBlockInst instruction.
This maps down to a _Block_copy call that gives us the result, which may be different from the original object, back.

Swift SVN r16042
2014-04-08 02:43:17 +00:00
Chris Lattner
9b5b140e7a add some more sil verification smarts to check dominance properties
of SILArgument operands.  I was trying to track down the root of
the problem in rdar://16509020 but this wasn't enough for me.



Swift SVN r15855
2014-04-03 05:17:18 +00:00
Michael Gottesman
2bcc30ee5c [verifier] Make sure that every BB is a successor of its predecessors and a predecessor of its successors.
This will help to catch errors where one improperly modifies terminators
without updating the appropriate state in a successor/predecessor.

Swift SVN r15824
2014-04-02 20:05:56 +00:00
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +00:00
Michael Gottesman
2dcc1e7a8e Remove unnecessary Resolver argument from SILType::isSuperclassOf since SILTypes are only used after type checking.
Thanks Joe!

Swift SVN r15759
2014-04-01 22:55:43 +00:00
Michael Gottesman
13d23eac06 [irgen] Implement lowering of unchecked_checked_cast downcasts of addresses.
rdar://16490450.

Swift SVN r15756
2014-04-01 22:42:19 +00:00
Michael Gottesman
4a09e409cc Teach IRGen how to lower upcast of addresses.
This is apart of teaching the specializer how to specialize
unconditional_checked_casts. Specifically, we might have an
archetype_to_archetype transformation that after specialization become an upcast
between two type pointers.

rdar://16490450

Swift SVN r15748
2014-04-01 21:09:42 +00:00
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
Joe Groff
584009d27e SIL: Remove copy_value's result.
We won't have any types where copying has an effect on the bit pattern (except for blocks, which need special handling anyway), and copy_value having a result makes optimizations more complex, so remove it.

Swift SVN r15640
2014-03-30 03:40:45 +00:00
Michael Gottesman
2235221854 [deserialization] Unique normal protocol conformances in ASTContext like we do for specialized/inherited protocol conformances.
This fixes the following two bugs:

1. We sometimes would create new conformances when deserializing a
witness method which would not be mapped in the SILModule to the
appropriate witness table. This would cause us to be unable to perform
devirtualization of this witness method. This is tested via a new
verifier check.

2. Different conformances would be created for an instance of a base
protocol and the original protocol. This would cause IRGen to try to
emit witness table global variables with differing types, hitting an
assertion. This is tested via a traditional test.

Swift SVN r15362
2014-03-22 05:05:48 +00:00
Michael Gottesman
8016a1cf4d Refactor out code for checking operands into checkLegalTypes and enable checking (via checkLegalTypes) of generic types of SILArguments/SILInstructions.
These checks will make sure that any SILArgument, SILInstruction that is
generic has a primary archetype that matches a primary archetype in the
generic parameter list of the function which contains it.

Swift SVN r15281
2014-03-20 20:05:16 +00:00
Michael Gottesman
5d2a25f0b9 Make sure that every operand of every SILInstruction that is generic has primary archetypes which are valid in the current function's context.
I also refactored out common code used both here and in checkApplyInst
that does the same thing but for ApplyInst substitution parameters.

Swift SVN r15278
2014-03-20 19:47:13 +00:00
Doug Gregor
3cc834714c SILGen for initialization using an existential metatype value.
Loosen the restrictions on open_existential_ref to also allow it to
refer to an existential metatype. When it does, open_existential_ref
returns the metatype for the opened archetype.



Swift SVN r15113
2014-03-16 20:52:54 +00:00
Michael Gottesman
df649b724b [serialization] Do not serialize the bodies of sil functions with external linkage.
They should always be deserialized from their original modules.

Swift SVN r15089
2014-03-14 23:11:54 +00:00
John McCall
794360d312 Permit optional class types to be returned autoreleased.
Swift SVN r15042
2014-03-14 07:10:10 +00:00
Michael Gottesman
5b88963e78 [SIL] Implement external SIL Witness Table declarations.
This will help with ensuring that we do not create multiple witness
table "definitions" one of which is null. That situtation yields an
IRGen assertion to be hit since the external declaration (in the guise
of a definition) has a different type from the actual deserialized
definition.

Swift SVN r14999
2014-03-13 19:52:59 +00:00
Dave Abrahams
156e867eab [SIL] Fix a broken string literal
Swift SVN r14911
2014-03-11 06:11:30 +00:00
Joe Groff
c5feea4697 SILGen: Emit conformances for external definitions.
Teach IRGen to honor the linkage of SILWitnessTables, and teach SILGen to emit witness tables and protocol witness thunks for external definitions with shared linkage. Fixes <rdar://problem/16264703>.

Swift SVN r14908
2014-03-11 05:08:58 +00:00
Michael Gottesman
6f5e78c0df [deserialization] Add in verifier check that makes sure an applies replacement is equal to one of its parent functions archetypes.
Swift SVN r14891
2014-03-10 23:37:11 +00:00
Michael Gottesman
3181ecc4fe Remove trailing whitespace. NFC.
Swift SVN r14890
2014-03-10 23:37:11 +00:00
Michael Gottesman
b4430012b2 [deserialization] Change isPublic(SILLinkage) -> hasPublicVisibility(SILLinkage) which is makes it 100% clear what the function is attempting to do.
Swift SVN r14823
2014-03-08 02:49:35 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Michael Gottesman
5e96e105a3 If we have duplicate witness table conformances, assert in the verifier like other duplicate checks instead of just printing an error.
Swift SVN r14624
2014-03-04 00:51:03 +00:00
Michael Gottesman
d495eb8d9e All SILWitnessTables have public conformances now. Teach the verifier to ensure that we do not create private witness table SILFunction references until we are ready.
Swift SVN r14619
2014-03-03 23:04:30 +00:00
Doug Gregor
82c1ba2e29 Remove peer_method instruction; we're no longer using it.
Swift SVN r14599
2014-03-03 17:13:06 +00:00