Commit Graph

258 Commits

Author SHA1 Message Date
Joe Groff
069ad18620 Revert "SILGen: Avoid using a stdlib function to get optional values."
This reverts commit r22533. The optimizing bots seem to have problems with it.

Swift SVN r22534
2014-10-06 04:40:58 +00:00
Joe Groff
28805f0d2a SILGen: Avoid using a stdlib function to get optional values.
When we've already established that the optional has a value, using unchecked_take_enum_data_addr to directly extract the enum payload is sufficient and avoids a redundant call and check at -Onone. Keep using the _getOptionalValue stdlib function for checked optional wrapping operations such as "x!", so that the stdlib can remain in control of trap handling policy.

Swift SVN r22533
2014-10-06 04:31:52 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
John McCall
f20225a34b Access properties and subscripts in the most efficient
semantically valid way.

Previously, this decision algorithm was repeated in a
bunch of different places, and it was usually expressed
in terms of whether the decl declared any accessor
functions.  There are, however, multiple reasons why a
decl might provide accessor functions that don't require
it to be accessed through them; for example, we
generate trivial accessors for a stored property that
satisfies a protocol requirement, but non-protocol
uses of the property do not need to use them.

As part of this, and in preparation for allowing
get/mutableAddressor combinations, I've gone ahead and
made l-value emission use-sensitive.  This happens to
also optimize loads from observing properties backed
by storage.

rdar://18465527

Swift SVN r22298
2014-09-26 06:35:51 +00:00
John McCall
6923101341 Rename "AccessKind" to "AccessSemantics". NFC.
There are a lot of different ways to interpret the
"kind" of an access.  This enum specifically dictates
the semantic rules for an access:  direct-to-storage
and direct-to-accessor accesses may be semantically
different from ordinary accesses, e.g. if there are
observers or overrides.

Swift SVN r22290
2014-09-25 23:12:39 +00:00
Joe Groff
9eb4f5b512 SILGen: Use Array._allocateUninitialized to form array literals.
This avoids a pointless copy every time an array literal is written, and will let us retire the horrible "alloc_array" instruction and globs of broken IRGen code. Implements rdar://problem/16386862, and probably fixes a bunch of bugs related to alloc_array brokenness.

Swift SVN r22289
2014-09-25 22:26:20 +00:00
John McCall
b0a843630e Add some SILGen tests for addressors and fix some
bugs involving non-member variables with addressors.

Swift SVN r22256
2014-09-24 07:18:20 +00:00
John McCall
defaf07046 SILGen support for addressors.
Addressors now appear to pass a simple smoke-test; in
order to allow some parallel developement, I'll be
committing actual SILGen tests for this later and
separately.

Swift SVN r22243
2014-09-23 23:46:52 +00:00
Joe Groff
6cd5123712 SILGen: Use the formal type when taking dynamicTypes of values.
The metatype is associated with the formal AST type of the value, not whatever lowered SIL type we happen to have lying around. Adjust the SIL verifier to check that value_metatype instructions produce a metatype for which the instance is a potential lowering rather than by exact type match. This lets us take the metatype of metatypes (and incidentally, of functions, and of tuples thereof), fixing rdar://problem/17242770.

Swift SVN r22202
2014-09-23 02:56:48 +00:00
John McCall
2fc49df319 Teach SILGen to take advantage of materializeForSet
accessors on non-dynamic storage.

This allows us to take advantage of dynamic knowledge
that a property is implemented as stored in order to
gain direct access to it instead of copying into a
temporary.  When a class or protocol-member property
is expensive to copy, and particularly when it's of
copy-on-write type, such direct accesses can massively
improve the performance of a program.

We are currently only able to apply this when the
property is implemented purely as stored.  A willSet
observer inherently blocks the optimization, but we
should be able to make it work even for properties
with didSet observers.  This could be done by returning
an arbitrary callback from materializeForSet instead
of returning a flag indicating whether to call the
setter.

rdar://17416120

Swift SVN r22122
2014-09-19 05:25:22 +00:00
Anna Zaks
5fca94b1b2 [SIL Unreachability] Remove spurious warnings in the deinit method.
Mark the deinitializer auto-generated code as cleanup.

radar://18225133

Swift SVN r22111
2014-09-19 01:40:08 +00:00
John McCall
8cae5ba1d0 Generalize 'isDirectPropertyAccess' to allow for
direct (i.e. non-polymorphic) access to accessor
functions, and use this in materializeForSet for
computed properties.

Swift SVN r22059
2014-09-18 05:51:32 +00:00
Joe Groff
53bbefbe42 SILGen: Thread direct access through all uses of emitRValueForDecl.
Swift SVN r21715
2014-09-04 18:11:04 +00:00
Joe Groff
4be861da99 SILGen: Don't crash when a 'static let' models a 'class var { get }' protocol requirement.
A couple of issues here:

- We didn't apply the base metatype when emitting calls to the getter for static properties, causing a crash when references to the accessor are emitted (such as when modeling a protocol requirement)
- We didn't propagate isDirectPropertyAccess through emitRValueDecl, causing the getter to recursively call itself when it was emitted successfully.

Together these fix rdar://problem/17986478.

Swift SVN r21695
2014-09-04 01:38:25 +00:00
Joe Groff
8f52302f8e SILGen: Implement artificial main for NSApplicationMain.
We're not sure how to trigger this from source code yet, so trigger it with a hidden -emit-NSApplicationMain frontend flag for now.

Swift SVN r21563
2014-08-29 04:45:47 +00:00
Joe Groff
88da4626b8 SILGen: Clean up 'self' before entering the failure block of a failing initializer.
A couple reasons for this:

- How 'self' gets cleaned up is dependent on where the failure occurs. If we propagate failure from a class initializer, the failed 'super.init' or 'self.init' has already cleaned up the object, so we only need to deallocate the box. In cases where we fail explicit, we release 'self', which works out because we're only supporting failure with a fully-initialized object for now.
- This lets us set the location info for the cleanup to the AST node that instigated failure, giving better QoI for DI failures (such as failing with a partially-initialized object).

Swift SVN r21505
2014-08-28 01:13:49 +00:00
Joe Groff
d63be086e0 SILGen: Forward failure from a delegated value constructor.
Swift SVN r21427
2014-08-23 00:14:56 +00:00
Doug Gregor
344ecfd3f9 Add a new 'fail' statement to the AST for failing from an initializer.
The spelling of the 'fail' statement is simply 'return nil', but
distinguishing it in the AST clarifies intent for SILGen.

Swift SVN r21310
2014-08-20 17:22:36 +00:00
Chris Lattner
e466b4621b revert r20658, restoring us back to producing the "inout writeback to computed property"
error when detecting an inout writeback problem.


Swift SVN r20681
2014-07-29 18:12:51 +00:00
Chris Lattner
4d03ef63f7 Rip out my previous work that produced perplexing "inout writeback to
computed property" errors when SILGen could determine that there was
an inout writeback alias, and have the code instead perform CSE of the
writebacks directly.

This means that we produce more efficient code, that a lot of things
now "just work" the way users would expect, and that the still erroneous
cases now get diagnosed with the "inout arguments are not allowed to 
alias each other" error, which people have a hope of understanding.

There is still more to do here in terms of detecting identical cases,
but that was true of the previous diagnostic as well.




Swift SVN r20658
2014-07-28 23:55:14 +00:00
Joe Groff
4bacaffaa7 SILGen: Implement lvalue BindOptionalExprs.
Factor out the code for emitting the "bind" branching logic, and share it to implement an LValueComponent for optional binds, which makes optional assignments work.

Swift SVN r20614
2014-07-28 04:05:28 +00:00
Joe Groff
c556d92ccd SILGen: Implement codegen for lvalue ForceValueExprs.
Add a set of _preconditionOptionalHasValue intrinsics that merely test that an optional has a case. Emit an lvalue ForceValueExpr as a physical lvalue, first asserting the precondition then projecting out the Some payload.

Swift SVN r20188
2014-07-18 22:49:49 +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
Joe Groff
e37829e49b SILGen: Factor 'getMethodDispatch' out of SILGenApply.
We need to be able to ask whether a method requires dynamic dispatch in other places in SILGen. NFC yet, but a step on the way to fixing <rdar://problem/17577579>.

Swift SVN r19636
2014-07-07 21:24:29 +00:00
John McCall
e57d928c44 Remove the last code in SILGen which was making address-only
casts with the non-address checked_cast instructions.

Swift SVN r19338
2014-06-30 12:04:50 +00:00
John McCall
f40e9ef0ae Rewrite switch dispatch emission.
Specialization now recurses on only that prefix of the
current matrix which shares a specialization form
(essentially, a pattern kind) with the head row.  This is
inferior to the previous algorithm in a number of ways: we
may require more switches to perform a single dispatch, and
we may introduce more redundant variables in the leaves.
However, it also means that we will have fully specialized a
row along exactly one path in the decision tree, which makes
it much easier to work with dispatches that introduce new
cleanups.

This change also changes switch-dispatch to use the new
dynamic-cast instructions.

Incidentally fixes rdar://16401831.

Swift SVN r19336
2014-06-30 11:55:28 +00:00
John McCall
ba597ece5d Add a convenience method for emitting a break
out of a particular statement exactly like a
break-statement would.

Swift SVN r19335
2014-06-30 11:55:27 +00:00
John McCall
c178a69ec5 Add an optional "afterBB" parameter to SGF::createBasicBlock.
Swift SVN r19334
2014-06-30 11:55:26 +00:00
John McCall
519645daa0 Add ConsumableManagedValue, which allows a value to
declare whether it's owned by the emission code that's
working with it.

This is convenient when working extensively with values
that are being propagated into multiple, often-disjoint
paths, like switches.

Swift SVN r19333
2014-06-30 11:55:25 +00:00
Adrian Prantl
3ae5326d21 Tweak the scope guessing for instructions without SILDebugScopes to reuse
the scope of the previous instruction.

<rdar://problem/17021591> Gap in lexical block coincides with the first line-table entry for a line => no variables at that line

Swift SVN r19318
2014-06-28 02:08:26 +00:00
Joe Groff
954f746b92 SILGen: Implement pointer-to-pointer conversions.
Perform pointer-to-pointer argument conversions with the help of the _convertPointerToPointerArgument stdlib helper function.

Swift SVN r19105
2014-06-23 23:22:02 +00:00
John McCall
20b1f2de3e Switch isa and as? processing over to use the new
indirect cast instructions when necessary.

Swift SVN r19079
2014-06-22 09:53:36 +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
18b4650f50 Sema/SILGen: Make default argument generators work for generic functions.
Tweak the AST representation and type-checking of default arguments to preserve a full ConcreteDeclRef with substitutions to the owner of the default arguments. In SILGen, emit default argument generators with the same genericity as the original function.

Swift SVN r18760
2014-06-09 22:16:57 +00:00
Dmitri Hrybenko
406e5ca206 SILGen: when emitting default argument generator functions that contain magic
literals, don't actually use the source information of the *function
definition* to generate these functions.  Doing so leaks information about
source code into the binary, and these default argument generators are never
called anyway.

rdar://17054642


Swift SVN r18654
2014-05-28 20:48:32 +00:00
Joe Groff
ef52068e43 SILGen: Don't +1 'self' references for direct property access in constructors.
The CALayer brittleness in <rdar://problem/17014037> is worse than we thought—we can't r/r *at all* before super.init. Go through some contortions to ensure that, when doing direct stored property access in an initializer, we always base off of a +0 value. I tried fixing this in a more general and principled way using SGFContext::AllowPlusZero, but that introduced miscompiles we don't have the luxury of tracking down right now, so hack a more targeted fix that only affects class initializers.

Swift SVN r18635
2014-05-26 18:09:25 +00:00
Joe Groff
456284464d SILGen: Carefully preserve 'self' at +1 through init delegation.
CALayer and potentially other framework classes implement their own refcounting
schemes that assume [self retainCount] == 1 at initialization time, a guarantee
SILGen didn't attempt to meet until now. Set a flag in SILGenFunction while
doing initializer delegations to indicate that a 'self' reference can consume
the current 'self' binding, and reinitialize rather than reassign 'self' with
the result of the delegation if it was successfully consumed. Fixes
<rdar://problem/17014037>.

Swift SVN r18608
2014-05-23 23:50:53 +00:00
Joe Groff
793fe06a34 SILGen: Emit an artificial toplevel for files with @UIApplicationMain classes.
If a source file contains the main class for its module, then implicitly emit a top_level_code that invokes UIApplicationMain with the name of the marked class.

Swift SVN r18088
2014-05-15 00:53:38 +00:00
Doug Gregor
f369a22a0a Remove the isConvenienceInit hack from SILGen
Swift SVN r17932
2014-05-12 15:13:53 +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 Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Chris Lattner
7e93a509a9 enhance the AST representation of break and continue statements to specify the
LabeledStmt that they target: have sema fill this in, and make silgen respect it.

NFC, because this was specifically written to behave the same as before (e.g. no
break out of switches).


Swift SVN r16610
2014-04-21 05:53:44 +00:00
Joe Groff
e6276a1c2f SILGen: Emit brace stmt exprs and for stmt initializers as ignored exprs.
Add an emitIgnoredExpr entrypoint to SILGenFunction that emits an expression, ignoring its result. This isn't an extensive implementation but just tackles the low-hanging fruit of allowing +0 rvalues and not crashing on sudden lvalues, fixing <rdar://problem/16650625>.

Swift SVN r16536
2014-04-18 17:55:41 +00:00
Doug Gregor
8bc2ea4ea1 Use designated/convenience initializer terminology throughout. NFC
Introduce CtorInitializerKind to describe the kind of an enum, rather
than a bool, to make way for more initializer kinds in the future.

Swift SVN r16525
2014-04-18 15:10: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
Chris Lattner
afea47b621 rename "destroy_value" to "release_value", part of rdar://15889208.
Swift SVN r15777
2014-04-02 05:33:52 +00:00
Joe Groff
ba34976f87 SILGen: Implement lowering for writeback conversion.
Lower LValueConversionExprs to LValueConversionComponents of SILGen's LValues, which add the conversion pair as a logical component of a writeback chain.

Swift SVN r15771
2014-04-02 03:15:12 +00:00
Doug Gregor
9189145cc5 Change DeclName over to basename(arg1:arg2:...argN:).
Swift will use the basename + argument names formulation for
names. Update the DeclName interfaces, printing, and __FUNCTION__ to
use the method syntax.

We'll still need to rework the "x.foo:bar:wibble:" syntax; that will
come (significantly) later.

Swift SVN r15763
2014-04-02 00:00:03 +00:00
Joe Groff
b3e9a17269 SILGen: Implement inout address conversion.
Implement lowering for the LValueToPointer and InOutConversion expressions. For the former, we emit the lvalue, then convert it to a RawPointer; for the latter, we introduce an InOutConversion scope, which suppresses any nested writeback conversion scopes.

This completes the implementation of inout address conversion, except that we don't implement reabstraction of the lvalue prior to taking its address. Simply report them unimplemented for now, since reabstraction should not come up for our immediate use case with C types.

Swift SVN r15595
2014-03-29 02:50:26 +00:00
John McCall
c388bb9fc0 Raise emitOptionalToOptional up to be more generally available
in SILGen.

Swift SVN r15571
2014-03-28 05:39:22 +00:00