Commit Graph

1251 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
11ef6e58d8 Merge pull request #71659 from xedin/noncopyable-circularity-fixes
[AST/Sema] NonCopyableGenerics: Address some of the request circularity issues
2024-02-20 12:38:16 -08:00
Pavel Yaskevich
7a3736ac29 [Tests] NFC: Add a test-case for self-conforming protocols and Copyable interaction 2024-02-20 10:23:42 -08:00
Kavon Farvardin
70878a65dd NCGenerics: add more extension test coverage 2024-02-20 00:00:06 -08:00
Kavon Farvardin
722282ee4f ASTPrinter: fix nested inverse printing
Nested types with inverse requirements on generic parameters would
sometimes print incorrectly. We only print the inverses on outer generic
parameters for extensions.

fixes rdar://123281976
2024-02-19 23:50:15 -08:00
Pavel Yaskevich
b09aad8065 [Tests] NFC: Adjust previous fixed test-case 2024-02-19 10:39:02 -08:00
Kavon Farvardin
08b71e0136 NCGenerics: rebuild stdlib from its interface
When a NoncopyableGenericsMismatch happens between the compiler and
stdlib, allow the compiler to rebuild the stdlib from its interface
instead of exiting with an error.
2024-02-15 18:08:54 -08: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
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
Kavon Farvardin
3a45393e17 NCGenerics: break cycle with SuperclassTypeRequest
With NoncopyableGenerics, we get a cycle involving
`SuperclassTypeRequest` with this program:

  public struct RawMarkupHeader {}
  final class RawMarkup: ManagedBuffer<RawMarkupHeader, RawMarkup> { }

Because we generally don't support the following kind of relationship:

  class Base<T: P>: P {}
  class Derived: Base<Derived> {}

This commit works around the root-cause, which is that Derived's
synthesized conformance to Copyable gets superceded by the inherited one
from Base. Instead of recording conformances in the ConformanceLookup
table at all, create builtin conformances on the fly, since classes
cannot be conditionally Copyable or Escapable.
2024-02-13 09:19:12 -08:00
Kavon Farvardin
5e51773718 NCGenerics: find conflicts in PCT's
We weren't diagnosing conflicts in PCT's like `Copyable & ~Copyable`,
instead deferring until that PCT was constrained to something like the
existential Self or a generic parameter, which then we'd diagnose.

But we should canonicalize PCT's such as `Copyable & Copyable` into
`Any`, which represents the empty composition. That's what the assert in
 PCT::build is about.
2024-02-08 15:56:50 -08:00
Kavon Farvardin
312ac1be55 NCGenerics: handle MoveOnlyClasses correctly 2024-02-04 23:03:20 -08:00
Kavon Farvardin
9f3743dec0 NCGenerics: mark hanging tests as unsupported 2024-02-04 19:14:53 -08:00
Slava Pestov
8db0af48bd Merge pull request #71352 from slavapestov/remove-redundant-requirements
Remove -warn-redundant-requirements flag
2024-02-03 08:28:02 -05:00
Slava Pestov
dcca5ced0f RequirementMachine: Remove -warn-redundant-requirements flag 2024-02-02 14:57:19 -05:00
Slava Pestov
ea15d9f9b2 Stop passing -warn-redundant-requirements in tests 2024-02-02 14:57:19 -05:00
Kavon Farvardin
7612682621 NCGenerics: update a number of tests
These tests were not updated in the transition to
`REQUIRES: noncopyable_generics` and thus running them with a
correctly-built stdlib that has the Copyable requirements.
2024-02-02 11:11:17 -08:00
Slava Pestov
80205ecf9c Merge pull request #71241 from slavapestov/ncgenerics-fixes
Non-copyable generics fixes
2024-02-01 07:18:29 -05:00
Slava Pestov
9e247469a1 Sema: Implement new behavior of extensions with non-copyable generics
We want extensions to introduce default Copyable/Escapable just like
other generic contexts, so that once Optional adopts ~Copyable,
an `extension Optional` actually adds `Wrapped: Copyable` by default.
2024-01-31 21:56:45 -05:00
Slava Pestov
23b1690f6b ASTPrinter: Refactor printing of RequirementSignatures 2024-01-31 21:55:52 -05:00
Slava Pestov
2355cb4090 Sema: Move -debug-generic-signatures behavior to TypeCheckDeclPrimary.cpp 2024-01-31 18:41:43 -05:00
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Slava Pestov
6cca6e5466 Merge pull request #70375 from slavapestov/type-witness-system-inference-enable
Turn on -enable-experimental-associated-type-inference by default
2024-01-30 07:22:05 -05:00
Slava Pestov
96b6e9e9f1 Sema: Fix logic error in associated type inference solver
This problem was introduced in 2017 by commit bbaa7f7163.

If a protocol requirement has multiple potential witnesses, and one
of those witnesses only introduces tautological type witness bindings,
we would be forced to choose among the remaining witnesses.

However, this did not account for the possibility that the
tautological witness is the correct choice; it's possible that we
will infer the same type witnesses via a different protocol
requirement.
2024-01-29 23:38:45 -05:00
Meghana Gupta
4dcda843e2 Infer lifetime dependence info for functions that return ~Escapable type 2024-01-29 15:45:19 -08:00
Slava Pestov
5eb32261aa Merge pull request #71169 from slavapestov/one-more-round-of-fixes
One more round of associated type inference fixes
2024-01-26 17:32:00 -05:00
Slava Pestov
05f04c0996 Sema: Try to resolve type witnesses on a more specific conformance first 2024-01-25 22:01:44 -05:00
Kavon Farvardin
6d1e5c3b18 [test] coverage for conditional conformances 2024-01-23 22:42:38 -08:00
Kavon Farvardin
25aa49be55 [NCGenerics] Sendable doesn't require Copyable 2024-01-23 22:42:38 -08:00
Kavon Farvardin
c7c9d80520 [NCGenerics] fix Combine issue
The solution is to add the unconditional conformances when building the
conformance lookup table for each nominal, instead of waiting until
conformance lookup infers it.

At the moment, because the stdlib isn't being built with Copyable
conformances injected into it, we still end up needing to infer Copyable
conformances for nominals like `Int` from the stdlib when trying to test
the feature, since it loads those nominals, but they lack conformance.

That should go away once we do enable NoncopyableGenerics for the stdlib
by default, and we'll be left with only inferring the conditional
conformance in TypeCheckInvertible.
2024-01-23 22:42:38 -08:00
Kavon Farvardin
3e03c674c7 [NCGenerics] remove arg from isNoncopyable(DC)
It should be the responsibility of callers to map the type to a
contextual type, as needed. When it's not possible or repetitive to do
so, there is a special-purpose function `isInterfaceTypeNoncopyable` for
 Sema.
2024-01-23 22:42:38 -08:00
Kavon Farvardin
b4985f7fde [NFC] replace canBeNoncopyable
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.

Also renames `TypeDecl::isEscapable` to match.
2024-01-23 22:42:38 -08:00
Allan Shortlidge
bb38de355b Add REQUIRES: asserts to NoncopyableGenerics tests. 2024-01-11 15:31:40 -08:00
Kavon Farvardin
a2defd5367 [NCGenerics] fix AnyObject and inverses
resolves rdar://120512544
2024-01-10 19:37:21 -08:00
Kavon Farvardin
e0412269fd [NCGenerics] infinite substitution hack
Workaround for rdar://119950540 when dealing with invertible protocols.

This should be sound because "its an invariant that subst() on a
conformance returns the same thing as a global lookup with subst() of
the conforming type, assuming you don't have overlapping conformances."
2024-01-10 19:37:21 -08:00
Doug Gregor
b9c5aca15f Enable SE-0413 "Typed Throws" by default 2024-01-02 15:34:07 -08:00
Andrew Trick
ace9937e95 Rename NonesapableTypes feature
Follow the feature flag convention for capitalization and be
consistent with the related NoncopyableGenerics feature.

This is a new feature that no wild Swift code has used it yet:

commit e99ce1cc5d
Author: Kavon Farvardin <kfarvardin@apple.com>
Date:   Tue Dec 5 23:25:09 2023

    [NCGenerics] add `~Escapable`

    Basic implementation of `~Escapable` in the type system.
2023-12-14 11:32:03 -08:00
Kavon Farvardin
0c5748fa15 [NCGenerics] ensure builtins are Escapable 2023-12-13 11:19:22 -08:00
Slava Pestov
026d3f0078 Merge pull request #70311 from slavapestov/type-witness-system-inference-stdlib
Get the standard library to build with -enable-experimental-associated-type-inference
2023-12-10 17:50:33 -05:00
Kavon Farvardin
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00
Kavon Farvardin
338d426b3d Merge pull request #70278 from kavon/refactor-InverseType
[NCGenerics] fold InverseType into PCT
2023-12-08 02:44:45 -08:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00
Slava Pestov
b1ed3c270c Add regression tests for rdar://116434843 and #59772 2023-12-07 19:27:59 -05:00
Slava Pestov
67740fd7b3 ASTPrinter: Don't crash if parent type of member type was concrete 2023-12-06 14:59:19 -05:00
Kavon Farvardin
2cd298926f [NCGenerics] fix existential conformances
I was not expanding default requirements in
AbstractGenericSignatureRequest or ExistentialLayout.

Also fixes printing of composition types.
2023-11-15 15:43:11 -08:00
Kavon Farvardin
28890ba580 [Sema] no Copyable conformance if marked ~Copyable
Much like when the type defines a deinit, if the nominal's declaration
is marked with ~Copyable, that prevents conformance to Copyable.

This meant that when trying to auto-derive Copyable conformance, we'll
skip types marked with ~Copyable. But now, we'll also reject
explicitly-requested conformances to Copyable because of that marking
too.

In reality right now, all marker protocols have conformances that are
always trivally checked and marked "complete", so when I refer to
rejecting a conformance here, I mean raising a diagnostic while checking
 for validity.
2023-11-07 13:09:15 -08:00
Kavon Farvardin
a4e9919f29 [Sema] require value deinit absence for Copyable
A value type like a struct or enum cannot conform to Copyable if it has
a deinit. When NoncopyableGenerics is enabled, we make that part of what
 is required to verify that such a nominal type conforms to Copyable.

This change also does some refactoring to share common code to point out
 how to make a type noncopyable.
2023-11-06 19:44:58 -08:00
Kavon Farvardin
d4522fa33c [Sema] emit conditional Copyable conformance note
For containment issues, where an unconditionally or conditionally
Copyable type contains a fixed noncopyable element, remind users about
the conditional conformance in addition to the fix-it to add ~Copyable
2023-11-06 15:41:46 -08:00
Kavon Farvardin
f8d688ce12 [Sema] overhaul NoncopyableAnnotationRequest
We need to know whether the noncopyable annotation is inferred from its
generic parameters. This allows us to synthesize the conditional
conformance.
2023-11-06 15:41:46 -08:00
Kavon Farvardin
29acda5136 Merge pull request #69406 from kavon/noncopyable-generics-pt2
[NoncopyableGenerics] handle `~Copyable` in `where`, `some`, and compositions.
2023-10-28 22:36:22 -07:00