Commit Graph

21976 Commits

Author SHA1 Message Date
Kathy Gray
e25cfc6d23 Expand support for PackExpansion type in requirements maching
Types where pack expansion required nested subsitution could cause the compiler to crash rather than properly expanding the pack. Both for populated types and infinityly expanding types which should generate an error.
This expands the support for these to generate more errors and populated types, and correspondingly expands the test suite
2025-10-10 17:46:22 +01:00
Kathy Gray
ce9368c39c Diagnostics change for ambiguous overloads previously specifying 'this'
Updates the message to use the type or ValueDecl instead of saying 'this' on 'Found this candidate' messages to provide more information where possible in selecting overloads

Per comment during draft iteration uses getInterfaceType and adds removeSelfParam to ValueDecl.t

Migrate to calling interfaceType and remove SelfParam

Update tests to reflect type information in ambiguity resolution

All but 5 tests now passing. Those 5 either do not refer to overloading errors or do pass even when modified to accept type specification

Move implementation to ValueDecl now that tests largely pass
2025-10-10 17:46:22 +01:00
Hamish Knight
d829d1596f [AST] NFC: Remove an unnecessary allocation
I missed this when changing the case body vars to be tail allocated,
remove the use of `AllocateCopy`.
2025-10-10 17:46:22 +01: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
Allan Shortlidge
ecd2b8af61 Merge pull request #84189 from tshortli/clang-feature-avail-kind-switch
AST: Avoid covered switches over `Clang::FeatureAvailKind`
2025-09-09 21:09:13 -07:00
Slava Pestov
45e3f1bc00 AST: Add TypeBase::eraseDynamicSelfType() 2025-09-09 18:58:09 -04:00
Allan Shortlidge
888ec24c03 AST: Avoid covered switches over Clang::FeatureAvailKind.
Make it possible to expand the `Clang::FeatureAvailKind` enum without breaking
the Swift compiler build.
2025-09-09 15:28:42 -07:00
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
Egor Zhdan
5dc2817913 Merge pull request #83874 from egorzhdan/egorzhdan/redecl-context-assertion
[cxx-interop] Fix an assertion for `extern "C"` blocks
2025-09-09 23:11:39 +01:00
John McCall
c7cad4ba54 Add a function for querying the isolation of an Initializer. 2025-09-09 14:26:57 -04: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
John McCall
3088b85c2c Don't crash if there's a request cycle with DefaultArgumentExprRequest. 2025-09-09 14:26:57 -04:00
Hamish Knight
79fe1b3548 [AST] Remove findParentPatternCaseStmtAndPattern
Add the extra logic to `VarDecl::getParentPattern` necessary to
handle fallthrough and case body variables instead. This also changes
the behavior for case body vars - previously we would return the first
pattern in the CaseStmt, but that's not necessarily correct. Instead,
return the first pattern that actually binds the variable.
2025-09-09 13:48:40 +01:00
Hamish Knight
413824c082 [AST] Simplify getRecursiveParentPatternStmt
`findParentPatternCaseStmtAndPattern` does more work than is necessary
for this, we just want the parent of the canonical var.
2025-09-09 13:48:40 +01:00
Hamish Knight
dc13b1f442 [AST] Tail-allocate case body variables on CaseStmt 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
3e97d729e8 [AST] Turn CaseBodyVariables into an ArrayRef
We don't need to store a `MutableArrayRef`.
2025-09-09 13:48:40 +01:00
Hamish Knight
9db82cbe62 [AST] Avoid walking a few more expressions in WalkToVarDecls
Avoid walking TapExprs, SingleValueStmtExprs, and key paths. The latter
is important since they can contain invalid VarDecls that will no
longer be visited by the ASTWalker after key path resolution, so we
don't want to create case body vars for them.
2025-09-09 13:48:40 +01:00
Henrik G. Olsson
33a059f689 Merge pull request #84136 from hnrklssn/print-lifetime-arg-backticks
[ASTPrinter] Escape @_lifetime arguments when needed

Printing a LifetimeDescriptor would never wrap it in backticks (even if originally wrapped in backticks). This would result in the output not being able to be parsed

rdar://159992995
2025-09-08 15:29:16 -07:00
Henrik G. Olsson
d7d839e9f3 [ASTPrinter] Escape @_lifetime arguments when needed
rdar://159992995
2025-09-05 23:03:46 -07:00
Henrik G. Olsson
fe14d5d636 [ASTPrinter] Move LifetimeDescriptor::getString and add test (NFC)
This refactor and test case are preparations for the implementation in
the next commit.
2025-09-05 23:03:26 -07:00
Allan Shortlidge
e0eba4ed5e AST: Add printing support for #available and #_hasSymbol conditions.
Teach `ASTPrinter` to print `if #available` and `if #_hasSymbol` statements.
2025-09-05 18:34:31 -07: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 `ktoso` Malawski
706348a368 Merge pull request #84118 from ktoso/wip-remove-not-used-func 2025-09-05 17:55:10 +09:00
Allan Shortlidge
5f67a9a410 Merge pull request #84107 from tshortli/custom-availability-in-library-level-api-swiftinterfaces
AST: Use availability to control decl visibility in public swiftinterfaces
2025-09-04 18:13:08 -07:00
Konrad Malawski
dd9dc0936b [Distributed] We're currently not using this isDistributedThunk func 2025-09-05 08:26:23 +09:00
Andrew Trick
592642087f Merge pull request #84010 from atrick/lifedep-mutating-default
@_lifetime defaults
2025-09-04 15:44:46 -07:00
Slava Pestov
cb2c0b122d AST: Remove TypeBase::replaceCovariantResultType() 2025-09-04 17:25:08 -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
a5a49aaab6 ModuleInterface: Stop printing $CustomAvailability guards in swiftinterfaces.
All supported compilers can now parse `@available` attributes that reference
custom availability domains.
2025-09-04 09:12:27 -07:00
Doug Gregor
ba2af97a91 Merge pull request #84095 from DougGregor/embedded-deferred-codegen 2025-09-04 06:05:39 -07:00
Ahmed Elrefaey
1bc96857a8 Merge pull request #82464 from a7medev/feat/full-documentation-in-code-completion
[IDE] Add full documentation to code completion result
2025-09-04 10:06:21 +01:00
Andrew Trick
37acd5781e Infer @_lifetime for mutating methods without experimental feature
Infer @_lifetime(self: copy self) for mutating methods without requiring the
experimental Lifetimes feature to be disabled. Treatment of mutating 'self' is
now consistent with other 'inout' parameters.

Example:

    extension MutableSpan {
      mutating func mutatingMethod() {...}
    }
2025-09-03 22:42:13 -07:00
Andrew Trick
ada46a0cf0 Lifetime inference: restructure to support multiple dependencies.
Restructure the inference logic to allow the same function declaration to
independently annotate or infer different lifetime targets.

For example:

   @_lifetime(borrow a)
   /* DEFAULT: @_lifetime(b: copy b)
   func f(a: A, b: inout B) -> NE

The fact that we prevented this was somewhat accidental and surprising.

This restructuring simplifies the code but also gives us much more control over
the inference logic.

Fixes: rdar://159288750 ("A function cannot have a ~Escapable 'inout' parameter
in addition to other ~Escapable parameters" is not actionable)
2025-09-03 22:42:12 -07:00
Doug Gregor
ed93b46fa6 [Embedded] Introduce DeferredCodeGen feature.
Introduce an experimental feature DeferredCodeGen, that defers the
generation of LLVM IR (and therefore object code) for all entities
within an Embedded Swift module unless they have explicitly requested
to not be emitted into the client (e.g., with
`@_neverEmitIntoClient`).

This feature is meant to generalize and subsume
-emit-empty-object-file, relying on lazy emission of entities rather
than abruptly ending the compilation pipeline before emitting any IR.

Part of rdar://158363967.
2025-09-03 15:55:47 -07:00
Pavel Yaskevich
0bcc9560b9 Merge pull request #83886 from janbaig/temp-branch
[SILGen] Remove and replace ad-hoc `assign_by_wrapper` instruction
2025-09-03 13:37:43 -07:00
Allan Shortlidge
a4da07efc5 Merge pull request #84070 from tshortli/universally-unavailable-at-runtime
AST: Fix runtime unavailability for universally unavailable decls
2025-09-03 12:45:49 -07: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
e390cce662 AST: Fix runtime unavailability for universally unavailable decls.
The logic that computes whether a decl is unavailable at runtime was allowing
`@available` attributes for specific availability domains override
`@available(*, unavailable)`. Universally unavailable decls are always
unavailable, regardless of their other `@available` attributes.
2025-09-03 07:04:25 -07:00
Allan Shortlidge
707c4aa52c AST: Factor out a utility for computing runtime unavailability.
In anticipation of needing to compute runtime unavailability to determine
whether declarations should be printed in swiftinterfaces, factor out the code
that computes runtime unavailability into a shared utility based on
`DeclAvailabilityConstraints`.

NFC.
2025-09-02 23:18:05 -07:00
Janat Baig
f21eb5375e Merge branch 'main' into temp-branch 2025-09-02 20:23:25 -04: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
ff200137a8 [AST] Add ErrorType originator for PlaceholderType 2025-08-30 16:05:01 +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
Slava Pestov
4f6d7f40ec Merge pull request #83986 from slavapestov/fix-rdar158774099
AST: Remove old hack that appears to be obsolete and revert a revert of another fix
2025-08-28 23:59:46 -04:00