Commit Graph

177 Commits

Author SHA1 Message Date
swift-ci d18d9d8455 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-03-09 09:38:10 -08:00
Arnold Schwaighofer 5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08:00
swift-ci 2aae3162a3 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-23 13:18:22 -08:00
Michael Gottesman b4daf6e982 [ownership-verifier] SuperMethod can take a metatype.
rdar://34222540
2018-02-23 12:06:14 -08:00
swift-ci d830b970db Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-19 10:50:38 -08:00
Michael Gottesman 71b508e402 Refactor compatibleOwnershipKind, trivialOrCompatibleOwnershipKinds onto ValueOwnershipKind instead of being free functions.
I have a bunch of work that I have done on a side branch some time ago to split
determining what value ownership kinds are able to be associated with a specific
operand.

This PR just upstreams a small part of the larger change.
2018-02-19 07:01:44 -08:00
Michael Gottesman d390308bd9 [ownership-verifier] Improve error message for owned values leaked due to lack of "lifetime ending uses".
The ownership verifier diagnoses leaks of owned objects in two different
places/ways:

1. If the owned value does not have any "consuming" uses, we bail early without
performing dataflow verification.
2. If the owned value has at least 1 "consuming" uses, we perform dataflow to
determine the blocks where the leaked value escapes without being destroyed.

In the latter case, we give a nice error message saying that a leak occured. In
contrast in the former, we go down a "generic error" path that just says that a
"lifetime ending use" is required. This commit changes that generic error
message for owned parameters to say that the value was leaked, resulting in a
clearer message. The other cases are still left along though.

I also added a test file to specifically test leaks/leak error messages. I added
a few tests to make sure this error message is correct and a few more tests just
for fun.
2018-02-18 10:36:01 -08:00
swift-ci 2b9b846f42 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-14 05:38:02 -08:00
Arnold Schwaighofer a9fa8c9c2b Merge pull request #14514 from aschwaighofer/wip_closure_capture_abi_part2
WIP: Closure ABI - Make @noescape Swift closures trivial
2018-02-14 05:19:25 -08:00
swift-ci 51fd06dda7 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-13 07:58:32 -08:00
Joe Shajrawi 102b6f0b61 Merge pull request #14587 from shajrawi/newinstr
Optimizer peephole for tagged BridgeObjects
2018-02-13 07:38:53 -08:00
Arnold Schwaighofer 48b3737404 SIL: Add support for trivial @noescape function types
- @noescape functions are trivial types
That makes @noescape functions incompatible with escaping functions.
- Forward ownership of mark_dependence %3 : callee_guaranteed () -> () on %0 : noescape @callee_guaranteed () -> ()
- SIL: Add ABIEscapeToNoEscapeConversion to SILFunctionType::ABICompatibilityCheckResult
- SIL: A thin_to_thick_function with a @noescape result type has trivial ownership
- SIL: thin_to_thick_function can create noescape function types

Part of:
SR-5441
rdar://36116691
2018-02-13 04:19:58 -08:00
Joe Shajrawi 6538d543f7 Builtins: add StringObjectOr and use it in the standard library 2018-02-13 11:12:55 +02:00
Joe Shajrawi f732ea66ef Builtins: add ValueToBridgeObject instruction 2018-02-12 13:27:59 +02:00
swift-ci 7ca497aedd Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-12 00:18:39 -08:00
Michael Gottesman 1476f8f033 [ownership-verifier] Allow owned enum arguments to be passed as guaranteed function arguments.
Enums require special handling in the ownership verifier since an enum is a sum
type whose triviality or non-triviality is erased at function arguments. When
the ownership verifier was changed to allow for owned values to be passed as
guaranteed objects via instantaneous borrowing, this code was not updated.

rdar://34222540
2018-02-11 22:43:59 -08:00
swift-ci 9097df627e Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-02-07 05:18:18 -08:00
Arnold Schwaighofer d51053b003 Add convert_escape_to_noescape instruction for converting escaping to noescape functions
@noescape function types will eventually be trivial. A
convert_escape_to_noescape instruction does not take ownership of its
operand. It is a projection to the trivial value carried by the closure
-- both context and implementation function viewed as a trivial value.

A safe SIL program must ensure that the object that the project value is based
on is live beyond the last use of the trivial value. This will be
achieve by means of making the lifetimes dependent.

For example:

  %e = partial_apply [callee_guaranteed] %f(%z) : $@convention(thin) (Builtin.Int64) -> ()
  %n = convert_escape_to_noescape %e : $@callee_guaranteed () -> () to $@noescape @callee_guaranteed () -> ()
  %n2 = mark_dependence %n : $@noescape @callee_guaranteed () -> () on %e : $@callee_guaranteed () -> ()
  %f2 = function_ref @use : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  apply %f2(%n2) : $@convention(thin) (@noescape @callee_guaranteed () -> ()) -> ()
  release_value %e : $@callee_guaranteed () -> ()

Note: This is not yet actually used.

Part of:
SR-5441
rdar://36116691
2018-02-06 18:01:23 -08:00
swift-ci c552df85f8 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-12 11:39:41 -08:00
Michael Gottesman 9f8df425de Revert "[+0-all-args] Accept guaranteed arguments to unsafe guaranteed."
This reverts commit 0bc964801b.

This turned out to be a bad idea and just add more complication than is
necessary.
2018-01-12 10:09:49 -08:00
swift-ci cc373f9c30 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-08 12:27:47 -08:00
Andrew Trick 4bba7685d5 Comment SIL ownership checker for the @guaranteed case. 2018-01-08 11:26:56 -08:00
Andrew Trick 0da82bfaa2 SIL ownership: treat guaranteed args like normal uses. 2018-01-08 11:26:56 -08:00
swift-ci ed1cf3bc48 Merge remote-tracking branch 'origin/master' into master-next 2018-01-02 15:29:18 -08:00
Chris Lattner 415cd50ba2 Reduce array abstraction on apple platforms dealing with literals (#13665)
* Reduce array abstraction on apple platforms dealing with literals

Part of the ongoing quest to reduce swift array literal abstraction
penalties: make the SIL optimizer able to eliminate bridging overhead
 when dealing with array literals.

Introduce a new classify_bridge_object SIL instruction to handle the
logic of extracting platform specific bits from a Builtin.BridgeObject
value that indicate whether it contains a ObjC tagged pointer object,
or a normal ObjC object. This allows the SIL optimizer to eliminate
these, which allows constant folding a ton of code. On the example
added to test/SILOptimizer/static_arrays.swift, this results in 4x
less SIL code, and also leads to a lot more commonality between linux
and apple platform codegen when passing an array literal.

This also introduces a couple of SIL combines for patterns that occur
in the array literal passing case.
2018-01-02 15:23:48 -08:00
swift-ci 9ae11b7cff Merge remote-tracking branch 'origin/master' into master-next 2017-12-02 18:58:23 -08:00
Michael Gottesman 5263e9e74e [sil] Eliminate redundant method SILFunction::hasUnqualifiedOwnership().
We can just !SILFunction::hasQualifiedOwnership(). Plus as Andy pointed out,
even ignoring the functional aspects, having APIs with names this close can
create confusion.
2017-12-02 17:42:34 -08:00
swift-ci d3ebb4b288 Merge remote-tracking branch 'origin/master' into master-next 2017-11-30 22:10:01 -08:00
Michael Gottesman 0bc964801b [+0-all-args] Accept guaranteed arguments to unsafe guaranteed.
rdar://34222540
2017-11-30 22:04:53 -08:00
swift-ci 90cc83fabc Merge remote-tracking branch 'origin/master' into master-next 2017-11-13 02:09:19 -08:00
John McCall 045998544f Add begin_apply, abort_apply, and end_apply instructions to allow
yield_once coroutines to be executed.
2017-11-13 04:03:54 -05:00
swift-ci 4b5fce50e7 Merge remote-tracking branch 'origin/master' into master-next 2017-11-07 03:29:00 -08:00
John McCall 14d6390352 Add "yield" and "unwind" instructions to SIL. 2017-11-07 03:51:54 -05:00
swift-ci 8a681dbef9 Merge remote-tracking branch 'origin/master' into master-next 2017-10-25 19:29:32 -07:00
Michael Gottesman 573655d46c [ownership] Allow for objc_super_method to take a metatype as well as a non-trivial object.
rdar://29791263
2017-10-25 17:53:09 -07:00
swift-ci 7ad712de8e Merge remote-tracking branch 'origin/master' into master-next 2017-10-24 18:49:07 -07:00
Michael Gottesman 36a8d0d5c0 [sil] Add support for the destructure_{struct,tuple} instructions.
rdar://31521023
2017-10-24 18:36:37 -07:00
Michael Gottesman 6df5462ee2 [sil] Add support for multiple value instructions by adding MultipleValueInstruction{,Result}.
rdar://31521023
2017-10-24 18:36:37 -07:00
swift-ci 2fd5f7ad4c Merge remote-tracking branch 'origin/master' into master-next 2017-10-13 19:09:33 -07:00
Slava Pestov 0acf3ac8d9 SIL: Remove is_nonnull instruction 2017-10-13 17:38:32 -07:00
swift-ci 68cb01cc77 Merge remote-tracking branch 'origin/master' into master-next 2017-10-04 12:48:58 -07:00
swift-ci 7a2d0a8242 Merge remote-tracking branch 'origin/master' into master-next 2017-10-04 04:08:57 -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
swift-ci 980abcf525 Merge remote-tracking branch 'origin/master' into master-next 2017-10-02 16:18:33 -07:00
Jordan Rose b6c28b02d0 [SIL] Remove the builtins related to UnknownObject.
No functionality change; nothing is using them.
2017-10-02 09:05:31 -07:00
swift-ci 135a4286b5 Merge remote-tracking branch 'origin/master' into master-next 2017-09-25 10:29:30 -07:00
John McCall ab3f77baf2 Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode.

This is in preparation for allowing instructions to have multiple
results.  It is also a somewhat more elegant representation for
instructions that have zero results.  Instructions that are known
to have exactly one result inherit from a class, SingleValueInstruction,
that subclasses both ValueBase and SILInstruction.  Some care must be
taken when working with SILNode pointers and testing for equality;
please see the comment on SILNode for more information.

A number of SIL passes needed to be updated in order to handle this
new distinction between SIL values and SIL instructions.

Note that the SIL parser is now stricter about not trying to assign
a result value from an instruction (like 'return' or 'strong_retain')
that does not produce any.
2017-09-25 02:06:26 -04:00
swift-ci 4135e9c841 Merge remote-tracking branch 'origin/master' into master-next 2017-09-21 16:09:54 -07:00
Mark Lacey c0c848d2b3 Add Builtin.type_join* family of functions.
These will be used for unit-testing the Type::join functionality in the
type checker. The result of the join is replaced during constraint
generation with the actual type.

There is currently no checking for whether the arguments can be used to
statically compute the value, so bad things will likely happen if
e.g. they are type variables. Once more of the basic functionality of
Type::join is working I'll make this a bit more bullet-proof in that
regard.

They include:
  // Compute the join of T and U and return the metatype of that type.
  Builtin.type_join<T, U, V>(_: T.Type, _: U.Type) -> V.Type

  // Compute the join of &T and U and return the metatype of that type.
  Builtin.type_join_inout<T, U, V>(_: inout T, _: U.Type) -> V.Type

  // Compute the join of T.Type and U.Type and return that type.
  Builtin.type_join_meta<T, U, V>(_: T.Type, _: U.Type) -> V.Type

I've added a couple simple tests to start off, based on what currently
works (aka doesn't cause an assert, crash, etc.).
2017-09-21 14:43:26 -07:00