Commit Graph

1572 Commits

Author SHA1 Message Date
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
swift-ci
22d76fab11 Merge remote-tracking branch 'origin/main' into rebranch 2025-07-21 10:58:28 -07:00
Anthony Latsis
c1d794364b Adjust code after changes to llvm::TrailingObjects API
See:
- https://github.com/llvm/llvm-project/pull/138970
- https://github.com/llvm/llvm-project/pull/144930
2025-07-19 01:48:18 +01:00
Hamish Knight
33b58d25d8 [CS] NFC: Factor out Solution::hasAppliedSelf 2025-07-18 10:54:17 +01:00
Hamish Knight
3244bffe71 [CS] Handle TVO_CanBindToPack in mergeEquivalenceClasses
Previously we could incorrectly propagate `TVO_CanBindToPack` to a
type variable that cannot bound to a pack type.
2025-07-14 12:44:23 +01:00
Slava Pestov
b39d3aee57 Sema: Special-case recording of Bind constraint in PreparedOverload 2025-07-11 19:57:29 -04:00
Slava Pestov
6e212de774 Sema: Lazily build prepared overload when simplifying BindOverload constraint 2025-07-11 19:57:29 -04:00
Slava Pestov
9a8f3baa06 Sema: Add room for a PreparedOverload to BindOverload constraint 2025-07-10 19:53:19 -04:00
Slava Pestov
83f95aeaed Sema: Allocate PreparedOverload in solver arena 2025-07-10 19:53:19 -04:00
Slava Pestov
7916ed982f Sema: Move DeclReferenceType to PreparedOverload.h 2025-07-10 19:53:19 -04:00
Slava Pestov
f7a552385c Sema: PreparedOverload => PreparedOverloadBuilder 2025-07-10 19:53:18 -04:00
Slava Pestov
8527e88423 Sema: Extract prepareOverload() from resolveOverload() 2025-07-10 19:53:15 -04:00
Slava Pestov
751edee921 Sema: Rework PreparedOverload to store a list of changes 2025-07-09 15:00:10 -04:00
Slava Pestov
2a0b11a22e Sema: Collect property wrappers in PreparedOverload 2025-07-09 15:00:03 -04:00
Slava Pestov
be6cf92982 Sema: Plumb PreparedOverload through to replaceInferableTypesWithTypeVars() 2025-07-09 15:00:03 -04:00
Slava Pestov
ab72407108 Sema: Collect opened pack expansion types in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
c5741e31ed Sema: Stash the existential archetype in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
426c7a3fdf Sema: Collect constraints in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
543793564e Sema: Record opened type variables in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
b9256307b5 Sema: Stub out PreparedOverload 2025-07-09 15:00:02 -04:00
Pavel Yaskevich
3efb948ad8 [ConstraintSystem] Add a option to re-enable performance hacks
Instead of checking `EnableConstraintSolverPerformanceHacks`
directly, let's use an option which is easier to set i.e.
when a block list is implemented.
2025-06-27 23:43:12 -07:00
Pavel Yaskevich
9e97b8e3a1 [CSOptimizer] Skip disfavored choices when they would result in a worse solution 2025-06-27 23:43:11 -07:00
Pavel Yaskevich
617338f250 [CSOptimizer] Prevent candidate inference from unresolved generic parameters and ternary expressions
We need to have a notion of "complete" binding set before
we can allow inference from generic parameters and ternary,
otherwise we'd make a favoring decision that might not be
correct i.e. `v ?? (<<cond>> ? nil : o)` where `o` is `Int`.
`getBindingsFor` doesn't currently infer transitive bindings
which means that for a ternary we'd only have a single
binding - `Int` which could lead to favoring overload of
`??` and has non-optional parameter on the right-hand side.
2025-06-27 23:43:11 -07:00
Pavel Yaskevich
2f8a343aef [CSOptimizer] Infer result types through ternary expressions 2025-06-27 23:43:09 -07:00
Pavel Yaskevich
0a5bd787d0 [ConstraintSystem] Narrowly disable tryOptimizeGenericDisjunction when some of the arguments are number literals
Don't attempt this optimization if call has number literals.
This is intended to narrowly fix situations like:

```swift
func test<T: FloatingPoint>(_: T) { ... }
func test<T: Numeric>(_: T) { ... }

test(42)
```

The call should use `<T: Numeric>` overload even though the
`<T: FloatingPoint>` is a more specialized version because
selecting `<T: Numeric>` doesn't introduce non-default literal
types.

(cherry picked from commit 8d5cb112ef)
2025-06-27 23:43:09 -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
Pavel Yaskevich
c04068db1c [ConstraintSystem] Initial implementation of disjunction optimizer
This brings back CSOptimizer from https://github.com/swiftlang/swift/pull/63585
2025-06-27 23:43:09 -07:00
Pavel Yaskevich
1b2ba7e059 [CSStep] Modify selectDisjunction to return favored choices directly
This is currently unused because current mechanism set favored choices
directly but it would be utilized by the disjunction optimizer.

(cherry picked from commit e404ed722a)
2025-06-27 23:43:09 -07:00
Slava Pestov
487918f07b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:23 -04:00
Artem Chikin
705b1a667f Merge pull request #82429 from artemcm/ScannerInvalidBinaryModuleRefactor
[Dependency Scanning] Refactor the scanner to simplify layering
2025-06-25 09:03:18 -07:00
Artem Chikin
68883a1014 [Dependency Scanning] Refactor Swift Scanner loader to be standalone
- 'SwiftModuleScanner' will now be owned directly by the 'ModuleDependencyScanningWorker' and will contain all the necessary custom logic, instead of being instantiated by the module interface loader for each query
- Moves ownership over module output path and sdk module output path directly into the scanning worker, instead of the cache
2025-06-23 13:39:36 -07:00
Pavel Yaskevich
286f975c29 Merge pull request #82320 from xedin/hide-solver-hacks-behind-a-flag
[ConstraintSystem] Guard all the performance hacks with a flag
2025-06-20 00:12:16 -07:00
Pavel Yaskevich
fc573b6612 [ConstraintSystem] Guard all the performance hacks with a flag
Package the flag into `performanceHacksEnabled()` method on
`ConstraintSystem` and start using it to wrap all of the hacks
in constraint generator and the solver.
2025-06-17 13:53:05 -07:00
Hamish Knight
71d20b7635 [CS] NFC: Remove FreeTypeVariableBinding::UnresolvedType
This is now unused.
2025-06-12 12:11:19 +01:00
Anthony Latsis
d10dfb3ae9 Merge pull request #82020 from AnthonyLatsis/camellia-sinensis
Sema: Never record argument label mismatches for unlabeled trailing closures
2025-06-07 01:29:54 +01:00
Anthony Latsis
7c431c9a9a [NFC] Make a function static 2025-06-05 17:59:34 +01:00
John McCall
b3493bfa23 Prevent PrintOptions from being implicitly copied.
NFC *except* that I noticed a bug by inspection where we suppress
`@escaping` when print enum element types. Since this affects
recursive positions, we end up suppressing `@escaping` in places
we shouldn't. This is unlikely to affect much real code, but should
still obviously be fixed.

The new design is a little sketchy in that we're using `const` to
prevent direct use (and allow initialization of `const &` parameters)
but still relying on modification of the actual object.  Essentially,
we are treating the `const`-ness of the reference as a promise to leave
the original value in the object after computation rather than a
guarantee of not modifying the object. This is okay --- a temporary
bound to a `const` reference is still a non-`const` object formally
and can be modified without invoking UB --- but makes me a little
uncomfortable.
2025-06-05 12:52:01 -04:00
Pavel Yaskevich
65e83a8bb1 [CSSimplify] Increase impact of a generic argument mismatch if mismatch is contextual
If generic arguments mismatch ends up being recorded on the result
of the chain or `try` expression it means that there is a contextual
conversion mismatch.

For optional conversions the solver currently generates a disjunction
with two choices - bind and optional-to-optional conversion which is
anchored on the contextual expression. If we can get a fix recorded
there that would result in a better diagnostic. It's only possible
for optional-to-optional choice because it doesn't bind the
variable immediately, so we need to downgrade direct fixes to prevent
`bind` choice from considered better.
2025-06-02 23:49:52 -07:00
Pavel Yaskevich
10186d664b [Diagnostics] Assign missing member eagerly when there is no context
Without contextual information it won't be possible to bind a missing
member to a concrete type later, so let's bind them eagerly and propagate
placeholders outward.

Resolves: rdar://152021264
Resolves: https://github.com/swiftlang/swift/issues/81770
2025-05-30 09:52:52 -07:00
Michael Gottesman
3ed4059a60 [sema] Change non-sendable -> non-Sendable in diagnostics.
This matches send non sendable but importantly also makes it clear that we are
talking about something that doesn't conform to the Sendable protocol which is
capitalized.

rdar://151802975
2025-05-22 11:37:58 -07:00
Artem Chikin
8cd193fc08 [Dependency Scanning] Remove 'ClangImporter' instance from dependency scanning worker
Move relevant logic directly into the worker
2025-05-07 16:43:45 -07:00
Artem Chikin
d484ec7c1f [Compile Time Values] Implement a mandatory SIL pass to verify '@const' values 2025-03-27 14:33:35 -07:00
Hamish Knight
a84b53f6fd Merge pull request #80248 from hamishknight/fix-error-type
[CS] Map caught error type into context
2025-03-25 06:42:38 +00:00
Hamish Knight
c597023d38 [CS] Map caught error type into context
Factor out `ConstraintSystem::getExplicitCaughtErrorType` from 
`getCaughtErrorType`. Then use this for the contextual
type for a `throw` syntactic element.

rdar://139000351
2025-03-24 20:08:43 +00:00
Artem Chikin
c36ae0d0d6 Merge pull request #79818 from artemcm/SeparateSDKExplicitModules
[Dependency Scanning] Add support for placing explicitly-built SDK modules into a separate module cache
2025-03-24 12:27:06 -06: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
Pavel Yaskevich
552106d536 Merge pull request #80081 from xedin/rdar-143161190
[CSSimplify] Open key path type before assignment to its record requirements
2025-03-19 09:50:11 -07:00
Amritpan Kaur
a96b780a28 [Sema] Diagnose method arg captures that are not Hashable/Equatable. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
970159c09d [CSDiagnostics] Block async, throws and mutating methods. 2025-03-19 08:56:03 -07:00