Commit Graph

27803 Commits

Author SHA1 Message Date
Michael Gottesman
97c73768af Merge pull request #35253 from gottesmm/pr-7d30d56fcab9d42f3788104b987f62df27540e00
[sil-inst-opt] Improve performance of InstModCallbacks by eliminating indirect call along default callback path.
2021-01-04 15:25:53 -08:00
Andrew Trick
3a1c8fdd8b Merge pull request #35248 from atrick/fix-operandownership
OperandOwnership fixes required for CanonicalOSSA
2021-01-04 15:06:12 -08:00
Michael Gottesman
0de00d1ce4 [sil-inst-opt] Improve performance of InstModCallbacks by eliminating indirect call along default callback path.
Specifically before this PR, if a caller did not customize a specific callback
of InstModCallbacks, we would store a static default std::function into
InstModCallbacks. This means that we always would have an indirect jump. That is
unfortunate since this code is often called in loops.

In this PR, I eliminate this problem by:

1. I made all of the actual callback std::function in InstModCallback private
   and gave them a "Func" postfix (e.x.: deleteInst -> deleteInstFunc).

2. I created public methods with the old callback names to actually call the
   callbacks. This ensured that as long as we are not escaping callbacks from
   InstModCallback, this PR would not result in the need for any source changes
   since we are changing a call of a std::function field to a call to a method.

3. I changed all of the places that were escaping inst mod's callbacks to take
   an InstModCallback. We shouldn't be doing that anyway.

4. I changed the default value of each callback in InstModCallbacks to be a
   nullptr and changed the public helper methods to check if a callback is
   null. If the callback is not null, it is called, otherwise the getter falls
   back to an inline default implementation of the operation.

All together this means that the cost of a plain InstModCallback is reduced and
one pays an indirect function cost price as one customizes it further which is
better scalability.

P.S. as a little extra thing, I added a madeChange field onto the
InstModCallback. Now that we have the helpers calling the callbacks, I can
easily insert instrumentation like this, allowing for users to pass in
InstModCallback and see if anything was RAUWed without needing to specify a
callback.
2021-01-04 12:51:55 -08:00
Andrew Trick
24fa28808e Comment OwnershipConstraints with respect to Unowned values. 2021-01-01 21:20:23 -08:00
Andrew Trick
93c884e6b5 Comment OperandOwnership 2021-01-01 19:22:19 -08:00
Andrew Trick
cead6a5122 Add an OptimizedMandatoryCombine pass variant.
It's against the principles of pass design to check the driver mode
within the pass. A pass always needs to do the same thing regardless
of where it runs in the pass pipeline. It also needs to be possible to
test passes in isolation.
2021-01-01 19:22:19 -08:00
Andrew Trick
ab42f753f7 Remove OperandOwnership::NestedBorrow.
Now that OperandOwnership determines the operand constraints, it
doesn't make sense to distinguish between Borrow and NestedBorrow at
this level. We want these uses to automatically convert between the
nested/non-nested state as the operand's ownership changes. The use
does not need to impose any constraint on the ownership of the
incoming value.

For algorithms that need to distinguish nested borrows, it's still
trivial to do so.
2021-01-01 19:22:19 -08:00
Andrew Trick
ce2a7cfe0e Clearly discriminate OperandOwnership::NonUse and TrivialUse.
A NonUse operand does not use the value itself, so it ignores
ownership and does not require liveness. This is for operands that
represent dependence on a type but are not actually passed the value
of that type (e.g. they may refer an open_existential). This could be
used for other dependence-only operands in the future.

A TrivialUse operand has undefined ownership semantics aside from
requiring liveness. Therefore it is only legal to pass the use a value
with ownership None (a trivial value). Contrast this with things like
InstantaneousUse or BitwiseEscape, which just don't care about
ownership (i.e. they have no ownership semantics.

All of the explicitly listed operations in this category require
trivially typed operands. So the meaning is obvious to anyone
adding SIL operations and updating OperandOwnership.cpp, without
needing to decifer the value ownership kinds.
2021-01-01 19:22:10 -08:00
Doug Gregor
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00
Meghana Gupta
b99533aced Merge pull request #34895 from meg-gupta/cseossa
Enable CSE on OSSA
2020-12-23 09:58:46 -08:00
Kavon Farvardin
179474e185 Merge pull request #35153 from kavon/warn-unqualified-await
[concurrency] warn about future reservation of 'await' as contextual keyword
2020-12-23 09:20:18 -08:00
Rintaro Ishizaki
e1f7bd2edc Merge pull request #35204 from rintaro/ide-comformingmethodlist-asan-rdar72605086
[SourceKit] Fix asan failure in ConformingMethodList request
2020-12-23 08:51:59 -08:00
Meghana Gupta
42c031985c Enable CSE on OSSA 2020-12-22 23:20:06 -08:00
Meghana Gupta
68ec810b32 Rename stripOwnershipInsts to lookThroughCopyValueInsts 2020-12-22 22:01:55 -08:00
Meghana Gupta
372efd5a76 Add a new overload of SILInstruction::getOperandValues to get
transformed values of the operands
2020-12-22 22:01:48 -08:00
Rintaro Ishizaki
ab63c127c3 [SourceKit] Fix asan failure in ConformingMethodList request
rdar://problem/72605086
2020-12-22 19:03:43 -08:00
Slava Pestov
5022b723f3 Merge pull request #35156 from slavapestov/active-request-dense-set
Refactor request evaluator dependency tracking a bit
2020-12-22 19:10:02 -05:00
Kavon Farvardin
463003194e add warning that 'await' will become contextual keyword 2020-12-22 15:46:24 -08:00
Slava Pestov
161d832140 AST: Refactor request evaluator dependency tracking a bit
Other than simplifying some code, the big improvement here is
that we 'freeze' the reference dependencies for a request down
to a simple vector. We only use a DenseSet to store dependencies
of active requests.
2020-12-22 16:12:04 -05:00
Mike Ash
7ad3455f8d Merge pull request #35185 from mikeash/fix-StableAddressConcurrentReadableHashMap
[Runtime] Fix StableAddressConcurrentReadableHashMap threading crash.
2020-12-22 16:02:09 -05:00
Slava Pestov
f5e47ea5d2 AST: Add AnyRequest::isDependencySource() 2020-12-22 01:42:04 -05:00
Slava Pestov
d1a2a612b1 AST: Change some writeDependencySink() methods to take the result by const reference 2020-12-22 01:42:04 -05:00
Slava Pestov
b9e664af8e Merge pull request #35162 from slavapestov/remove-expand-astscope-request
Remove the ExpandASTScopeRequest
2020-12-22 01:41:34 -05:00
Mike Ash
4ccfdfb72a [Runtime] Fix StableAddressConcurrentReadableHashMap threading crash.
StableAddressConcurrentReadableHashMap::getOrInsert had a race condition in the first lookup, where the snapshot was destroyed before the pointer was extracted from the returned wrapper. Fix this by creating the snapshot outside the if so that it stays alive.

rdar://problem/71932487
2020-12-21 16:52:56 -05:00
swift-ci
07dbf4ef57 Merge pull request #35157 from atrick/remove-deadblocks 2020-12-20 17:07:35 -08:00
Andrew Trick
fe6e87913a Remove the default DEBlocks = nullptr argument from verifyOwnership.
Passing nullptr was undefined behavior because ReborrowVerifier takes
a reference to DeadEndBlocks.
2020-12-20 14:46:43 -08:00
Alex Hoppen
fd932a6b42 [SILOpt] Fix build by only accessing seenUse in non-assert builds 2020-12-19 12:23:58 +01:00
Michael Gottesman
5714a59d62 Merge pull request #35165 from gottesmm/pr-ad9a97a586d0760867436cf845d17da4412bc75b
[sil] Eliminate a confusing optional method result by changing type dependent operands to have OwnershipKind::None instead of returning Optional::None from Operand::getOperandOwnership().
2020-12-18 22:11:41 -08:00
Michael Gottesman
368f8acc4b [sil] Eliminate a confusing optional method result by changing type dependent operands to have OwnershipKind::None instead of returning Optional::None from Operand::getOperandOwnership().
This eliminates when talking about this API an ambiguity in between
Optional::None (the C++ ADT) and OwnershipKind::None (the ownership kind).
2020-12-18 19:33:27 -08:00
Andrew Trick
bab19976a6 Add a PrunedLiveness utility.
This bare-bones utility will be the basis for
CanonicalizeOSSALifetime. It is maximally flexible and can be adopted
by any analysis that needs SSA-based liveness expressed in terms of
the live blocks. It's meant to be layered underneath various
higher-level analyses.

We could consider revamping ValueLifetimeAnalysis and layering it on
top of this. If PrunedLiveness is adopted widely enough, we can
combine it with a block numbering analysis so we can micro-optimize
the internal data structures.
2020-12-18 18:49:59 -08:00
Slava Pestov
b1f9c10d07 ASTScope: Small optimization to ASTScopeImpl memory layout
Combine the wasExpanded flag with the parent pointer, and remove
the haveAddedCleanup flag since it's no longer necessary now that
"re-expansion" is gone.
2020-12-18 15:43:33 -05:00
Slava Pestov
0fa84c14a0 ASTScope: Remove the ExpandASTScopeRequest
This doesn't really fit the request evaluator model since the
result of evaluating the request is the new insertion point,
but we don't have a way to get the insertion point of an
already-expanded scope.

Instead, let's change the callers of the now-removed
expandAndBeCurrentDetectingRecursion() to instead call
expandAndBeCurrent(), while checking first if the scope was
already expanded.

Also, set the expanded flag before calling expandSpecifically()
from inside expandAndBeCurrent(), to ensure that re-entrant
calls to expandAndBeCurrent() are flagged by the existing
assertion there.

Finally, replace a couple of existing counters, and the
now-gone request counter with a single ASTScopeExpansions
counter to track expansions.
2020-12-18 15:43:33 -05:00
Rintaro Ishizaki
8ef504acf3 Merge pull request #35050 from rintaro/ide-completion-rdar72198530
[CodeCompletion] Annotate 'async' functions/initializers in results
2020-12-18 09:29:07 -08:00
Evan
d48393bd10 Merge pull request #35108 from etcwilde/ewilde/fixit-actor-protocol-conformance
[Concurrency] Emit fixit to add actorIndependent attribute
2020-12-18 08:59:00 -08:00
Alex Hoppen
beb6caf6a9 Merge pull request #35118 from ahoppen/moveonly-syntaxcontext
Make the SyntaxParsingContext move-only
2020-12-18 17:12:38 +01:00
Alex Hoppen
79a7d3804b Merge pull request #35117 from ahoppen/syntaxnode-child-getters-const
Make the child getters of SyntaxNodes const
2020-12-18 17:12:16 +01:00
Andrew Trick
e2f427ab1b Merge pull request #35152 from atrick/ownershipenum
Convert OperandOwnership from an enum class to a struct enum.
2020-12-18 00:04:42 -08:00
Andrew Trick
c9283e31c3 Merge pull request #35130 from atrick/unowneduse
OSSA: Add strict requirements on Unowned uses.
2020-12-17 23:23:16 -08:00
swift-ci
df365e7bce Merge pull request #34695 from meg-gupta/fixcrashineaa 2020-12-17 23:09:56 -08:00
Andrew Trick
f777e0a70e Convert OperandOwnership from an enum class to a struct enum. 2020-12-17 21:24:41 -08:00
Andrew Trick
84768bcdb3 OSSA: Add requirements on Unowned uses.
Clarify which uses are allowed to take Unowned values. Add enforcement
to ensure that Unowned values are not passed to other uses.

Operations that can take unowned are:

- copy_value
- apply/return @unowned argument
- aggregates (struct, tuple, destructure, phi)
- forwarding operations that are arbitrary type casts

Unowned values are currently borrowed within ObjC deinitializers
materialized by the Swift compiler. This will be banned as soon as
SILGen is fixed.
2020-12-17 21:08:56 -08:00
Evan Wilde
1d53d748d3 Cleanup actor protocol conformance error
This patch cleans up how we emit the errors for disallowing the
properties and methods of an actor to be applied to the protocol
conformance. Rather than having multiple error messages for each case,
we keep one error message saying that the actor-isolated
method/variable/what-have-you cannot be used to satisfy a protocol
requirement, then allow multiple notes with fix-its to allow the
programmer to choose what they want to do. The notes have a better
description of what each option does.
2020-12-17 16:12:41 -08:00
Meghana Gupta
db24e3e94c Fix crash in EpilogueArcAnalysis
EpilogueARCState for unreachable blocks can be non-existent. Fix the
EpilogueARCContext::getState method and its users.
2020-12-17 13:39:22 -08:00
Pavel Yaskevich
3e1b01ac7a Merge pull request #35098 from xedin/dont-precompute-default-bindings
[CSBindings] Don't generate bindings for defaults
2020-12-17 00:33:37 -08:00
John McCall
fcb1864a89 Merge pull request #35116 from rjmccall/builtin-synthesis-1
[NFC] Switch a bunch of builtins over to use ASTSynthesis
2020-12-16 22:34:55 -05:00
Dan Liew
8e95189d24 Merge pull request #35074 from apple/dliew/rdar-69335186
Disable "UseOdrIndicator" ASan instrumentation mode by default.
2020-12-16 19:19:40 -08:00
swift-ci
f23f5b88b5 Merge pull request #34999 from ktoso/wip-task-groups-impl-channel-rebased 2020-12-16 16:26:14 -08:00
Slava Pestov
bf23faa3ed Merge pull request #35112 from slavapestov/request-evaluator-caching-optimization
Hacks to avoid request evaluator caching overhead
2020-12-16 19:15:50 -05:00
John McCall
2422e0342c [NFC] Switch a bunch of builtins over to use ASTSynthesis 2020-12-16 17:12:01 -05:00
Konrad `ktoso` Malawski
b267778bf1 Rebased to use new global executor 2020-12-17 06:05:13 +09:00