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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
- 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
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
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
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
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
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
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
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
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
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
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