Commit Graph

28941 Commits

Author SHA1 Message Date
Hamish Knight
17fe3de8c7 [Sema] Clean up extension binding a little
- Turn `BindExtensionsForIDEInspectionRequest` into the main extension
binding request.
- Change `ExtendedNominalRequest` such that it's no longer what
extension binding calls into to do the name lookup, instead it calls
directly into `computeExtendedNominal`. `getExtendedNominal` can
then be the entrypoint for `ExtendedNominalRequest` and assumes that
extension binding has already run. This avoids needing to fake the
dependency relationship in the DeclChecker.
2025-09-09 23:18:52 +01:00
Hamish Knight
d9d0b2e6a3 [Sema] Make extension binding lazy for SourceLoader
This will mainly be useful once extension binding is fully
requestified, but even now it's a good idea to ensure module loading
isn't kicking name lookup.
2025-09-09 23:18:52 +01:00
Meghana Gupta
a09e258f7f Enable SIL parsing of borrow and mutate accessors 2025-09-09 14:45:49 -07:00
Meghana Gupta
280fc83292 Avoid synthesizing read when borrow is present and modify when mutate is present 2025-09-09 14:45:07 -07:00
Meghana Gupta
075d44ac43 Sema support for borrow and mutate accessors 2025-09-09 14:41:51 -07:00
Meghana Gupta
9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
John McCall
367520cd3f Fix two bugs with the isolation of defer bodies.
The first bug is that we weren't computing isolation correctly for
nested defers. This is an unlikely pattern of code, but it's good to fix.

The second bug is that getActorIsolationOfContext was looking through
defers, but getActorIsolation itself was not. This was causing defer
bodies to be emitted in SILGen without an isolation parameter, which
meant that #isolation could not possibly provide the right value. Fixing
this involves teaching SILGen that non-async functions can have
nonisolated(nonsending) isolation, but that's relatively straightforward.

This commit doesn't fix #isolation or adequately test SILGen, but that'll
be handled in a follow-up.
2025-09-09 14:26:57 -04:00
Hamish Knight
10ed17549c [CS] Set the naming pattern in markInvalid
This normally gets populated by successful type-checking, we still want
to populate it if we fail though to avoid attempting to type-check the
parent statement again.
2025-09-09 13:48:40 +01:00
Hamish Knight
84847bcd06 [Sema] Relax a check in VarDeclUsageChecker
We don't want to just check the first pattern, we're interested in
the first pattern that binds the given variable. That can be determined
by checking if it's canonical or not.
2025-09-09 13:48:40 +01:00
Hamish Knight
1983172278 [Sema] Rename bindSwitchCasePatternVars -> diagnoseCaseVarMutabilityMismatch
Now that we wire up the parents up-front, this no longer needs to
set the parents. As such, remove the logic and rename to reflect the
fact that it now just diagnoses mutability mismatches.
2025-09-09 13:48:40 +01:00
Hamish Knight
c02c69a783 [AST] Introduce CaseStmt::createImplicit
This allows us to re-use the same logic to create the case body
variables.
2025-09-09 13:48:40 +01:00
Hamish Knight
245e2874ae [AST] Eagerly wire up VarDecl parents when creating CaseStmt
Rather than waiting until type-checking, we can set the parents
immediately when we create the CaseStmt. This requires fixing up
NamingPatternRequest to look at the recursive parent statement as
now the VarDecl may have a variable parent.
2025-09-09 13:48:40 +01:00
Hamish Knight
84befd43ab [AST] Make case body variables for CaseStmt non-optional
We don't really care about the distinction between empty and nil here.
2025-09-09 13:48:40 +01:00
Hamish Knight
805b6d9c39 [CS] Remove some dead code in visitCaseItemPattern
We don't wire up the parent variables until after type-checking, and
`recordInferredSwitchCasePatternVars` already handles joining the
pattern types, so we can remove this.
2025-09-09 13:48:40 +01:00
Henrik G. Olsson
a43c8474bc [ClangImporter] Add clang module imports to Swift wrapper module
When macros like _SwiftifyImport are added to a wrapper module for a
clang module, they may need to refer to symbols declared in another
clang module that the wrapped module imports (e.g. because they are used
in the original signature). This adds all the imported clang modules as
implicit imports to the wrapper module.

rdar://151611573
2025-09-08 17:25:26 -07:00
Allan Shortlidge
0c5eac5c3e Sema: Downgrade missing import diagnostics for key paths.
For now, downgrade the `MemberImportVisibility` diagnostics introduced in
https://github.com/swiftlang/swift/pull/83934 to warnings.

Resolves rdar://160146503.
2025-09-08 16:15:49 -07:00
Slava Pestov
af3b5e8e3b Sema: Clean up getMemberReferenceTypeFromOpenedType() 2025-09-08 10:31:49 -04:00
Slava Pestov
6b2e5985d6 Sema: Small cleanup in getMemberReferenceTypeFromOpenedType() 2025-09-08 10:31:49 -04:00
Slava Pestov
ab4e754ef9 Sema: Don't stick CovariantReturnConversionExpr around property access with DynamicSelfType base
It could be that refTy->hasDynamicSelfType() is true whereas
varDecl->getValueInterfaceType()->hasDynamicSelfType() is false.
This happens if the base of the access is dynamic Self, so the
refTy is (Self) -> @lvalue Int or whatever.

Note that replaceDynamicSelfType() behaves correctly in this case;
it leaves that Self in place, because it's in contravariant
position.

However, the other place where we check the condition would then
form a nonsensical CovariantReturnConversionExpr around the result
of the access, even though no conversion was necessary here; the
type of the returned value does not involve Self.

Simplify this logic further with the correct condition.

Fixes rdar://159531634.
2025-09-08 10:31:27 -04:00
Konrad Malawski
eff8cc2e7e [Distributed] Simplify checking for Any type 2025-09-08 11:29:59 +09:00
Hamish Knight
4d1a04b856 [CS] Remove AllowUnresolvedTypeVariables (#84146)
This has been unused for a while now.
2025-09-07 18:36:01 +01:00
Hamish Knight
23560df5f4 [CS] Remove AllowUnresolvedTypeVariables
This has been unused for a while now.
2025-09-07 12:17:18 +01:00
Hamish Knight
cac98f3a18 Merge pull request #84142 from hamishknight/for-none
[CS] NFC: Remove `CTP_ForEachStmt`
2025-09-06 22:43:28 +01:00
Hamish Knight
71d825dcb8 [CS] NFC: Remove CTP_ForEachStmt 2025-09-05 22:20:28 +01:00
Slava Pestov
aa3a0756f4 Merge pull request #84115 from slavapestov/remove-covariant-result-type
Remove TypeBase::replaceCovariantResultType()
2025-09-05 07:40:34 -04:00
Konrad Malawski
9c0c70be5d [Distributed] Allow disabling SerializationRequirement by using Any
It should be possible to disable SerializationRequirement by assigning
Any to it. This effectively disables the checking, since any type
conforms to that.

Previously we would crash trying to check for this conformance; or
rather, emitting diagnostics about un-necessary casts then encountering
incomplete types in CSDiagnostics.

Avoiding the cast entirely sounds like a good solution here.

resolves rdar://159285863
2025-09-05 17:02:07 +09:00
Pavel Yaskevich
3ae34e8e68 [Concurrency] Fix @Sendable closures not inferring nonisolated(nonsending)
If there are no explicit concurrency attributes, isolated parameters,
or captures associated with the closure it should infer `nonisolated(nonsending)`
for the parent conversion injected by the solver (this conversion is injected
because the solver cannot check captures to elide it).

The change pushes `isIsolationInferenceBoundaryClosure` check down
with added benefit of getting preconcurrency context from the parent.
2025-09-04 16:51:45 -07:00
Slava Pestov
55082c4eea Sema: Split off buildVarMemberRef() from buildMemberRef() 2025-09-04 18:07:46 -04:00
Slava Pestov
1ddcdc74d4 Sema: Convert conditional into an assert 2025-09-04 17:54:00 -04:00
Slava Pestov
250e3fd08b Sema: Split off buildStaticCurryThunk() from buildMemberRef() 2025-09-04 17:53:14 -04:00
Slava Pestov
d81fbd6c63 Sema: Split off buildDynamicMemberRef() from buildMemberRef() 2025-09-04 17:46:40 -04:00
Slava Pestov
853f50c90d Sema: Remove usage of replaceCovariantResultType() 2025-09-04 17:24:07 -04:00
Allan Shortlidge
b047396246 AST: Use availability to control decl visibility in public swiftinterfaces.
Declarations that are unavailable at runtime because of an `@available`
attribute referencing a custom domain that was imported `@_spiOnly` should be
hidden from public swiftinterface files in `-library-level=api` modules. For
remaining declarations that do get printed in the public swiftinterface, skip
printing any `@available` attribute that refers to the domains from those
`@_spiOnly` dependencies. This allows API developers to control declaration
visibility using availability defined by another module.

Resolves rdar://156512028.
2025-09-04 12:32:19 -07:00
Allan Shortlidge
ddca4b7404 Sema: Refactor diagnoseValueDeclRefExportability().
This is meant to make it clearer how exceptions for each `DisallowedOriginKind`
are handled.
2025-09-04 09:13:23 -07:00
Konrad `ktoso` Malawski
385938f731 Merge pull request #84072 from swiftlang/wip-nonisolated-thunks-retain-semantics 2025-09-04 08:29:26 +09:00
Hamish Knight
7fb532e4e6 Merge pull request #83776 from hamishknight/the-diags-never-stop-no
[Diags] Allow multiple in-flight diagnostics
2025-09-03 19:59:44 +01:00
Allan Shortlidge
d8cbb57304 Merge pull request #84069 from tshortli/available-attr-exportability-reason
Sema: Introduce an `ExportabilityReason` for availability attributes
2025-09-03 09:07:02 -07:00
Pavel Yaskevich
4236db7d30 Merge pull request #84066 from xedin/rdar-129359362
[TypeChecker] Avoid checking lazy property accessors if they haven't …
2025-09-03 07:14:54 -07:00
Konrad Malawski
ced1756142 [Concurrency/Distributed] ensure distributed thunks are @concurrent
Otherwise the "nonisolated nonsending by default" mode blows up as
distributed thunk signatures dont match expectations.

This undoes the fix from https://github.com/swiftlang/swift/pull/83940
and applies the fix on the synthesis side of the distributed thunks,
such that they are @concurrent always -- which keeps their old semantics
basically, regardless of what "default" mode we have.
2025-09-03 18:54:09 +09:00
Allan Shortlidge
91ddf93d0f Sema: Introduce an ExportabilityReason for availability attributes.
This allows diagnostics to be more precise and will also support logic that
allows for special cases for `@available` attributes in exportability checking.

Also fixes a bug where the exportability of `@available` attributes attached to
extensions were diagnosed twice for slightly differing reasons.
2025-09-02 23:13:08 -07:00
Pavel Yaskevich
6e7de5c1e0 [TypeChecker] Avoid checking lazy property accessors if they haven't been synthesized yet
Ttheir availability is going to match the property itself.
This is a workaround for lazy type-checking because synthesis
of accessors for such properties requires a reference to
`self` which won't be available because pattern binding
for the variable was skipped.

Resolves: rdar://129359362
Resolves: rdar://159463230
Resolves: https://github.com/swiftlang/swift/issues/84041
2025-09-02 17:12:28 -07:00
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