Commit Graph

1296 Commits

Author SHA1 Message Date
Joe Groff
52d7781758 Merge pull request #81424 from jckarter/same-type-constraint-stop-copyable
Sema: Allow `T == NonCopyableOrEscapable` same-type constraints without a redundant `T: ~Copyable`.
2025-05-14 08:09:05 -07:00
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
Slava Pestov
df02862c2a Sema: Disallow SE-0361 with variadic generic types for now
`extension G<Int>` introduces a same-type requirement, and
this isn't supported for variadic generic types yet.

Make sure we pass a valid source location here to diagnose
instead of dropping the error.

- Fixes https://github.com/apple/swift/issues/70432
- Fixes rdar://119613080
2025-05-05 16:04:17 -04:00
Tony Allevato
a3993f972a Merge pull request #80498 from allevato/json-usr-fixes
[AST] More JSON AST dump improvements.
2025-04-23 15:35:17 -04:00
Anthony Latsis
2cd90bdd69 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-22 18:23:36 +01:00
Anthony Latsis
2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Tony Allevato
fa1f82967f Also show the new conformance details in the default dump. 2025-04-03 12:37:15 -04:00
Slava Pestov
43d9d7f3dc Add regression test for fixed crasher 2025-03-27 15:36:21 -04:00
Slava Pestov
d77c6f413d RequirementMachine: Skip protocol type aliases that contain unbound dependent member types
In the below, 'Self.A.A' is not a type parameter; rather, since
'Self.A' is concretely known to be 'S', we resolve it as 'S.A',
which performs a name lookup and finds the concrete type alias 'A':

    public struct S {
      public typealias A = Int
    }

    public protocol P {
      typealias A = S
    }

    public struct G<T> {}

    public protocol Q: P {
      typealias B = G<Self.A.A>
    }

This is fine, but such a type alias should not participate in
the rewrite system. Let's exclude them like any other invalid
requirement.

The type alias itself is not an error; however, it is an error
to use it from a 'where' clause requirement. This is not
diagnosed yet, though.

Fixes rdar://136686001.
2025-03-26 10:55:23 -04: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
e8b393430f Merge pull request #78459 from AnthonyLatsis/tuber-magnatum-2
TypeCheckType: Unconditionally warn about missing existential `any` until Swift 7
2025-02-14 19:08:33 +00: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
Slava Pestov
e9266c25d3 Sema: Fix accepts-invalid with throwing function types
We can't unconditionally skip the conformance check if the type contains type
parameters; instead, we only want to skip it in the structural resolution
stage. In interface resolution stage, we proceed by mapping the type into
the generic environment first.
2025-02-10 09:17:40 -05: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
Anthony Latsis
18669a0fcc Merge pull request #78044 from AnthonyLatsis/nelumbo-nucifera
ASTDumper: Do not escape Unicode chars in quoted fields
2024-12-10 19:12:47 +00:00
Anthony Latsis
1001c46e4c ASTDumper: Do not escape Unicode chars in quoted fields
Context: https://github.com/swiftlang/swift/pull/68438#discussion_r1449272860
2024-12-10 12:51:19 +00:00
Meghana Gupta
e8abd59da5 Update tests 2024-11-18 18:09:19 -08:00
Slava Pestov
ef5b9dca1c Merge pull request #77385 from slavapestov/fix-rdar139232031
AST: Fix request cycle from ParameterizedProtocolType::getRequirements()
2024-11-05 11:28:20 -05:00
Slava Pestov
dd252c1331 AST: Fix request cycle from ParameterizedProtocolType::getRequirements()
This fixes a regression from https://github.com/swiftlang/swift/pull/76585.

Fixes rdar://problem/139232031.
2024-11-04 23:36:57 -05: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
Allan Shortlidge
f827e7c6d3 Tests: Remove -disable-availability-checking in variadic generics tests. 2024-10-20 15:37:15 -07:00
Allan Shortlidge
6f55aa4170 Tests: Remove -disable-availability-checking in tests that use opaque types.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of opaque types, instead
of disabling availability checking.
2024-10-19 19:39:18 -07:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of _Concurrency APIs,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00
Slava Pestov
f35c90a6b7 Merge pull request #76445 from slavapestov/maptypeintocontext
Overhaul mapTypeIntoContext()
2024-09-14 08:45:20 -04:00
Slava Pestov
4afdc9d0bf AST: Lazily map archetype superclass into context
We don't really want to support this, at least not yet, but there
are ways to sneak it past the diagnostic that are hard to close.

Fixes rdar://problem/135348472.
2024-09-13 15:34:48 -04:00
Pavel Yaskevich
890e45d1e1 [CSSimplify] Increase impact of treat r-value as l-value fix in certain situations
If location (member) isn't mutable in the current context
or there are other problems at this location, increase impact
of the fix since it compounds the problem.
2024-09-10 10:35:28 -07:00
Slava Pestov
b7af52fd03 Add regression test for long-since fixed crasher 2024-09-04 10:42:20 -04:00
Slava Pestov
8c8b700ece Fix name of test case and move it to test/Generics/ 2024-08-29 16:18:14 -04:00
Alex Hoppen
577727ad55 Remove DiagnosticsEditorMode
Migrate the last diagnostic to be independent of `DiagnosticEditorMode` and remove that option.

rdar://133111163
2024-08-14 11:24:31 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Sima Nerush
6400a294a8 Merge pull request #70227 from simanerush/same-element-requirements
[Requirement Machine] Implement same-element requirements.
2024-08-06 14:24:33 -07:00
Joe Groff
044d8c9f56 Merge pull request #75378 from jckarter/warn-on-runtime-function-symbol-references
Stage in a warning when trying to access symbols used by the compiler.
2024-07-24 08:18:57 -07:00
Kavon Farvardin
5230b19ef6 Test: replace '@_moveOnly' with '~Copyable' 2024-07-23 11:05:33 -07:00
Joe Groff
8bc5a1f1fc Stage in a warning when trying to access symbols used by the compiler.
Attempting to bypass the compiler and access runtime functions directly has
a long history of breaking in hard-to-predict ways, and there's usually a better
way. Put up a warning to try to flush out misuses of runtime functions to see
if we can turn this into an error.
2024-07-19 16:55:11 -07:00
Holly Borla
2c0ab08192 [NFC] Add -dump-input=fail to a FileCheck test. 2024-07-15 10:19:32 -07:00
Holly Borla
dbda2738a6 [Features] Gate same-element requirements behind an experimental feature flag. 2024-07-15 10:19:32 -07:00
Holly Borla
2ea4586580 [Requirement Machine] Implement same-element requirements. 2024-07-15 10:19:32 -07:00
Kavon Farvardin
04454054b7 NCGenerics: add availability checking
Not all runtimes can correctly operate with types that use noncopyable
generics. When the generic argument of a type is noncopyable, old
runtimes can't recognize that to correctly check conformances that may
be conditional on those arguments being Copyable, etc.

resolves rdar://126239335
2024-07-07 15:38:00 -07:00
Kavon Farvardin
4b98498bf2 Merge pull request #74672 from kavon/post-vacation-misc-cleanups
Handful of small NoncopyableGenerics fixes / cleanups.
2024-06-25 18:35:40 -07:00
Slava Pestov
f34e57c016 RequirementMachine: Use ProtocolDecl::getAllInheritedProtocols() 2024-06-25 15:20:42 -04:00
Kavon Farvardin
05f5e511fc Diags: say "actors" cannot be ~Copyable
rdar://130450351
2024-06-25 12:06:22 -07:00
Slava Pestov
f747121080 Sema: Re-introduce the hack for re-using generic signature of extended protocol
In Swift 5.10 if you wrote `extension Foo {}` for some protocol Foo,
the extension would always re-use the generic signature of Foo, which
is <Self where Self: Foo>. In Swift 6 this no longer works because Foo
might be ~Copyable, in which case `extension Foo {}` adds default
requirements, so we changed GenericSignatureRequest to just always
build a new signature if we're given an extension.

However, to avoid a request cycle with a code example that really should
have never worked at all, I'm re-introducing the hack for re-using the
signature.

Fixes rdar://problem/129540617.
2024-06-19 13:25:09 -04: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