Commit Graph

28941 Commits

Author SHA1 Message Date
Henrik G. Olsson
8a6b7f0b93 [ImportResolution] Remove early exit that will never trigger
There's only one caller to performImportResolutionForClangMacroBuffer,
which always passes a newly allocated SourceFile. This removes a
redundant check for whether its imports have been resolved, and instead
asserts that they haven't.
2025-09-16 21:10:07 -07:00
Henrik G. Olsson
33634becd8 [ImportResolution] Remove redundant "Swift" module import
Import resolution now adds the Swift module to the list of imports, so
we no longer need to add it manually.
2025-09-16 21:10:06 -07:00
Henrik G. Olsson
0ea5677aa1 [ImportResolution] Deduplicate top-level clang modules from import list
Importing clang submodules results in an implicit import of the
top-level module as well. This can result in the same TLM being imported
many different times, if multiple submodules are imported from the same
module. This deduplicates these imports.

Other imports are not expected to be duplicated, so care is taken to
only deduplicate clang TLM imports.
2025-09-16 21:10:05 -07:00
Allan Shortlidge
d8fac32dd8 Sema: Fix a crash in migrate mode for MemberImportVisibility.
`TypeChecker::resolveDeclRefExpr()` would leave error nodes in the AST when
performing fallback name lookups with `MemberImportVisibility`. When running in
migration mode for `MemberImportVisibility`, these error nodes would then cause
the compiler to either diagnose a missing error or to crash during SILGen.

Instead of restricting name lookup during `TypeChecker::resolveDeclRefExpr()`,
allow it to find candidates with missing imports and then diagnose them if
necessary before forming a resolve decl ref.

Resolves rdar://154361861.
2025-09-15 20:48:06 -07:00
Hamish Knight
63d63d8c60 [CS] Bail from conjunction for non-zero SK_Hole
Previously we would only do this for `SK_Fix`, do the same for `SK_Hole`
since otherwise the score clearing logic for the conjunction could
result in losing the hole score.
2025-09-15 21:43:58 +01:00
Doug Gregor
01873c996f Merge pull request #84283 from DougGregor/embedded-swift-untyped-throws-restriction
[Embedded] Diagnose untyped throws as an Embedded Swift restriction
2025-09-15 12:55:16 -07:00
Pavel Yaskevich
5207b0ec8a Merge pull request #84287 from xedin/issue-84150
[CSSimplify] Fix key path to function conversion to check key path re…
2025-09-15 11:48:30 -07:00
Meghana Gupta
c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Doug Gregor
865c643cac Suppress Embedded Restriction diagnostics in code that won't be compiled as Embedded
When emitting diagnostics for the Embedded Swift restrictions outside
of Embedded Swift mode, consider `#if $Embedded` and `#if
hasFeature(Embedded)` configurations. If the code where we would emit
the diagnostic would be disabled in Embedded Swift by one of those
checks, don't emit the diagnostic. This helps code that can compile
either with Embedded or regular Swift stay within the restrictions on
Embedded Swift.
2025-09-15 07:10:00 -07:00
Hamish Knight
be1f82e36b [CS] Avoid emitting duplicate note for generic argument diagnostic
Since we can run CSGen multiple times, we need to guard the emission
of the note on whether the TypeRepr was already marked invalid (i.e
whether we already emitted a diagnostic for it).
2025-09-15 11:48:56 +01:00
Hamish Knight
b7519fabe6 [CS] Add IgnoreInvalidASTNode fix for invalid generic argument
Make sure we record a fix here to ensure we don't try to do CSApply
with holes.
2025-09-15 11:48:56 +01:00
Hamish Knight
6761d8474d Merge pull request #84273 from hamishknight/the-whole-hole
[CS] Avoid forming DependentMemberType with hole base in `InferableTypeOpener`
2025-09-15 09:33:34 +01:00
Hamish Knight
411e14d00b Merge pull request #84275 from hamishknight/skippy
[CS] Avoid skipping SingleValueStmtExpr branch with ReturnStmt for completion
2025-09-15 09:33:17 +01:00
Pavel Yaskevich
ac27f53c04 [CSSimplify] Fix key path to function conversion to check key path requirements
`KeyPath` types now have conformance requirements placed on their
`Root` and `Value` types which need to be checked even when there
is a key path to function conversion involved, otherwise the solver
would be accepting invalid code.

Note that without function conversion the requirements come from
a type opened during assignment - https://github.com/swiftlang/swift/pull/80081/files.

Resolves: https://github.com/swiftlang/swift/issues/84150
2025-09-15 00:35:19 -07:00
Doug Gregor
7d21bc332a [Embedded] Diagnose untyped throws as an Embedded Swift restriction
Untyped throws depends on existentials (`any Error`), and is therefore
not available in Embedded Swift. Introduce a diagnostic that diagnoses
any use of untyped throws, suggesting that one use typed throws
instead.

Make this an opt-in diagnostic enabled with `-Wwarning
EmbeddedRestrictions`, whether in Embedded Swift or not, using the
"default ignore" flag on these new warnings. Document this new
diagnostic group, and put the existing Embedded Swift error about
weak/unowned references in it as well.

Part of the general push to have the type checker identify code that
will not compile as Embedded Swift earlier, rdar://133874555.
2025-09-14 21:48:50 -07:00
Hamish Knight
0f7490aae1 [CS] Avoid forming DependentMemberType with hole base in InferableTypeOpener
Type substitution can form DependentMemberTypes with error base types,
avoid forming a DependentMemberType with a hole base in
`InferableTypeOpener`, instead form a hole that covers the entire type.
2025-09-14 10:09:39 +01:00
Hamish Knight
f1ad703430 [CS] Avoid skipping SingleValueStmtExpr branch with ReturnStmt for completion
We still need to solve a branch with a ReturnStmt to avoid leaving
the contextual result type unbound. This isn't currently legal anyway,
so isn't likely to come up often in practice, but make sure we can
still solve.
2025-09-13 19:15:34 +01:00
Slava Pestov
6bf5213d41 Merge pull request #84251 from slavapestov/fix-rdar151171381
Fix @_opaqueReturnTypeOf module interface syntax for parameter packs
2025-09-13 08:44:44 -04:00
Hamish Knight
8e460d1e6c Merge pull request #84225 from hamishknight/access-noted
Requestify the loading of access notes
2025-09-13 12:06:43 +01:00
Henrik G. Olsson
8e802be2b8 Merge pull request #81663 from hnrklssn/swiftify-debug-logging
[Swiftify] add debug logs for safe interop
2025-09-12 18:40:55 -07:00
Slava Pestov
af78807313 Sema: Generalize @_opaqueReturnTypeOf syntax to correctly handle parameter packs
We now allow the dummy identifier to be a qualified reference, so
that we can reconstruct generic parameter lists from multiple levels:

    @_opaqueReturnTypeOf(...) __.<OuterArgs...>.__<InnerArgs...>

This fixes an ambiguity with parameter packs, where flattening the
packs from multiple levels of nested types no longer produced an
unambiguous result.

To maintain backward compatibility, we still accept the old "flat"
form when no parameter packs are present.
2025-09-12 15:43:30 -04:00
Alexis Laferrière
b00a561cc1 Merge pull request #84238 from xymus/spi-avail-in-ext
Sema: Narrow fix to allow `@_spi_available` in extensions
2025-09-12 09:09:29 -07:00
Hamish Knight
014ed51ab1 Merge pull request #84220 from hamishknight/times-arrow
[AST] Allow storing original expression in `ErrorTypeRepr`
2025-09-12 17:06:34 +01:00
Slava Pestov
38f178838e Sema: Extract resolveGenericArguments() from applyGenericArguments() 2025-09-11 22:55:10 -04:00
Konrad `ktoso` Malawski
d2a03b45d1 Merge pull request #84119 from ktoso/wip-allow-any-serialization-requirement 2025-09-12 11:08:20 +09:00
Henrik G. Olsson
8208b3a50a [Macros] Add debug logs for macro expansions
These can be enabled with `-Xcc -mllvm -debug-only=macros`.
2025-09-11 18:46:20 -07:00
John McCall
a71336ca40 Merge pull request #84206 from rjmccall/capture-defer-isolation
Make sure that we capture the isolation of a defer function that implicitly uses the isolation
2025-09-11 19:54:54 -04:00
Alexis Laferrière
1adbe37f35 Sema: Narrow fix to allow @_spi_available in extensions
Allow referencing an `@_spi_available` decl in extensions to
`@_spi_available` types. This is a narrow fix as it should really be
handled as part of the context check but that check is currently too
permissive.

Fow now let's narrowly allow legal code. And then we should look at
revisiting the SPI availability logic, separate it from normal SPI and
treat more like availability.

Adding a test comparing the behavior of `@_spi` with `@_spi_available`
to document the current implementation.

rdar://159292698
2025-09-11 16:49:20 -07:00
Hamish Knight
5c334c5f21 Requestify the loading of access notes
Replace `loadAccessNotesIfNeeded` with a request that loads the access
notes on-demand.
2025-09-11 16:54:08 +01:00
Hamish Knight
033638e5c7 NFC: Split out TypeCheckAccessNotes.cpp 2025-09-11 16:54:08 +01:00
John McCall
d780b62812 Make sure that we capture the isolation of a defer function that
implicitly uses the isolation.
2025-09-11 09:40:44 -04:00
Konrad Malawski
644aa87447 Harden diagnoseForcedCastExpr for lack of cast-to type 2025-09-11 22:00:56 +09:00
Slava Pestov
79035e99f0 Merge pull request #84210 from slavapestov/remove-has-dynamic-self-result
AST: Remove AbstractFunctionDecl::hasDynamicSelfResult()
2025-09-11 08:45:08 -04:00
Hamish Knight
c84d2abb05 [AST] Allow storing original expression in ErrorTypeRepr
This is useful for ArrowExpr when the sub-expressions aren't valid
TypeExprs. Rather than throwing away the AST, attach it to the
ErrorTypeRepr to ensure we can still type-check it. This ensures
semantic functionality still works correctly, and fixes a crash where
we'd stop visiting an invalid binding pattern, losing track of the
nested VarDecl.
2025-09-11 13:21:03 +01:00
Hamish Knight
e1bd9038b3 [AST] NFC: Remove DelayedDiag from ErrorTypeRepr
This is no longer used.
2025-09-11 13:21:03 +01:00
Pavel Yaskevich
ae9bae7bdc Merge pull request #84117 from xedin/sendable-closures-with-nonisolated-nonsending
[Concurrency] Fix `@Sendable` closures not inferring `nonisolated(non…
2025-09-10 16:59:49 -07:00
Slava Pestov
d6fb460bde Sema: Clean up curry thunk logic in buildMemberRef() 2025-09-10 19:26:02 -04:00
Slava Pestov
59b7599f8a Sema: Simplify handling of DynamicSelfType in buildSingleCurryThunk() 2025-09-10 19:25:37 -04:00
John McCall
e5b6a88c5e Merge pull request #84181 from rjmccall/isolation-fixes
Isolation fixes for closures and defer bodies
2025-09-10 08:39:09 -04:00
Hamish Knight
f8218e3254 Merge pull request #83777 from hamishknight/ext-cleanup
[Sema] Clean up extension binding a little
2025-09-10 09:37:20 +01:00
Hamish Knight
872176bdd1 Merge pull request #84149 from hamishknight/case-and-pat
A few pattern cleanups + fixes
2025-09-10 09:36:22 +01:00
Slava Pestov
0063c3c522 Merge pull request #84131 from slavapestov/remove-covariant-result-type-post-cleanup
Sema: Clean up getTypeOfMemberReference() and buildMemberRef()
2025-09-10 01:39:38 -04:00
Slava Pestov
60246a2889 Sema: Further split up getTypeOfMemberTypeReference() 2025-09-09 18:58:10 -04:00
Slava Pestov
68be47f166 Sema: Re-organize some logic in getTypeOfMemberReference() 2025-09-09 18:58:10 -04:00
Slava Pestov
13b4b03aca Sema: Fix crash in IgnoreAssignmentDestinationType::diagnoseForAmbiguity() 2025-09-09 18:58:10 -04:00
Slava Pestov
45ec809330 Sema: Clean up property wrapper application in getTypeOfMemberReference()
If there are no property wrappers to unwrap, we don't need to take the
FunctionType apart and put it back together again.
2025-09-09 18:58:10 -04:00
Slava Pestov
6dc2e7558d Sema: Don't modify openedType in getMemberReferenceTypeFromOpenedType() 2025-09-09 18:58:09 -04:00
Slava Pestov
b6676fa38f Sema: Move ConstructorDecl hack out of getMemberReferenceTypeFromOpenedType() 2025-09-09 18:58:09 -04:00
Slava Pestov
27c52eb4a9 Sema: Clean up buildOtherConstructorRef() 2025-09-09 18:58:09 -04:00
Slava Pestov
9e2d4c520f Sema: More DynamicSelfType cleanup 2025-09-09 18:58:09 -04:00