Commit Graph

7628 Commits

Author SHA1 Message Date
Doug Gregor
3387b65117 Try harder to fix executable tests on Linux 2021-04-07 21:15:07 -07:00
Pavel Yaskevich
c509c030ea [CSSimplify] Transfer conformance requirements of a parameter to an argument
Performance optimization to help rule out generic overload choices sooner.

This is based on an observation of the constraint solver behavior,
consider following example:

```swift
func test<U: ExpressibleByStringLiteral>(_: U) {}

test(42)
```

Constraint System for call to `test` is going to look like this:

```
$T_test := ($T_U) -> $T_U
$T_U <conforms to> ExpressibleByStringLiteral
$T_42 <argument conversion> $T_U
$T_42 <literal conforms to> ExpressibleByIntegerLiteral
```

Currently to find out that `test` doesn't match, solver would have
to first find a binding for `$T_42`, then find a binding for `$T_U`
(through `<argument conversion>` constraint) and only later fail
while checking conformance of `Int` to `ExpressibleByStringLiteral`.

Instead of waiting for parameter to be bound, let's transfer conformance
requirements through a conversion constraint directly to an argument type,
since it has to conform to the same set of protocols as parameter to
be convertible (restrictions apply i.e. protocol composition types).

With that change it's possible to verify conformances early and reject
`test<U: ExpressibleByStringLiteral>` overload as soon as type of an
argument has been determined. This especially powerful for chained calls
because solver would only have to check as deep as first invald argument
binding.
2021-04-07 17:55:11 -07:00
Doug Gregor
74902c1dcc Mark several tests that now require libdispatch 2021-04-06 21:14:34 -07:00
Pavel Yaskevich
c82729bad9 [TypeChecker] NFC: Disable a couple of perf tests on Linux (they fail on community CI) 2021-04-06 21:07:56 -07:00
Nathan Hawes
927c709a50 Merge pull request #36738 from nathawes/fix-completion-crash
[CodeCompletion][Parse] Don't drop the contained expression when completing within an InOutExpr
2021-04-06 15:54:44 +10:00
Alexis Laferrière
ed16e1bd1c Merge pull request #36666 from xymus/nullable-memcmp
[SwiftShims] Make the void* arguments of memcmp nullable on Apple targets
2021-04-05 13:55:56 -07:00
Pavel Yaskevich
1d8c2a10c6 Merge pull request #36545 from xedin/rdar-75476311
[ConstraintSystem] Bind external closure parameter type to a concrete…
2021-04-05 10:04:42 -07:00
Eric Miotto
d350a0525e [build] Clean llbuild before building by default (#36686)
Introduce a new parameter `--skip-llbuild-clean` to prevent this from
happening.

This mimicks similar logic in place for `swiftpm`, `swift-driver`
(#33563)  and `xctest` (#19512)

Addresses rdar://75057069
2021-04-05 07:19:40 -07:00
Robert Widmann
2e9fb5a057 Merge pull request #36723 from CodaFi/extension-cord
Add a Null Check for Missing Generic Signatures
2021-04-04 23:14:38 -07:00
Slava Pestov
bcee54b936 GSB: The combination of a superclass and conformance requirement might force a type to be concrete
A protocol can constrain an associated type to Self:

    protocol P {
      associatedtype A : Q where A.B == Self
    }

    protocol Q {
      associatedtype B
    }

And a class might conform to this protocol:

    class C : P {
      typealias A = D
    }

    class D : Q {
      typealias B = C
    }

The generic signature <Self where Self : P, Self : C> is built during
conformance checking. Since Self : C, we must have that Self.A == D;
since D.B == C, the requierement 'A.B == Self' in protocol P implies
that 'Self == C'. So the correct minimized signature here is
<Self where Self == C>.

This wasn't handled properly before, because of assumptions in
removeSelfDerived() and a couple of other places.

Fixes rdar://71677712, rdar://76155506, https://bugs.swift.org/browse/SR-10033,
https://bugs.swift.org/browse/SR-13884.
2021-04-03 23:04:39 -04:00
Pavel Yaskevich
225e2dbeed [ConstraintSystem] Bind external closure parameter type to a concrete contextual type
Performance optimization.

If there is a concrete contextual type we could use, let's bind
it to the external type right away because internal type has to
be equal to that type anyway (through `BindParam` on external type
i.e. <internal> bind param <external> conv <concrete contextual>).

```swift
func test(_: ([String]) -> Void) {}

test { $0 == ["a", "b"] }
```

Without this optimization for almost all overloads of `==`
expect for one on `Equatable` and one on `Array` solver would
have to repeatedly try the same `[String]` type for `$0` and
fail, which does nothing expect hurts performance.

Resolves: rdar://19836070
Resolves: rdar://19357292
Resolves: rdar://75476311
2021-04-02 22:11:03 -07:00
Nathan Hawes
b8f5bf3434 [CodeCompletion][Parse] Don't drop the contained expression when completing within an InOutExpr
When completing within an InOutExpr like `&foo.<complete>`, we were forming a
CodeCompletionExpr with a base when parsing the content of the InOutExpr and
storing it in CodeCompletionCallbacksImpl::CodeCompleteTokenExpr. When the
result of that parse contained a code completion though, we were dropping the
sub-expression completely and forming an empty code completion result in place
of the inout expression, which resulted in later code inserting a code
completion expression with no base into the AST. The solver based completion
was later asking for the type of the code completion and its base using the
expression stored in CodeCompletionCallbacksImpl::CodeCompleteTokenExpr, but
that never ended up in the AST so we hit an assertion about the expression not
have a type in the formed solutions.

Resolves rdar://75366814
2021-04-03 13:39:23 +10:00
Alexis Laferrière
c6acc94328 [Tests] memcmp-definitions should run only on Apple plaftorms 2021-04-02 15:28:50 -07:00
Slava Pestov
1ab451157c Merge pull request #36697 from slavapestov/unsubstitutable-sil-function-type
AST: Skip requirement checks in IsBindableVisitor::visitBoundGenericType() if substituted type is an interface type
2021-04-02 16:00:23 -04:00
Alexis Laferrière
36f7f1bc87 [SwiftShims] Make the void* arguments of memcmp _Nullable on Darwin
This should correspond to the definition of memcmp in
usr/include/string.h and keep it from being a source of confusion for
the compiler.

rdar://69876253
2021-04-02 10:38:50 -07:00
Robert Widmann
9e496d38f9 Add a Null Check for Missing Generic Signatures
When an extension is nested inside of an invalid decl context, it is
going to pull the signature of its nearest enclosing context instead of
its extended type. This leads to a null signature since the nearest
enclosing context for an extension should always be its parent source
file.

rdar://76049852
2021-04-02 09:43:35 -07:00
Pavel Yaskevich
e26ada5d06 [TypeChecker] NFC: Add an additional test-case for rdar://46713933 with literal arguments 2021-04-01 11:44:31 -07:00
Slava Pestov
f3f2ea6f62 AST: Skip requirement checks in IsBindableVisitor::visitBoundGenericType() if substituted type is an interface type
IsBindableVisitor is part of TypeBase::substituteBindingsTo(), which
is used for two things:

- Checking if one contextual type is a proper substitution of another
  contextual type, used in the solver

- To compute the substituted generic signature when lowering a SIL
  function type

In the first case, we're interested in knowing if the substitution
succeeds or fails. In the second case, we know the substitution is
correct by construction, and we're trying to recover the generic
requirements.

In the second case though, the substituted type might be an
interface type, and if the interface type is constrained to a
concrete type in the original type's generic signature, we would
conclude that the substitution should fail.

This is incorrect, and we should just skip the check if the
substituted type is an interface type -- we do not have enough
information to know if it succeeds, and instead we must assume it
does because otherwise the substituted type passed in to type
lowering must be incorrect.

Fixes https://bugs.swift.org/browse/SR-13849.
2021-04-01 01:02:38 -04:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Erik Eckstein
dccaa8f01f diagnose duplicated @_cdecl and @_silgen_name function names
Prints a regular error instead of crashing.
The check is done in SILGen, because it's simple. We could also do it earlier, but I don't see a strong reason for this.

rdar://75950093
2021-03-31 13:30:22 +02:00
Karoy Lorentey
f7f44763eb [test] Add missing version guards to tests for new stdlib behavior
rdar://75837172
2021-03-30 22:06:55 -07:00
Pavel Yaskevich
d196842092 Merge pull request #36635 from xedin/move-two-tests-to-fast
[TypeChecker] NFC: Adjust scale thresholds and move to test-cases to "fast"
2021-03-30 17:03:57 -07:00
Pavel Yaskevich
d155b5c209 [TypeChecker] NFC: Extend scale and move test-case for rdar://30606089 to "fast"
Resolves: SR-6520
2021-03-29 16:06:05 -07:00
Pavel Yaskevich
ee81665d6b [TypeChecker] NFC: Extend scale and move test-case for rdar://27585838 to "fast" 2021-03-29 16:00:05 -07:00
Slava Pestov
1d9b202719 GSB: Fix inconsistent 'redundant conformance' diagnostic 2021-03-27 00:35:19 -04:00
Alex Hoppen
2c0b8ac479 Merge pull request #36517 from ahoppen/pr/rdar64141399
[CodeComplete] Fix code completion of initialization for variable wrapped by generic property wrapper
2021-03-26 11:24:52 +01:00
Slava Pestov
99d49f0ccb GSB: When rebuilding a signature, use the as-written requirements instead of the minimized ones
We rebuild a signature after dropping redundant conformance requirements,
since conformance requirements change the canonical type and conformance
access path computation.

When doing this, instead of using the canonical requirements from the
signature, use the original as-written requirements.

This fixes some weirdness around concrete same-type requirements.

There's a philosophical benefit here too -- since we rebuild the
signature without ever having built the old signature, we never create
an invalid GenericSignature in the ASTContext.

Fixes rdar://problem/75690903.
2021-03-25 17:35:52 -04:00
Pavel Yaskevich
fe10f31808 Merge pull request #36558 from xedin/rdar-74356736
[CSGen] Fallback to a type variable if preferred type for placeholder…
2021-03-23 23:14:42 -07:00
Pavel Yaskevich
6e628c4874 [CSGen] Fallback to a type variable if preferred type for placeholder is invalid
Type inside of an editor placeholder is more of a hint than anything else,
so if it's incorrect let's diagnose that and use type variable instead to
allow solver to make forward progress.

Resolves: SR-14213
Resolves: rdar://74356736
2021-03-23 18:56:21 -07:00
nate-chandler
64c75828f7 Merge pull request #36529 from nate-chandler/rdar75547146
Sema: Stop checking @main if no decl synthesized.
2021-03-23 08:04:40 -07:00
Alex Hoppen
ef75cf7c77 Merge pull request #36534 from ahoppen/pr/rdar64265821
Add test case for rdar://64265821
2021-03-23 08:29:33 +01:00
Alex Hoppen
efbfbc4200 Merge pull request #36495 from ahoppen/pr/rdar71566576
Add test case for rdar://71566576
2021-03-22 17:32:52 +01:00
Alex Hoppen
86e5e7dbf3 Add test case for rdar://64265821
rdar://64265821 [SR-12985] appears to have been fixed already. Let’s add a test case for it.
2021-03-22 14:02:11 +01:00
Alex Hoppen
3d2fd566cc Merge pull request #36523 from ahoppen/pr/revert-remove-unreachable-code
Revert "Sema: Remove some unreachable code from CSApply"
2021-03-22 13:05:02 +01:00
Nate Chandler
6c5d62c011 Sema: Stop checking @main if no decl synthesized.
When requestifying the synthesis of the main function for the type
annotated @main via SynthesizeMainFunctionRequest, what were previously
were bailouts from AttributeChecker::visitMainTypeAttr had to become
returns of nullptr from SynthesizeMainFunctionRequest::evaluate.
Consequently, AttributeChecker::visitMainTypeAttr must check whether
synthesis actually succeeded before proceeding to to register the main
decl for a file.

In simple cases, this happened to work because
SourceFile::registerMainDecl would return early if the decl being
registered was the same as the already registered main decl and in
particular if the decl being registered was nullptr and the previously
registered one was nullptr as well.  When, however, there are multiple
types annotated @main, if a function is successfully synthesized for one
type but synthesis fails for the second, an attempt will be made to
register nullptr as the main decl and will move past the check at the
beginning of SourceFile::registerMainDecl, resulting in a crash.

Here, we bail from AttributeChecker::visitMainTypeAttr if function
synthesis fails and add an assert to SourceFile::registerMainDecl that
the provided decl is non-null.

rdar://75547146
2021-03-19 16:54:16 -07:00
Alex Hoppen
28ee60e893 [CodeComplete] Fix code completion of initialization for variable wrapped by generic property wrapper
If completing the initialization of a variable that’s wrapped in a generic, unbound property wrapper, the expression's type is an `UnboundGenericType`. AFAICT that’s expected and the correct type to assign.

We hit the first assertion failure by trying to retrieve that type's substitution map. `UnboundGenericType`s were not handled here, so we crashed. AFAICT we can't get any substitutions out of an unbound generic type, so we should just continue looking into the parent type.

We hit the second assertion when trying to retrieve the property wrapper’s backing type, which is null (becuase it couldn't be resolved). However, we haven’t emitted a diagnostic because the variable declaration is perfectly valid. Hence I’m removing the assertion.

Fixes rdar://64141399
2021-03-19 20:51:48 +01:00
Alex Hoppen
dc88b4b735 Add test case for rdar://71566576
rdar://71566576 appears to have been fixed already. Still, add a test case for it to ensure we don’t hit it again.
2021-03-19 19:54:20 +01:00
Alex Hoppen
180dd2b2c9 [IDE] Add test cases for compiler crashes fixed by reverting 9d3c8ca 2021-03-19 19:38:52 +01:00
Robert Widmann
ee5f2c3131 Redo getConditionalRequirements as a Request 2021-03-18 23:28:52 -07:00
Slava Pestov
891e053b65 Merge pull request #36454 from slavapestov/rebuild-signature-without-redundant-conformances
GSB: Formalize the old hack where we rebuild a signature that had redundant conformance requirements
2021-03-17 22:38:30 -04:00
Pavel Yaskevich
1dd914a651 Merge pull request #36445 from xedin/rdar-75367157
[Diagnostics] Check whether missing conformance could be fixed by using `.rawValue`
2021-03-17 15:24:33 -07:00
Slava Pestov
504d4f526a Add two passing regression tests and a failing one 2021-03-17 17:25:41 -04:00
Pavel Yaskevich
4b01c8fd11 [ConstraintSystem] Adjust impact of implicit Double <-> CGFloat conversions
- Prefer CGFloat -> Double over the other way around to avoid
  ambiguities;

- Every new conversion impacts the score by factor of number of
  previously applied conversions to make it possible to select
  solutions that require the least such conversions.

- Prefer concrete overloads with Double <-> CGFloat conversion
  over generic ones.
2021-03-17 00:18:14 -07:00
Pavel Yaskevich
5e10f0822e [TypeChecker] NFC: Temporary mark test-case for rdar://46541800 as slow 2021-03-17 00:18:13 -07:00
Andrew Trick
eb15f3376c Temporarily move FixedPoint.swift.gyb into long_test
[SR-14363] FixedPoint.swift.gyb slowed down with -Onone copy propagation
2021-03-16 09:13:13 -07:00
Pavel Yaskevich
2a9903dfe4 [Diagnostics] Check whether missing conformance could be fixed by using .rawValue
A lot of operators (and most likely regular functions a well) have
overloads that accept i.e. a generic parameter that conforms to
`StringProtocol`, so the best fix in situations when argument is
a raw representable type would be to check whether `.rawValue`
conforms to the expected protocol and use it if so.

Resolves rdar://problem/75367157
2021-03-15 16:53:45 -07:00
Ben Rimmington
aac2caf7c6 [stdlib] Speed up the FixedPointConversion tests (#36434) 2021-03-15 11:50:57 -04:00
eeckstein
5acd5e65c4 Merge pull request #36426 from benrimmington/sr-14282
[SR-14282] Compiler crash in DictionaryTrapsObjC.swift
2021-03-14 11:32:54 +01:00
Andrew Trick
8ba6868c35 Fix stdlib/Dictionary tests for copy-propagation.
[NSArray getObjects] does not retain the objects.
2021-03-12 19:33:23 -08:00
Ben Rimmington
cbba5042d8 [SR-14282] Compiler crash in DictionaryTrapsObjC.swift 2021-03-12 19:28:07 +00:00