Commit Graph

48 Commits

Author SHA1 Message Date
Karoy Lorentey
9ecfac21ff [test] Adjust tests now that Optional supports nonescapable use
`Optional` is now depending on `$NonescapableTypes`, and thus the compiler no longer generates `#else` branches to allow suppressing that feature.
2025-03-24 12:15:57 -07:00
Karoy Lorentey
4ff38db976 [test] Adjust for Optional relying on $NonescapableTypes now 2025-03-24 12:15:50 -07: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
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
Meghana Gupta
68bfc0d3b4 Make NonEscapableTypes as a suppressible experimental feature 2024-09-13 13:13:17 -07:00
Kavon Farvardin
972373b129 NCGenerics: begin process of removing compat hack
The reverse-condfail workaround needs to be removed, and this is the
first step to allowing the stdlib to build with conditionally escapable
types.

resolves rdar://132453000
2024-07-29 17:27:17 -07:00
Kavon Farvardin
1fa02fb0fe Revert "NCGenerics: remove the reverse-condfail workaround"
This reverts commit 5b2f2cbfcf.
2024-07-16 08:10:00 -07:00
Kavon Farvardin
4529f3b295 Merge pull request #75183 from kavon/remove-reverse-condfail-workaround
NCGenerics: remove the reverse-condfail workaround
2024-07-12 09:39:12 -07:00
Kavon Farvardin
5b2f2cbfcf NCGenerics: remove the reverse-condfail workaround
This should no longer be needed, after having staged the first set of
changes in, as it was a temporary workaround.

resolves rdar://131560183
2024-07-11 14:30:27 -07:00
Allan Shortlidge
9e5a9b963f AST: Remove NoncopyableGenerics feature suppression.
It is no longer necessary to produce `.swiftinterface` files the support older
compilers that lack support for the NoncopyableGenerics feature. Cleaning this
up makes the stdlib `.swiftinterface` far more readable.
2024-07-08 17:44:24 -07:00
Kavon Farvardin
1e2111afca NCGenerics: add flag to opt-out SE-427 strictness
This is mainly for tests to avoid the reverse condfail.
2024-06-26 17:10:33 -07:00
Kavon Farvardin
545844ce8f ASTPrinter: fix nested signatures with inverses
A generic signature's `getInnermostGenericParams` will find the generic
parameters in the innermost scope. That's not quite right for printing
inverses, since we don't want to print an inverse for `T` when emitting
the generic signature of `f` below:

```swift
    struct S<T: ~Copyable, E> {
        func f() where E == Never {}
    }
```

Since `f` has its own generic signature, but doesn't define any generic
parameters, it shouldn't have an inverse emitted. The solution here is
to filter inverses by depth of the generic parameter.

We also want to print _all_ of the inverses in other situations, rather
than just the innermost ones. This aids in debugging and other
tools like the API digester.

resolves rdar://130179698
2024-06-25 12:06:23 -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
6edc0ad1e9 Merge pull request #73777 from kavon/expand-swiftskell
Test: Implement a functional-style noncopyable List
2024-05-21 12:42:54 -07:00
Kavon Farvardin
b72824d167 Test: start implementing List 2024-05-20 22:53:45 -07:00
Kavon Farvardin
210cfb2b55 ASTPrinter: handle inverses in compositions
The basic inheritance clause emission in ASTPrinter operates on
InheritedEntry's, but does not canonicalize types. It's been
designed to consider an entire composition unprintable because one
member is unprintable (e.g., the protocol is not public).

This rejection is what was causing `~Copyable` in some compositions to
be missing from interface files (rdar://126090425). Fixing that is the
purpose of this patch.

What happens, then, if you mix public and nonpublic protocols in a
composition? A second facility called the InheritedProtocolCollector
later does find the public protocols, and emits extensions at the end of
the interface file to declare the additional conformances the ininitial
declaration printer missed.

We can't generally emit `~Copyable` on an extension, so the fix can't
happening there. Refactoring things so there's one source of truth about
the protocols being printed is a sizable refactoring that I will defer
for another time.

resolves rdar://126090425
2024-05-20 17:10:44 -07:00
Joe Groff
10f9289ef8 Enable 'BorrowingSwitch' feature. 2024-05-14 07:31:59 -07:00
Kavon Farvardin
7177d9009d Merge pull request #73492 from kavon/ncgeneric-avoid-spam
NCGenerics: avoid feature-guarding in some cases
2024-05-08 18:42:09 -07:00
Kavon Farvardin
f0f91eedc9 NCGenerics: avoid feature-guarding in some cases
With the generalization of Optional to support noncopyable types, our
feature-guarding in swiftinterface files would double-print functions
that simply refer to the Optional type.

Since NoncopyableGenerics is a suppressible feature, by default
a second version of Optional and UnsafePointer are emitted into
swiftinterface files, where the ~Copyable generalization is stripped
away.

We can rely on that to avoid double-printing the function, if the types
substituted for the generic parameters are all Copyable.

We need a bit more checking for when
`@_disallowFeatureSuppression(NoncopyableGenerics)` is used, since this
trick relies on there always being a definition of the type we refer to,
whether the feature is enabled or not.

resolves rdar://127389991
2024-05-08 15:48:54 -07:00
Kavon Farvardin
0420310623 NCGenerics: it's no longer "experimental"
resolves rdar://127701059
2024-05-08 10:49:12 -07:00
Nate Chandler
ba467d2bd2 [Sema] Enable suppression of inferred conformances.
Add the machinery to support suppression of inference of conformance to
protocols that would otherwise be derived automatically.

This commit does not enable any conformances to be suppressed.
2024-04-15 16:46:22 -07:00
Kavon Farvardin
179bc4b605 Merge pull request #72820 from kavon/conditional-copyable-restriction
NCGenerics: restrict conditional Copyable reqs
2024-04-09 17:56:34 -07:00
Kavon Farvardin
215c4e1c25 NCGenerics: restrict conditional Copyable reqs
It doesn't really make sense for a conditional conformance requirement
for `Copyable` to depend on any other requirement other than other
`Copyable` conformance requirements.

resolves rdar://124967739
2024-04-04 14:20:28 -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
Allan Shortlidge
37034282a1 stdlib: Adopt @_disallowFeatureSuppression(NoncopyableGenerics).
This prevents some re-declaration errors when building the standard library
from its `.swiftinterface` with older compilers.
2024-03-27 22:20:50 -07:00
Allan Shortlidge
ee73ff7737 AST: Adjust declaration printing when NoncopyableGenerics2 is suppressed.
When printing declarations with `NoncopyableGenerics2` suppressed we must avoid
printing the `@_preInverseGenerics` attribute and any `borrowing` or
`consuming` parameter ownership modifiers.
2024-03-27 22:20:49 -07:00
Doug Gregor
164ae687ff Make NoncopyableGenerics a suppressible feature
Emit Swift interface files that are compatible with Swift compilers that
predate the introduction of noncopyable generics.
2024-03-15 14:50:40 -07:00
Slava Pestov
dcea491dbe Sema: Remove inference of conditional Copyable conformance from generic parameters 2024-03-06 22:47:54 -05:00
Kavon Farvardin
777e3d945f NCGenerics: @_preInverseGenerics across modules 2024-03-06 14:56:07 -08:00
Kavon Farvardin
108fd05619 flesh out more of Swiftskell test 2024-03-05 21:50:19 -08:00
Meghana Gupta
ca73cba046 Enable lifetime dependence inference when NonescapableTypes is on 2024-02-23 01:49:47 -08:00
Kavon Farvardin
19933d0a00 NFC: move Swiftskell to shared test/Inputs directory 2024-02-21 22:38:23 -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
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
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
Kavon Farvardin
5f977ca763 NCGenerics: force module mismatches 2024-01-31 14:00:08 -08:00
Kavon Farvardin
a2defd5367 [NCGenerics] fix AnyObject and inverses
resolves rdar://120512544
2024-01-10 19:37:21 -08:00
Kavon Farvardin
af7ff43d0d [NCGenerics] printing class-constrained generics
In cases where the generic parameter is class-constrained,
`GenericSignature::requiresProtocol` will not contain `Copyable` or
`Escapable` because GenericSignature minimization will recognize that
the class already requires them.

Thus, because classes always require those protocols, we can
simply ask if the generic parameter is required to be a class to
determine if it had any inverses.
2024-01-10 19:37:21 -08:00
Andrew Trick
979334e723 Merge pull request #70459 from atrick/rename-nonescapable
Rename NonesapableTypes feature
2023-12-14 16:00:46 -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
040e95cd7d [NCGenerics] extra coverage for interface emission 2023-12-14 08:45:27 -08:00
Kavon Farvardin
bd1330715c [NCGenerics] only print ~Copyable in interface
We can't simply emit the desugared, expanded version of the requirements
because there's no way to pretty-print the type `some ~Copyable` when
the `~Copyable`'s get replaced with the absence of `Copyable`. We'd be
left with just `some _` or need to invent a new top type so we can write
`some Top`. Thus, it's best to simply reverse the expansion of default
requirements when emitting a swiftinterface file.
2023-12-12 16:40:26 -08:00
Kavon Farvardin
ffc06f9d31 [NCGenerics] add tests for modules/interface files 2023-12-12 16:40:26 -08:00
Becca Royal-Gordon
1e6cafb9e7 Fix ModuleInterface/noncopyable_generics.swift
Experimental features are disabled in no-asserts compilers.
2023-12-02 10:01:48 -08:00
Kavon Farvardin
d432b8eb46 [Noncopyable] fix subscripts 2023-11-13 13:29:41 -08:00