Commit Graph

561 Commits

Author SHA1 Message Date
omochimetaru
eb2d4b62b2 add regression test 2024-12-15 21:11:46 +09:00
Pavel Yaskevich
fb54682753 [CSSimplify] Don't match pack expansion patterns if shapes are not the same
This helps to avoid spurious failures pointing to involved pattern types
because they won't match exactly if shape types are not the same.
2024-12-12 20:55:02 -08:00
Pavel Yaskevich
7701f4e0dd [CSSimplify] Avoid resolving extraneous (trailing) closures
If a (trailing) closure is determined to be an extraneous argument
for one of the overload choices it needs to be marked as hole as
eagerly as possible and prevented from being resolved because
otherwise it's going to be disconnected from the rest of the
constraint system and resolution might not be able to find all of
the referenced variables. This could result either in crashes
or superfluous diagnostics.

Resolves: rdar://141012049
2024-12-06 16:41:49 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Pavel Yaskevich
9eaad6315c Merge pull request #77689 from JanBaig/issue-65500
[CSGen] Fix compiler crash when property wrapper applied to a param lacks wrappedValue initializer
2024-11-20 08:44:49 -08:00
JanBaig
8af3aef7c4 [CSGen] Fix compiler crash when property wrapper applied to a param lacks wrappedValue initializer 2024-11-18 19:23:28 -05:00
Pavel Yaskevich
7c35c881a9 [CSSimplify] CGFloat-Double: Fix ambiguity when assigning CGFloat to double property/variable
Situations like:
```
  let _: Double = <<CGFloat>>
  <var/property of type Double> = <<CGFloat>>
```

Used to be supported due to an incorrect fix added in
diagnostic mode. Lower impact here means that right-hand
side of the assignment is allowed to maintain CGFloat
until the very end which minimizes the number of conversions
used and keeps literals as Double when possible.

Resolves: rdar://139675914
2024-11-13 13:45:56 -08:00
Slava Pestov
f702e46751 Merge pull request #77475 from slavapestov/fix-rdar139237781
Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
2024-11-08 15:15:27 -05:00
Slava Pestov
d67e89d89c Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
When we replay a solution, we must record changes in the trail, so fix the
logic to do that. This fixes the first assertion failure with this test case.

The test case also exposed a second issue. We synthesize a CustomAttr in
applySolutionToClosurePropertyWrappers() with a type returned by simplifyType().
Eventually, CustomAttrNominalRequest::evaluate() looks at this type, and passes
it to directReferencesForType(). Unfortunately, this entry point does not
understand type aliases whose underlying type is a type parameter.
However, directReferencesForType() is the wrong thing to use here, and we
can just call getAnyNominal() instead.

Fixes rdar://139237781.
2024-11-08 10:46:07 -05:00
Pavel Yaskevich
392dac41f1 [CSSolver] DynamicMemberLookup: Ignore disabled choices while filtering disjunctions
`filterDisjunction` should ignore the choices that are already
disabled while attempting to optimize disjunctions related to
dynamic member lookup.

Resolves: rdar://139314763
2024-11-07 18:31:52 -08:00
Pavel Yaskevich
c5d0916746 [BuildTransform] Fix walkExplicitReturnStmts to walk implicit statements
Some statements introduce implicit braces and other things,
`walkExplicitReturnStmts` cannot ignore that while trying
to find explicit returns.

Resolves: rdar://139235128
2024-11-04 16:42:50 -08:00
Slava Pestov
308b4f4161 Sema: Re-enable validation-test/Sema/type_checker_perf/slow/nil_coalescing.swift.gyb 2024-10-22 20:14:42 -04:00
Pavel Yaskevich
6754918b08 Merge pull request #77153 from xedin/issue-77003
[CSBindings] Limit `BindingSet::isViable` binding skipping to stdlib …
2024-10-22 11:11:48 -07:00
Pavel Yaskevich
2b11ecbec9 [CSBindings] Limit BindingSet::isViable binding skipping to stdlib collection types
This is follow-up to https://github.com/swiftlang/swift/pull/76487

It's reasonable to coalesce bindings of different kind if they don't
allow implicit conversions like stdlib collection types do.

Resolves: https://github.com/swiftlang/swift/issues/77003
2024-10-21 14:48:45 -07:00
Slava Pestov
6648508184 type_checker_perf tests should require no_asan
Fixes rdar://problem/138246764.
2024-10-21 17:25:38 -04:00
Slava Pestov
d502e556e9 Add a couple of solver performance tests 2024-10-18 17:54:25 -04:00
Pavel Yaskevich
2c9d05991f [CSBindings] Prevent BindingSet::isViable from dropping viable bindings
I think the original idea was to elide `Array<$T>` if there is
a binding a resolved generic arguments i.e. `Array<Float>`, but
the check doesn't account for the fact that bindings could be
of different kinds and there are some implicit conversions that
could be missed if we remove the bindings.

For example, given the following constraints:

`Array<$T0> conv $T1`
`$T1 conv Array<(String, Int)>`

`$T0` can be a supertype of `Array<$T0>` and subtype of `Array<(String, Int)>`.

The solver should accept both types as viable bindings because the
`$T0` could be bound to `(key: String, value: Int)` and that would
match `Array<(String, Int)>` conversion.
2024-09-16 09:54:12 -07:00
Slava Pestov
6fb66db6da Merge pull request #76318 from slavapestov/favored-over-disjunction-heuristic
Sema: Generalize heuristic in favoredOverDisjunction()
2024-09-14 08:45:09 -04:00
Pavel Yaskevich
c49aeaf177 Merge pull request #76354 from xedin/improve-mismatch-diagnostics-in-optional-context
[CSSimplify] Rework how/when mismatches between optional types are fixed
2024-09-11 10:14:19 -07: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
Jan
6236b258d2 [Sema] Fixes for mutability handling in property wrappers (#76357)
Prevents a crash when a parameter references an invalid property wrapper. The original code assumed that mutability information would always be available, but this assumption fails when the property wrapper is invalid

Resolves https://github.com/swiftlang/swift/issues/65640
2024-09-10 00:20:29 -07:00
Slava Pestov
73aa029a8b Sema: Generalize heuristic in favoredOverDisjunction() 2024-09-09 11:18:58 -04:00
Hamish Knight
ee0e408a8c [Sema] Remove separate closure type-checking logic
`participatesInInference` is now always true for
a non-empty body, remove it along with the separate
type-checking logic such that empty bodies are
type-checked together with the context.
2024-09-08 16:17:11 +01:00
Hamish Knight
72fe29f7f4 [CS] Add custom diagnostic for missing result builder element
If we have a single missing argument for an empty
`buildBlock` call, emit a custom diagnostic.
2024-09-08 16:17:11 +01:00
Pavel Yaskevich
dab01bc1fe [Tests] NFC: Update some of the changed/improved tests 2024-08-30 15:39:25 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Holly Borla
7dbec846f7 [NFC] Update a few tests for concurrency diagnostics changes. 2024-08-05 17:26:07 -07:00
Alexander Cyon
4a2942bb4e Fix typos in: cmake, tools, utils, unittests, validation-test
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2024-07-12 02:34:00 +03:00
Hamish Knight
26e8245e22 [Sema] Requestify pattern resolution
Add a cached request to perform pattern resolution.
This is needed to prevent the constraint system
from resolving the same pattern multiple times
along different solver paths, which could result
in creating different pattern nodes for each path.
Once pattern resolution is moved to pre-checking
we ought to be able to make this uncached.

rdar://128661960
2024-06-13 15:27:47 +01:00
Holly Borla
1b0dca035e [NFC] Update concurrency validation test. 2024-05-16 10:18:34 -07:00
Holly Borla
a3ac8ec28f [Test] Remove overload of count(where:) from type checker performance test now
that it's in the standard library.
2024-04-02 08:33:05 -07:00
Holly Borla
8834861218 [ConstraintSystem] Order VarDecls before other kinds of decls in disjunctions. 2024-04-01 17:19:53 -07:00
Holly Borla
9ba481ad53 [Diagnostics] Clarify the wording of error_in_future_swift_version. 2024-03-01 12:05:51 -08:00
Pavel Yaskevich
239bfacee3 [ConstraintSystem] Account for situations when witness for associated type is null
In some circularity cases `getAssociatedType` would produce a `Type()`,
we need to account for that in `TypeSimplifier` to avoid crashing.
2024-02-22 10:55:33 -08:00
Pavel Yaskevich
2eda1cb9a6 [CSSimplify] Adjust isBindable to reject binding if it's directly to a type variable
Although inference doesn't allow direct bindings to
type variables, they can still get through via `matchTypes`
when type is a partially resolved pack expansion that simplifies
down to a type variable.
2024-02-20 13:42:43 -08:00
Pavel Yaskevich
da14b97875 [Tests] NFC: Remove one of SwiftUI test-cases because its overly SDK sensitive 2024-01-24 21:15:14 -08:00
Holly Borla
d60a06760b Merge pull request #71050 from hborla/global-actor-unsafe
[Concurrency] Deprecate `@GlobalActor(unsafe)` in favor of `@preconcurrency @GlobalActor`
2024-01-22 16:52:56 -08:00
Pavel Yaskevich
be39c05df2 Merge pull request #71026 from xedin/rdar-111120803
[CSSimplify] Increase impact of requirement failures in special result builder methods
2024-01-22 13:10:59 -08:00
Holly Borla
2a18edc178 [NFC][Concurrency] Update validation tests for @MainActor(unsafe) changes. 2024-01-22 08:43:27 -08:00
Pavel Yaskevich
b3152d8bc0 [CSSimplify] Increase impact of requirement failures in special result builder methods
Handle requirement failures in result builder `build*` methods explicitly
and give them a high impact rating because issues if such positions
imply that the transform didn't work and it shouldn't shadow errors
in user code.

Resolves: rdar://111120803
Resolves: rdar://120342129
2024-01-19 15:11:41 -08:00
Holly Borla
79593411d9 [Concurrency] Set preconcurrency for actor isolation created from unsafe global
actor attributes.
2024-01-19 09:29:13 -08:00
Pavel Yaskevich
e4f9965ff7 [ConstraintSystem] Fail key path capability inference if root is a placeholder
If root type of a key path has been determined to be a hole there
is no reason to delay the inference decision which should be a
failure because none of the components would be inferrable from
a placeholder root.
2024-01-01 12:48:31 -08:00
Pavel Yaskevich
dde501485e [CSBinding] Prefer array literal type over a disjunction in certain cases
If array literal type is not delayed and doesn't have any type variables
associated with it, let's prefer it over a disjunction to facilitate
type propagation through its `Element` type to element expressions.

Resolves: rdar://118993030
2023-11-30 17:43:13 -08:00
Pavel Yaskevich
2701d431cf [CSBindings] Prefer key path type over a disjunction if key path is resolved
If key path type has bindings and is no longer delayed it means
that it's fully resolved and ready to be bound (even though value
type might not be resolved yet).
2023-11-30 16:26:10 -08:00
Pavel Yaskevich
9f21b95fcb [CSDiagnostics] A tailored diagnostic when passing key path as an argument to non-key path parameter
Produce a tailored diagnostic that omits a fully unresolved key path
type (`KeyPath<_, _>`) when key path without an explicit root type is
passed as an argument to non-keypath parameter type (i.e. `Int`).
2023-11-08 19:54:32 -08:00
Pavel Yaskevich
863058757d [TypeChecker] NFC: Add test-case for rdar://112095973 2023-10-25 14:58:11 -07:00
Pavel Yaskevich
4c38d72230 [Tests] NFC: Add a FIXME about use of <<error type>> in a diagnostic 2023-10-16 12:37:54 -07:00
Pavel Yaskevich
a90bd1cbe1 [Tests] NFC: Add a test-case for rdar://116122902 2023-10-13 10:50:15 -07:00
Holly Borla
2e9c64d36c [Concurrency] Do not allow actor isolation violations in function conversions
to impact constraint solving.
2023-09-21 19:44:03 -07:00
Holly Borla
d4f3bc6cd3 Merge pull request #68081 from hborla/sendable-self-in-reference 2023-08-23 06:13:38 -07:00