Commit Graph

28850 Commits

Author SHA1 Message Date
Ben Barham
52b28717ce Merge pull request #84036 from hamishknight/pothole
[CS] Avoid increasing score for unbound outer type vars for completion
2025-09-02 09:32:03 -07:00
Pavel Yaskevich
96900f9bd0 Merge pull request #84012 from xedin/rdar-158063151
[CSOptimizer] Don't match `nil` to `_OptionalNilComparisonType`
2025-09-02 07:05:21 -07:00
Pavel Yaskevich
df962a83c6 [CSOptimizer] Don't match nil to _OptionalNilComparisonType
This type is only intended for pattern matching against `nil`
and the solver shouldn't early attempt to infer this type for
`nil` for arguments of `==` and `!=` operators it should instead
be inferred from other argument or result.

Resolves: rdar://158063151
2025-09-01 20:47:56 -07:00
Gábor Horváth
1b856e1fc9 Merge pull request #84040 from Xazax-hun/func-ptr-is-not-fragile
[cxx-interop] Do not consider function types fragile
2025-09-01 20:39:37 +01:00
Gabor Horvath
ff6679da28 [cxx-interop] Do not consider function types fragile
We can refer to these types in resilient interfaces when compiled in ObjC
interop mode.
2025-09-01 15:05:41 +01:00
Gabor Horvath
7ac9a81b1e [cxx-interop] Add attribute to hide Swift declarations from interop
This can help work around problems when the names of a C++ declaration
and a Swift declaration would collide, or to temporarily work around
compiler bugs.

rdar://152838988&140802127&158843666
2025-09-01 12:29:34 +01:00
Hamish Knight
ebad04f133 [CS] Avoid increasing score for unbound outer type vars for completion
When doing code completion it's entirely expected we'll end up with 
ambiguities in the body of a closure if we're completing e.g
`someOverloadedFn(#^CC^#)`. As such we don't want to penalize the
solution for unbound type variables outside of the body since that 
will prevent us from being able to eagerly prune e.g disfavored
overloads in the outer scope. This gives up to a 7% perf win in the
stress tester.
2025-09-01 10:56:45 +01:00
Hamish Knight
57ae9ded43 Merge pull request #84030 from hamishknight/hole-in-one
[CS] Avoid unnecessary type variables when opening ErrorTypes
2025-09-01 09:25:30 +01:00
Anthony Latsis
a6ec4a9cd0 Merge pull request #84034 from swiftlang/jepa-main3
[presets] Escalate `uninitialized` warnings to errors in macOS smoke test
2025-08-31 17:34:33 +01:00
Anthony Latsis
380736292e Sema: Fix -Wsometimes-uninitialized warning 2025-08-31 11:18:27 +01:00
Hamish Knight
a1e4a08ac7 Merge pull request #83593 from hamishknight/disable-fallback
[IDE] Remove fallback type-checking logic
2025-08-31 10:09:22 +01:00
Hamish Knight
9b3d2a00c0 Merge pull request #84005 from hamishknight/duet 2025-08-30 17:41:53 +01:00
Hamish Knight
ef7d69631b [CS] Avoid unnecessary type variables when opening ErrorTypes
Produce the holes directly.
2025-08-30 16:05:01 +01:00
Hamish Knight
d7fea157a1 [IDE] Remove fallback type-checking logic
This should no longer be necessary, rip it out.
2025-08-30 14:08:42 +01:00
Hamish Knight
a9e339b973 [CS] Strengthen check for completion in CSApply
Turns out we don't always set a completion callback for some unqualified
completion positions. Upgrade the check for a completion callback to
a check for a completion buffer to account for this. This avoids
unnecessary type-checker work as well as fixing a couple of
double-type-checking crashers.
2025-08-29 16:20:06 +01:00
Hamish Knight
28772234bc [CS] Allow contextual types with errors
Previously we would skip type-checking the result expression of a
`return` or the initialization expression of a binding if the contextual
type had an error, but that misses out on useful diagnostics and
prevents code completion and cursor info from working. Change the logic
such that we open ErrorTypes as holes and continue to type-check.
2025-08-29 15:04:20 +01:00
Hamish Knight
1b0eed22be [CS] Better propagate holes from contextual types
Eagerly bind invalid type references to holes and propagate contextual
type holes in `repairFailures`. This avoids some unnecessary diagnostics
in cases where we have an invalid contextual type.
2025-08-29 15:04:20 +01:00
Hamish Knight
b4fe5df669 [CS] Avoid introducing Void closure result binding for hole
If we have a hole binding for the result of a closure, avoid
introducing Void as an additional binding since that'll just cause
local solution ambiguities. This doesn't affect regular type-checking
since we end up treating such ambiguities as "identical", so we just
pick one. But for completion, we don't do such filtering so need to
make sure we end up with the hole solution to avoid treating Void as
the contextual type for cases such as:

```
_ = {
    x.#^CC^#
}
```

Currently we avoid this by not handling holes in `repairFailures`
for closure body locators, but I'm changing that in the next commit.
2025-08-29 15:04:20 +01:00
Hamish Knight
23ee6fb853 Merge pull request #83982 from hamishknight/unattached-fix
[Completion] Avoid type-checking parent closure for unattached node
2025-08-29 10:23:40 +01:00
Hamish Knight
cbacececd9 Merge pull request #83971 from hamishknight/set-point 2025-08-29 09:56:59 +01:00
Konrad `ktoso` Malawski
a9a6bf4cd6 Merge pull request #83940 from ktoso/wip-nonisolatednonsending-by-default-and-distributed 2025-08-29 16:34:42 +09:00
Hamish Knight
a309fc0ac9 Merge pull request #83992 from hamishknight/tweak-assert 2025-08-29 06:08:57 +01:00
Kavon Farvardin
bb8b1e1b42 Merge pull request #83984 from kavon/avoid-not-noncopyable
nfc: avoid !isNoncopyable()
2025-08-28 17:46:39 -07:00
Hamish Knight
2f5cfad7bc Merge pull request #83974 from hamishknight/reprap
[Sema] Avoid marking TypeRepr invalid with `SilenceErrors`
2025-08-29 01:09:55 +01:00
Hamish Knight
627f41ccbc [CS] Fix an overly strict assert
`matchExistentialTypes` can handle existential metatypes, fix the
assert to handle that.
2025-08-29 00:17:14 +01:00
Kavon Farvardin
3bb8fa848a nfc: !isNoncopyable() -> isCopyable() 2025-08-28 12:13:21 -07:00
Hamish Knight
3d9b7f3ac2 [Completion] Avoid type-checking parent closure for unattached node
We should have already type-checked a parent closure, and we wouldn't
be able to correctly locate the node anyway since it's not actually
part of the AST. While here, also walk up to the parent-most closure
instead of recursing to avoid unnecessary stack frames for nested
closures.
2025-08-28 19:30:54 +01:00
Hamish Knight
5b8dfc70ab [CS] Emit fallback diagnostic if needed for IgnoreInvalidASTNode
If no other error has been emitted, make sure we emit a fallback
diagnostic rather than crashing in the ASTVerifier or SILGen.
2025-08-28 15:31:48 +01:00
Hamish Knight
79e8a6cb3c [Sema] Avoid marking TypeRepr invalid with SilenceErrors
Pattern resolution currently invokes type resolution with this flag
since it's trying to see if it can treat a given expression as a
TypeRepr for e.g an enum pattern. Make sure we don't `setInvalid` on
such TypeRepr nodes since that will avoid diagnosing in cases where
the node also then gets treated as a TypeRepr for an ExprPattern,
where we actually want the diagnostic emitted.
2025-08-28 15:31:48 +01:00
Slava Pestov
a5a8cf4a36 Merge pull request #83858 from slavapestov/covariant-result-type-part-2
AST: Continue process of removing replaceCovariantResultType()
2025-08-28 10:07:13 -04:00
Konrad Malawski
c1491c8022 [Concurrency/Distributed] nonisolated-nonsending by default breaks distributed thunks
the new NonisolatedNonsendingByDefault upcoming feature breaks remote
calls in distributed actors, because the expected isolation doesn't
match and the runtime swift_distributed_execute_target_resume will
crash.

This is a short term fix to unblock adopters, however preferably we
should mark the thunks as nonisolated(nonsending), though that seems to
be more involved.

resolves rdar://159247975
2025-08-28 21:53:41 +09:00
Hamish Knight
8cc5d06625 [Sema] Avoid crashing in IsAccessorTransparentRequest for implicit setter
We can synthesize these for invalid stored properties in extensions and
enums, just return `false` instead of asserting.
2025-08-28 12:56:06 +01:00
Hamish Knight
7296c82625 Merge pull request #83944 from hamishknight/walkerr
[AST] Walk ErrorExpr's original expr in ASTWalker
2025-08-28 11:48:41 +01:00
Allan Shortlidge
c23af5f3fe Merge pull request #83934 from tshortli/key-path-member-import-visibility
Sema: Diagnose key paths when `MemberImportVisibility` is enabled
2025-08-27 17:46:11 -07:00
Hamish Knight
9c898206e8 Merge pull request #83870 from hamishknight/overrun
[CS] Open generic requirements for types with unbound + placeholder types
2025-08-27 23:20:33 +01:00
Felipe Mussi Ferreira Peixoto
9779591212 [CSDiagnostics] Prevent nested type references in KeyPath components (#83625)
This change adds detection for nested type references in KeyPath
components and applies the appropriate fix to generate meaningful error
messages, following the same pattern already established for method
references.

The fix ensures that invalid KeyPath references fail gracefully in
normal mode and provide helpful diagnostics in diagnostic mode,
improving the developer experience when working with KeyPaths.

Resolves: https://github.com/swiftlang/swift/issues/83197
2025-08-27 14:50:14 -07:00
Slava Pestov
a7d12e7919 Sema: Small CSApply cleanup 2025-08-27 15:34:26 -04:00
Slava Pestov
1716832a7a AST: Remove most usages of AbstractFunctionDecl::hasDynamicSelfResult() 2025-08-27 15:34:26 -04:00
Slava Pestov
9e3d0e0a8c Sema: Move weird ConstructorDecl hack from getEffectiveOverloadType() to simplifyAppliedOverloadsImpl() 2025-08-27 15:34:26 -04:00
Slava Pestov
d8bf4a96e3 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:26 -04:00
Slava Pestov
aa35045008 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:26 -04:00
Slava Pestov
b871a08065 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:25 -04:00
Slava Pestov
75cf2c1df5 Sema: Remove a usage of replaceCovariantResultType() 2025-08-27 15:34:25 -04:00
Slava Pestov
68f69fadca Sema: Refactor ConstraintSystem::getEffectiveOverloadType() 2025-08-27 15:34:25 -04:00
Slava Pestov
fc4b85e0bc Sema: Maintain adjusted/original distinction in getTypeOfReference() 2025-08-27 15:34:25 -04:00
Allan Shortlidge
ea714d246f Sema: Diagnose key paths when MemberImportVisibility is enabled.
The diagnostic pass that checks whether expressions reference member
declarations that have not been imported failed to handle key path expressions.

Resolves rdar://159093481.
2025-08-27 09:44:38 -07:00
Allan Shortlidge
2d5824ef1a Sema: Diagnose key path setter availability.
Diagnose the availability of the specific accessors that are referenced
implicitly via a key path reference. This causes setter availability to be
diagnosed when passing a key path to a function that takes a `WritableKeyPath`.

Resolves rdar://157232221.
2025-08-27 07:58:35 -07:00
Hamish Knight
7e22297b71 [AST] Walk ErrorExpr's original expr in ASTWalker
We set an original expression on ErrorExpr for cases where we have
something semantically invalid that doesn't fit into the AST, but is
still something that the user has explicitly written. For example
this is how we represent unresolved dots without member names (`x.`).
We still want to type-check the underlying expression though since
it can provide useful diagnostics and allows semantic functionality
such as completion and cursor info to work correctly.

rdar://130771574
2025-08-27 15:27:06 +01:00
Allan Shortlidge
7ac68cecb1 Sema: Check access, availability, and exportability of availability domains.
Teach Sema to diagnose the access level, exportability, and availability of
availability domains that are referenced by `@available` attributes and
`if #available` statements.

Resolves rdar://159147207.
2025-08-26 08:20:12 -07:00
Allan Shortlidge
9de88624b2 Sema: Diagnose availability of availability domains in if #available queries.
When emitting statement diagnostics for `if #available` queries, diagnose the
availability of the decls representing the referenced availability domains.
Among other things, this checks that the domains are sufficiently visible to be
used in the containing function body context.
2025-08-26 08:20:12 -07:00