Commit Graph

555 Commits

Author SHA1 Message Date
Joe Groff
232cec4b61 SIL: Rename TypeConverter::getInterfaceType{In,OutOf}Context
It extracts an interface type out of a contextual type, but the name made it sound like it put it into a context. NFC.

Swift SVN r22188
2014-09-22 21:56:47 +00:00
Doug Gregor
78a28c01eb Materialize temporaries properly when translating between init? and init! in witnesses.
Thanks, Joe!


Swift SVN r21854
2014-09-10 22:51:02 +00:00
Doug Gregor
e762e73bf7 Handle failability differences in initializer witnesses.
A failable initializer can satisfy a failable initializer requirement
(regardless of whether either is spelled with init! or
init?). Handle the optional translation within the witness.

Additionally, a failable initializer requirement spelled with
"init!" can satisfy a non-failable initializer requirement, in which
case we force the optional within the witness.

Swift SVN r21812
2014-09-09 21:47:26 +00:00
Doug Gregor
a8a09fd2c2 In a protocol witness thunk for an 'init!' witness of an 'init' requirement, force the optional.
Swift SVN r21793
2014-09-08 23:51:14 +00:00
Joe Groff
620170e795 SILGen: Handle 'init' witnesses less failable than their requirement.
This fix should also extend to the general case of witnesses that return non-optional for optional-returning requirements, when/if we support that.

Swift SVN r21721
2014-09-04 22:24:16 +00:00
Doug Gregor
7cae0cfc8e Remove -enable-dynamic and its language option; it's always on anyway.
Swift SVN r21354
2014-08-21 15:15:12 +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
Joe Groff
893ca42780 SILGen: Have protocol witnesses honor 'dynamic'.
The witness table entry needs to dispatch through the ObjC entry point if the witness is dynamic. Slot this into the existing code path by consing up a small transparent thunk to exercise the existing code paths for adjusting calling convention from ObjC to Swift.

Swift SVN r19864
2014-07-11 23:13:51 +00:00
John McCall
ace9e8e406 Allow cleanups to declare that they should not be
completely destroyed when forwarded.

Also, make forwarding a cleanup a first-class operation
on cleanups, rather than setting the cleanup state directly.

Swift SVN r19332
2014-06-30 11:55:24 +00:00
John McCall
48d6a833a5 SILGen unconditional dynamic casts using the new
unconditional_dynamic_cast_addr instruction.

Also, fix some major semantic problems with the
existing specialization of unconditional dynamic
casts by handling optional types and being much
more conservative about deciding that a cast is
infeasible.

This commit regresses specialization slightly by
failing to turn indirect dynamic casts into scalar
ones when possible; we can fix that easily enough
in a follow-up.

Swift SVN r19044
2014-06-20 07:47:03 +00:00
Joe Groff
692ef04b72 SILGen: Always dispatch Swift class witnesses natively even when @objc.
Maybe we should wrap the @objc dispatch in another thunk in order to account for ObjC dynamic magic, but this is the shortest path to getting proper class dispatch behavior for witnesses in all cases and close <rdar://problem/14620454>.

Swift SVN r17757
2014-05-09 03:28:31 +00:00
Joe Groff
fcd0816179 SILGen: Emit witness function refs through 'emitGlobalFunctionRef'.
This ensures that if the witness is a foreign-to-native, curry, or other lazily-generated thunk, that the thunk gets generated. This fixes natively-ObjC witnesses to Swift protocols.

Swift SVN r17739
2014-05-09 00:14:43 +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
61d7421fba [sil-gen] Emit class methods for in protocol methods for classes so that
inherited conformances can result in virtual calls to overriding
subclass methods.

Previously given the following swift code:

  protocol P {
    func x()
  }
  class B : P {
    func x() { ... }
  }
  class B2 : B {
    func x() { ... }
  }
  func doX<T : P>(t : T) {
    t.x()
  }

  var b2 = B2()
  doX(b2)

We would have b2 reference the protocol method for B.x. But since the
protocol method B.x would have a direct function reference to B.x, we
would not get the correct behavior that doX(b2) should invoke B2.x. This
is fixed by changing SILGen to emit class_method calls in protocol
methods for classes.

Swift SVN r16645
2014-04-22 04:45:09 +00:00
Joe Groff
d90f9d46ae SILGen: Lifetime-extend the "self" parameters of inner-pointer methods.
Do this the lazy way, just autoreleasing "self" after the call. A future optimization pass may be able to eliminate this autorelease when it recognizes the lifetime of the derived value, but that's not immediately necessary.

Swift SVN r16635
2014-04-22 00:25:17 +00:00
Joe Groff
c73acc67f2 SIL: Add an "UnownedInnerPointer" result convention.
This will represent the return convention of imported __attribute__((objc_returns_inner_pointer)) methods. Leave it unimplemented for now until we can autorelease things sanely.

Swift SVN r16628
2014-04-21 21:57:13 +00:00
Joe Groff
e245f9ee89 SILGen: Thunk blocks into native Swift functions when bridging into Swift.
Emit Swift thunk functions to bridge blocks into native function values. On entry into @objc thunks, copy_block blocks to ensure they've been lifted off the stack.

Swift SVN r16177
2014-04-10 22:35:42 +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
Chris Lattner
6540423613 rename CopyValueInst -> RetainValueInst. The .sil syntax
isn't changed yet.


Swift SVN r15775
2014-04-02 05:11:31 +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
Joe Groff
ea3edcdf3a SILGen: Forward all nested archetypes to reabstraction thunks.
Fixes a crash when a closure required reabstraction in a generic method context.

Swift SVN r15370
2014-03-22 19:13:56 +00:00
John McCall
1e9227993f Make some internal functions static.
Swift SVN r15080
2014-03-14 22:00:08 +00:00
John McCall
446a9bd4a7 Introduce CanType versions of the various "getXOrBoundGenericX"
accessors.

Optimize these accessors by making them check for
BoundGenericXType instead of BoundGenericType and dyn_cast'ing
the Decl.  (The latter used to be necessary before we split
BoundGenericType.)

Swift SVN r15037
2014-03-14 05:59:44 +00:00
Chris Lattner
a121e9798e implement support for property references on archetypes, implementing rdar://14195801
Swift SVN r14282
2014-02-23 08:02:22 +00:00
Joe Groff
c876b55942 SILGen: Upcast 'self' of a witness if the requirement is satisfied by a base method.
Fixes <rdar://problem/16076301>.

Swift SVN r14214
2014-02-21 18:30:37 +00:00
Doug Gregor
a1673d7c8f Add an Objective-C metatype representation spelled with @objc_metatype.
This representation is just a placeholder at the moment.


Swift SVN r14076
2014-02-19 07:21:38 +00:00
Doug Gregor
c54f98fbc9 Convert thick/thin metatype bool to an enumeration. NFC
Swift SVN r14075
2014-02-19 06:05:48 +00:00
John McCall
dce0931793 Remove an over-aggressive assert. Curried methods work in
protocols; we treat the method's natural uncurrying level as
the specified level.

Swift SVN r14053
2014-02-18 22:16:53 +00:00
Joe Groff
df356b475b SIL: Set the context generic params of reabstraction thunks less greedily.
Don't try to set the generic params of a reabstraction thunk until we've established it hasn't already been defined, fixing an issue where the same generic reabstraction pattern occurred in different contexts and we ended up clobbering the archetypes of a thunk that was already defined in terms of other archetypes.

Swift SVN r13964
2014-02-16 16:56:43 +00:00
Joe Groff
b19cfb27ea Drop the context generic params from SILFunctionType.
SILFunctionType is now 100% context free!

Swift SVN r13775
2014-02-11 04:21:20 +00:00
Joe Groff
05c1594441 SILGen: Derive protocol witness context generic params independent of type.
We still glue the generic params of the requirement to the generic params of the conformance, but now we do it without relying on TypeLowering.

Swift SVN r13771
2014-02-11 02:05:00 +00:00
Joe Groff
30a3a9a0a0 SILGen: Hand down context generic params for reabstraction thunks independent from their type.
Pass the context generic params for a reabstraction thunk down to getOrCreateReabstractionThunk from the enclosing function, where it can either use them to define a new thunk or ignore them if it has an equivalent thunk already. Tweak the mangling of reabstraction thunks to use the generic signature with decontextualized "from" and "to" types instead of the generic param list.

Swift SVN r13763
2014-02-10 23:37:11 +00:00
Joe Groff
481fbb7b91 Drop the non-interface types from SILFunctionType.
There are some straggling references to the context generic param list, but nothing uses the non-interface param or result types anymore!

Swift SVN r13725
2014-02-09 22:39:01 +00:00
Joe Groff
34e51a1ec8 SILGen: Clean up some straggling non-interface types.
Swift SVN r13699
2014-02-09 06:50:25 +00:00
Chris Lattner
827acad533 Various inout improvements:
- purge @inout from comments in the compiler except for places talking about
   the SIL argument convention.
 - change diagnostics to not refer to @inout
 - Change the astprinter to print InoutType without the @, so it doesn't show
   up in diagnostics or in closure argument types in code completion.
 - Implement type parsing support for the new inout syntax (before we just 
   handled patterns).
 - Switch the last couple of uses in the stdlib (in types) to inout.
 - Various testcase updates (more to come).



Swift SVN r13564
2014-02-06 06:22:27 +00:00
Joe Groff
3b0159f376 SILGen: Process reabstraction thunks using interface types.
The expected and original types of reabstracted functions are nongeneric and thus don't depend on generic context.

Swift SVN r13060
2014-01-28 17:43:07 +00:00
Chris Lattner
e57f8e436d simplify tuple processing code. We only want to do tuple element operations
in memory of the available type is address only, so simplify a check and
remove the predicate (which happens to be out of date anyway).


Swift SVN r12814
2014-01-22 23:36:49 +00:00
Chris Lattner
7cd0f1739a A big part of handling address-only types is making sure that various
emission routines use the SGFContext passed in.  To help with this and
to help the handshake, add a new "isInContext()" representation to 
ManagedValue.  This makes the code producing and consuming these more
explicit.  NFC.


Swift SVN r12783
2014-01-22 21:31:44 +00:00
Chris Lattner
63784ca41c remove the ManagedValue::Unmanaged marker, lets just use ManagedValue::forUnmanaged()
instead, which is shorter.  It is better to have one way to do things than two.


Swift SVN r12710
2014-01-22 06:26:34 +00:00
Joe Groff
0776c4b6b8 SIL: Reorient function type lowering toward interface types.
Lower types for SILDeclRefs from the interface types of their referents, dragging the old type along for the ride so we can still offer the context to clients that haven't been weaned off of it. Make SILFunctionType's interface types and generic signature independent arguments of its  Derive the context types of SILFunctionType from the interface types, instead of the other way around. Do a bunch of annoying inseparable work in the AST and IRGen to accommodate the switchover.

Swift SVN r12536
2014-01-18 19:42:02 +00:00
John McCall
5da6defa1f Clean up the linkage model and the computation of linkage.
In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
2014-01-09 08:58:07 +00:00
Chris Lattner
1ca2722e83 introduce ManagedValue::forLValue(x) as a helper function for
making LValue ManagedValues, and switch SILGenLValue to use
this form of managed value consistently for lvalues, instead of
using unmanaged values in some cases.  NFC. 


Swift SVN r11878
2014-01-04 00:45:05 +00:00
Joe Groff
f6205d25c3 SILGen: Fix the protocol witness label mismatch problem a third way.
r11586 is still too weak to handle both a label and an abstraction change. Instead of trying to handle this case in the guts of the reabstraction machine, where it ends up breaking other things, pre-sanitize the witness and requirement types before feeding them in. This is gross, but the keyword overhaul will hopefully make this unnecessarily before long.

Swift SVN r11588
2013-12-23 02:16:43 +00:00
Joe Groff
9888b43d33 Fix r11580 in a more targeted fashion.
Gratuitously stripping the labels interferes with (T : U -> V) abstraction changes. Only strip the labels where strictly necessary for correct behavior for now.

Swift SVN r11586
2013-12-23 00:59:29 +00:00
Joe Groff
d241f19719 SILGen: Handle abstraction differences involving single-element labeled tuples.
In a case like:

protocol LabeledRequirement {
  func method(x: Loadable)
}

struct UnlabeledWitness : LabeledRequirement {
  func method(_: Loadable) {}
}

The original requirement type is represented as a labeled single-element TupleType, and the witness is represented as a scalar, but we want to disregard the label and consider the scalars in parallel. Do a pre-pass to strip single-element labels first before trying to destructure or indirect tuples.

Swift SVN r11580
2013-12-23 00:03:50 +00:00
Joe Groff
63d08c786d SIL: Handle metatype abstraction differences.
Lower metatype types as @thin or @thick based on whether the type is static and whether the abstraction pattern allows for a thin metatype. Add a '@thick' attribute and require SIL metatypes to always be annotated with either '@thin' or '@thick' to distinguish them from unlowered metatypes.

Swift SVN r11525
2013-12-20 23:06:16 +00:00
Doug Gregor
c19f9e3719 Add newline at the end of the file.
Swift SVN r11265
2013-12-13 21:20:08 +00:00
Joe Groff
402f4daa58 SILGen: Emit protocol witnesses.
Reuse John's abstraction thunking machinery in SILGenPoly to emit the abstraction change from a protocol requirement to a concrete witness. There are potentially two abstraction changes necessary; if a witness is generic, we need to reabstract again from the concrete substituted type of the witness to the generic witness function's original signature. This currently leads to a bunch of extra temporaries in cases where an argument or return gets unabstracted to a loadable value then reabstracted to a generic parameter, but optimizations should be able to clean this up. Protocol witnesses also have additional potential abstraction changes in their 'self' parameter: the 'self' parameter of the protocol requirement is always considered @inout, but class 'self' parameters are not; also, an operator requirement can be satisfied by a free function, in which case 'self' is discarded.

Also, fix a bug in return value thunking where, if the thunk could reuse its @out parameter as the @out parameter of the underlying function, we would not disable the cleanup we install on the result value, leading to the result getting overreleased.

Swift SVN r11245
2013-12-13 05:58:51 +00:00