Commit Graph

3719 Commits

Author SHA1 Message Date
swift_jenkins
702a96fd9b Merge remote-tracking branch 'origin/master' into master-next 2019-12-11 09:41:08 -08:00
Ravi Kandhadai
af3aa03e0d Merge pull request #28697 from ravikandhadai/oslog-generic-operator-bug-fix
[Constant Evaluator] Fix a bug in the composition of substitution maps
2019-12-11 09:29:31 -08:00
Ravi Kandhadai
7744720df3 [Constant Evaluator] Fix a bug in the composition of substitution
maps in the handling of partial applies. In particular, when using
substMap.subst(otherSubstMap), ensure that otherSubstMap is not empty.

Also, store the partial-apply instruction in the symbolic closure,
which makes it easier to debug errors in the folding of partial applies.
2019-12-10 20:13:49 -08:00
swift_jenkins
51b2144406 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 16:20:02 -08:00
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -08:00
Joe Groff
5dab3cbf25 Clarify comments on new ABIDifference constants 2019-12-10 12:08:42 -08:00
Michael Gottesman
61e5653000 [semantic-arc-opts] Convert load [copy] -> load_borrow given single init alloc_stack. 2019-12-09 11:33:50 -08:00
Joe Groff
41a116b95a Merge pull request #28541 from apple/subst-function-type-conversion
SIL: Distinguish "compatible convention" and "compatible representation" function conversions.
2019-12-04 09:27:27 -08:00
Erik Eckstein
8bc5daca77 SIL: always update the linkage of a function with the serialized linkage in the swiftmodule.
The cross-module-optimization can change the linkage of a function to public. Then the SILLinkage is "out of sync" with the linkage derived from the AST. We need to make sure to read the correct SILLinkage from the module file.
2019-12-04 09:16:28 +01:00
Joe Groff
351c94dbf2 SIL: Distinguish "compatible convention" and "compatible representation" function conversions.
We want to be able to use different representations for function types with otherwise compatible
calling conventions. Distinguish these concepts in the `checkForABIDifferences` SIL APIs, so that
we correctly handle representation-only conversions, which can be handled by `convert_function`,
from full reabstractions, making sure to note that the representation-only case is not transitive
for function arguments, since a function that takes a function with a representation change needs
a thunk to change the argument's representation.
2019-12-03 11:35:48 -08:00
Joe Groff
e544d367ac Merge pull request #28424 from jckarter/subst-function-type-reabstraction
SIL: Plumb abstraction patterns through type lowering.
2019-12-03 10:11:34 -08:00
Erik Eckstein
0b6e3bf6f6 DeadFunctionElimination: factor out function/method visiting of keypath components into a general utility.
This is a NFC
2019-12-03 14:37:01 +01:00
Erik Eckstein
402e228b39 SIL: add a table in SILModule to mark method declarations as externally visible.
This is needed for cross-module-optimization: CMO marks functions as inlinable. If a private or internal method is referenced from such an inlinable function, it must not be eliminated by dead function elimination after serialization (a method is basically an AbstractFunctionDecl).
For SILFunctions we can do this by simply setting the linkage, but for methods we need another mechanism.
2019-12-03 14:37:01 +01:00
Michael Gottesman
e4680a3678 [sil] Refactor Alloc{Stack,Box}Inst::getDecl() onto AllocationInst so that all AllocationInsts (e.x. AllocRefInst) have access to that functionality. 2019-12-02 20:29:10 -08:00
swift-ci
45df041c4f Merge pull request #28526 from gottesmm/pr-adc7dd569017e879cf605515924e93300c72e6d6 2019-12-02 16:18:28 -08:00
Michael Gottesman
4c6d2f04f2 [sil] Change usages of SILArguments in SILArgument.h to use exhaustive switches over ArgumentKinds.
This will ensure we get uncovered switch warnings when we add new argument
kinds, easing adding of such arguments without introducing errors.
2019-12-02 14:44:54 -08:00
Michael Gottesman
df47eb2c1f [sil] Use SILNodes.def to define ARGKIND##ArrayRef instead of hard coding names.
I also changed all of the places that vended these to use SILNodes.def as well
so that when new argument kinds are added, things just work.
2019-12-02 14:39:02 -08:00
Joe Groff
0926d2380b SIL: Sink GenericContextScope into IRGen.
All the context dependencies in SIL type lowering have been eradicated, but IRGen's
type info lowering is still context-dependent and doesn't systemically pass generic
contexts around. Sink GenericContextScope bookkeeping entirely into IRGen for now.
2019-12-02 12:20:05 -08:00
Joe Groff
5140174eb5 SIL: Plumb abstraction patterns through type lowering.
Lowering a SIL type should be a pure function of the formal type of a value and the
abstraction pattern it's being lowered against, but we historically did not carry
enough information in abstraction patterns to lower generic parameter types, so we
relied on a generic context signature that would be pushed and popped before lowering
interface types. This patch largely eliminates the necessity for that, by making it
so that `TypeClassifierBase` and its subclasses now take an `AbstractionPattern`
all the way down, and fixing up the visitor logic so that it derives appropriate
abstraction patterns for tuple elements, function arguments, and aggregate fields too.
This makes it so that type lowering is independent of the current generic context.
(Unfortunately, there are still places scattered across the code where we use the
current generic context in order to build abstraction patterns that we then feed
into type lowering, so we can't yet completely eliminate the concept.)

This then enables us to integrate substituted function type construction into type
lowering as well, since we can now lower a generic parameter type against an
abstraction pattern without that generic parameter having to be tied to the same
generic signature (or any generic signature at all, which in the case of a
substituted function type hasn't necessarily even been finalized yet.)
2019-12-02 12:15:56 -08:00
Michael Gottesman
37dcacf4e8 [sil] Add 'const' to SILArgument methods that are actually 'const' 2019-11-27 09:50:23 -08:00
Michael Gottesman
5d2137b4ca [gardening] Cleanup SILArgument a little bit by reorganizing the declaration.
I fixed up variable names to be camelCase, moved constructors to be right
beneath field declarations.
2019-11-27 09:50:23 -08:00
Michael Gottesman
d93eacdb95 [gardening] Remove llvm:: from references to SmallVectorImpl in SILArgument.h 2019-11-27 09:50:23 -08:00
swift_jenkins
8be3f2244f Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 23:40:29 -08:00
Slava Pestov
53bfc767a3 SIL: Track target formal type for casts
SIL type lowering erases DynamicSelfType, so we generate
incorrect code when casting to DynamicSelfType. Fixing this
requires a fair amount of plumbing, but most of the
changes are mechanical.

Note that the textual SIL syntax for casts has changed
slightly; the target type is now a formal type without a '$',
not a SIL type.

Also, the unconditional_checked_cast_value and
checked_cast_value_br instructions now take the _source_
formal type as well, just like the *_addr forms they are
intended to replace.
2019-11-20 21:30:28 -05:00
swift_jenkins
746bd7f6d9 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 04:19:54 -08:00
Erik Eckstein
bb38711894 DestoyHoisting: handle infinite loops correctly
Ignore blocks in infinite loops and don't insert destroys where they don't belong.

Fixes an ownership verifier crash.
2019-11-20 11:16:05 +01:00
swift_jenkins
b9f998ffa4 Merge remote-tracking branch 'origin/master' into master-next 2019-11-15 15:56:48 -08:00
Andrew Trick
38c29e231e Generalize and fix SinkAddressProjections.
Fixes a potential real bug in the case that SinkAddressProjections moves
projections without notifying SimplifyCFG of the change. This could
fail to update Analyses (probably won't break anything in practice).

Introduce SILInstruction::isPure. Among other things, this can tell
you if it's safe to duplicate instructions at their
uses. SinkAddressProjections should check this before sinking uses. I
couldn't find a way to expose this as a real bug, but it is a
theoretical bug.

Add the SinkAddressProjections functionality to the BasicBlockCloner
utility. Enable address projection sinking for all BasicBlockCloner
clients (the four different kinds of jump-threading that use it). This
brings the compiler much closer to banning all address phis.

The "bugs" were originally introduced a week ago here:

commit f22371bf0b (fork/fix-address-phi, fix-address-phi)
Author: Andrew Trick <atrick@apple.com>
Date:   Tue Sep 17 16:45:51 2019

    Add SIL SinkAddressProjections utility to avoid address phis.

    Enable this utility during jump-threading in SimplifyCFG.

    Ultimately, the SIL verifier should prevent all address-phis and we'll
    need to use this utility in a few more places.

    Fixes <rdar://problem/55320867> SIL verification failed: Unknown
    formal access pattern: storage
2019-11-14 16:11:00 -08:00
swift-ci
aa57f0c92b Merge remote-tracking branch 'origin/master' into master-next 2019-11-12 12:09:57 -08:00
Arnold Schwaighofer
8a4d61fb1d Remove FIXME in TypeExpansionAnalysis: It's cache needed to be keyed by the type expansion context 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
74d14785d5 Address review comment TypeBase::hasOpaqueArchetypePropertiesOrCases 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
8aaa7b4dc1 SILOptimizer: Pipe through TypeExpansionContext 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
9ecda0c574 SIL: Plumb TypeExpansionContext through SIL 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
e67b96139d SIL: Add getTypeExpansionContext to SILFunction 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
6b3e1b3987 SIL: Add TypeExpansion to SIL type lowering 2019-11-11 14:21:52 -08:00
swift-ci
dd9ce7adfe Merge remote-tracking branch 'origin/master' into master-next 2019-11-07 18:31:15 -08:00
Ravi Kandhadai
957dc8e302 [Constant Evaluator] Make symbolic closures, which are representations
of closure literals in the constant evaluator, store the
substitution map that was in the constant evaluator state when
the closure creation site (partial_apply or thin_to_thick_function)
that created the symbolic closure was evaluated.

A substitution map is a mapping from generic type parameters to types.
This map is updated and maintained by the constant evaluator as it
evaluates function calls. At a partial-application site, the substitution
map captures the mapping from the types of the captured arguments (which
could be generic types) to the types of the symbolic value they represent
(which has to be concrete types). The substitution map would be necessary
to fold the symbolic closure into SIL code that constructs the closure
it represents.
2019-11-07 15:04:48 -08:00
swift-ci
4e26c6ac10 Merge remote-tracking branch 'origin/master' into master-next 2019-11-06 16:49:27 -08:00
Andrew Trick
9931aab33b Merge pull request #28103 from atrick/cleanup-escapes
EscapeAnalysis cleanup and add utilities [nearly NFC]
2019-11-06 16:48:22 -08:00
swift-ci
c7902f9d7a Merge remote-tracking branch 'origin/master' into master-next 2019-11-06 15:09:56 -08:00
Ravi Kandhadai
48bc63bb8a [Constant Evaluator] Add support for tracking types with aggregate
symbolic values, which are used to represent constant struct and tuple
instances. Associating those symbolic values with the types of the
aggregate they are representing will allow writing some sanity checks,
and will also make constant folding of the symbolic values easier and
more robust.
2019-11-06 12:47:42 -08:00
Andrew Trick
f009cf3de8 EscapeAnalysis cleanup and add utilities [nearly NFC]
This is the first in a series of patches that reworks
EscapeAnalysis. For this patch, I extracted every change that does not
introduce new features, rewrite logic, or appear to change
functionality.

These cleanups were done in preparation for:

- adding a graph representation for reference counted objects

- rewriting parts to the query logic

- ...which then allows the analysis to safely assume that all
  exclusive arguments are unique

- ...which then allows more aggressive optimization of local variables
  that don't escape

There are two possible functional changes:

1. getUnderlyingAddressRoot in InstructionUtils now sees through OSSA
instructions: begin_borrow and copy_value

2. The getPointerBase helper in EscapeAnalysis now sees through all of
these reference and pointer casts:

+  case ValueKind::UncheckedRefCastInst:
+  case ValueKind::ConvertFunctionInst:
+  case ValueKind::UpcastInst:
+  case ValueKind::InitExistentialRefInst:
+  case ValueKind::OpenExistentialRefInst:
+  case ValueKind::RawPointerToRefInst:
+  case ValueKind::RefToRawPointerInst:
+  case ValueKind::RefToBridgeObjectInst:
+  case ValueKind::BridgeObjectToRefInst:
+  case ValueKind::UncheckedAddrCastInst:
+  case ValueKind::UnconditionalCheckedCastInst:
+  case ValueKind::RefTo##Name##Inst:
+  case ValueKind::Name##ToRefInst:

This coalesces a whole bunch of nodes together that were just there
because of casts. The existing code was already doing this for one
level of casts, but there was a bug that prevented it from happening
transitively. So, in theory, anything that breaks with this fix could
also break without this fix, but may not have been exposed. The fact
that this analysis coalesces address-to-reference casts at all is what
caused me to spent vast amounts of time debugging any time I tried to
force some structure on the graph via assertions. If it is done at
all, it should be done everywhere consistently to expose issues as
early as possible.

Here is a description of the changes in diff order. If something in
the diff is not listed here, then the code probably just moved around
in the file:

Rename isNotAliasedIndirectParameter to
isExclusiveIndirectParameter. The argument may be aliased in the
caller's scope and it's contents may have already escaped.

Add comments to SILType APIs (isTrivial, isReferenceCounted) that give
answers about the AST type which don't really make sense for address
SILTypes.

Add comments about CGNode's 'Value' field. I spent lots of time
attempting to tighten this down with asserts, but it's only possible
for non-content nodes. For content nodes, the node's value is highly
unpredictable and basically nonsense but needed for debugging.

Add comments about not assuming that the content nodes pointsTo edge
represents physical indirection. This matters when reasoning about
aliasing and it's a tempting assumption to make.

Add a CGNode::mergeProperties placeholder for adding node properties.

Factor out a CGNode::canAddDeferred helper for use later.

Rename `setPointsTo` to `setPointsToEdge` because it actually creates
an edge rather than just setting `pointsTo`.

Add CGNode::getValue() and related helpers to help maintain invariants.

Factor out a `markEscaping` helper.

Clean up the `escapesInsideFunction` helper.

Add node visitor helpers: visitSuccessors, visitDefers. This made is
much easier to prototype utilities.

Add comments to clarify the `pointsTo` invariant. In particular, an
entire defer web may have a null pointsTo for a while.

Add an `activeWorklist` to avoid nasty bugs when composing multiple
helpers that each use the worklist.

Remove the `EA` argument from `getNode`. I ended up needing access to
the `EA` context from the ConnectionGraph many times during
prototyping and passing `this` was all the `getNode` calls was very
silly.

Add graph visitor helpers: backwardTraverse, forwardTraverseDefer,
forwardTraversePointsToEdges, and mayReach for ease in developing new
logic and utilities.

Add isExclusiveArgument helper and distinguish exclusive arguments
from local objects. Confusing these properties could lead to scary
bugs. For example, unlike a local object, an exclusive argument's
contents may still escape even when the content's connection graph
node is non-escaping!

Add isUniquelyIdentified helper when we want to treat exclusive
arguments and local objects uniformly.

getUnderlyingAddressRoot now looks through OSSA instructions.

Rename `getAccessedMemory` to `getDirectlyAccessedMemory` with
comments. This is another dangerous API because it assumes the memory
access to a given address won't touch memory represented by different
graph nodes, but graph edges don't necessarily represent physical
indirection. Further clarify this issue in comments in
AliasAnalysis.cpp.

Factor out a 'findRecursiveRefType' helper from the old
'mayContainReference' for checking whether types may or must contain
references. Support both kinds of queries so the analysis can be
certain when a pointer's content is a physical heap object.

Factor out 'getPointerBase' and 'getPointerRoot' helpers that follow
address projections within what EscapeAnalysis will consider a single
node.

Create a CGNodeWorklist abstraction to safely formalize the worklist
mechanism that's used all over the place. In one place, there were
even two separate independent lists used independently (nodes added to
one list could appear to be in the other list).

The CGNodeMap abstraction did not significantly change, it was just moved.

Added 'dumpCG' for dumping .dot files making it possible to remote debug.

Added '-escapes-enable-graphwriter' option to dump .dot files, since
they are so much more useful than the textual dump of the connection
graph, which lacks node identity!
2019-11-06 11:07:52 -08:00
swift-ci
afe71a79f3 Merge remote-tracking branch 'origin/master' into master-next 2019-11-04 17:49:58 -08:00
Saleem Abdulrasool
32151c6463 SIL: silence -Wunused-variable (NFC) 2019-11-04 15:07:30 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
swift-ci
2689ff9343 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 07:49:45 -07:00
Robert Widmann
5f3b1da22a Merge pull request #27949 from CodaFi/protoplasmic-supine-jellies
[NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
2019-10-30 07:47:17 -07:00
swift-ci
b73ff1cdc2 Merge remote-tracking branch 'origin/master' into master-next 2019-10-29 23:09:59 -07:00