Commit Graph

22 Commits

Author SHA1 Message Date
Andrew Trick
7ceb43fda9 Add support to AccessEnforcementSelection for borrowed SILValues.
Previously, this asserted on unexpected situations that the
optimizer couldn't handle.

It makes more sense now to handle these cases conservatively since we can't
catch them in early testing.

Fixes <rdar://problem/35402799> [4.1] Assertion failed: (user->getResults().empty())
2017-11-13 17:05:20 -08:00
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -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
Slava Pestov
5973a2722c SILOptimizer: Fix some unused variable warnings 2017-09-01 02:04:22 -07:00
Andrew Trick
ac56f91f47 Add a little tiny comment to AccessEnforcementSelection. 2017-07-05 14:10:05 -07:00
Andrew Trick
c2c55eea12 AccessSummaryAnalysis: handle @convention(block) in nested nonescape closures.
This analysis has a whitelist to ensure that we aren't missing any SIL
patterns and failing to enforce some cases.

There is a special case involving nested non-escaping closures being passed as a
block argument.  Whitelist this very special case even though we don't enforce
it because the corresponding diagnostics pass also doesn't enforce it.
2017-06-21 19:39:12 -07:00
Andrew Trick
4575525786 NFC: Cleanup ClosureScope/AccessEnforcementSelection/Tests.
Per Devin and John's review.
2017-06-20 14:57:56 -07:00
Andrew Trick
fcfabfd5d2 Implement and enable dynamic exclusivity checks for noescape closures.
This uses the new ClosureScopeAnalysis to process parent functions before the
closures they reference. The analysis now tracks captured variables in addition
to immediately accessed variables. If the variable escapes before it's capture
is applied, then that closure uses dynamic enforcement for the variable.

<rdar://problem/32061282> [Exclusivity] Enforcement selection for noescape closure captures.
2017-06-20 00:01:52 -07:00
Andrew Trick
50409b3b1a Make AccessEnforcementSelection a module pass.
Parent scopes need to be analyzed before enforcement in noescape closures can be
selected.
2017-06-16 19:09:24 -07:00
Andrew Trick
c76269ccd9 Comment typos. 2017-05-10 16:37:59 -07:00
Andrew Trick
dd31c40995 [Exclusivity] Disable dynamic enforcement in noescape closures. 2017-05-08 17:27:26 -07:00
Devin Coughlin
de9c646804 [Exclusivity] Use dynamic enforcement on boxes whose projections escape
In AccessEnforcementSelection, treat passing a projection from a box to
a partial_apply as an escape to force using dynamic enforcement on the box.

This will now correctly use dynamic enforcement on variables that are taken
as inout and also captured by storage address in a closure:

  var x = ...

  x.mutatingMethod { ... use x ...}

but does pessimize some of our existing enforcement into dynamic since
access enforcement selection.

Ideally we would distinguish between escaping via an nonescaping closures
(which can only conflict with accesses that are in progress) and
escaping via escaping closures (which can conflict for any reachable code
after the escape)
2017-05-02 14:54:12 -07:00
Andrew Trick
2336a87866 [Exclusivity] Enable access markers for the entire -Onone pipeline.
Dynamic markers are still conditional on the command line option.
2017-04-28 21:33:09 -07:00
Andrew Trick
f469fb73db [Exclusivity] Allow AccessEnforcementSelection to run before DI. 2017-04-28 21:33:09 -07:00
Andrew Trick
b872ae80c1 [Exclusivity] AccessMarkerEnforcementSelection support for unpaired markers. 2017-04-26 09:02:34 -07:00
Andrew Trick
39cd8126a6 [Exclusivity] Reenable AccessEnforcementSelection assert. 2017-04-25 15:58:11 -07:00
Andrew Trick
e461f4809c [Exclusivity] Temporarily disable an assert in AccessEnforcementSelector.
This pass doesn't do anything useful downstream yet, so it's safe to temporarily
disable the assert.

Reenable after fixing:
<rdar://problem/31797132> [Exclusivity] lldb asserts in AccessEnforcementSelector
2017-04-24 14:46:41 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
Andrew Trick
3fe16ac03c [Exclusivity] Fix AccessEnforcementSelection to handle unreachable blocks. 2017-04-16 22:46:04 -07:00
Andrew Trick
915b319810 [AccessEnforce] must handle undef before diagnostics. 2017-04-14 18:28:37 -07:00
Andrew Trick
66d42287a6 AccessEnforcementSelector: add support for arguments.
I'm using source-level tests to help bootstrap the -Onone pipeline
with access markers enabled.
2017-04-12 17:33:17 -07:00
John McCall
b9676d2002 Add a SIL pass to select an access enforcement for allocated boxes.
Tests to come.
2017-04-11 03:10:51 -04:00