Commit Graph

347 Commits

Author SHA1 Message Date
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Slava Pestov
561e63552f Pass -requirement-machine-protocol-signatures=off in three tests 2022-02-24 15:09:53 -05:00
Slava Pestov
54bf6adb58 Revert "Sema: Don't resolve protocol typealiases to DependentMemberTypes"
This reverts commit 1dd79ae3db.

Fixes rdar://problem/88230388.
2022-02-23 23:11:05 -05:00
Anthony Latsis
b0043966cd Merge pull request #40269 from AnthonyLatsis/assoc-inference-system
AssociatedTypeInference: Initial refactoring of abstract type witness inference
2022-02-20 15:51:58 +03:00
Anthony Latsis
2ebb123421 AssociatedTypeInference: Properly substitute into tentative type witnesses in inferAbstractTypeWitnesses()
A regular type.subst() is not enough, because tentative type witnesses may contain type parameters,
and we have to substitute them as well, recursively, e.g A := G<B>, B := G<C>, C := Never. Avoiding
subst() here also eliminates a use case of the getSubstOptionsWithCurrentTypeWitnesses() hack.
2022-02-16 00:56:09 +03:00
Anthony Latsis
789f90d7f6 TypeWitnessSystem: Handle ambiguities
Since we collect same-type constraints by scanning requirement signatures,
the type witness system must be prerared to face conflicting solutions
for a particular type witness
2022-02-16 00:56:09 +03:00
Anthony Latsis
4c68ecfdf5 TypeWitnessSystem: Add tests 2022-02-16 00:56:08 +03:00
Slava Pestov
4655fc359b Sema: Make a couple of TypeResolver methods idempotent
When emitting a diagnostic, mark the TypeRepr as invalid and
return an ErrorType to ensure that the diagnostic is not
emitted again, and to muffle downstream diagnostics.
2022-02-15 04:02:46 -05:00
Slava Pestov
5fa5ff7ce1 RequirementMachine: Update tests for protocol typealiases 2022-02-13 09:50:16 -05:00
Slava Pestov
6c714f4087 Sema: Try to avoid calling getGenericSignature() when performing structural resolution 2022-02-11 08:15:50 -05:00
Slava Pestov
f33eb17b75 GSB: Remove unsound cycle-breaking hack 2022-01-25 21:28:52 -05:00
Anthony Latsis
0eb7eaa43b Sema: Tighten up SwiftUI conformance hack and add a warning 2022-01-25 11:36:18 +03:00
Slava Pestov
1dd79ae3db Sema: Don't resolve protocol typealiases to DependentMemberTypes 2021-12-14 19:45:34 -05:00
Anthony Latsis
3282b86d76 AssociatedTypeInference: Fix regression introduced in 1cf9622 2021-11-09 18:32:27 +03:00
Holly Borla
ba2187aea8 [Diagnostics] Add the opaque type fix-it for failed associated type
inference from the element type of a subscript value witness.
2021-10-27 10:54:35 -07:00
Holly Borla
c75178e56f [Diagnostics] Add a fix-it to insert 'some' when associated type inference
failed because existential types can't conform to protocols.
2021-10-26 22:29:09 -07:00
Slava Pestov
4a019f0662 Sema: Improved recovery from circular generic signature construction
Returning a null GenericSignature is not the right way to break a cycle,
because then callers have to be careful to handle the case of a null
GenericSignature together with a non-null GenericParamList, for example
in applyGenericArguments().

An even worse problem can occur when a GenericSignatureRequest for a
nested generic declaration requests the signature of the parent context,
which hits a cycle. In this case, we would build a signature where
the first generic parameter did not have depth 0.

This makes the requirement machine upset, so this patch implements a new
strategy to break such cycles. Instead of returning a null
GenericSignature, we build a signature with the correct generic
parameters, but no requirements. The generic parameters can be computed
just by traversing GenericParamLists, which does not trigger more
GenericSignatureRequests, so this should be safe.
2021-09-04 00:13:03 -04:00
Slava Pestov
5790c70fb6 Sema: Add recursion guard to AssociatedTypeInference::computeFixedTypeWitness() 2021-09-02 23:02:52 -04:00
Anthony Latsis
c2e5d04669 Test: Find better locations for some updated tests 2021-08-31 19:21:26 +03:00
Suyash Srijan
396087d0d4 [Test] Update existing tests 2021-08-31 19:21:26 +03:00
Kavon Farvardin
c0607b345f Revert "Merge pull request #33767 from theblixguy/chore/remove-self-or-associated-type-diagnostic"
The following regression test added for this feature is not passing:

Swift(linux-x86_64) :: decl/protocol/protocols_with_self_or_assoc_reqs_executable.swift

with a compiler crash happening during SILFunctionTransform "Devirtualizer".

Reverting to unblock CI.

This reverts commit f96057e260, reversing
changes made to 3fc18f3603.
2021-08-26 16:46:42 -07:00
Anthony Latsis
749a0ae853 Test: Find better locations for some updated tests 2021-08-16 18:30:26 +03:00
Suyash Srijan
7834120a87 [Test] Update existing tests 2021-08-16 18:30:26 +03:00
Rajagopalan-Gangadharan
585350d405 Add example code as test 2021-07-29 00:11:04 +05:30
Slava Pestov
68957078c5 GSB: Set HadAnyError in two more places
If we don't set this flag, we can end up making an invalid GSB into
the canonical builder for some signature. This was caught by
requirement machine cross-checking on the compiler_crashers suite.
2021-07-12 23:52:49 -04:00
Slava Pestov
2481503298 Sema: Clean up associated type inference using getSelfBoundsFromWhereClause()
Fixes https://bugs.swift.org/browse/SR-14639 / rdar://problem/78276768.
2021-05-25 15:47:28 -04:00
Anthony Latsis
3d317938ad AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
* Swift.Array preserves variance in its 'Element' type
* Swift.Dictionary preserves variance in its 'Value' type
2021-02-11 03:22:20 +03:00
Slava Pestov
b18c7fb22b Sema: Allow re-declarations of typealiases in constrained extensions with different generic signatures
Associated type inference will synthesize typealiases in
constrained extensions for conditional conformances, but
then we might later flag them as re-declarations.

Let's not do this, since name lookup does check if generic
requirements are satisfied, so such redeclarations are not
in fact erroneous.

Fixes <rdar://problem/68933045>.
2021-01-13 21:59:27 -05:00
Anthony Latsis
8f43d888b8 Sema: Disallow usage of settable Self-returning storage requirements on existential base 2020-10-07 20:48:16 +03:00
Anthony Latsis
103a821838 Sema: Allow non-final classes to satisfy properties and subscripts with covariant Self 2020-09-20 22:33:44 +03:00
Anthony Latsis
8cae50aab4 AssociatedTypeInference: Generalize computeFixedTypeWitness to consider type parameters
While we're here, remove the return on a null generic signature. The request for
the generic signature of a protocol is a trivial computation that is never expected
to fail
2020-09-11 01:02:22 +03:00
Slava Pestov
e05a7326f3 Sema: Fix crash-on-invalid on protocol requirements with 'where' clause constraints
RequirementEnvironment wasn't prepared to handle a protocol
requirement with additional 'where' clause constraints but
no generic parameters.

Since such a requirement necessarily runs afoul of the existing
"protocol requirements cannot constrain Self" rule, it suffices
to ignore such requirements when matching witnesses and let
the declaration checker diagnose this situation later.

Fixes <rdar://problem/61876053>.
2020-08-18 17:38:31 -04:00
Slava Pestov
6d84c18ba4 Sema: Check 'where' clause requirements on type witnesses
In the included test case, conformance checking of Wrapper : B would
pick up typealias Foo as a witness for the associated type B.Foo.

However, this typealias Foo is defined in a constrained extension where
T : A, and the underlying type references the associated type A.Foo
on T.

The resulting substitution is invalid when the conformance Wrapper : B
is used in a context where T does not conform to A.

Instead, we should ignore this typealias entirely, since it appears
in an unusable constrained extension.

Fixes <rdar://problem/60219705>, <https://bugs.swift.org/browse/SR-12327>,
<https://bugs.swift.org/browse/SR-12663>.
2020-08-15 01:43:13 -04:00
Anthony Latsis
b37491ad62 AssociatedTypeInference: Stop skipping the current protocol when looking for a fixed type witness 2020-08-10 01:52:07 +03:00
Anthony Latsis
28531141d2 AssociatedTypeInference: Self is a valid fixed type witness 2020-07-15 22:34:24 +03:00
Anthony Latsis
54ccdc67e7 AssociatedTypeInference: Delay substitutions into abstract type witnesses until after they have been computed 2020-07-12 02:55:22 +03:00
Suyash Srijan
be79d341e6 [AssociatedTypeInference] Strip 'self' parameter from function type of an enum case witness 2020-07-08 14:37:48 +01:00
Slava Pestov
8305d51365 Sema: Relax associated type default circularity check
We should allow an associated type's default to reference the
same associated type with a base other than 'Self'.

Note that it now becomes easier to defeat this check, but it
was never air-tight anyway -- for example, you could have a
cycle of length two if each associated type's default was the
other associated type.

This is fine, because this check is purely 'cosmetic'; nothing
goes really wrong if you have a cycle here, except that the
diagnostic shifts from the declaration of the protocol to the
conforming type.

Fixes <rdar://problem/62355224>.
2020-06-16 22:18:24 -04:00
Pavel Yaskevich
ac8dfcf89b [CSGen] Replace getInterfaceType() -> mapTypeIntoContext() for VarDecl with getType
In `ConstraintGenerator::visitDeclRefExpr` instead of using
`getInterfaceType()` for unknown type and later mapping it into
context, let's use `getType()` which does that interally, that
allows to detect presence of error types in resulting type and
abort constraint generation.
2020-06-11 17:03:28 -07:00
Robert Widmann
d42ac6264f Account for Deserialized VarDecls in Setter Mismatch Diagnostics
If the setter conflict occurs in a deserialized declaration, the parent
pattern binding can be NULL. Guard the fixit on the existence of the
pattern binding so

1) we don't crash
2) we don't try to emit a fixit in otherwise extremely broken code

rdar://56558082
2020-05-21 19:22:09 -07:00
Slava Pestov
0a79beb39c Merge pull request #31871 from slavapestov/superclass-nested-type-fix
GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
2020-05-20 09:16:53 -04:00
Slava Pestov
653fa07260 GSB: Fix maybeResolveEquivalenceClass() with member type of superclass-constrained type
Name lookup might find an associated type whose protocol is not in our
conforms-to list, if we have a superclass constraint and the superclass
conforms to the associated type's protocol.

We used to return an unresolved type in this case, which would result in
the constraint getting delayed forever and dropped.

While playing wack-a-mole with regressing crashers, I had to do some
refactoring to get all the tests to pass. Unfortuanately these refactorings
don't lend themselves well to being peeled off into their own commits:

- maybeAddSameTypeRequirementForNestedType() was almost identical to
  concretizeNestedTypeFromConcreteParent(), except for superclasses
  instead of concrete same-type constraints. I merged them together.

- We used to drop same-type constraints where the subject type was an
  ErrorType, because maybeResolveEquivalenceClass() would return an
  unresolved type in this case.

  This violated some invariants around nested types of ArchetypeTypes,
  because now it was possible for a nested type of a concrete type to
  be non-concrete, if the type witness in the conformance was missing
  due to an error.

  Fix this by removing the ErrorType hack, and adjusting a couple of
  other places to handle ErrorTypes in order to avoid regressing with
  invalid code.

Fixes <rdar://problem/45216921>, <https://bugs.swift.org/browse/SR-8945>,
<https://bugs.swift.org/browse/SR-12744>.
2020-05-19 20:28:51 -04:00
Greg Titus
6216242c9c If the missing generic requirement includes type variables, don't emit an unhelpful note for it.
Fixes SR-12759
2020-05-18 13:40:29 -07:00
Anthony Latsis
2643a7d8cd Sema: Apply substitutions when checking type witnesses against associatedtype superclass bounds 2020-05-15 02:16:32 +03:00
Slava Pestov
c3d93d28c5 Merge pull request #30712 from AnthonyLatsis/constrained-inference
AssociatedTypeInference: Allow inference in compatible constrained extensions
2020-05-13 23:32:46 -04:00
Robert Widmann
5dc060ee57 Define ResolveTypeRequest 2020-04-30 16:10:25 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Anthony Latsis
f5cf8cd2d5 AssociatedTypeInference: Allow inference in compatible constrained extensions 2020-04-23 07:15:27 +03:00
Suyash Srijan
f724d1ff85 [SE-0280] Enum cases as protocol witnesses (#28916)
* [Typechecker] Allow enum cases without payload to witness a static get-only property with Self type protocol requirement

* [SIL] Add support for payload cases as well

* [SILGen] Clean up comment

* [Typechecker] Re-enable some previously disabled witness matching code

Also properly handle the matching in some cases

* [Test] Update typechecker tests with payload enum test cases

* [Test] Update SILGen test

* [SIL] Add two FIXME's to address soon

* [SIL] Emit the enum case constructor unconditionally when an enum case is used as a witness

Also, tweak SILDeclRef::getLinkage to update the 'limit' to 'OnDemand' if we have an enum declaration

* [SILGen] Properly handle a enum witness in addMethodImplementation

Also remove a FIXME and code added to workaround the original bug

* [TBDGen] Handle enum case witness

* [Typechecker] Fix conflicts

* [Test] Fix tests

* [AST] Fix indentation in diagnostics def file
2020-03-28 10:44:01 +00:00
Suyash Srijan
543d649278 [Diagnostics] Warn when the result of a Void-returning function is ignored (by assigning into '_') (#29576) 2020-02-04 20:19:37 +00:00