Commit Graph

7604 Commits

Author SHA1 Message Date
Anthony Latsis
35f1370f6e TypeCheckType: Rework IUO diagnostics using behavior limitation
Also stop suggesting a '?' fix-it for casts, where it is not likely to
be helpful because the common intention is either to force the optional
or declare an IUO.
2025-01-21 21:41:00 +00:00
Alejandro Alonso
11fbd94668 Merge pull request #78664 from Azoy/unicode-16
[stdlib] Unicode 16
2025-01-21 09:29:35 -08:00
Alastair Houghton
760cc57bef [Backtracing] Rename _Backtracing to Runtime.
Move the backtracing code into a new Runtime module.  This means renaming
the Swift Runtime's CMake target because otherwise there will be a name
clash.

rdar://124913332
2025-01-17 10:09:36 +00:00
Slava Pestov
cfcc73f164 Sema: Add -solver-disable-splitter flag for debugging
We're not planning on removing the splitter because it is a big win
in some cases, but we want to run it less often since it can also
be a source of overhead. This flag allows us to compare performance
to understand the tradeoffs better.
2025-01-15 22:30:33 -05:00
Alejandro Alonso
708d72d2c3 Update tests for 6.1 Unicode 16 stdlib 2025-01-15 14:09:57 -08:00
Hiroshi Yamauchi
1d8e48dcf7 Merge pull request #78563 from hjyamauchi/issue78447
Add a reproducer for issue 78447
2025-01-15 10:56:06 -08:00
Hiroshi Yamauchi
7abb94a5f4 Add a reproducer for issue 78447
https://github.com/swiftlang/swift/issues/78447
2025-01-13 11:28:44 -08:00
Pavel Yaskevich
84c7188219 Merge pull request #78526 from xedin/issue-78371
[CSOptimizer] Literal arguments should cause score reset only for operators
2025-01-13 08:59:36 -08:00
Pavel Yaskevich
e3987beffb [CSOptimizer] Literal arguments should cause score reset only for operators
Resetting score to `0.1` is intended to make sure that the
solver picks the outermost disjunction in literal chains like
`1 + 2 + 3 ...` because that would provide context to the
inner choices.

Resolves: https://github.com/swiftlang/swift/issues/78371
Resolves: rdar://142105691
2025-01-09 11:28:24 -08:00
Anthony Latsis
28160c9d09 Merge pull request #78049 from AnthonyLatsis/nelumbo-lutea
build: Unhardcode Swift source directory name
2025-01-09 11:23:17 +00:00
Pavel Yaskevich
8e3943c4c1 Merge pull request #78506 from xedin/disable-swiftui-test-due-to-141262107
[Tests] NFC: Disable a test-case to unblock update to Xcode 16.2
2025-01-09 00:13:25 -08:00
Pavel Yaskevich
8b4a809482 [Tests] NFC: Disable a test-case to unblock update to Xcode 16.2 2025-01-08 16:07:02 -08:00
Alexis Laferrière
a046a0d6b7 Tests: Disable verify_all_overlays on Linux platforms 2025-01-07 11:59:53 -08:00
Anthony Latsis
4a5e0daa9d build: Unhardcode Swift source directory name
This is useful if you maintain several swift worktrees that reside in
the source root directory.
2025-01-07 09:58:47 +00:00
Pavel Yaskevich
5cac7dba79 Merge pull request #78357 from xedin/too-complex-with-count
[CSOptimizer] Few tweaks to make unapplied disjunction and literal array arguments faster
2025-01-03 00:20:40 -08:00
Hamish Knight
4e33cef20c [AST] Walk into LocatableType in TypeWalker
Make sure we walk into the underlying type for
LocatableType.
2025-01-02 15:02:11 +00:00
Pavel Yaskevich
cfd34e54c4 [CSOptimizer/Tests] NFC: Add a perf test-case fixed by improved literal array handling 2024-12-30 10:20:57 -08:00
Pavel Yaskevich
8a304f88c6 [CSOptimizer] Extend candidate/parameter matching to support array literals
Match `[...]` to Array<...> and/or `ExpressibleByArrayLiteral`
conforming types. This is very helpful for expressions like:
`[...] + [...]`.
2024-12-25 12:51:01 -08:00
Pavel Yaskevich
0737542da8 [CSOptimizer] Favor choices that don't require application
When disjunction is not applied, don't only bump its score
but also favor all of the choices that don't require application
because selection algorithm uses that for comparison.

This is important for situation when property is overload with
a method i.e. `Array.count`.
2024-12-24 17:12:36 -08:00
Pavel Yaskevich
443d011feb [Tests] NFC: Restrict SIMD related perf test to macOS to make it more stable 2024-12-20 10:33:17 -08:00
Slava Pestov
d3f736972b Merge pull request #78304 from slavapestov/too-complex-tests
Add formerly-slow expressions found by building projects from the Swift package index
2024-12-20 09:55:34 -05:00
Henrik G. Olsson
ef9d2b744d Rename pointer bounds (#78210)
* Make pointer bounds non-experimental

* Rename @PointerBounds to @_SwiftifyImport

* Rename filenames containing PointerBounds

* Add _PointerParam exception to stdlib ABI test

* Add _PointerParam to stdlib API changes

* Rename _PointerParam to _SwiftifyInfo
2024-12-20 11:36:01 +01:00
Slava Pestov
8d0d9577f6 Add formerly-slow expressions found by building projects from the Swift package index
These were slow in 6.0 and are now fast(er).
2024-12-19 17:26:16 -05:00
Pavel Yaskevich
19350d9737 Merge pull request #63585 from xedin/solver-perf
[CSSolver] Implementation of disjunction choice favoring algorithm
2024-12-18 09:47:59 -08:00
Pavel Yaskevich
bc3a15fbe6 [CSOptimizer] Disable CGFloat -> Double conversion for unary operators
Some of the unary operators, i.e. prefix `-`, don't have
CGFloat variants and expect generic `FloatingPoint` overload
to match CGFloat type. Let's not attempt `CGFloat` -> `Double`
conversion for unary operators because it always leads
to a worse solutions vs. generic overloads.
2024-12-18 00:22:49 -08:00
Pavel Yaskevich
636525ebd9 Merge pull request #78171 from xedin/rdar-140300022
[TypeChecker/SILGen] Allow `any Sendable` to match `Any` while matching generic arguments
2024-12-17 20:24:34 -08:00
Pavel Yaskevich
40a41c82d9 [CSBindings] Don't attempt to strip optional for closure result types
Let's not perform $T? -> $T for closure result types to avoid having
to re-discover solutions that differ only in location of optional
injection.

The pattern with such type variables is:

```
$T_body <conv/subtype> $T_result <conv/subtype> $T_contextual_result
```

When `$T_contextual_result` is `Optional<$U>`, the optional injection
can either happen from `$T_body` or from `$T_result` (if `return`
expression is non-optional), if we allow  both the solver would
find two solutions that differ only in location of optional
injection.
2024-12-17 11:36:42 -08:00
Pavel Yaskevich
56d6635e46 [CSOptimizer] Implement special prioritization rules for result builder contexts
Prioritize `build{Block, Expression, ...}` and any chained
members that are connected to individual builder elements
i.e. `ForEach(...) { ... }.padding(...)`, once `ForEach`
is resolved, `padding` should be prioritized because its
requirements can help prune the solution space before the
body is checked.
2024-12-17 11:36:42 -08:00
Pavel Yaskevich
bf8ae3bc1b [CSOptimizer] Allow only widening CGFloat->Double conversions while matching candidate arguments
Allow CGFloat -> Double widening conversions between
candidate argument types and parameter types. This would
make sure that Double is always preferred over CGFloat
when using literals and ranking supported disjunction
choices. Narrowing conversion (Double -> CGFloat) should
be delayed as much as possible.
2024-12-17 11:36:42 -08:00
Pavel Yaskevich
87cd5f8733 [CSOptimizer] Add support for chained members without arguments
If disjunction represents a member reference that has no arguments
applied, let's score that as `1` to indicate that it should be priorized.

This helps in situations like `a.b + 1` where resolving `a.b` member
chain helps to establish context for `+`.
2024-12-17 11:36:41 -08:00
Pavel Yaskevich
15c773b9d7 [CSOptimizer] Make a light-weight generic overload check if some requirements are unsatisfiable
If some of the requirements of a generic overload reference other
generic parameters, the optimizer won't be able to satisfy them
because it only has candidates for one (current) parameter. In
cases like that, let's fallback to a light-weight protocol conformance
check instead of skipping an overload choice altogether.
2024-12-17 11:36:41 -08:00
Pavel Yaskevich
c2a55886f0 [CSOptimizer] Fix selectDisjunction to use favored choices even if disjunction was not optimized
Some disjunctions e.g. explicit coercions, compositions of restrictions,
and implicit CGFloat initializers have favored choices set independently
from optimization algorithm, `selectDisjunction` should account for
such situations.
2024-12-17 11:36:41 -08:00
Pavel Yaskevich
ff8663ff16 [Tests] NFC: Update a couple of type-checker tests 2024-12-17 11:36:41 -08:00
Pavel Yaskevich
28396a6dce [Tests] NFC: Move simd related test-case from slow to fast 2024-12-17 11:36:41 -08:00
Pavel Yaskevich
3996b25fbd [CSOptimizer] Rank results of operators regardless of whether anything is known about parameters
When operators are chained it's possible that we don't know anything
about parameter(s) but result is known from the context, we should
use that information.
2024-12-17 11:36:40 -08:00
Pavel Yaskevich
66981364fe [Tests] NFC: Adjust a couple of improved tests 2024-12-17 11:36:40 -08:00
Pavel Yaskevich
670127abd6 [Tests] NFC: Add a test-case for rdar://133340307 which is now fast 2024-12-17 11:36:39 -08:00
Pavel Yaskevich
bc5f70a9a3 [CSOptimizer] Allow generic operator overloads without associated type parameters 2024-12-17 11:36:38 -08:00
Pavel Yaskevich
672ae3d252 [CSOptimizer] Initial implementation of disjunction choice favoring algorithm
This algorithm attempts to ensure that the solver always picks a disjunction
it knows the most about given the previously deduced type information.

For example in chains of operators like: `let _: (Double) -> Void = { 1 * 2 + $0 - 5 }`

The solver is going to start from `2 + $0` because `$0` is known to be `Double` and
then proceed to `1 * ...` and only after that to `... - 5`.

The algorithm is pretty simple:

- Collect "candidate" types for each argument
  - If argument is bound then the set going to be represented by just one type
  - Otherwise:
    - Collect all the possible bindings
    - Add default literal type (if any)

- Collect "candidate" types for result

- For each disjunction in the current scope:
  - Compute a favoring score for each viable* overload choice:
    - Compute score for each parameter:
      - Match parameter flags to argument flags
      - Match parameter types to a set of candidate argument types
        - If it's an exact match
          - Concrete type: score = 1.0
          - Literal default: score = 0.3
        - Highest scored candidate type wins.
      - If none of the candidates match and they are all non-literal
        remove overload choice from consideration.

    - Average the score by dividing it by the number of parameters
      to avoid disfavoring disjunctions with fewer arguments.

    - Match result type to a set of candidates; add 1 to the score
      if one of the candidate types matches exactly.

  - The best choice score becomes a disjunction score

- Compute disjunction scores for all of the disjunctions in scope.

- Pick disjunction with the best overall score and favor choices with
  the best local candidate scores (if some candidates have equal scores).

- Viable overloads include:
  - non-disfavored
  - non-disabled
  - available
  - non-generic (with current exception to SIMD)
2024-12-17 11:36:38 -08:00
Slava Pestov
8eb9e745a6 Merge pull request #78225 from slavapestov/optimized-shifts
Sema: Filter out protocol extension default implementations of operators
2024-12-17 07:44:10 -05:00
Slava Pestov
27812856dc Sema: Extend DisjunctionStep::shouldSkip() hack to cover ~ & | ^ << >> 2024-12-16 18:08:01 -05:00
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
70b07af38b Merge pull request #78035 from xedin/rdar-141012049
[CSSimplify] Avoid resolving extraneous (trailing) closures
2024-12-09 14:30:32 -08:00
Alexis Laferrière
224efd72c5 Merge pull request #77964 from xymus/optional-memcmp
SwiftShims: memcmp should accept optional pointers on Darwin
2024-12-09 13:35:23 -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
Slava Pestov
302b163edc AST: Optimize TypeAliasType representation 2024-12-06 17:39:55 -05:00
Egor Zhdan
7704534132 Merge pull request #77754 from swiftlang/egorzhdan/swiftinterface-no-cxx-flag
[cxx-interop] Do not emit C++ interop flag in textual interfaces
2024-12-06 14:30:21 +00:00
Egor Zhdan
7ae2bebfe8 [cxx-interop] Do not emit C++ interop flag in textual interfaces
This makes sure that the compiler does not emit `-enable-experimental-cxx-interop`/`-cxx-interoperability-mode` flags in `.swiftinterface` files. Those flags were breaking explicit module builds. The module can still be rebuilt from its textual interface if C++ interop was enabled in the current compilation.

rdar://140203932
2024-12-05 19:25:09 +00:00
nate-chandler
0d76250033 Merge pull request #77908 from nate-chandler/rdar139840307
[BarrierAccessScopes] Handle end_access instructions' barrierness introduced during run.
2024-12-04 15:29:02 -08:00