Commit Graph

2777 Commits

Author SHA1 Message Date
Michael Gottesman
e4e48e81f1 [pa-combiner] Modernize some appending code to use a range instead of iterators. NFC. 2019-12-12 09:52:28 -08:00
Michael Gottesman
0d88ff1432 [pa-combiner] Some further updates for supporting ossa.
Specifically:

1. I converted a bunch of cases where we were emitting releases/unqualified
loads to use instead the *Operation commands that work in both modes.
2. I renamed some methods/variables that referred to releases to instead refer
to destroys.
2019-12-12 09:52:28 -08:00
swift_jenkins
1fba729d62 Merge remote-tracking branch 'origin/master' into master-next 2019-12-11 18:40:34 -08:00
Michael Gottesman
0d08f8c802 Merge pull request #28724 from gottesmm/pr-4e2a94eb74331d3c9eadc35c9c0df4c978adc200
[sil] Move partial apply combiner code from SILCombiner into InstOptUtils.h/SILCombinerApplyVisitor.cpp.
2019-12-11 18:28:40 -08:00
Michael Gottesman
113c22a680 [sil] Move partial apply combiner code from SILCombiner into InstOptUtils.h/SILCombinerApplyVisitor.cpp.
This is in preparation for moving this into the mandatory combiner.
2019-12-11 14:48:19 -08:00
swift_jenkins
702a96fd9b Merge remote-tracking branch 'origin/master' into master-next 2019-12-11 09:41:08 -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
Joe Groff
fb34044408 Merge remote-tracking branch 'origin/master' into master-next 2019-12-10 12:46:41 -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
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
Slava Pestov
0e0e4efebe Merge pull request #28401 from slavapestov/fix-cast-to-self
Fix casts involving the 'Self' type
2019-12-02 19:56:51 -05: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
Yuta Saito
e5331919db Add possibility of public class 2019-12-02 11:04:15 -08:00
zoecarver
2913dbc430 Check dominance order and add .sil test 2019-12-01 10:50:18 -08:00
zoecarver
3ab158ef68 Merge branch 'master' into fix/substitution-map-composition 2019-11-30 01:46:18 -08:00
Erik Eckstein
66ccfd78ed Inliner: fix condition to prevent inlining of functions with dynamic-self.
Now the condition matches exactly what's checked in asserts in SILBuilder.

fixes an assert in the PerformanceInliner
https://bugs.swift.org/browse/SR-11817
rdar://problem/57369847
2019-11-26 12:53:40 +01:00
Slava Pestov
efe4883eef SILOptimizer: Fix to deal with casts involving dynamic Self
The cast optimizer was too eager to fold casts where the source and
target lowered types were the same, even though the formal types
might be different. Move the classifyFeasibility() check to deal
with this case.

Also in dead code elimination we have to mark all operands of a
cast branch instruction as live, not just the first operand,
otherwise we miss the special 'type dependent' self metadata
operand and replace it with 'undef'.
2019-11-22 16:39:17 -05:00
Andrew Trick
8052a61a56 Merge pull request #28430 from atrick/fix-existential-conformance
Fix ExistentialSpecializer: inherited conformance
2019-11-22 09:13:21 -08:00
Andrew Trick
7d0a772542 Fix ExistentialSpecializer: inherited conformance
The ExistentialSpecializer incorrectly assumed that an existential's conformances match an opened archetype. They don't. Opened archetypes strip inherited conformances per the ABI for generic argument passing. Existential values retain those inherited conformances (for some inexplicable reason).

- Rename ASTContext::getExistentialSignature() to
  getOpenedArchetypeSiganture() because it was doing exactly the wrong
  thing for existentials.

- Fix ConcreteExistentialInfo to produce the correct SubstitutionMap.

- Fix ExistentialSpecializer to generate the correct conformances for
  init_existential by adding a collectExistentialConformances() helper.

Fixes <rdar://problem/57025861> "Assertion failed: (conformances.size() == numConformanceRequirements)" in ExistentialSpecializer on inlined code
2019-11-22 01:56:20 -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
3034aaf182 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 14:00:00 -08:00
Slava Pestov
291364b2f1 Merge pull request #28037 from zoecarver/semantics-def
Semantics attribute definition file
2019-11-20 16:42:29 -05:00
zoecarver
12883d07d9 Merge branch 'master' into semantics-def 2019-11-19 13:02:47 -08:00
swift_jenkins
8d8be15df0 Merge remote-tracking branch 'origin/master' into master-next 2019-11-16 14:00:27 -08:00
Robert Widmann
9732f811fd Merge pull request #23070 from gottesmm/pr-593fd7aed5142c9e2b0b2f18bf47074e65a04005
[cast-opt] Fix obvious bug.
2019-11-16 13:53:44 -08: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
8aaa7b4dc1 SILOptimizer: Pipe through TypeExpansionContext 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
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
zoecarver
febbb702e4 Merge branch 'master' into fix/substitution-map-composition 2019-11-05 11:12:15 -08:00
zoecarver
6c48a8d35f Ensure that only correct patterns are optimized 2019-11-04 20:01:27 -08:00
zoecarver
f1c15d26f3 Fix tests 2019-11-04 13:06:38 -08:00
zoecarver
f1c75f6d62 Remove assertion all together and use getAddressOfStackInit instead of dyn_cast to StoreInst 2019-11-04 11:01:39 -08:00
zoecarver
f3ac3bd08b Cleanup and fix spacing (again) 2019-11-03 13:03:05 -08:00
zoecarver
bfb3dd72d7 Clean up implementation and remove debug 2019-11-03 12:50:26 -08:00
zoecarver
d9b95a026f Implement devirtualization calls to composition type protocols 2019-11-03 11:56:11 -08:00
zoecarver
2ca448b23d Address review comments
* add namespace
* fix block comment style
* SEMA_ATTR -> SEMANTICS_ATTR
* error when SEMANTICS_ATTR isn't defined
2019-11-02 21:58:26 -07:00
swift-ci
12921530ac Merge remote-tracking branch 'origin/master' into master-next 2019-11-02 19:30:15 -07:00
Michael Gottesman
719ee25693 [constant-folding] When simplifying destructures, do not handle cases where we have a non-trivial value with .none ownership.
In certain cases, in OSSA, non-trivial values with .none ownership can be merged
into .owned aggregates such that when we extract the value back out from the
aggregate we lost the information that the original value was not .owned. As an
example of this consider the following SIL:

bb0(%0 : @owned Builtin.NativeObject):
  %1 = enum $Optional<Builtin.NativeObject>, #Optional.none!enumelt
  %2 = tuple(%0 : $Builtin.NativeObject, %1 : $Optional<Builtin.NativeObject>)
  (%3, %4) = destructure_tuple %2 : $(Builtin.NativeObject, Optional<Builtin.NativeObject>)

In this case, %4 has .owned ownership, while %1 has .none ownership. This is
because we have lost the refined information that we originally had a .none
value as input to the tuple we are destructuring. Due to this when we RAUW, we
would need to insert a destroy on %4 to make sure that we maintain ossa
invariants. This is safe since the destroy_value will be on a dynamically .none
value, which is a no-op.

That being said, the intention here was actually not to implement this pattern
in the code (as can be seen by not handling @owned destructures). Thus this
commit just makes the constant folding code more conservative to ensure that we
do not try to handle this case.
2019-11-02 14:34:30 -07:00
zoecarver
9c1a614efb Fix based on review comments 2019-11-02 13:07:20 -07:00
zoecarver
d4129d8659 Add def file for semantics attributes and use constants instead of cstring literals 2019-11-02 11:36:13 -07: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