Commit Graph

1516 Commits

Author SHA1 Message Date
Hamish Knight
00d8774032 [Sema] Upgrade tuple shuffle warning to error in future lang mode
This has been deprecated for a while now, flip it to an error for a
future language mode.
2025-10-29 15:14:23 +00:00
Hamish Knight
24347812f5 [Diag] Reword the tuple shuffle diagnostic
"reorder" seems a bit less jargony than "shuffle", and include the 
labels that are being reordered.
2025-10-29 15:14:23 +00:00
Becca Royal-Gordon
e6d8b02626 Make module selectors non-experimental
Approved by SE-0491.
2025-10-24 16:23:50 -07:00
Becca Royal-Gordon
78a7df8d4a Merge pull request #85018 from beccadax/this-is-the-key-path 2025-10-21 16:27:38 -07:00
Becca Royal-Gordon
c58c307c2e Don’t redundantly diagnose key path components
A key path component that resolved to an `ErrorExpr` would be diagnosed twice: once when the `ErrorExpr` was created, then again when it was processed. Fix this redundant diagnostic.
2025-10-20 15:11:14 -07:00
Becca Royal-Gordon
96e6b1d618 Fix malformed arg label error with module selector
The legacy parser has a special case for code like `fn(:)` which corrects it to `fn(_:)`, but the new `::` token was interfering with cases where there were two adjacent colons (e.g. `fn(::)`). Correct this issue.
2025-10-18 03:15:53 -07:00
Becca Royal-Gordon
58954734a0 [NFC-ish] Do lookahead without llvm::function_ref 2025-10-16 13:30:29 -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
9f5a754b77 [Sema] Ban placeholders in typed throws
This never worked correctly and would crash in SILGen, ban the use
of placeholder types. While here, ensure we replace any ErrorTypes
with holes when solving the closure in the constraint system.
2025-09-17 20:41:20 +01: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
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
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
5c3f6703a0 Remove diag::type_of_expression_is_ambiguous
This is a diagnostic that is only really emitted as a fallback when
the constraint system isn't able to better diagnose the expression.
It's not particulary helpful for the user, and can be often be
misleading since the underlying issue might not actually be an
ambiguity, and the user may well already have a type annotation. Let's
instead just emit the fallback diagnostic that we emit in all other
cases, asking the user to file a bug.
2025-08-19 17:14:23 +01:00
Mykola Pokhylets
89f8f8b9bf Wrap only changes related to the closure frontend logic 2025-08-02 20:24:46 +02:00
Mykola Pokhylets
ae48446716 Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved 2025-08-02 20:24:21 +02:00
Allan Shortlidge
99380bf00f Sema: Sometimes allow universally unavailable declarations to be referenced.
In implicit contexts that are universally unavailable, allow writable key paths
to be formed to properties with setters that are also marked as universally
unavailable. This fixes a regression from the previous commit where the code
synthesized for `@Observable` properties in universally unavailable classes was
rejected by the availability checker.
2025-07-15 14:08:57 -07:00
Allan Shortlidge
4076fa6b2e ConstraintSystem: Make key paths for properties with unavailable setters read-only.
Previously, only conditional unavailability was considered, but setters that
are always unavailable must also make a keypath read-only.

Resolves rdar://155832511.
2025-07-15 10:33:44 -07:00
Pavel Yaskevich
2957da3591 [ConstraintSystem] Disable performance hacks by default
This also changes the flag to `-enable-constraint-solver-performance-hacks`.
2025-06-27 23:43:09 -07:00
Doug Gregor
c34f81e110 Allow #selector to reference async method in non-async code
Fixes rdar://153118331
2025-06-23 12:41:18 -07:00
Hamish Knight
b37e34ea8d [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:46 +01:00
Mike Ash
53aa827f8f Merge pull request #81957 from mikeash/implicit-weak-capture-test-timing-fix
[Test] Make implicit_weak_capture.swift more robust.
2025-06-10 15:14:35 -04:00
Anthony Latsis
f2e1420a90 Sema: Never record argument label mismatches for unlabeled trailing closures
Fixes a crash on invalid. The previous logic was causing a label
mismatch constraint fix to be recorded for an unlabeled trailing closure
argument matching a variadic paramater after a late recovery argument
claim in `matchCallArgumentsImpl`, because the recovery claiming skips
arguments matching defaulted parameters, but not variadic ones. We may
want to reconsider that last part, but currently it regresses the
quality of some diagnostics, and this is a targeted fix.

The previous behavior is fine because the diagnosis routine associate
with the constraint fix (`diagnoseArgumentLabelError`) skips unlabeled
trailing closures when tallying labeling issues — *unless* there are no
other issues and the tally is zero, which we assert it is not.

Fixes rdar://152313388.
2025-06-05 18:01:20 +01:00
Mykola (Nickolas) Pokhylets
87e536ebec Merge pull request #80440 from nickolas-pohilets/mpokhylets/weak-let 2025-06-05 09:59:33 +02:00
Mike Ash
d0248afd14 [Test] Make implicit_weak_capture.swift more robust.
This test creates an object then checks a weak reference to that object on a background thread. It was doing this check after 10ms, and any small hiccup could potentially delay the object's destruction enough to spuriously fail.

Rearrange the test to check the weak reference in a loop for several seconds before giving up. This makes it very fast on success (it's done the moment it sees nil) while being robust against up to several seconds of delay in destroying the object if that happens.

rdar://149868181
2025-06-03 17:08:41 -04:00
Pavel Yaskevich
4132aa04f9 [Tests] NFC: Update all of the test-cases improved by changes to generic argument mismatch handling 2025-06-03 00:49:06 -07:00
Pavel Yaskevich
dad81fb4bc Merge pull request #81779 from xedin/diagnostic-fixes
[Diagnostics] A collection of diagnostic fixes/improvements
2025-05-30 18:37:16 -07:00
Doug Gregor
73031240fa Effects: Treat #selector as covering throws/async effects in its operand
Fixes rdar://151968656
2025-05-30 10:50:32 -07:00
Pavel Yaskevich
ded6158cc3 [CSSimplify] Detect when generic argument mismatch applies to argument and produce a tailed fix
The problem detection logic currently expects `generic argument #<N>`
location to always be associated with two generic types, but that
is not always the case, this locator element is sometimes used for
i.e. optional object types and pointer `Pointee` type when types
appear in argument positions. This needs to be handled specifically.

Resolves: rdar://82971941
2025-05-30 09:52:57 -07:00
Mykola Pokhylets
b138c2cc35 Updated logic for diagnosting implicit self capture to handle immutable weak capture (minor source-breaking change) 2025-05-19 16:31:01 +02:00
Mykola Pokhylets
4aa2847ad6 Fixed some tests
Remaining failures:

DebugInfo/guard-let-scope4.swift
expr/closure/closures.swift
SILGen/capture-transitive.swift
SILGen/dynamic_self.swift
SILGen/unowned-class-bound-generic-parameter.swift
2025-05-19 09:37:03 +02:00
Mykola Pokhylets
3e0de8672a Removed the feature and made changes unconditional 2025-05-15 10:52:09 +02:00
Mykola Pokhylets
5a69c8ebdb Added REQUIRES: swift_feature_WeakLet 2025-05-15 10:26:27 +02:00
Mykola Pokhylets
26106107eb Updated existing tests to run with feature enabled 2025-05-15 10:26:27 +02:00
Hamish Knight
3c67271869 [AST] Handle a few more cases in getStartLoc()
Handle PatternBindingDecls with missing var locations, which can
happen for loop iterator vars, and FuncDecls with missing name and
func locations, which can happen for `defer`. Also while here make
sure we set the source location of a parser-produced ErrorExpr.
2025-05-14 11:15:42 +01:00
Anthony Latsis
4f4141fea8 Frontend: Obsolete -fixit-all and -emit-fixits-path
With `ARCMigrate` and `arcmt-test` removed from clang in
https://github.com/llvm/llvm-project/pull/119269 and the new code
migration experience under way (see
https://github.com/swiftlang/swift-evolution/pull/2673), these options
are no longer relevant nor known to be in use. They were introduced
long ago to support fix-it application in Xcode.

For now, turn them into a no-op and emit a obsoletion warning.
2025-05-07 02:30:30 +01:00
Pavel Yaskevich
f61a3c941b Merge pull request #80443 from xedin/rdar-148256978
[CSBindings] Avoid delaying leading-dot inference only if chain is di…
2025-04-02 11:08:44 -07:00
Pavel Yaskevich
d34222d461 [CSBindings] Avoid delaying leading-dot inference only if chain is directly connected to a contextual type
Additional restrictions on when protocol inference could be considered
viable. If the chain is connected directly to a contextual type there
cannot be any other inference sources for the base type.

Resolves: rdar://148256978
2025-04-01 10:33:30 -07:00
Doug Gregor
fd24d29055 Merge pull request #80357 from DougGregor/strict-safety-improvements
Strict safety improvements
2025-03-28 11:58:44 -07:00
Doug Gregor
d86f41a922 Improve Fix-It for if let x where x is a reference to an unsafe value
When we encounter unsafe code in `if let x`, we would produce a Fix-It
that would change it to the ill-formed `if let unsafe x`. Improve
tracking of the expressions that are synthesized for the right-hand
side of these conditions, so that we can produce a Fix-It that turns
this into the proper

    if let x = unsafe x

Fixes rdar://147944243.
2025-03-27 16:20:30 -07:00
Karoy Lorentey
26176cc929 [stdlib] Allow metatypes of noncopyable/nonescapable types to get compared 2025-03-24 12:16:08 -07:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
15c219cd70 [Tests] Add tests. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
78e7f6a72d [Tests] Update tests. 2025-03-19 10:54:09 -07:00
Pavel Yaskevich
db2b9f08d2 [Tests] NFC: Update and add a few test-cases related to noncopyable types in key path context 2025-03-18 13:47:00 -07:00
Slava Pestov
f07a16f92d Sema: Disable special handling of OneWayEqual constraints 2025-03-11 13:55:39 -04:00
Doug Gregor
2989770cd6 Merge pull request #79352 from DougGregor/strict-sendable-metatypes
Add StrictSendableMetatypes to require Sendable requirements on metatypes
2025-02-14 03:40:36 -08:00
Doug Gregor
ed6dccf12c Diagnose captured of non-sendable metatypes crossing isolation boundaries
Keep track of all of the type parameters and archetypes that are captured
by a local function or closure. Use that information to diagnose cases
where a non-Sendable metatype crosses an isolation boundary.
2025-02-13 17:07:09 -08:00
Pavel Yaskevich
725bd910be [ConstraintSystem] Revert new disjunction favoring algorithm (#79128)
* Revert "[CSOptimizer] Look through `OptionalEvaluationExpr`s when dealing with unapplied disjunctions"

This reverts commit 72340f39b8.

* Revert "[CSOptimizer] Don't consider disabled overloads when checking whether disjunction is supported"

This reverts commit 6bc23b5057.

* Revert "[CSOptimizer] Disjunctions with IUO overload choices are unsupported"

This reverts commit 471ee21535.

* Revert "[CSOptimizer] MemberImportVisibility: Don't consider overloads that come from implicit imports"

This reverts commit aa4a2b9071.

* Revert "[CSOptimizer] Don't consider CGFloat widening when explicit initializer is used"

This reverts commit 3cc76eacdd.

* Revert "[CSOptimizer] Literal arguments should cause score reset only for operators"

This reverts commit e3987beffb.

* Revert "[CSOptimizer] NFC: check whether a choice is of operator instead of whole disjunction"

This reverts commit 6c82892c3c.

* Revert "[CSOptimizer/Tests] NFC: Add a perf test-case fixed by improved literal array handling"

This reverts commit cfd34e54c4.

* Revert "[CSOptimizer] Extend candidate/parameter matching to support array literals"

This reverts commit 8a304f88c6.

* Revert "[CSOptimizer] Favor choices that don't require application"

This reverts commit 0737542da8.

* Revert "[CSOptimizer] Disable CGFloat -> Double conversion for unary operators"

This reverts commit bc3a15fbe6.

* Revert "[CSOptimizer] Mark bitwise operators as supported"

This reverts commit 860ae08d1b.

* Revert "[CSOptimizer] Simplify handling of non-applied disjunctions"

This reverts commit 43ca7dfff9.

* Revert "[ConstraintSystem] Fix `getEffectiveOverloadType` handling of `mutating` methods"

This reverts commit c767f7aff7.

* Revert "[CSOptimizer] Reduce overload types before ranking"

This reverts commit 95b47aead6.

* Revert "[CSOptimizer] Implement special prioritization rules for result builder contexts"

This reverts commit 56d6635e46.

* Revert "[CSOptimizer] Allow only widening CGFloat->Double conversions while matching candidate arguments"

This reverts commit bf8ae3bc1b.

* Revert "[CSSimplify] CGFloat-Double: Rank narrowing correctly when result is injected into an optional"

This reverts commit cb876cbd9e.

* Revert "[CSBindings] Prevent `BindingSet::isViable` from dropping viable bindings (v2)"

This reverts commit b7e7493076.

* Revert "[CSOptimizer] Add support for chained members without arguments"

This reverts commit 87cd5f8733.

* Revert "[CSOptimizer] Mark compiler synthesized disjunctions as optimized"

This reverts commit 867e64182f.

* Revert "[CSOptimizer] Make a light-weight generic overload check if some requirements are unsatisfiable"

This reverts commit 15c773b9d7.

* Revert "[CSOptimizer] Fix `selectDisjunction` to use favored choices even if disjunction was not optimized"

This reverts commit c2a55886f0.

* Revert "[CSOptimizer] Limit "old" behavior compatibility to unlabeled unary arguments"

This reverts commit 9fb73143f6.

* Revert "[Tests] NFC: Update a couple of type-checker tests"

This reverts commit ff8663ff16.

* Revert "[Tests] NFC: Move simd related test-case from `slow` to `fast`"

This reverts commit 28396a6dce.

* Revert "[CSGen] NFC: Remove obsolete `ConstraintSystem::{get, set}FavoredType`"

This reverts commit 8bd288447f.

* Revert "[CSOptimizer] Allow literal arguments to match parameters that conform to `ExpressibleBy{Integer, Float}Literal`"

This reverts commit 2fdd4b6c35.

* Revert "[CSOptimizer] Adjust `scoreCandidateMatch` to indicate when match cannot be decided"

This reverts commit 9b62c84a4f.

* Revert "[CSOptimizer] Fix Double<->CGFloat implicit conversion support when arguments are literals"

This reverts commit 6caf1ccbb2.

* Revert "[CSOptimizer] A more comprehensive generic overload checking when candidates are fully resolved"

This reverts commit e30587bda4.

* Revert "[CSOptimizer] Restore old hack behavior which used to favor overloads based on arity matches"

This reverts commit a3a3ec4fe0.

* Revert "[CSOptimizer] Desugar types before checking for equality"

This reverts commit 802f5cd105.

* Revert "[ConstraintSystem] Narrowly disable `tryOptimizeGenericDisjunction` when some of the arguments are number literals"

This reverts commit 8d5cb112ef.

* Revert "[CSOptimizer] Infer argument candidates from calls to `Double` and CGFloat constructors"

This reverts commit f2a6677a6d.

* Revert "[CSOptimizer] Score all of the overload choices matching on literals uniformly"

This reverts commit 59109c2d60.

* Revert "[CSOptimizer] Enable ranking of `Int*`, `Float{80}` and `Double` initializers"

This reverts commit 6fb6d1cf90.

* Revert "[CSOptimizer] Rank disjunctions based on score only if both sides are supported"

This reverts commit 8818d399f9.

* Revert "[CSOptimizer] Rank results of operators regardless of whether anything is known about parameters"

This reverts commit 3996b25fbd.

* Revert "[Tests] NFC: Add more test-cases that were previously solved due to old hacks behavior"

This reverts commit d0ff6c81b8.

* Revert "[CSOptimizer] Average score should reflect number of defaulted parameters"

This reverts commit 23589add74.

* Revert "[Tests] NFC: Adjust a couple of improved tests"

This reverts commit 66981364fe.

* Revert "[CSOptimizer] Don't optimize (implicit) calls with code completion arguments"

This reverts commit 8a918e2369.

* Revert "[CSOptimizer] attempt to rank only standard/simd operators and fully concrete overload sets"

This reverts commit deca9b61c5.

* Revert "[CSOptimizer] Record best scores for each disjunction and use them in `selectDisjunction`"

This reverts commit 3819ddfb40.

* Revert "[CSOptimizer] Let `determineBestChoicesInContext` return the best disjunction if one is available"

This reverts commit cf05405eae.

* Revert "[CSOptimizer] Emulate old behavior related to favoring of unary calls to members"

This reverts commit 527de22bec.

* Revert "[Tests] NFC: Add a test-case for rdar://133340307 which is now fast"

This reverts commit 670127abd6.

* Revert "[CSOptimizer] Prefer homogeneous arithmetic operator overloads when argument(s) or result match"

This reverts commit d69b6a0594.

* Revert "[CSOptimizer] Remove an outdated optimization to compare resolved argument types with all else equal"

This reverts commit 1760bd1f1e.

* Revert "[CSOptimizer] NFC: Switch from llvm::Optional to std::optional post-rebase"

This reverts commit c429f5b9ec.

* Revert "[CSOptimizer] Increase score when type matches opaque type"

This reverts commit 2869dff995.

* Revert "[CSOptimizer] NFC: Switch to llvm::Optional"

This reverts commit 0fc6806922.

* Revert "[CSOptimizer] NFC: Adjust conformance check to use `ConstraintSystem::lookupConformance`"

This reverts commit da65333d41.

* Revert "[CSOptimizer] Treat all type parameters equally"

This reverts commit 957a5f4270.

* Revert "[CSStep] Remove disjunction pruning logic from DisjunctionStep"

This reverts commit 2c44e37948.

* Revert "[CSOptimizer] Relax candidate type requirements from equality to set of no-impact conversions"

This reverts commit 11b897b32f.

* Revert "[CSOptimizer] Use `matchCallArguments` to establish argument-to-parameter relationships"

This reverts commit cb1cb2018d.

* Revert "[CSOptimizer] Don't attempt to optimize calls with code completion token(s) in argument position"

This reverts commit 14e2a16fce.

* Revert "[CSOptimizer] Allow generic operator overloads without associated type parameters"

This reverts commit bc5f70a9a3.

* Revert "[CSOptimizer] Make sure that all parameters without arguments are defaulted"

This reverts commit 7c1c46d4e4.

* Revert "[CSStep] Don't favor choices until the disjunction is picked"

This reverts commit e404ed722a.

* Revert "[CSOptimizer] Keep track of mismatches while evaluating candidates"

This reverts commit a094c3ebb0.

* Revert "[CSOptimizer] Favor SIMD related arithmetic operator choices if argument is SIMD<N> type"

This reverts commit c2f7451c7b.

* Revert "[CSOptimizer] Initial implementation of disjunction choice favoring algorithm"

This reverts commit 672ae3d252.

* Revert "[ConstraintSystem] Add skeleton of constraint optimizer"

This reverts commit b5f08a4009.

* Revert "[CSGen] Remove ConstraintOptimizer and all favoring logic"

This reverts commit 4432c51f57.

* Revert "[ConstraintSystem] Remove `shrink`"

This reverts commit 757ca24e8a.

* [TypeChecker] NFC: Remove resurrected use of `SolverShrinkUnsolvedThreshold`

* [TypeChecker] Bring back `SolverDisableShrink`

* [Tests] NFC: Mark tests affected by solver-perf revert as slow

* [Tests] NFC: Adjust async tests that are affected by performance hacks
2025-02-13 08:06:24 -08:00
Hamish Knight
f828882668 Merge pull request #78738 from calda/cal--fix-nested-weak-self-issue
Fix issue where implicit self was unexpectedly not allowed in nested weak self closure in Swift 6 mode
2025-02-11 11:17:11 +00:00