Commit Graph

2864 Commits

Author SHA1 Message Date
Michael Gottesman
29378a849c [mandatory-inline] Roll some more acceptable callee checks from runOnFunctionRecursively into getCalleeFunction. NFC.
I also did a little bit of cleaning up by converting a couple of

  Type *F = dyn_cast<Type>(X).

To:

  auto *F = dyn_cast<Type>(X).

rdar://31521023
2017-09-11 16:16:07 -07:00
Michael Gottesman
54dbdbc677 [mandatory-inline] Add a note about the weird behavior where II later in Mandatory inlining may no longer be the original apply.
This is one reason for the weird iteration maintainance code in
MandatoryInlining. This comment at least makes it clear what is going on (more
for historical purposes, since I am hoping to fix this soon).

rdar://31521023
2017-09-11 14:07:29 -07:00
Andrew Trick
443e244d37 [sil-opaque-values] NFC, Allow SIL conventions to be set within SILBuilder.
This keeps the `create*` API simple for *normal* users and forces
AddressLowering to declare conventions when creating a builder.
2017-09-10 18:11:05 -07:00
Michael Gottesman
5981cc30f5 [mandatory-inline] Refactor out cleanupLoadedCalleeValue from cleanupCalleeValue.
I am refactoring this for two reasons:

1. This code was 60-70% of cleanupCalleeValue, yet cleanupCalleeValue also
performs other tasks. This is a classic situation where one should extract a
subroutine to make cleanupCalleeValue more readable.

2. I am going to be extracting out the cleanup of the callee to be outside the
main inlining loop. Without this refactoring, I would have to use goto to
perform a continue from the inside of an inner for loop of an outer for loop.
Instead by refactoring it this way, I can separate continuing in the inner loop
from continuing in the outer loop.

rdar://31521023
2017-09-10 13:35:07 -07:00
Michael Gottesman
49bf82245b [mandatory-inlining] Make fixupReferenceCounts not delete instructions.
The main loop of mandatory inlining is spending a lot of time managing complex
iterator invalidation issues. This is the first in a series of commits that move
the main inlining loop to only delete the callee and to do all cleanups after we
have finished inlining.

This specific optimization (the quick retain/release peephole), I am not going
to do in MandatoryInlining, we already have guaranteed arc opts afterwards that
will be able to hit such a peephole so no perf should be lost.

*NOTE* The reason why I had to touch some of the code motion tests is that the
routine I am using to ensure that strong_retain/release_value is emitted as
appropriate is also used by codemotion. Code motion tests had cargo culted some
code from previous tests that retained Builtin.Int32. I changed the routines
though so that when a retain/release is inserted, if it is trivial, nothing is
inserted. No routine was relying on the actual usage of the inserted
retain/releases, so everything will be safe. This addition to the relevant code
caused me to need to change the tests in code motion to use actual non-trivial
values. The same code paths are being tested in terms of blocking code
motion/etc.

rdar://31521023
2017-09-10 13:23:48 -07:00
Michael Gottesman
2722b98003 [mandatory-inlining] Improve readability by using standard loop variable names for instructions, basic blocks.
F{I,E} is generally used for function iterators over a module's functions.
B{I,E} are generally standard for block iterator, block end. I make the II
change just to make it clearer that the given value is an instruction iterator
like in other parts of the SIL Optimizer.

rdar://31521023
2017-09-09 21:17:36 -07:00
swift-ci
cf27ab9d93 Merge pull request #11839 from gottesmm/pr-8aae8140c859cc0621e37aa723e638253cf585b7 2017-09-09 20:04:17 -07:00
Michael Gottesman
600edc32d2 [mandatory-inline] Extract out tryDevirtualizeCode into its own helper function. NFC.
Just trying to slim down/refactor this huge loop.

rdar://31521023
2017-09-09 19:39:29 -07:00
Michael Gottesman
a26ab976c6 [gardening] Convert two typedefs to using. 2017-09-09 16:23:50 -07:00
Michael Gottesman
fc1a639a9e [mandatory-inline] Move the creation of the inliner and bailing upon knowing that inlining will fail, before any side-effect having work occurs.
rdar://31521023
2017-09-08 22:18:07 -07:00
Michael Gottesman
430f865f73 [inliner] Extract out checking if we can inline from inlineFunction into canInlineFunction. NFC.
The reason to do this is:

1. The check in SILInliner if we can inline can be done without triggering
side-effects.

2. This enables us to know if inlining will succeed before attempting to inline.
This enables for arguments to be adjusted with new SILInstructions and the like
before inlining occurs. I use this in a forthcoming patch that updates mandatory
inlining for ownership.

rdar://31521023
2017-09-08 18:25:57 -07:00
Michael Gottesman
4c087097f3 [di] Update definite_initialization for ownership.
rdar://31521023
2017-09-07 15:23:22 -07:00
Graydon Hoare
8f4266067a [SILOptimizer] Handle a missing case in DataflowDiagnostics.cpp 2017-09-04 20:02:21 -07:00
Slava Pestov
5973a2722c SILOptimizer: Fix some unused variable warnings 2017-09-01 02:04:22 -07:00
Erik Eckstein
020a283bbb SIL: Let the OpenedArchetypesTracker be constructed with a null SILFunction.
NFC
2017-08-23 09:15:00 -07:00
Roman Levenstein
7bda199db0 [sil-constant-propagation] If an overflow/underflow would happen only in a specialized function, just don't perform the copy propagation in such a case
Do not report any constant propagation issues in (generic) function specializations, because these issues are eventually not visible in the original function and thus would be very misleading and difficult to understand.
2017-08-22 15:16:19 -07:00
Roman Levenstein
a73fbdb3fe Define a GenericSpecializationInformation class which can be used to track the history of generic specializations
GenericSpecializationInformation contains information regarding how a given specialized function was created, e.g. which caller function triggered this specialization, which substitutions were used, etc. Provide some debugging flags to dump the collected specialization information.

The information about generic specializations is referenced by the specialized functions and by call-sites originating from specialized functions.

This information can be created/used by the generic specializer to detect generic call-sites whose specialization would result in non-terminating sequence of subsequent generic specializations.
2017-08-06 12:51:49 -07:00
Erik Eckstein
6377cc095a SIL: Replace TransitivelyUnreachableBlocks with DeadEndBlocks
We had both utilities doing the same thing.
NFC
2017-07-24 09:50:42 -07:00
Andrew Trick
f657ad2d3a Rename *ExistentialOpaque instructions to *ExistentialValue.
These instructions have the same semantics as the *ExistentialAddr instructions
but operate directly on the existential value, not its address.

This is in preparation for adding ExistentialBoxValue instructions.
The previous name would cause impossible confusion with "opaque existentials"
and "opaque existential boxes".
2017-07-17 23:46:41 -07:00
Devin Coughlin
6dcc8ce9b2 [Exclusivity] Don't suggest copying to a local when swapAt() is appropriate
Update static exclusivity diagnostics to not suggest copying to a local
when a call to swapAt() should be used instead. We already emit a FixIt in
this case, so don't suggest an an helpful fix in the diagnostic.

rdar://problem/32296784
2017-07-16 13:48:52 -07:00
Michael Gottesman
9e720c6308 [di] Extract out a helper routine. NFC intended. 2017-07-12 16:50:15 -07:00
Devin Coughlin
47d9de9751 [Exclusivity] Relax closure enforcement on separate stored properties (#10789)
Make the static enforcement of accesses in noescape closures stored-property
sensitive. This will relax the existing enforcement so that the following is
not diagnosed:

struct MyStruct {
   var x = X()
   var y = Y()

  mutating
  func foo() {
    x.mutatesAndTakesClosure() {
      _ = y.read() // no-warning
   }
  }
}

To do this, update the access summary analysis to summarize accesses to
subpaths of a capture.

rdar://problem/32987932
2017-07-10 13:33:22 -07:00
Devin Coughlin
2501dd71de Revert "[Exclusivity] Relax closure enforcement on separate stored properties" 2017-07-05 20:19:50 -07:00
swift-ci
eb5d21b6e2 Merge pull request #10595 from devincoughlin/exclusivity-interprocedural-separate-stored-structs 2017-07-05 18:52:57 -07:00
Devin Coughlin
86dff5c0a7 [Exclusivity] Relax closure enforcement on separate stored properties
Make the static enforcement of accesses in noescape closures stored-property
sensitive. This will relax the existing enforcement so that the following is
not diagnosed:

struct MyStruct {
   var x = X()
   var y = Y()

  mutating
  func foo() {
    x.mutatesAndTakesClosure() {
      _ = y.read()
   }
  }
}

To do this, update the access summary analysis to be stored-property sensitive.

rdar://problem/32987932
2017-07-05 16:09:54 -07:00
Andrew Trick
d45f171c98 Cleanup AccessMarkerElimination.
In raw SIL, access markers are unconditionally retained. In canonical SIL,
markers are still removed prior to optimization.

A new flag, -sil-optimized-access-markers, allows testing access markers in
optimized builds, but it is not yet fully supported.
2017-07-05 15:18:48 -07:00
Andrew Trick
ac56f91f47 Add a little tiny comment to AccessEnforcementSelection. 2017-07-05 14:10:05 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Devin Coughlin
2eef7cd470 [Exclusivity] Fix unreachable when diagnosing on BoundGenericStructType
Fix an unreachable when constructing the description of the accessed subpath
when diagnosing an exclusivity violation on a variable of
BoundGenericStructType.

rdar://problem/33031311
2017-06-28 12:09:46 -04:00
Alex Hoppen
949968a182 Adjust printing to take into account special DeclNames
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
2017-06-24 11:39:09 +02: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
swift-ci
ca3227f93c Merge pull request #10346 from atrick/exclusivity 2017-06-18 14:04:12 -07:00
Devin Coughlin
5ec0563c16 [Exclusivity] Statically enforce exclusive access in noescape closures (#10310)
Use the AccessSummaryAnalysis to statically enforce exclusive access for
noescape closures passed as arguments to functions.

We will now diagnose when a function is passed a noescape closure that begins
an access on capture when that same capture already has a conflicting access
in progress at the time the function is applied.

The interprocedural analysis is not yet stored-property sensitive (unlike the
intraprocedural analysis), so this will report violations on accesses to
separate stored properties of the same struct.

rdar://problem/32020710
2017-06-17 22:52:29 +01: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
Devin Coughlin
06b9ed7501 [Exclusivity] Switch static checking to use IndexTrie instead of ProjectionPath
IndexTrie is a more light-weight representation and it works well in this case.
This requires recovering the represented sequence from an IndexTrieNode, so
also add a getParent() method.
2017-06-15 18:37:23 -07:00
Devin Coughlin
f6df5c79b2 [Exclusivity] Update static diagnostic text for "simultaneous" accesses
Remove the descriptive decl kind (since with subpaths it is not correct and
cannot represent a tuple element) and change "simultaneous" to "overlapping"
in order to lower the register slightly and avoid connoting threading.

For example, for the following:

   takesTwoInouts(&x.f, &x.f)

the diagnostic will change from

"simultaneous accesses to var 'x.f', but modification requires exclusive access;
consider copying to a local variable"

to

"overlapping accesses to 'x.f', but modification requires exclusive access;
consider copying to a local variable"
2017-06-13 20:08:48 -07:00
Devin Coughlin
d76ec6a8ff [Exclusivity] Relax enforcement for separate struct stored properties
Relax the static enforcement of exclusive access so that we no longer diagnose
on accesses to separate stored structs of the same property:

takesInout(&s.f1, &s.f2) // no-warning

And perform the analogous relaxation for tuple elements.

To do this, track for each begin_access the projection path from that
access and record the read and write-like modifications on a per-subpath
basis.

We still warn if the there are conflicting accesses on subpaths where one is
the prefix of another.

This commit leaves the diagnostic text in a not-so-good shape since we refer
to the DescriptiveDeclKind of the access even describing a subpath.

I'll fix that up in a later commit that changes only diagnostic text.

https://bugs.swift.org/browse/SR-5119
rdar://problem/31909639
2017-06-13 19:15:38 -07:00
Devin Coughlin
480222c36e [Exclusivity] Make helper functions to static. NFC.
Make helper functions static and avoid defining one except when assertions
are enabled.
2017-06-13 17:00:25 -07:00
Alex Hoppen
d922944af0 Merge pull request #9976 from ahoppen/pdm-diagnostics2
Migration to DeclBaseName in diagnostic definitions
2017-06-13 12:55:16 +02:00
Slava Pestov
2192470213 DI: Fix 'self.init' delegation to an imported factory initializer inherited from a base class
Fixes <rdar://problem/32697794>.
2017-06-10 23:16:15 -07:00
Michael Gottesman
f85da6860a [sil] Delete SILInstruction::removeFromParent().
This is a very easily misused API since it allows for users to leak instructions
if they are not careful. This commit removes this API and replaces the small
number of uses of this API with higher level APIs that accomplish the same task
without using removeFromParent(). There were no API users that specifically
required removeFromParent.

An example of one way we were using removeFromParent is to move a SILInstruction
to the front of a block. That does not require exposing an API like
removeFromParent()... we can just create a higher level API like the one added
in this commit: SILInstruction::moveFront(SILBasicBlock *).

rdar://31276565
2017-06-07 16:52:10 -07:00
Andrew Trick
b44bc36834 Guaranteed ARC Opts: Access instructions do not reduce refcounts.
Fixes <rdar://problem/32560531> MatMul regression with dynamic
exclusivity checks due to retain/release.
2017-06-04 20:27:25 -07:00
Alex Hoppen
faa1720c48 [Diagnostics] Adjustments for DeclBaseName
Adjust the definition of some diagnostics that are already called with
DeclBaseNames so that the implicit conversion from DeclBaseName to
Identifier is no longer needed.

Adjust the call side of diagnostics which don't have to deal with
special names to pass an Identifier to the diagnostic.
2017-05-31 15:58:46 +02:00
Alex Hoppen
8946015d5a [SIL] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Adrian Prantl
d966a8b104 Share the debug scope of unreachable instructions with the preceding BB.
This causes the debug info to be smaller and easier to read, but
otherwise has no effect.
2017-05-25 17:19:41 -07:00
Devin Coughlin
8974392a56 [Exclusivity] Weaken assert when suggesting swap() Fix-It
This fixes a too-strong assertion when suggesting a Fix-It to replace
module-qualified calls to swap():

Swift.swap(&a[i], &a[j])

Other than weakening the assert, there is no functional change here.

rdar://problem/32358872
2017-05-23 20:07:24 -07:00
Devin Coughlin
f239ae2ad7 [Exclusivity] Suggest Fix-Its to replace swap() with swapAt()
Extend the static diagnostics for exclusivity violations to suggest replacing

  swap(&collection[index1], &collection[index2]

with

  collection.swapAt(index1, index2).

when 'collection' is a MutableCollection.

To do so, repurpose some vestigial code that was previously used to suppress all
exclusivity diagnostics for calls to swap() and add some additional syntactic,
semantic,  and textual pattern matching.

rdar://problem/31916085
2017-05-17 17:48:58 -07:00
Andrew Trick
94ad1403e2 [Exclusivity] Check that accesses are well-formed during diagnostics.
This whitelists all the operations that produce an address that
may be accessed and adds SIL test cases.
2017-05-16 10:22:49 -07:00