Commit Graph

357 Commits

Author SHA1 Message Date
Karoy Lorentey
26176cc929 [stdlib] Allow metatypes of noncopyable/nonescapable types to get compared 2025-03-24 12:16:08 -07: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
Pavel Yaskevich
11b897b32f [CSOptimizer] Relax candidate type requirements from equality to set of no-impact conversions
Candidate is viable (with some score) if:

- Candidate is exactly equal to a parameter type
- Candidate type differs from a parameter type only in optionality
- Parameter is a generic parameter type and all conformances are matched by a candidate type
- Candidate tuples matches a parameter tuple on arity
- Candidate is an `Array<T>` and parameter is an `Unsafe*Pointer`
- Candidate is a subclass of a parameter class type
- Candidate is a concrete type and parameter is its existential value (except Any)
2024-12-17 11:36:38 -08:00
Pavel Yaskevich
55b8d9538d [CSSimplify] Rework how/when mismatches between optional types are fixed
- Don't attempt to insert fixes if there are restrictions present, they'd inform the failures.

  Inserting fixes too early doesn't help the solver because restriction matching logic would
  record the same fixes.

- Adjust impact of the fixes.

  Optional conversions shouldn't impact the score in any way because
  they are not the source of the issue.

- Look through one level of optional when failure is related to optional injection.

  The diagnostic is going to be about underlying type, so there is no reason to print
  optional on right-hand side.
2024-09-10 10:35:05 -07:00
Hamish Knight
4beaaf32ad [CS] Improve placeholder diagnostics slightly
Make sure `CouldNotInferPlaceholderType` can
produce a diagnostic for a `PlaceholderType`
locator element, and avoid emitting an extra
diagnostic for a placeholder type in an invalid
position.
2024-07-07 23:42:33 +01:00
Crazy凡
4e346c1cf8 Add test cases for the 'nil coalescing operator'. 2023-07-04 18:21:26 +08:00
Luciano Almeida
fef908efac [Sema] Increase impact of ternary then branch aiming better diagnostics 2023-05-30 20:55:50 -03:00
Pavel Yaskevich
4f2a1752c2 [ConstraintSystem] Produce ambiguity notes based on the fix aggregate
It shouldn't matter how many fixes does the solution have overall,
what matter is how many fixes are there for the location in question.
2023-03-06 10:17:51 -08:00
Luciano Almeida
22a18de1b1 [Sema] Improving integer literal as boolean diagnostic 2023-02-21 10:30:48 -03:00
Pavel Yaskevich
1c076f0e2b [CSSimplify] Allow conversions between tuple element type and a placeholder
If a placeholder appears on one of the side of tuple element matching
conversion, consider that conversion to be solved, because the actual
error is related to the placeholder.
2023-01-12 18:16:43 -08:00
Doug Gregor
9d24f447b7 Remove special handling of __FILE__, __LINE__, etc.
These were replaced by `#file`, `#line`, etc. with SE-0028, prior to
Swift 3. We don't need this custom error message any more, and they
shouldn't be keywords. Stop treating them as keywords in the lexer.
2022-12-10 15:38:09 -08:00
Pavel Yaskevich
149e57a0cb Merge pull request #60893 from calda/cal--warn-redundant-comparison-to-optional.none-case
Add warning when comparing a non-optional value to `Optional.none`
2022-09-12 00:36:24 -07:00
Cal Stephens
c2bf0f943e Revert "Combine the two diagnostics"
This reverts commit 2e7656218e.
2022-09-01 08:11:46 -07:00
Cal Stephens
2e7656218e Combine the two diagnostics 2022-09-01 06:23:42 -07:00
Cal Stephens
88b65f406f Update tests 2022-08-31 20:14:41 -07:00
Anthony Latsis
45f5f08fa0 Gardening: Migrate test suite to GH issues: expr 2022-08-26 22:20:52 +03:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Pavel Yaskevich
8f69b9f2e0 [ConstraintSystem] Use '# of overloads' as a tie-breaker in ambiguities
The deepest expression is the one that introduced the ambiguity into
the chain, so depth and index should be deciding factors and number of
overloads - a tie-breaker, while choosing what to diagnose.

Resolves: rdar://94360230
2022-06-07 15:53:13 -07:00
Serena
e05f68c822 Change diagnostic error thrown for when string interpolations aren't closed by a parenthesis (#58882)
[Parse] Diagnose unclosed string interpolations
2022-06-04 19:32:41 +03:00
Josh Soref
92a1c4bc28 Spelling test expr (#58577)
* spelling: expressions

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: lousy

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: refers

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: should

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-04 14:16:58 -07:00
Pavel Yaskevich
a0d132582e [Diagnostics] Improve diagnostic message for extraneous &
Resolves: https://github.com/apple/swift/issues/58389
2022-04-25 15:08:04 -07:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Slava Pestov
4655fc359b Sema: Make a couple of TypeResolver methods idempotent
When emitting a diagnostic, mark the TypeRepr as invalid and
return an ErrorType to ensure that the diagnostic is not
emitted again, and to muffle downstream diagnostics.
2022-02-15 04:02:46 -05:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Pavel Yaskevich
67d87e104f [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2021-11-15 16:42:06 -08:00
Robert Widmann
ffff35465c Restore Top-Level Placeholder Restrictions in Expression Position
Respect the text of https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md#top-level-type-placeholders and re-restrict the usage of placeholders in top-level expressions.
2021-11-03 12:50:02 -07:00
Robert Widmann
22ad19f64b Revert "[Sema] Diagnose and reject top-level placeholders"
This reverts commit f6b6bff6de.
2021-11-03 10:29:14 -07:00
Hamish Knight
8c2b88abc0 [CS] Adopt ArgumentList
- Explicitly limit favoring logic to only handle
unary args, this seems to have always been the
case, but needs to be handled explicitly now that
argument lists aren't exprs
- Update the ConstraintLocator simplification to
handle argument lists
- Store a mapping of locators to argument lists
in the constraint system
- Abstract more logic into a getArgumentLocator
method which retrieves an argument-to-param locator
from an argument anchor expr
2021-09-01 18:40:25 +01:00
Frederick Kellison-Linn
f6b6bff6de [Sema] Diagnose and reject top-level placeholders 2021-08-19 14:53:34 -04:00
Frederick Kellison-Linn
16a4031c32 [tests] Update tests with modified diagnostics 2021-08-19 14:53:34 -04:00
Pavel Yaskevich
1965f3ec3c [CSBindings] Literal coverage checking should account for type variable/hole embedded in optional
Currently `isLiteralCoveredBy` only checks for top-level type variable or hole.

That check has to be sunk down so it could be used after optionality is stripped
away (when possible), otherwise bindings like `$T0?` are (incorrectly) determined
to cover literal requirements (because conformance check always succeeds when
attempted on a type variable).
2021-02-01 17:52:29 -08:00
Minhyuk Kim
7eaabe1996 Simplify unused lvalue warning wording 2021-01-15 22:14:56 +09:00
Luciano Almeida
0638a9af33 [test] Adjusting l-value resolves to unused variable test cases 2020-12-28 22:03:03 -03:00
Pavel Yaskevich
607f49dc2e [TypeChecker] Find outermost paren or tuple while checking invalid inout use
Unwrap `InOutExpr` from all parens until the outermost paren or a tuple
to correctly diagnose calls like `foo(((&bar)))` or `foo(x: (&bar))`,
 and suggest a fix-it with moves `&` outside parens.

Resolves: rdar://problem/71356981
2020-11-19 13:31:10 -08:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Slava Pestov
bd36100cb3 Update tests in preparation for disabling parser lookup
I created a second copy of each test where the output changes
after disabling parser lookup. The primary copy now explicitly
calls the frontend with -disable-parser-lookup and expects the
new diagnostics; the *_parser_lookup.swift version calls the
frontend with -enable-parser-lookup and has the old expectations.

This allows us to turn parser lookup on and off by default
without disturbing tests. Once parser lookup is completely
removed we can remove the *_parser_lookup.swift variants.
2020-10-03 09:37:55 -04:00
Pavel Yaskevich
7ce37dd14d [TypeChecker] NFC: Adjust test-cases improved by changes in binding inference 2020-07-15 20:50:50 -07:00
Pavel Yaskevich
b0070f5739 [Diagnostics] Check whether all contextual mismatches has the same type before diagnosing ambiguity
Instead of requiring sub-classes of `ContextualMismatch` to implement
`diagnoseForAmbiguity` let's implement it directly on `ContextualMismatch`
itself and check whether all of the aggregated fixes have same types on
both sides and if so, diagnose as-if it was a single fix.
2020-06-12 11:47:04 -07:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Pavel Yaskevich
16c1f50eda [ConstraintSystem] Diagnose incorrect use of _ during constraint generation
`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
0ecedfa5ea Revert "[ConstraintSystem] Make it possible to infer subtype bindings through argument conversions"
Reverts apple/swift#30006. It caused a regression that we'd like to address before re-landing:

```swift
struct X {
  var cgf: CGFloat
}

func test(x: X?) {
  let _ = (x?.cgf ?? 0) <= 0.5
}
```

This reverts commit 0a6b444b49.
This reverts commit ed255596a6.
This reverts commit 3e01160a2f.
This reverts commit 96297b7e39.

Resolves: rdar://problem/60185506
2020-03-07 20:16:56 -08:00
Pavel Yaskevich
96297b7e39 [CSStep] Always attempt literal bindings in diagnostic mode
In case of contextual failures such bindings could produce
better solutions with fewer fixes.
2020-02-21 17:47:39 -08:00
Pavel Yaskevich
f6b7df161c [ConstraintSystem] Increase impact of a missing conformance related to stdlib type
Prioritize type mismatches over conformance failures when stdlib
types are involved because it wouldn't be appropriate to suggest
to add such a conformance, so the problem is most likely related
to something else e.g. other overload choice has a better fix.

Consider following example:

```swift
struct S {
  init(_: Double) {}
  init<T: BinaryInteger>(_: T) {}
}

_ = S(Double("0"))
```

In cases like that it's better to prefer failable initializer
which takes a `String` and returns `Double?` and diagnose a
problem related to missing optional unwrap instead of missing
conformances related to a `String` argument of other `Double`
initializer just because it returns a concrete type.
2020-02-17 16:09:11 -08:00
Pavel Yaskevich
0a8de8bda8 [ConstraintSystem] Allow simplifyRestrictedConstraintImpl to diagnose contextual failures with optionals
Since `simplifyRestrictedConstraintImpl` has both parent types and
does nested type matching it's a good place to diagnose top-level
contextual problems like mismatches in underlying types of optionals.
2020-02-17 16:09:11 -08:00
Robert Widmann
a9e871a0b1 [Sema] Warn About Tuple Shuffles
Emit a warning that tuple shuffling is deprecated across the board. In
the future, we should try to unshuffle these expressions where we can,
but that's a diagnostic improvement for another day.

See also https://forums.swift.org/t/deprecating-tuple-shuffles-round-2/16884/30
2020-02-13 17:29:03 -08:00
Owen Voorhees
166555c34f [Diagnostics] Better diagnostic for integer used as a boolean condition 2020-02-03 21:20:41 -08:00
Pavel Yaskevich
dea79e09c6 [ConstraintSystem] Detect that function type has failures before applying arguments
If a type variable representing "function type" is a hole
or it could be bound to some concrete type with a help of
a fix, let's propagate holes to the "input" type. Doing so
provides more information to upcoming argument and result matching.
2020-01-27 16:53:33 -08:00
Holly Borla
74f65ba2ce [ConstraintSystem] Find solutions for code with invalid '_' using
holes.
2020-01-23 10:48:55 -08:00
Holly Borla
f9a1ab28f4 [ConstraintSystem] Port tuple type mismatches to the new framework 2019-12-06 13:12:57 -08:00
Slava Pestov
1df3d1a33c Frontend: Don't interleave parsing and typechecking for the main file
SIL files still require this behavior; if we cleaned that up we
could simplify a fair bit of code here.

Fixes <https://bugs.swift.org/browse/SR-284>,
<https://bugs.swift.org/browse/SR-4426>.
2019-12-05 08:45:55 -05:00