Commit Graph

1223 Commits

Author SHA1 Message Date
Arnold Schwaighofer
0971d82f70 SILGen: Remaining fixes for @callee_guaranteed closures and enable it
- Fix block to func reabstraction thunks block argument handling
- Forward cast ownership
- Fix applyPartiallyAppliedSuperMethod ownership for @callee_guaranteed closures
- Avoid a copy in buildBlockToFuncThunkBody
- Update tests for callee_guaranteed closures

SR-5441
rdar://33255593
2017-11-15 19:46:08 -08:00
Arnold Schwaighofer
982db5ac39 Merge pull request #12866 from aschwaighofer/fix_silgen_emit_dynamic_partial_apply
SILGen: With @callee_guaranteed closures emitDynamicPartialApply will…
2017-11-12 07:05:33 -08:00
Arnold Schwaighofer
f60f95e5ce SILGen: With @callee_guaranteed closures emitDynamicPartialApply will leave a
cleanup for the closure context that needs to be cleared

SR-5441
rdar://33255593
2017-11-10 17:29:34 -08:00
swift-ci
2996e332b4 Merge pull request #12861 from adrian-prantl/35430708 2017-11-10 16:33:21 -08:00
Adrian Prantl
b998c103fc Debug Info: Associate a function call with the beginning of the expression.
Before this change, stepping through the code
  1 foo(x,
  2     f(a)
  3     f(b)
  4   )

would visit the code in the order 2, 3, 4, with the function call
being on line 4.  After this patch the order is 2, 3, 1 with the
function call being on line 1. This is both closer to what clang
generates for simialar C code and more useful to the programmer since
it is easier to understand which function is being called in a nested
expression.

rdar://problem/35430708
2017-11-10 14:37:47 -08:00
Slava Pestov
17da172b01 SILGen: Factor out SILGenFunction::emitClassMethodRef() 2017-11-08 21:27:31 -08:00
Slava Pestov
24ec007d73 SILGen: Remove "assume +0" hack
Now that we emit the callee at the right time, we no longer need
to force emit the 'self' argument source at +0 and possibly
convert it to +1 later.

This is NFC, except it means we end_borrow the self value a bit
sooner sometimes, which is a good thing.
2017-11-08 21:27:30 -08:00
Slava Pestov
661069430c SILGen: Simplify SILGenApply::visitDeclRefExpr() 2017-11-08 19:18:07 -08:00
Slava Pestov
5fd8e71ace SILGen: More dynamic method call cleanup 2017-11-08 01:31:56 -08:00
Slava Pestov
2a0cb060f8 SILGen: Look up the callee method after evaluating arguments 2017-11-08 01:31:55 -08:00
Slava Pestov
cb75ab74f6 SILGen: Simplify AnyObject dispatch logic a bit 2017-11-07 16:10:06 -08:00
Slava Pestov
806935ccbb SILGen: Remove a usage of the callee ManagedValue before emitting arguments
Ideally we would evaluate arguments before the callee value,
but more changes have to happen before that.
2017-11-07 16:09:35 -08:00
swift-ci
69a6e5e260 Merge pull request #12789 from rjmccall/sil-coroutines 2017-11-07 03:22:22 -08:00
John McCall
5c33d2106a Add simple accessor/generator coroutine support to SILFunctionType. 2017-11-07 01:50:12 -05:00
Slava Pestov
ced25fb0d7 SILGen: Remove more references to the 'uncurry level' concept 2017-11-06 18:48:20 -08:00
Slava Pestov
e2e73d2711 SILGen: Clean up some duplication in getConstantAtUncurryLevel() and getTypeInfoAtUncurryLevel() 2017-11-06 18:28:06 -08:00
Arnold Schwaighofer
f352ef1839 Merge pull request #12719 from aschwaighofer/silgen_callee_guaranteed
SILGen: Conditionally use @callee_guaranteed contexts
2017-11-03 12:21:54 -07:00
Arnold Schwaighofer
b25344b02b SILGen: Conditionally use @callee_guaranteed contexts
We need to borrow guaranteed values with sil ownership and need to
distinguish between @callee_guaranteed and other context conventions in
a few places.

SR-5441
rdar://33255593
2017-11-03 07:09:50 -07:00
Huon Wilson
0236db7be1 [SIL] Witness methods store the conformance from which they come. 2017-11-01 11:33:26 -07:00
Slava Pestov
73311c61f8 SILGen: Use ManagedValue variant of createAllocRefDynamic(), NFC
Also, enable the SIL ownership verifier for test/SILGen/objc_protocols.swift.
2017-10-24 18:17:53 -07:00
Slava Pestov
045c6496ff SILGen: Fix memory leak when calling constructor requirement of @objc protocol
Fixes <rdar://problem/30478887> / <https://bugs.swift.org/browse/SR-3935>.
2017-10-21 01:42:51 -07:00
Doug Gregor
cd3c63cbfd [AST] Stop including GenericSignature.h in other headers.
Except GenericEnvironment.h, because you can't meaningfully use a
GenericEnvironment without its signature. Lots less depends on
GenericSignature.h now. NFC
2017-10-12 14:23:46 -07:00
Robert Widmann
053164be0c [NFC] Remove dead code in EnumElement construction
Seems to have been copied and pasted from the other
apply paths but its condition is directly refuted by
an assert.
2017-10-12 03:02:54 -04:00
Slava Pestov
514aa991b3 SILGen: Clean up SILGenApply a bit 2017-10-04 03:53:16 -07:00
Slava Pestov
e806b6248d SIL: Remove dynamic_method instruction 2017-10-04 03:53:16 -07:00
Slava Pestov
7bf3b90b62 SIL: Split off objc_method / objc_super_method from class_method / super_method
This replaces the '[volatile]' flag. Now, class_method and
super_method are only used for vtable dispatch.

The witness_method instruction is still overloaded for use
with both ObjC protocol requirements and Swift protocol
requirements; the next step is to make it only mean the
latter, also using objc_method for ObjC protocol calls.
2017-10-03 22:13:31 -07:00
Slava Pestov
a85f602636 SILGen: Clean up class_method instruction construction a bit 2017-10-03 18:48:19 -07:00
Jordan Rose
31f97cf93c Use AnyObject instead of Builtin.UnknownObject
...for addressors and for dynamic self.
2017-10-02 09:05:35 -07:00
John McCall
16122cef58 Cleanup correctness for upcasts. 2017-09-10 04:56:01 -04:00
Michael Gottesman
e0b0f5f06f [silgen] Once we have exclusively borrowed self, do not use the let +0 self peephole. Instead always access self via the lvalue code.
This eliminates a bunch of complexity from delegating init self since now we
have a clear bifurcation, before the begin of the super.init call, you use the
normal cleanup machinery, but once you have begun the super.init call, you use
the lvalue/formal evaluation machinery.

rdar://31521023
2017-09-06 16:31:20 -07:00
swift-ci
110aefa0aa Merge pull request #11758 from gottesmm/pr-e61caa58dce1a2e25fd7db36e27ca45b22967778 2017-09-04 11:11:06 -07:00
Michael Gottesman
dc8b1c2c3a [silgen] When pushing an RValue through a scope, use dealloc_box on any boxes we create instead of destroy_value.
It is only safe to perform a destroy_value on an alloc_box that contains an
initialized value. We preserve the original cleanups for the value we are
pushing through the scope implying that the box will not contain an initialized
value when its lifetime ends (just like an alloc_stack). Thus we must use
dealloc_box here.

The surprising thing about tracking down this error is that I was not hitting
any memory issues at -Onone. Instead what was happening was that at -O, we were
miscompiling (creating non-dominating uses of SSA values) in the face of an
address being taken twice.

This does not seem to hit any SILGen tests today (I hit this when testing a
patch I am trying to land today).

rdar://31521023
2017-09-04 10:46:37 -07:00
Michael Gottesman
adcf43b98c [silgen] Add the ability to push an RValue through an ArgumentScope.
This comes down to popping the formal evaluation scope and then performing a
popPreservingValue through the resulting normal Scope.

As a cleanup, I changed ArgumentScope.popPreservingValue(ManagedValue) to just
Scope::popPreservingValue instead of reimplementing said functionality.

rdar://31521023
2017-09-04 10:01:03 -07:00
Michael Gottesman
8f30ce51a6 [silgen] Delete CallEmission::getAtUncurryLevel!
rdar://33358110
2017-08-27 22:55:45 -07:00
Michael Gottesman
179aa4bd48 [silgen] Split getAtUncurryLevel into a typeinfo and a value API.
This decouples in SILGen when we produce a function's type info and when we
produce the actual object.

rdar://33358110
2017-08-27 09:09:17 -07:00
Michael Gottesman
5a19ef83f3 [silgen] Refactor the epilogue of getAtUncurryLevel into a helper and call the helper in the switch cases instead of after the switch.
This will make the routine easier to split.

rdar://33358110
2017-08-27 08:44:41 -07:00
Michael Gottesman
8669d9300b [silgen] Change getAtUncurryLevel to return a ManagedValue and a CalleeTypeInfo.
This is in prepatation for splitting getAtUncurryLevel into one function that
returns the CalleeTypeInfo (which is needed early) and a later one that returns
a ManagedValue, which can occur later.

rdar://33358110
2017-08-27 09:10:32 -06:00
Michael Gottesman
8a446ca1a1 [silgen] Eliminate the rest of the out parameters from CallEmission::apply* methods.
This is done by introducing a new result parameter called
FirstLevelApplicationResult. This communicates that the given parameters are not
inout parameters, but rather just result parameters.

As a result of this, many of the apply* methods only take the uncurry level and
the SILGenFunction context.

rdar://33358110
2017-08-26 19:40:33 -07:00
Michael Gottesman
2029c6ccff [silgen] Hoist computation of origFormalType from applyRemainingCallSites into apply.
rdar://33358110
2017-08-26 19:18:53 -07:00
Michael Gottesman
a623643570 [silgen] Sink foreignError into applyFirstLevelCallee leaf functions.
Again, we were not using foreignError as an out parameter despite the convention
and always passed in .None. In the places, where the leaf function was not
setting the foreignError before passing it off to another routine, I changed the
code to just pass in .None so I can just eliminate the variable entirely.

The only place where I had to actually sink instead of delete was
emitNormalApply.

rdar://33358110
2017-08-26 17:31:09 -07:00
Michael Gottesman
f3b4f1df10 [silgen] Sink foreignError parameter into applyFirstLevelCallee.
We were always passing in foreignError as an out parameter initialized to None
and then never used that value in the caller afterwards. So there is no reason
to keep it as a parameter to applyFirstLevelCallee.

rdar://33358110
2017-08-26 17:24:47 -07:00
Michael Gottesman
936f24b646 [silgen] Remove unused foreignError parameter from emitArgumentsForNormalApply.
Before we ever used the value, we were setting foreignError to be None. This is
another example of a mechanical refactoring of spaghetti code. The specific
transformation here was most likely a flattening of a conditional in the
original code.

rdar://33358110
2017-08-26 17:24:47 -07:00
Michael Gottesman
fe9a2770fc [silgen] Pass foreignError to emitArgumentsForNormalApply by const ref instead of ref.
foreignError is never written to in emitArgumentsForNormalApply.

rdar://33358110
2017-08-26 17:24:47 -07:00
Michael Gottesman
4d0767a293 [silgen] Delete dead foreignSelf parameter to applyEnumElementConstructor.
rdar://33358110
2017-08-26 16:59:22 -07:00
Michael Gottesman
7f9fadeec7 [silgen] Pass foreignSelf to applyPartiallyAppliedSuperMethod by value instead of by ref.
We never write to foreignSelf in applyPartiallyAppliedSuperMethod. So this
communicates more clearly what is going on.

rdar://33358110
2017-08-26 16:59:22 -07:00
Michael Gottesman
4ee0183630 [silgen] Pass foreignSelf by value instead of by ref to CallEmission::applySpecializedEmitter.
This is safe since applySpecializedEmitter does not write to foreignSelf.

rdar://33358110
2017-08-26 16:59:11 -07:00
Michael Gottesman
1d0f90d318 [silgen] Pass foreignSelf to emitArgumentsForNormalApply by value instead of by ref.
By passing it by ref, we make it seem like foreignSelf is either an out
parameter or an inout parameter. By changing the API of
emitArgumentsForNormalApply to take foreignSelf as a value, the API clearly
communicates that foreignSelf is a value type that is passed as an in parameter.

rdar://33358110
2017-08-26 16:46:07 -07:00
Michael Gottesman
7ddd5185bd [silgen] Pass ImportAsMemberStatus by value instead of by const ref.
ImportAsMemberStatus is just a byte. There is no reason to pass it by const &.

I think this was from a mechanical refactoring change where I was trying to be
very conservative.

rdar://33358110
2017-08-26 16:46:07 -07:00
Michael Gottesman
c777e59b04 [silgen] Rather than passing in initialOptions as an out parameter to emitArgumentsForNormalApply, just use a return value.
The reason to do this is that we are already always passing in
ApplyOptions::None for this value at all call sites. By using a reference to
create an out parameter, we make it look like something more complex is occuring
here. In contrast the result makes it clear to the reader that there is no state
from the caller before the callee that can affect this variable.

rdar://33358110
2017-08-26 16:22:05 -07:00
swift-ci
84029a8856 Merge pull request #11639 from gottesmm/pr-2a0b571d62a29a67143aaf7a2e36463c807fa0e1 2017-08-26 15:50:50 -07:00