Commit Graph

1081 Commits

Author SHA1 Message Date
Holly Borla
5eb16ad3de [Conformance] Always downgrade redundant conformances to marker protocols to
a warning.

Previous compiler versions allowed this, so we should stage the change in as
a warning. This was already a warning across modules, so this change only impacts
redundant conformances to marker protocols within a module. This code also isn't
particularly harmful, because marker protocols don't have requirements, so there
isn't the same risk of unexpected behavior as other redundant conformances.
2024-07-23 14:08:14 -07:00
Slava Pestov
557300ba48 Move associated type inference tests into their own directory 2024-06-28 17:50:24 -04:00
Slava Pestov
005d83f8d2 Sema: Fix incorrect use of STL iterator in associated type inference
Fixes rdar://problem/127575477.
2024-06-27 18:21:14 -04:00
Holly Borla
966269d31a [Features] Promote IsolatedAny and its alias to a language feature.
The proposal is accepted and implemented for Swift 6.0.
2024-06-18 22:09:16 -07:00
Holly Borla
005b45c1cc [Sema] Diagnose deprecated default implementations in the witness checker.
If a protocol provides a deprecated default implementation for a requirement
that is not deprecated, the compiler should emit a warning so the programmer
can provide an explicit implementation of the requirement. This is helpful
for staging in new protocol requirements that should be implemented in
conforming types.
2024-06-10 07:10:38 -07:00
Anthony Latsis
44e5286d55 ExistentialTypeSyntaxChecker: Look through any and some 2024-06-04 02:13:08 +03:00
Holly Borla
135e3f2ee9 Merge pull request #73889 from hborla/deprecate-anyactor
[Concurrency] Deprecate `AnyActor`.
2024-05-30 09:36:35 -07:00
Holly Borla
c20b0e0956 [Concurrency] Obsolete AnyActor in Swift 6 using a typealias. 2024-05-29 22:59:19 -07:00
Holly Borla
1011e4ddb0 [Concurrency] Only deprecate AnyActor, and update more tests.
Obsoleting `AnyActor` in Swift 6 blocks the Concurrency library itself
from migrating to Swift 6, because `Actor` and `DistributedActor` have to
preserve their refinement of `AnyActor` to avoid breaking code currently
using the marker protocol. There's no way to move protocol refinement into
an extension so that the use-site declaration can be obsoleted, so we're
stuck with just the deprecation of `AnyActor`.
2024-05-24 12:58:02 -07:00
Holly Borla
8d6f16ef4b [Concurrency] @isolated(any) does not imply @Sendable. 2024-05-24 12:22:01 -07:00
Anthony Latsis
d18a7fd073 Sema: Require CS to certify conversions associated w/ existential member accesses 2024-04-18 22:54:19 +03:00
John McCall
b773c49368 Allow @isolated(any) mismatches in witness matching.
I'm not really convinced that this shouldn't be done by introducing a new
kind of constraint rather than hacking in what are essentially conversions
as "bind" constraints, but this is the most direct path for now.

Fixes rdar://125394096
2024-03-28 02:11:34 -04:00
Doug Gregor
96fd043638 Add tests for multiple @_implements on associated types 2024-03-25 17:13:33 -07:00
Kavon Farvardin
48beac231c Test: misc. test updates for NoncopyableGenerics 2024-03-14 23:10:44 -07:00
Slava Pestov
5afdb987e2 Merge pull request #72146 from slavapestov/ncgenerics-fixes-9
Non-copyable generics fixes, part 9
2024-03-07 22:14:33 -05:00
Slava Pestov
af8c8f1671 Sema: Remove non-experimental associated type inference 2024-03-07 17:30:17 -05:00
Slava Pestov
41df661160 AST: Use a builtin conformance for unconditional Copyable/Escapable
This generalizes what we were already doing for classes.
2024-03-07 15:07:47 -05:00
Slava Pestov
10a2ddb95e RequirementMachine: Fix MaxConcreteNesting check to take initial rules into account
Fixes rdar://123357717.
2024-03-06 21:42:49 -05:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Slava Pestov
1b99dd2451 RequirementMachine: Tweak RewriteSystem::recordConflict() heuristic again 2024-02-29 18:13:28 -05:00
Slava Pestov
d3aa3a8db9 Adjust XFAILs 2024-02-29 13:55:48 -05:00
Pavel Yaskevich
4e7425c03d [Tests] NFC: Add a test-case for rdar://123357062 2024-02-24 23:18:27 -08:00
Pavel Yaskevich
0c17b41d1e [Tests] NFC: Add a test-case for rdar://123336457 2024-02-24 23:15:36 -08:00
Slava Pestov
bf2a77ee86 Merge pull request #71865 from slavapestov/fix-rdar123543200
Sema: Fix checkTypeWitness() for Objective-C protocol compositions
2024-02-24 15:26:38 -05:00
Slava Pestov
6ac91cde5d Merge pull request #71821 from slavapestov/inheritance-clause-fixes
Refactor protocol inheritance clauses and existential layout for non-copyable generics
2024-02-24 11:58:03 -05:00
Slava Pestov
dde28e96a2 AST: Don't call getDirectlyInheritedNominalTypeDecls() on a protocol in ConformanceLookupTable 2024-02-24 07:25:59 -05:00
Slava Pestov
236d22ca8f Add regression test for bug already fixed 2024-02-24 07:25:59 -05:00
Slava Pestov
2befb08ed0 Sema: Fix checkTypeWitness() for Objective-C protocol compositions
I forgot that a protocol composition (C & P) can satisfy a superclass
requirement [T : D] in one narrow case implemented in
TypeBase::isExactSuperclassOf():

- D is a superclass of C
- P is an @objc protocol
- C is declared in Objective-C

This case was ruled out here because the code assumed the type witness
had to be a concrete class or archetype to satisfy a superclass
requirement.

Fixes rdar://problem/123543200.
2024-02-24 06:39:52 -05:00
Slava Pestov
14b110d2e8 Sema: Associated type inference optimization
This addresses a performance regression from 83cb420ee4.

In the old associated type inference implementation, we used to
fold valid solutions by comparing type witnesses, but this was
not correct as described in the commit message there.

After my fix we started to record more valid solutions from the
same search space, and this caused a performance regression
because we were already doing exponential work.

However in the program in question, each possible choice of witness
for a requirement would introduce the same bindings, so there was
nothing to gain from trying them all.

Since ranking only compares pairs of witnesses for the same
requirement, we can optimize this problem another way: by folding
identical terms in a disjunction, but only if *all* terms are
identical, which avoids the correctness issue in the old search
strategy.

Fixes rdar://problem/123334433.
2024-02-23 22:13:39 -05:00
Slava Pestov
ba90861602 Sema: Try a little harder to infer associated types to generic parameters if all else fails
If we have an abstract witness, we don't attempt a generic parameter
binding at all. But if simplifying the abstract witness failed, we
should still attempt it.

This would be cleaner as a disjunction in the solver but I want
to change behavior as little as possible, so this adds a new fallback
that we run when all else fails.

Fixes rdar://problem/123345520.
2024-02-21 05:42:39 -05:00
Slava Pestov
29b08a92a5 Add two test cases that regressed after a previous attempt at fixing a bug 2024-02-21 05:42:39 -05:00
Slava Pestov
b489baac95 Add two regression tests for bugs already fixed 2024-02-21 05:42:14 -05:00
Slava Pestov
0b2e168c56 Sema: Tweak abstract witness inference priority again
We used to do attempt things in this order:

- abstract witnesses, defaults, generic parameters

I tried this but it broke things:

- generic parameters, abstract witnesses, defaults

Hoping this sticks:

- abstract witnesses, generic parameters, defaults

Fixes rdar://123262178.
2024-02-21 05:42:14 -05:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Slava Pestov
1c24b880ec Merge pull request #70467 from AnthonyLatsis/recursive-member-typerepr
AST: Remodel `MemberTypeRepr` to be recursive
2024-02-16 11:36:31 -05:00
Slava Pestov
70c9f8a47e RequirementMachine: Leave behind conflicting requirements in the minimized signature
Requirement lowering only expects that it won't see two requirements
of the same kind (except for conformance requirements). So only mark
those as conflicting.

This addresses a crash-on-invalid and improves diagnostics for
move-only generics, because a conflict won't drop the copyability
of a generic parameter and expose a move-only-naive user to
confusing error messages.

Fixes #61031.
Fixes #63997.
Fixes rdar://problem/111991454.
2024-02-15 14:32:31 -05:00
Slava Pestov
cdd6f8d510 Add a test case 2024-02-14 10:36:42 -05:00
Slava Pestov
c34a74c6d9 Sema: More conservative 'tautological binding' check
Instead of computing the reduced type of the witness upfront and
then checking for canonical equality in type matching, check for
reduced equality in type matching.

This restores the old behavior and prevents us from considering too
many protocol extension witnesses, while fixing the request cycle
that motivated the change to instead match against the reduced type
of the witness.

Fixes rdar://problem/122589094, rdar://problem/122596633.
2024-02-14 06:34:52 -05:00
Slava Pestov
cfc684c00e Sema: Fix recent regression with -disable-experimental-associated-type-inference
This just brings back a bunch of old brittle logic conditionalized on the
negation of the flag.

Fixes rdar://problem/122810266.
2024-02-14 06:33:32 -05:00
Holly Borla
f1cd9cb422 [Test] Remove REQUIRES: asserts from tests that use -swift-version 6. 2024-02-13 07:13:35 -08:00
Slava Pestov
f95109d364 Sema: Restore old behavior of generic parameters with associated type inference
This effectively reverts d0bd026077, so
we now look for abstract type witnesses before generic parameters.

In particular, this means we again prefer the default type witness
over a generic parameter if nothing else forces it to be a generic
parameter:

    protocol P { associatedtype A = Int }
    struct S<T>: P {}
    // S.T is always Int

Fixing this properly requires modeling generic parameter bindings as
disjunctions, which is a more disruptive change than I want to take
for now.

Fixes rdar://problem/122587432.
2024-02-11 21:17:09 -05:00
Slava Pestov
23ef89322d Sema: New strategy for dealing with completely fixed associated types
If a protocol fixes an associated type of another protocol via a
concrete same-type requirement, we should make use of this fact
immediately when building the associated type inference constraint
system.

Previously we only introduced fixed type bindings at the end, and
only in the 'abstract type witness' inference path, which we
reach if a type witness cannot be resolved by looking at value
witnesses alone.

This meant that associated type inference would find valid or
ambiguous solutions which would then be contradicted by the
ensureRequirementsAreSatisfied() check.

Longer term, what I want to do is actually build the type witness
system upfront, and also teach the constraint solver here about
merging equivalence classes, so that we can split them again when
backtracking. This will combine the best of both approaches.

Fixes rdar://problem/122586992.
2024-02-10 23:56:02 -05:00
Slava Pestov
84921dbc36 Sema: Prefer abstract witnesses from the current protocol
A minimal Sequence conformance only needs to define an Iterator type,
with the Element type witness inferred from the Element of the iterator.

This trick didn't always work if the conforming type conformed to other
protocols with declared same-type requirements involving Self.Element.

Refine the heuristic introduced in 23599b667b
to prefer abstract type witnesses in the current protocol, even if there
is a shorter one in another protocol.

Fixes rdar://problem/122574126, rdar://problem/122588328.
2024-02-10 23:55:54 -05:00
Slava Pestov
2ed50ec276 Sema: If the structural occurs check skips a witness, treat it as tautological
Fixes rdar://problem/122584912.
2024-02-10 17:20:14 -05:00
Slava Pestov
f92a67d56e Check type witnesses in a couple of associated type inference tests 2024-02-10 17:20:14 -05:00
Slava Pestov
615f68664f Sema: Fix logic error in sanitizeProtocolRequirements()
If P is our protocol and it has an associated type A, we can't just
fold any dependent member type T.[Q]A to T.[P]A; this only makes
sense if T conforms to P.

Fixes rdar://problem/122587920.
2024-02-10 12:08:44 -05:00
Slava Pestov
8acd573598 Sema: Fix two problems in the solver's witness type matching logic
If we have an inner generic parameter of the requirement on the LHS,
it can't match anything other than an inner generic parameter on the RHS.

If we have the protocol Self type on the LHS, it can only match
something with the same nominal on the RHS. This should be an exact
match but ideally we would also recursively solve dependnet member
types, etc. Skip this all for now.
2024-02-10 12:08:44 -05:00
Slava Pestov
bfdafe6fcc Sema: Fix logic error in associated type inference solver
If matching a candidate value witness against a protocol requirement produced
non-viable bindings, then don't consider the witness in the solver; it can
never lead to a valid solution.
2024-02-10 12:08:44 -05:00
Slava Pestov
c999a87d98 Sema: Fold identical solutions at the end 2024-02-10 12:08:44 -05:00
Slava Pestov
83cb420ee4 Sema: Fix associated type solution ranking
We folded away viable solutions with identical type witnesses;
the first one "wins". However, solutions also store the value
witnesses from which those type witnesses were derived, and
this determines their ranking.

Suppose we have three solutions S_1, S_2, S_3 ranked as follows:

    S_1 < S_2 < S_3

If S_1 and S_3 have identical type witnesses, then one of two
things would happen:

Scenario A:
- we find S_1, and record it.
- we find S_2, and record it.
- we find S_3; it's identical to S_1, so we drop it.

Scenario B:
- we find S_3, and record it.
- we find S_2, and record it.
- we find S_1; it's identical to S_3, so we drop it.

Now, we the best solution Scenario A is S_1, and the best
solution in Scenario B is S_3.

To fix this and ensure we always end up with S_1, remove this
folding of solutions, except for invalid solutions where it
doesn't matter.

To avoid recording too many viable solutions, instead prune the
solution list every time we add a new solution. This maintains the
invariant that no solution is clearly worse than the others; when
we get to the end, we just check if we have exactly one solution,
in which case we know it's the best one.

Fixes rdar://problem/122586685.
2024-02-10 09:36:37 -05:00