Commit Graph

46 Commits

Author SHA1 Message Date
Joe Groff
e4a6faa3f2 Sema: Allow T == NonCopyableOrEscapable same-type constraints without a redundant T: ~Copyable.
Enhance the logic in `applyInverses` to also take into account same-type constraints spelled in
the generic signature, so that same-type-constraining a type parameter to a type that is itself
not `Copyable` or `Escapable` suppresses the default application of those constraints on the
type parameter. Fixes rdar://147757973.
2025-05-13 11:31:41 -07:00
Andrew Trick
64a48d08e1 Update tests for strict @lifetime type checking 2025-03-19 11:59:04 -07:00
coffmark
cc6f1a1548 Sema: Add missing space to Copyable conformance suppression fix-it 2025-02-25 08:48:46 +09:00
Anthony Latsis
fe2408c0ab TypeCheckType: Unconditionally warn about missing existential any until Swift 7
https://github.com/swiftlang/swift/pull/72659 turned out to have some
source compatibility fallout that we need to fix. Instead of introducing
yet another brittle compatibility hack, stop emitting errors about a
missing `any` altogether until a future language mode.

Besides resolving the compatibility issue, this will encourage
developers to adopt any sooner and grant us ample time to gracefully
address any remaining bugs before the source compatibility burden
resurfaces.

A subsequent commit adds a diagnostic group that will allow users to
escalate these warnings to errors with `-Werror ExistentialAny`.
2025-02-12 21:20:44 +00:00
Joe Groff
a0a26b8330 Require explicit statement of all Copyable/Escapable requirements for conditional Copyable/Escapable conformances.
As specified by the SE-0446 acceptance, extensions that declare a type's
conditional `Copyable` or `Escapable` ability must reiterate explicitly all
of the `Copyable` and/or `Escapable` requirements, whether required or not
required (by e.g. `~Copyable`) that were suppressed in the original
type declaration.
2025-01-21 09:36:39 -08:00
Andrew Trick
5581ab876b Remove the experimental LifetimeDependenceDiagnoseTrivial feature.
This was never used to generate a .swiftinterface, so can be safely removed. It
was used to guard compiler fixes that might break older .swiftinterface
files. Now, we guard the same fixes by checking the source file type.
2024-12-18 17:11:32 -08:00
Andrew Trick
5c89708def Add experimental-feature LifetimeDependenceDiagnoseTrivial to tests. 2024-12-16 16:09:37 -08:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Kavon Farvardin
5230b19ef6 Test: replace '@_moveOnly' with '~Copyable' 2024-07-23 11:05:33 -07:00
Kavon Farvardin
2893e3dd8d Sema: reword inverse-on-extension message
We should be saying "can't suppress Copyable" instead, since you can't
"suppress" ~Copyable.
2024-06-12 14:44:22 -07:00
Kavon Farvardin
ec4a125f3e NCGenerics: ext's might not infer invertible req's
If the extension adds conformance to an invertible protocol, it's
confusing for people to also infer conditional requirements on the
generic parameters for those invertible protocols. This came up in the
review of SE-427.
2024-06-12 14:44:22 -07:00
Kavon Farvardin
8090e39a30 NCGenerics: fix "vague diagnostic for locator"
resolves the assertion failure in rdar://125196271 but not the
underlying issue.
2024-06-04 15:11:44 -07:00
Kavon Farvardin
c9cfe28e6d NCGenerics: improve diagnostics
Removing the old, ad-hoc diagnostics code improves the diagnostics we
emit, since the existing diagnostics for missing conformances is already
pretty good.

rdar://127369509
2024-06-04 15:06:32 -07:00
Kavon Farvardin
41577b3b55 Test: add a little test case 2024-05-20 18:56:53 -07:00
Kavon Farvardin
0420310623 NCGenerics: it's no longer "experimental"
resolves rdar://127701059
2024-05-08 10:49:12 -07:00
Kavon Farvardin
30983530b6 NCGenerics: introduce SuppressedAssociatedTypes
The model for associated types hasn't been fully worked-out for
noncopyable generics, but there is some support already that is being
used by the stdlib for an internal-only (and rather cursed) protocol
`_Pointer` to support `UnsafePointer`, etc.

This patch gates the existing experimental support for associated types
behind a feature flag. This flag doesn't emit feature-guards in
interfaces, since support for it is tied closely to NoncopyableGenerics
and has been there from its early days.
2024-04-02 16:53:36 -07:00
Doug Gregor
bd696f9c05 Enable failable initializers for noncopyable types
Noncopyable types were prevented from having failable initializers
because `Optional` itself didn't support noncopyable types. Now
`Optional` does, so lift this restriction and add a test.
2024-04-01 17:29:41 -07:00
Karoy Lorentey
4b1477cc2c [test] Update tests for new stdlib 2024-03-18 11:08:32 -07:00
Kavon Farvardin
47676b2248 Test: fix a number of NCGenerics-specific tests 2024-03-14 23:10:44 -07:00
Kavon Farvardin
af933c6723 Sema: remove TypeResolver::diagnoseMoveOnlyGeneric 2024-03-14 23:10:44 -07:00
Slava Pestov
3a4d831e52 AST: Fix crash-on-invalid when writing ~ followed by a non-protocol
Also reword some diagnostics. We don't want to talk about 'invert' or
'inverse'.
2024-03-11 14:36:21 -04:00
Slava Pestov
708586baea Sema: Remove a usage of hasInverseMarking()
This addresses some duplicate diagnostics from the previous commit.
2024-03-07 15:07:48 -05:00
Slava Pestov
dcea491dbe Sema: Remove inference of conditional Copyable conformance from generic parameters 2024-03-06 22:47:54 -05:00
Kavon Farvardin
19a5bb007e Test: more existential coverage 2024-03-02 09:57:04 -08:00
Kavon Farvardin
18f00668ce NCGenerics: fix ExistentialAny handling
The checking for ExistentialAny diagnostics needed to be updated to both
 handle the new Copyable/Escapable protocols that appear in the Any and
 AnyObject existential layouts.

resolves rdar://123332844
2024-02-27 14:15:34 -08:00
Slava Pestov
48f46f0e3c Sema: Redo the normalization in TypeResolver::resolveCompositionType() 2024-02-24 07:25:59 -05:00
Slava Pestov
512a15939d Sema: Fix handling of inverse requirements in checkProtocolRefinementRequirements() 2024-02-24 07:25:59 -05:00
Slava Pestov
dde28e96a2 AST: Don't call getDirectlyInheritedNominalTypeDecls() on a protocol in ConformanceLookupTable 2024-02-24 07:25:59 -05:00
Meghana Gupta
ca73cba046 Enable lifetime dependence inference when NonescapableTypes is on 2024-02-23 01:49:47 -08:00
Kavon Farvardin
84b309d506 NCGenerics: conformances can depend on Copyable 2024-02-21 22:38:23 -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
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
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
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Meghana Gupta
4dcda843e2 Infer lifetime dependence info for functions that return ~Escapable type 2024-01-29 15:45:19 -08: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
Kavon Farvardin
a2defd5367 [NCGenerics] fix AnyObject and inverses
resolves rdar://120512544
2024-01-10 19:37:21 -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
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00