Commit Graph

3634 Commits

Author SHA1 Message Date
Slava Pestov f05d1cab32 Sema: Fix crash when declaring an old-style variadic parameter with nonescaping type
This is not supported for the same reason you can't have a noncopyable
variadic parameter, but the code was hard-coded to check for copyability
only.

Generalize this to apply the generic signature for Array via the
common code path, and add a custom note to explain why those requirements
are checked in the first place.

Cleaning this up also fixed some fuzzer crashes.

Reported on the forums:
https://forums.swift.org/t/variadic-escapable-arguments-crash-the-compiler/86727/2
2026-05-18 10:49:23 -04:00
Doug Gregor 86febb3a3e Merge pull request #88979 from DougGregor/export-interface-types-and-conformances
[Embedded] Extend @export(interface) to non-generic types and protocol conformances
2026-05-11 11:25:10 -07:00
Doug Gregor 8a23b460c9 Update code completion test 2026-05-10 16:49:23 -07:00
Artem Chikin a7bbffd953 Merge pull request #88205 from artemcm/DiagnoseAttr
[Source Warning Control] Rename `@warn` to `@diagnose` & prevent printing it in Textual Interfaces
2026-05-07 16:52:22 +01:00
Clinton Nkwocha 973d04d980 Revert "Reapply #87697 and fix overload resolution for Sequence+AsyncSequence types. (#88442)" (#88713)
<!--
The main branch is now in convergence, which means major changes, such
as large refactoring or new features, should be avoided. This strategy
is intended to maintain the stability of the Swift 6.4 release leading
up to the May 4th branch. For any work that requires broad changes or
introduces new features, create a feature branch and open a draft pull
request. All updates to the swiftlang/swift repository’s main branch
require approval from the release managers. A pull request targeting
swiftlang/swift will automatically add release managers. You can also
contact them via @release-managers in the forum group.
-->

<!-- Please fill out the following form: --> 
- **Explanation**: This reverts commit
5ece334724 which aimed to generalize
Sequence methods for typed throws and resolve its side effects on
overload resolution when a type conforms to both Sequence and
AsyncSequence. There appears to be, at least, one more unanticipated
side-effect, hence this pre-emptive revert in view of the soon-to-be
Swift 6.4 release branching.
  <!--
A description of the changes. This can be brief, but it should be clear.
  -->
- **Scope**: The said commit is reverted, preserving the recent
~Copyable/consuming alterations to Sequence.reduce(\_:\_:) (#85716).
  <!--
An assessment of the impact and importance of the changes. For example,
can
  the changes break existing code?
  -->
- **Issues**: Under investigation 
  <!--
  References to issues the changes resolve, if any.
  -->
- **Risk**: Low
  <!--
  The (specific) risk to the release for taking the changes.
  -->
- **Testing**: None
  <!--
  The specific testing that has been done or needs to be done to further
  validate any impact of the changes.
  -->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2026-04-30 16:01:48 +01:00
Artem Chikin 866371d73e [Source Warning Control] Rename '@warn' to '@diagnose'
Resolves rdar://173774670
2026-04-29 10:39:25 +01:00
Ben Cohen 8832c55107 Change reduce to take initial and partial value consuming 2026-04-21 12:57:39 -07:00
Clinton Nkwocha 5ece334724 Reapply #87698 and fix overload resolution for Sequence+AsyncSequence types. (#88442)
Since generalizing Sequence methods for typed throws, overload
resolution in an async context prefers the corresponding AsyncSequence
methods which cannot be generalized yet. To fix this, all rethrowing
Sequence methods (except withContiguousStorageIfAvailable) are now
duplicated in a new extension (`extension AsyncSequence where Self:
Sequence`).

_See also: #88221_
2026-04-17 12:28:03 +01:00
Clinton Nkwocha 8a51f7a706 Revert "[stdlib] Generalize Sequence algorithms for typed throws (#87698)" (#88269)
This reverts commit f2798f8ff4.
2026-04-03 10:36:31 +01:00
Steven Wu 12f8d9c6c9 [TEST] Switch to use new swift-driver when running tests
Default to use new swift-driver to run lit tests as legacy swift driver
is deprecated for a long time. The lit tests for legacy drivers are also
disable when running new swift-driver.

Tests that relies on legacy swift driver (for example, tests merge
module) can be enabled on conditions `legacy_swift_driver`. Fix and
split up some existing tests that relies on legacy driver.
2026-03-23 09:48:45 -07:00
Aviva b07c3fc0e8 Merge pull request #87838 from a-viv-a/improve-alias-attribute-diagnostic 2026-03-18 00:25:07 -07:00
Aviva Ruben 2f58b7c57a [Sema] Preserve type alias sugar when removing escaping
This change fixes rdar://172417385 and #45125 by using transformRec
to set no escape, instead of casting which drops sugar. This affects
how interfaces are printed, and could theoretically cause issues with
printing private aliases into public interfaces. Motivated by needing
to be able to diagnose issues with attributes on aliases; without this
change, the alias sugar is sometimes lost.
2026-03-17 11:33:58 -07:00
Clinton Nkwocha f2798f8ff4 [stdlib] Generalize Sequence algorithms for typed throws (#87698)
Generalizes the following `Sequence` methods for typed throws:
`min(by:)`, `max(by:)`, `starts(with:by:)`, `elementsEqual(_:by:)`,
`lexicographicallyPrecedes(_:by:)`, `contains(where:)`,
`allSatisfy(_:)`, `reduce(_:_:)`, `reduce(into:_:)`, `flatMap(_:)`,
`compactMap(_:)`.
2026-03-17 07:32:33 +00:00
Allan Shortlidge 9cfdb17d7e AST: Reorder platforms in PlatformKinds.def.
This allows stable sorting of availability domains to result in an order that
looks more natural when printed in swiftinterface files.
2026-03-12 01:50:31 -07:00
Clinton Nkwocha 2385488c84 Generalize String functions for typed throws (#87495)
Generalizes `String`:
- `init(unsafeUninitializedCapacity:initializingUTF8With:)`
- `withCString(_:)`
- `withCString(encodedAs:_:)`
- `withUTF8(_:)`
- `_withNFCCodeUnits(_:)`

and `Substring`:
  - `withCString(_:)`
  - `withCString(encodedAs:_:)`
  - `withUTF8(_:)`

for typed throws.
2026-03-10 11:27:06 +00:00
Hamish Knight 5a78195bd5 [Sema] Avoid lazy type-checking bindings in closures for completion
Completion can kick lazy type-checking for bindings, make sure we
decline to type-check in a closure since bindings cannot be
type-checked independently of their parent closure.
2026-02-16 11:18:49 +00:00
Hamish Knight 4912cd52a7 [CS] Refuse to match error types
We ought to consider making this an assert, but for now let's bail
out of solving.
2026-02-12 11:34:47 +00:00
Hamish Knight 905e8a04c3 [IDE] Avoid erasing opaque replacement types
The erasing we're doing here is only for printing purposes, that
doesn't really matter for the replacement types and avoids running into
a crash where we incorrectly grab the wrong generic signature.
2026-02-12 11:34:47 +00:00
Doug Gregor fb0f48339a Make @c attribute user-accessible
This makes it available for hasAttribute(c) checks and show up in code
completion.

Fixes rdar://167554912.
2026-01-05 09:39:15 -08:00
Doug Gregor 22ee05e2db Merge pull request #86273 from DougGregor/stdlib-alphabetical-order 2026-01-04 23:28:48 +00:00
Doug Gregor 13b590d99b Make test order-insensitive 2026-01-04 05:12:55 +01:00
Hamish Knight d104ab53fc [test] Disable editor_placeholder_exec.swift for back deployment 2025-12-16 11:02:24 +00:00
Artem Chikin 8e97cb4d8d Implement support for unified warning group behavior queries per-diagnostic
Unified across module-wide configuration flags (`-Wwarning`, `-Werror`, etc.) and syntactic configuration attribute `@warn`.
2025-12-12 10:14:20 -08:00
Kathy Gray fde49b8847 Diagnostics : Increase possibility for missed property diagnostic
Impact for an unknown property access was frequently higher than other options
on ambiguous selections, by 3 to 5 points, causing fix selections that were
farther away and frequently noted to be in accurate. This commit lowers the
impact to be in a similar range to other fixes and this causes property accesses
to be selected more proprotionaly.

In the existing test suite, this changed the diagnostic only in the case of
protocol composition, which was also discovered to be a flawed binding lookup.

Tests added for the property lookup, tests updated for protocol composition
(Including correcting a likely error in a test specification)
2025-12-11 16:08:22 +00:00
Hamish Knight d8a867df86 [Demangler] Handle invertible reqs for extensions in findDeclContext
If we didn't find an extension result, try again disregarding
invertible requirements since `demangleGenericSignature` won't
include them. This is just meant to be a quick low risk fix that we
can cherry-pick, the proper fix here is to delete all this logic and
just return the nominal along with the ABI module name to filter
lookup results.

rdar://165639044
2025-12-08 12:21:29 +00:00
Hamish Knight ae82b29e35 Rework emission of EditorPlaceholderExprs
Rather than synthesizing a semantic expression to emit, add a compiler
intrinsic to the stdlib that is simple enough to just SILGen the
emission.
2025-11-30 11:12:39 +00:00
Hamish Knight e7f5ca954b [Sema] Better handle recovery for structurally invalid ReturnStmts
Make sure we preserve the result expression for an out-of-place
`return`, or a non-`nil` result in an initializer. This ensures we
can still provide semantic functionality from them and fixes a crash
where we would fail to type-check a binding.
2025-11-17 13:07:36 +00:00
Hamish Knight ea79f675ff [test] Convert complete_return to batch-code-completion 2025-11-17 13:07:36 +00:00
Hamish Knight 14608cb059 [Sema] Skip type-checking catch bodies when computing the bound error type
Make sure we only ever type-check the `do` body of a `do-catch`
statement when lazily type-checking the bound error type, which we can
do for completion.

rdar://164481242
2025-11-11 23:04:30 +00:00
Doug Gregor 020b69d4b6 [SE-0497] Implement @export attribute syntax
Implement the @export(implementation) and @export(interface) attributes
to replace @_alwaysEmitIntoClient and @_neverEmitIntoClient. Provide a
warning + Fix-It to start staging out the very-new
@_neverEmitIntoClient. We'll hold off on pushing folks toward
@_alwaysEmitIntoClient for a little longer.
2025-11-07 22:00:40 -08:00
Allan Shortlidge 92227ad1cf AST: Introduce the Swift, anyAppleOS, and DriverKit platform kinds.
This change just stages in a few new platform kinds, without fully adding
support for them yet.

- The `Swift` platform represents availability of the Swift runtime across all
  platforms that support an ABI stable Swift runtime (see the pitch at
  https://forums.swift.org/t/pitch-swift-runtime-availability/82742).
- The `anyAppleOS` platform is an experimental platform that represents all of
  Apple's operating systems. This is intended to simplify writing availability
  for Apple's platforms by taking advantage of the new unified OS versioning
  system announced at WWDC 2025.
- The `DriverKit` platform corresponds to Apple DriverKit which is already
  supported by LLVM.
2025-10-27 19:15:04 -07:00
Guillaume Lessard dc759fded8 [test] add Android to availability attribute test (#85057)
Following up to https://github.com/swiftlang/swift/pull/84574
2025-10-23 19:31:31 +05:30
Hamish Knight 2ce7f1c3bb [Sema] Add for-in lazy type-checking hack for IDE inspection
Avoid type-checking the `where` clause when computing the interface
type of a variable bound in the pattern of the loop as otherwise that
will trigger cycles and give us an ErrorType result.
2025-10-08 21:16:02 +01:00
Hamish Knight 43970362ca [test] Convert complete_loop to %batch-code-completion 2025-10-08 21:16:02 +01:00
Henrik G. Olsson d3214de950 Merge pull request #84685 from hnrklssn/verify-all
This adds the -verify-ignore-unrelated flag. When -verify is used without -verify-ignore-unrelated, diagnostics emitted in buffers other than the main file and those passed with -verify-additional-file (except diagnostics emitted at <unknown>:0) will now result in an error. They were previously ignored. The old behaviour is still available as opt-in using -verify-ignore-unrelated, but by being strict by default it should make it harder to accidentally miss diagnostics.

To avoid unnecessary performance overhead, -verify-additional-file is still required to parse the expected-* directives in files other than the main file.
2025-10-06 18:01:47 -07:00
Henrik G. Olsson cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Hamish Knight 669a2ce9b0 [CS] Sink placeholder handling logic into Solution::simplifyType
Move the logic from `FailureDiagnostic::resolveType` into
`Solution::simplifyType` to allow completion to use it too. While
here, also handle cases where the placeholder is from a different
member of the equivalence class to the generic parameter.
2025-10-04 12:56:52 +01:00
Henrik G. Olsson 90e3d1c415 Merge pull request #84604 from ramonasuncion/test-ide-frontend-env
[Test][IDE] Add env to frontend commands
2025-10-01 18:55:11 -07:00
Ramon Asuncion a8433351eb [Test][IDE] Add env to frontend commands 2025-09-30 19:47:47 -07:00
Ramon Asuncion 1ba5cbcbe7 [Test][IDE] Replace process substitution with temp file for internal shell
Replace `diff -u <(tail -n +9 %s) %t.txt` substitution with a temp file
for LLVMs LIT internal shell

Note: Start tail at line 10 to skip `// EXPECTED OUTPUT STARTS BELOW THIS LINE`
so the temp file matches the actual compiler output
2025-09-30 19:45:31 -07:00
Hamish Knight cb61e89bc1 Merge pull request #84569 from hamishknight/ex-fail
[test] Remove some unnecessary completion XFAILs
2025-09-29 22:25:42 +01:00
Hamish Knight 3b056039de [test] Remove some unnecessary completion XFAILs
All the cases now work correctly and just need a small tweak to the
expectation.
2025-09-29 16:55:34 +01:00
Hamish Knight a7dd04ed6f Merge pull request #84403 from a7medev/refactor/signature-help-to-ide
[IDE] Move signature help formatting to IDE instead of SourceKit
2025-09-29 14:05:02 +01:00
Ahmed Mahmoud 456a40a7bb [Test] Improve signature help tests 2025-09-26 22:39:46 +03:00
Hamish Knight 0bfbe987b4 [AST] Print ErrorType as _
In preparation for removing UnresolvedType in favor of ErrorType,
start printing ErrorType as `_` unless we've enabled debug printing.
`<<error type>>` should never be presented to the user, instead `_`
now just consistently means "unknown type".
2025-09-21 23:19:06 +01:00
Hamish Knight 14a125c2ca [IDE] Use consistent PrintOptions in swift-ide-test
Use the same set of PrintOptions when printing the results for
different requests.
2025-09-21 23:19:06 +01:00
Ahmed Mahmoud 236fed20aa [Test] Remove redundant signature parameter name="" in swift-ide-test 2025-09-19 21:03:05 +03:00
Ahmed Mahmoud 979ccd1f50 [Test] Use swift-ide-test for signature help tests 2025-09-19 21:03:05 +03: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
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