Commit Graph

207 Commits

Author SHA1 Message Date
Doug Gregor
4ee4124228 Reduce end condition for type checker performance test.
This test is technically scaling linearly in the metrics being
checked, but it was still taking 5+ minutes to type check. Reduce the
upper bound so it finishes in a reasonable amount of time.
2019-03-06 10:14:21 -08:00
Doug Gregor
098470ddb7 Update tests for the removal of the strange "Any" preference rule 2019-03-06 08:58:56 -08:00
Doug Gregor
daf4610be1 [Constraint solver] Don't remove/reintroduce disjunction when favoring.
When favoring particular constraints in a disjunction, don't remove
the old disjunction and create a new one---it's just churn in the
constraint system. Instead, favor the constraints that need it.

This technically flips the SR-139 test case from "too complex" to
being fast enough, but it's still fairly slow.
2019-03-04 20:31:06 -08:00
Doug Gregor
a6902cc5a7 Add a "slow" type checker performance test for rdar://problem/46713933 2019-03-02 10:46:41 -08:00
Doug Gregor
6d8cdaf64c The test case from rdar://problem/20818064 is now scaling well. 2019-03-02 10:11:33 -08:00
David Zarzycki
51ef3c014a [Sema] NFC: fix assert-only crasher with overloaded generics 2019-02-18 08:49:42 -05:00
Pavel Yaskevich
43c547b0b8 [TypeChecker] Disable perf test-case for rdar://problem/21398466
Looks like obsoleted initializer has been removed,
and there are no solutions available for 'init(truncatingBitPattern:)'
which leads to performance regression with designated types enabled.

Resolves: rdar://problem/48061151
2019-02-13 21:07:42 -08:00
Pavel Yaskevich
0b29d9d4e6 [ConstraintSystem] Decouple designated types feature from Swift version
`selectApplyDisjunction` only makes sense in conjunction with
designated types feature because it's going to prioritize disjunctions
with arguments which are known to conform to literal protocols.

Prioritization like that is harmful without designated types feature
because it doesn't always lead to better constraint system splits,
and could prioritize bigger disjunctions which harms chances to
short-circuit solving.

Resolves: rdar://problem/47492691
2019-01-31 11:48:35 -08:00
Jordan Rose
37c30b1710 Merge pull request #21999 from jrose-apple/from-exponential-expletives-to-quadratic-quality
Cut down on exponential growth in checking switch exhaustivity.
2019-01-22 11:49:51 -08:00
Pavel Yaskevich
33cff97ab2 [Sema] Fix resolveDependentMemberType to properly handle nested types found in enum/struct/class
Currently if member has been found through same-type constraint
it would only be properly handled when it comes from a class type,
because that's the only time when base type gets replaced with
"concrete" type from equivalence class, but nested types could also
come from structs, enums and sometimes protocols (e.g. typealias)
which `resolveDependentMemberType` has to handle.

Resolves: rdar://problem/47334176
2019-01-20 01:59:40 -08:00
Jordan Rose
671944df0c Cut down on exponential growth in checking switch exhaustivity.
The problem Assume 'A' and 'B' are enums with cases .a1, .a2, etc. and
.b1, .b2, etc. If we try to typecheck this switch:

    switch (a, b) {
    case (.a1, .b1),
         (.a1, .b2):
      break
    ...

The compiler is going to try to perform the following series of
operations:

    > var s = (A, B)
    > s -= (.a1, .b1)
    ((A - .a1, B) | (A, B - .b1))
    > s -= (.a1, .b2)
    (((A - .a1, B) | (A - .a1, B - .b2)) |
     ((A - .a1, B - .b1) | (A, B - .b1 - .b2)))
    ...

As you can see, the disjunction representing the uncovered space is
growing exponentially. Eventually some of these will start
disappearing (for instance, if B only has .b1 and .b2, that last term
can go away), and if the switch is exhaustive they can /all/ start
disappearing. But several of them are also redundant: the second and
third cases are fully covered by the first.

I exaggerated a little: the compiler is already smart enough to know
that the second case is redundant with the first, because it already
knows that (.a1, .b2) isn't a subset of (A - .a1, B). However, the
third and fourth cases are generated separately from the first two,
and so nothing ever checks that the third case is also redundant.

This patch changes the logic for subtracting from a disjunction so
that

1. any resulting disjunctions are flattened, and
2. any later terms that are subspaces of earlier terms are dropped

This is a quadratic algorithm in the worst case (compare every space
against every earlier space), but because it saves us from exponential
growth (or at least brings down the exponent) it's worth it. For the
test case now committed in the repository, we went from 40 seconds
(using -switch-checking-invocation-threshold=20000000 to avoid cutting
off early) to 0.2 seconds.

I'll admit I was only timing this one input, and it's possible that
other complex switches will not see the same benefit, or may even see
a slowdown. But I do think this kind of switch is common in both
hand-written and auto-generated code, and therefore this is likely to
be a benefit in many places.

rdar://problem/47365349
2019-01-18 18:36:58 -08:00
Pavel Yaskevich
e26fc1efff [ConstraintSystem] Skip literal protocols without default types from minimalization
After collecting possible conformances and types for each argument,
`ArgumentInfoCollector` attempts literal protocol minimalization
to reduce the set of possible types argument could assume. Let's
exclude literal protocols without default types like
`ExpressibleByNilLiteral` from consideration by that algorithm.

Resolves: rdar://problem/47266563
2019-01-16 00:35:17 -08:00
Pavel Yaskevich
69c622fc06 Merge pull request #21783 from xedin/rdar-30933988
[AST] `Decl::is*AccessibleFrom` methods should respect access control…
2019-01-14 14:06:44 -08:00
Pavel Yaskevich
5426e0df9e [AST] Decl::is*AccessibleFrom methods should respect access control flag
Otherwise integrated REPL and other tools like LLDB would produce
incorrect results or crash.

Resolves: rdar://problem/30933988
2019-01-11 17:30:10 -08:00
Pavel Yaskevich
1f5462b310 [TypeChecker] NFC: Add a test-case for rdar://problem/46939892 2019-01-11 17:11:02 -08:00
Pavel Yaskevich
a7f4ee3964 [TypeChecker] NFC: Disable test-case rdar://26564101 to investigate whether it's fast or slow
Resolves: rdar://problem/46850561
2018-12-19 14:00:52 -08:00
Michael Gottesman
82de2b9468 Merge pull request #21401 from gottesmm/ossa_flag
[ownership] Use the SILFunction attribute [ossa] instead of the global flag -assume-parsing-unqualified-ownership-sil
2018-12-18 07:31:34 -08:00
Pavel Yaskevich
4cf741e9fb Merge pull request #21386 from xedin/mark-26564101-as-fast
[TypeChecker] Mark test-case for rdar://26564101 as fast
2018-12-18 01:00:21 -08:00
Michael Gottesman
40a09c9c21 Fixup tests for -assume-parsing-unqualified-ownership-sil => [ossa] transition. 2018-12-18 00:49:32 -08:00
Pavel Yaskevich
355390412e [TypeChecker] Mark test-case for rdar://26564101 as fast
Resolves: rdar://problem/46785202
2018-12-17 14:50:27 -08:00
Doug Gregor
e21a96f4ab [SIMD] Update tests to reflect the SIMD operators in the standard library
Introducing the SIMD operators back into the standard library regresses
one test (SR-139 goes exponential against without the designated types
for operatores feature). Split that part of the test out.
2018-12-17 11:43:45 -08:00
Doug Gregor
69c9fbc3c8 Move SIMD operators back into the Swift standard library
Moving them out to SIMDOperators didn't help, but the type checker hack
might. Move them back into the Swift standard library where they belong,
but leave SIMDOperators there to smooth over any short-term
incompatibilities.
2018-12-17 11:07:32 -08:00
Slava Pestov
f06fae36d9 Sema: Change a performance test case to not build a one-element tuple 2018-12-15 00:07:04 -05:00
Mark Lacey
10ef7347a7 [ConstraintSystem] Better handling of operators with multiple designated types.
For operators with multiple designated types, we attempt to decide the
best order for exploring the types. We were doing this by checking
for matching types. Extend this to also consider conforming types.

Fixes: rdar://problem/46687985
2018-12-14 13:24:23 -08:00
Doug Gregor
88d34a1c7c [Constraint solver] De-priority SIMD operators.
The new SIMD proposal introduced a number of new operators, the presence of
which causes more "expression too complex" failures. Route around the
problem by de-prioritizing those operators, visiting them only if no
other operator could be chosen. This should limit the type checker
performance cost of said operators to only those expressions that need
them OR that already failed to type-check.

Fixes rdar://problem/46541800.
2018-12-11 16:34:37 -08:00
Michael Gottesman
0af0d5fddc [ownership] Replace ValueOwnershipKind::Trivial with ValueOwnershipKind::Any.
In a previous commit, I banned in the verifier any SILValue from producing
ValueOwnershipKind::Any in preparation for this.

This change arises out of discussions in between John, Andy, and I around
ValueOwnershipKind::Trivial. The specific realization was that this ownership
kind was an unnecessary conflation of the a type system idea (triviality) with
an ownership idea (@any, an ownership kind that is compatible with any other
ownership kind at value merge points and can only create). This caused the
ownership model to have to contort to handle the non-payloaded or trivial cases
of non-trivial enums. This is unnecessary if we just eliminate the any case and
in the verifier separately verify that trivial => @any (notice that we do not
verify that @any => trivial).

NOTE: This is technically an NFC intended change since I am just replacing
Trivial with Any. That is why if you look at the tests you will see that I
actually did not need to update anything except removing some @trivial ownership
since @any ownership is represented without writing @any in the parsed sil.

rdar://46294760
2018-12-04 23:01:43 -08:00
Mark Lacey
b41b1c04e3 Add a scale test for SIMD addition. 2018-12-03 20:26:32 -08:00
Mark Lacey
df595379ce Move a few more type checker perf tests over to compiling with designated types. 2018-11-17 18:19:44 -08:00
Mark Lacey
a1be08230f [ConstraintSystem] Enable disjunction ordering change when use of designated types are enabled.
We try to work more-or-less bottom up in the expression when we
attempt apply disjunctions first. This is very helpful to get good
results with designated types enabled in the solver. Rather than
forcing tests to specify both `-swift-version 5` (which also enables
this bottom-up behavior) and enabling designated types, allow them to
just enable the later to get the behavior.

We'll eventually have to revisit this when we decide the specific
conditions that we'll enable the use of designated types under.
2018-11-16 22:01:04 -08:00
Mark Lacey
d7cf830842 [ConstraintSystem] Add Array as a designated type for + and +=.
Also add overloads for these operators to an extension of Array.

This allows us to typecheck array concatenation quickly with
designated type support enabled and the remaining type checker hacks
disabled.
2018-11-15 21:42:33 -08:00
Mark Lacey
347b060322 [ConstraintSystem] When we have multiple conversions/fixes, make equality favored.
This allows us to skip attempting actual conversions.

This speeds up one of our slow test cases, and perturbs the output of
another test. In the latter case, we stop emitting conversions as part
of the non-semantic piece of the array_expr. The fact that we're not
putting conversions in on that path is something I've seen before in
other instances. I'll open a bug if I cannot find one for it, although
I believe it's entirely cosmetic in this case since we don't rely on
the conversion being there.
2018-11-15 18:41:53 -08:00
Mark Lacey
540968aa12 Add another type checker test for which we're already quite fast. 2018-11-13 22:18:04 -08:00
Mark Lacey
958ee1a82b Add more type checker performance tests.
Also move one from fast to slow based on the fact that it wasn't
representative of the original issue (which was an expression that
didn't typecheck successfully).
2018-10-25 16:21:17 -07:00
Pavel Yaskevich
70d9b2dfa3 [CSDiagnostics] Fix requirement source lookup to support initializers
Resolves: rdar://problem/45470505
2018-10-22 18:32:32 -07:00
Mark Lacey
5b4a332b0e [ConstraintSystem] Sort the designated types based on actual argument types.
In cases where we have multiple designated types, sort the types that
were designated for this operator based on any information we can
gather about actual argument types at usage sites.

We can consider extending this further in a future commit to ignore
designated types when we have concrete type information that we are
confident of.
2018-10-21 13:14:27 -07:00
Mark Lacey
9a703f584d Update a few more tests to enable -solver-enable-operator-designated-types when possible.
Add the following to all the expression type checker performance tests
that do not regress as a result:

- `-swift-version 5`
- `-solver-disable-shrink`
- `-disable-constraint-solver-performance-hacks`
- `-solver-enable-operator-designated-types`

This is a follow-up to 6de03f709f, where
these should have been included.
2018-10-21 11:47:18 -07:00
Mark Lacey
6de03f709f Update tests to enable -solver-enable-operator-designated-types when possible.
Add the following to all the expression type checker performance tests
that do not regress as a result:

- `-swift-version 5`
- `-solver-disable-shrink`
- `-disable-constraint-solver-performance-hacks`
- `-solver-enable-operator-designated-types`
2018-10-21 10:50:33 -07:00
Mark Lacey
f2f771d2d5 Fix type checker performance test to compile successfully.
At some point this test case was updated such that it no longer
compiled successfully. The originally reported test case did compile
successfully, just slowly.
2018-10-19 10:49:02 -07:00
Mark Lacey
72ba110e5b [ConstraintSystem] Rework new constraint stat as a FRONTEND_STATISTIC.
In the process, remove the old incrementScopeCounter SWIFT_FUNC_STAT.
2018-10-18 07:18:02 -07:00
Mark Lacey
cc0386b461 [ConstraintSystem] Add a new stat to be used for expression type checker performance testing.
This counts the number of leaf scopes we reach while solving the
constraint sytem, and is a much better measure of the growth of
unnecessary work than the total number of scopes opened.

There were two tests where I had a difficult time getting scale-test
to fit the curve even after adjusting some of the parameters, so I've
left those to use the old stat for now.
2018-10-17 07:26:18 -07:00
Mark Lacey
3d6c93f3bd Merge pull request #19909 from rudkx/extend-operator-designated-type
[ConstraintSystem] Extend solver support for designated types for ope…
2018-10-16 10:42:17 -07:00
Mark Lacey
b158651119 [ConstraintSystem] Extend solver support for designated types for operators.
Have the constraint solver consider multiple designated types for an
operator. We currently consider the overloads from each in turn,
stopping as soon as we have a solution. As a result, we can still end
up with exponential type checking in some cases if an operator has
more than a single designated type. This still allows us to reduce the
base of that exponent, though, which makes it possible to increase the
number of expressions we can type check successfully in practice.
2018-10-15 23:51:43 -07:00
Pavel Yaskevich
59899a7911 [ConstraintSystem] Make sure that system is returned into its original state after solving
Currently (with or w/o failures) constraint system is not returned
back to its original state after solving, because constraints from
initial "active" list are not returned to the system. To fix that
let's allocate "initial" scope which captures state right before
solving begins, and add "active" list to the solver state to capture
information about "active" constraints at the time of its creation.

This is follow-up to https://github.com/apple/swift/pull/19873
2018-10-15 16:33:57 -07:00
Greg Parker
9043bf87df [test] Fix a solver flag rename that was missed in #19756. 2018-10-09 18:07:46 -07:00
Mark Lacey
36284ba377 Extend operator decls to allow any designated nominal type for lookup.
Rather than limiting this to protocols, allow any nominal type.

Rename -enable-operator-designated-protocols to
-enable-operator-designated-types to reflect the change.
2018-10-06 17:02:31 -07:00
Mark Lacey
5d6785bec5 Move another typechecker performance test to run with -solver-enable-operator-designated-protocols. 2018-10-04 20:10:13 -07:00
Mark Lacey
e17898c70a Revert a type checker perf test that apparently is still not consistently fast enough. 2018-10-04 15:48:22 -07:00
Mark Lacey
1f517d328d [ConstraintSystem] Distinguish between overloads from a type vs. an extension.
For operators with default implementations in an extension, we don't
want to typecheck it both with overloads from the protocol type and
the ones from the extension.
2018-10-03 18:51:43 -07:00
Mark Lacey
48c6cb40cf Fix release-build test failure due to unaccounted-for warning. 2018-10-03 16:53:04 -07:00
Mark Lacey
472d333a1b Test updates for -solver-enable-operator-designated-protocols.
These are cases that I know are faster when this is enabled. The test
updates all additionally disable the existing performance hacks as
well as the shrink phase of the solver.
2018-10-03 16:01:59 -07:00