Commit Graph

193 Commits

Author SHA1 Message Date
John McCall
70e2aea266 Merge pull request #18156 from rjmccall/generalized-accessors
Implement generalized accessors using yield-once coroutines
2018-07-23 22:58:25 -04:00
John McCall
7a4aeed570 Implement generalized accessors using yield-once coroutines.
For now, the accessors have been underscored as `_read` and `_modify`.
I'll prepare an evolution proposal for this feature which should allow
us to remove the underscores or, y'know, rename them to `purple` and
`lettuce`.

`_read` accessors do not make any effort yet to avoid copying the
value being yielded.  I'll work on it in follow-up patches.

Opaque accesses to properties and subscripts defined with `_modify`
accessors will use an inefficient `materializeForSet` pattern that
materializes the value to a temporary instead of accessing it in-place.
That will be fixed by migrating to `modify` over `materializeForSet`,
which is next up after the `read` optimizations.

SIL ownership verification doesn't pass yet for the test cases here
because of a general fault in SILGen where borrows can outlive their
borrowed value due to being cleaned up on the general cleanup stack
when the borrowed value is cleaned up on the formal-access stack.
Michael, Andy, and I discussed various ways to fix this, but it seems
clear to me that it's not in any way specific to coroutine accesses.

rdar://35399664
2018-07-23 18:59:58 -04:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
John McCall
34b0cbc11d Merge pull request #16237 from davezarzycki/metaprogram_ref_storage_types
[AST] NFC: Enable reference storage type meta-programming
2018-07-05 14:45:38 -04:00
Ben Cohen
2b04e9f105 Suppress a number of warnings in no-assert builds (#17721)
* Supress a number of warnings about things used only in asserts

* Re-use a couple of variables instead of supressing the warning
2018-07-04 07:15:14 -07:00
David Zarzycki
476d869e55 [SIL] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
Michael Gottesman
fa157871f0 [func-sig-opts][+0->+1] Extract out the LinearLifetimeChecker from the Ownership verifier.
I am doing this for two reasons:

1. I am going to use this in function signature opts to prove that a guaranteed
parameter is "consumed".
2. It puts the ownership verifier on a diet.

rdar://38196046
2018-05-08 16:47:17 -07:00
Michael Gottesman
903a9835b4 Merge pull request #16447 from gottesmm/pr-706a441a07092d7de9b9cb987dfcac30cfe7ec08
[func-sig-opts][+0->+1] Rename GeneralizedUser -> BranchPropagatedUse…
2018-05-08 16:20:47 -07:00
Michael Gottesman
0de2b76ec9 [func-sig-opts][+0->+1] Rename OwnershipChecker.h => OwnershipUtils.h
I am going to be expanding this to contain more general utilities so naming the
file OwnershipChecker.h really doesn't make sense.

rdar://38196046
2018-05-08 11:21:06 -07:00
Michael Gottesman
f6666aaac1 [func-sig-opts][+0->+1] Rename GeneralizedUser -> BranchPropagatedUser and move it to its own header.
rdar://38196046
2018-05-08 11:20:48 -07:00
Michael Gottesman
a264b1ed9c [gardening] Use SmallPtrSetImpl instead of SmallPtr<N> in more function parameters/return values.
This is good practice like using SmallVectorImpl instead of SmallVector.
2018-05-07 10:35:51 -07:00
Arnold Schwaighofer
678a99e76a Add a copy_block_without_escaping %block withoutEscaping %closure instruction
Mandatory pass will clean it up and replace it by a copy_block and
is_escaping/cond_fail/release combination on the %closure in follow-up
patches.

The instruction marks the dependence of a block on a closure that is
used as an 'withoutActuallyEscaping' sentinel.

rdar://39682865
2018-05-01 07:24:19 -07:00
Joe Groff
62771a0c9d stdlib: Add withUnsafeBytes(of:) and withUnsafePointer(to:) for immutable arguments.
Since the functions produce pointers with tightly-scoped lifetimes there's no formal reason these have to only work on `inout` things.  Now that arguments can be +0, we can even do this without copying values that we already have at +0.
2018-04-18 09:13:45 -07:00
Michael Gottesman
6350397ff2 [Exclusivity] Add builtins needed for dynamic enforcement of exclusivity.
This is chopped off from Devin Coughlin's PR so I can test the actual fix that should
make the rest of his commit work.

rdar://problem/31972680
2018-04-17 13:04:06 -07:00
Michael Gottesman
e567bc9028 [+0-all-args] Enable +0 normal arguments.
rdar://34222540
2018-03-19 20:25:31 -07:00
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