Commit Graph

2865 Commits

Author SHA1 Message Date
Doug Gregor
88d630446c [Constraint solver] Delay Sendable on static method references involving possibly-nonsendable metatypes
Thank you, Pavel!
2025-04-14 10:19:11 -07:00
Pavel Yaskevich
9da457d129 [Sema/SILGen] NFC: Remove all mentions of @execution from comments 2025-04-11 15:59:25 -07:00
Slava Pestov
7399eeb602 AST: Remove type parameter from ProtocolConformanceRef::getWitnessByName() 2025-04-03 17:35:33 -04:00
Joe Groff
562d7dc832 Merge pull request #80438 from jckarter/substitute-away-escapable-lifetime-deps
Type substitution eliminates dependencies with Escapable targets.
2025-04-02 16:56:54 -07:00
Joe Groff
6b605f41cb Type substitution eliminates dependencies with Escapable targets.
When a generic function has potentially Escapable outputs, those outputs
declare lifetime dependencies, which have no effect when substitution
leads to those types becoming `Escapable` in a concrete context.
This means that type substitution should canonically eliminate lifetime
dependencies targeting Escapable parameters or returns, and that
type checking should allow a function value with potentially-Escapable
lifetime dependencies to bind to a function type without those dependencies
when the target of the dependencies is Escapable.

Fixes rdar://147533059.
2025-04-02 08:54:45 -07:00
Pavel Yaskevich
bf2d01e562 Merge pull request #80419 from xedin/revert-pr-79397
Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
2025-04-02 00:10:23 -07:00
Pavel Yaskevich
35077a01d1 Revert "Sema: Allow optional-to-optional CGFloat <-> Double conversion"
This reverts commit f0f5ffcebf.
2025-03-31 13:58:38 -07:00
Allan Shortlidge
5dc7a204cb Sema: Address -Wunused-but-set-variable warnings. 2025-03-28 12:33:40 -07:00
Pavel Yaskevich
367e5e20f1 Merge pull request #80329 from xedin/execution-caller-func-to-parameter-isolation-func
[CSSimplify] Allow conversion from caller isolated to parameter isola…
2025-03-27 10:35:09 -07:00
Pavel Yaskevich
cdae26aece [CSSimplify] Allow conversion from caller isolated to parameter isolation function types
This requires special handling during function type matching
because caller isolated function types don't get an isolated
parameter until SILGen.
2025-03-26 17:55:48 -07:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Doug Gregor
731f58443c Address review feedback on AbstractConformance in ProtocolConformanceRef 2025-03-23 20:54:39 -07:00
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -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
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00: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
0e895c6a2b [CSApply] Solve keypath methods and initializers. 2025-03-19 08:56:03 -07:00
Slava Pestov
f7b0b72766 Sema: Refactor TypeChecker::containsProtocol() a bit 2025-03-18 19:38:21 -04:00
Pavel Yaskevich
e0f9e65976 [CSSimplify] NFC: assignFixedType no longer accepts a locator
`assignFixedType` now accepts `bool` as a third parameter but
not all call sites were updated to reflect that, some of them
are still passing `ConstraintLocator *` which implicitly gets
converted to a `bool`.
2025-03-18 00:16:22 -07:00
Pavel Yaskevich
a8baec6c41 [CSSimplify] Open key path type before assignment to its record requirements
`Root` and `Value` generic parameters now have conformance requirements
which we need to account for post-binding inference.
2025-03-17 17:03:09 -07:00
Pavel Yaskevich
6c22036931 [CSSimplify] NFC: Perform assignments to a key path in a separate method
Previously key path type didn't have any requirements on their
root and value types but now that they do, we need a dedicated
place to perform an assignment and open/record all of the requirements.
2025-03-17 14:06:45 -07:00
eeckstein
47b449372e Merge pull request #79917 from eeckstein/rename-opened-archetype-type
AST: rename OpenArchetypeType -> ExistentialArchetypeType
2025-03-12 06:01:10 +01:00
Slava Pestov
9e721a35f2 Merge pull request #79914 from slavapestov/retry-removing-one-way-equal
Sema: Mostly remove one-way constraints
2025-03-11 21:24:57 -04:00
Erik Eckstein
d225c47d25 AST: rename OpenArchetypeType -> ExistentialArchetypeType
NFC
2025-03-11 20:21:46 +01:00
Slava Pestov
4c60e036ac Merge pull request #79882 from slavapestov/sizeof-constraint
Sema: Optimize Constraint layout to save 24 bytes
2025-03-11 14:30:44 -04:00
Slava Pestov
6d8b55a9f6 Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()
The two GatherKinds no longer share any implementation, so there's
no point keeping the logic together. Doing this also allows removing
the acceptConstraintFn from gatherAllConstraints(), which further
simplifies depthFirstSearch().
2025-03-11 13:55:40 -04:00
James Brown
edb0fa7b3d [CS] Deep-equality match OpenedArchetypeTypes
When we have two distinct OpenedArchetypeTypes that have the same
interface type and UUID, we need to match their generic arguments.
2025-03-10 19:19:53 -04:00
Slava Pestov
83118a73ed Sema: Shave another 8 bytes off of Constraint 2025-03-10 14:53:48 -04:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Doug Gregor
6a4d1a41c4 Prohibit isolated conformances with Sendable(Metatype) constraints
Within the constraint system, introduce a new kind of conformance constraint,
a "nonisolated conforms-to" constraint, which can only be satisfied by
nonisolated conformances. Introduce this constraint instead of the normal
conforms-to constraint whenever the subject type is a type parameter that
has either a `Sendable` or `SendableMetatype` constraint, i.e., when the type
or its values can escape the current isolation domain.
2025-03-01 08:19:42 -08:00
Slava Pestov
3a01f206c5 Sema: Rename LocatorPathElt::OptionalPayload to ::OptionalInjection 2025-02-25 17:22:41 -05:00
Hamish Knight
c69590fbdd [CS] Clean up pack expansion environment handling a little
- Track environments for `PackExpansionExpr` directly
instead of using a locator.
- Split up the querying and creation of the environment
such that the mismatch logic can be done directly in
CSSimplify instead of duplicating it.
- Just store the environment directly instead of
the shape and UUID.
2025-02-20 21:31:46 +00:00
Hamish Knight
9c04fd8cd3 [CS] NFC: Factor out matchPackElementType 2025-02-20 21:31:46 +00:00
Pavel Yaskevich
9cbd8e1f10 Merge pull request #79382 from xedin/more-Sendable-to-Any-problems
[Concurrency] Fix a few issues with `Senable` and `Any`
2025-02-15 08:23:28 -08:00
Pavel Yaskevich
515221c959 Merge pull request #79375 from xedin/isolation-caller-in-type-context
[AST/Sema] Add new function type isolation - `caller` to cover `@execution(caller)` attribute
2025-02-14 16:01:28 -08:00
Slava Pestov
f0f5ffcebf Sema: Allow optional-to-optional CGFloat <-> Double conversion
After https://github.com/swiftlang/swift/pull/78957, there is no
technical reason to not allow this conversion. This is needed for
an upcoming optimization.
2025-02-14 13:08:57 -05:00
Pavel Yaskevich
484e0a7437 [ConstraintSystem] Sendable-to-Any: Allow conversion when in inout positions
It should be possible to pass values with `any Sendable` as arguments
to `inout` parameters that expect `Any`. This is pretty much the same
as an l-value conversion.

Resolves: https://github.com/swiftlang/swift/issues/79361
Resolves: rdar://144794132
2025-02-13 17:03:00 -08:00
Pavel Yaskevich
cdb5396c00 [AST] Declare NonIsolatedCaller as kind of FunctionTypeIsolation
This would make sure that async function types marked as `@execution(caller)`
have correct isolation.

Also defines all of the possible conversions to and from `caller`
isolated function types.
2025-02-13 14:35:54 -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
Alejandro Alonso
4a8d4d271a Update lib/Sema/CSSimplify.cpp
Co-authored-by: Guillaume Lessard <glessard@tffenterprises.com>
2025-02-11 13:34:05 -08:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Pavel Yaskevich
23ace7d770 [ConstraintSystem] Store declaration context in which application occurs in ApplicableFunction constraint
This is required because `ApplicableFunction` constraint can
inject member reference constraints that require a declaration
context.

For example, `_ = { Double(...) }` would now produce a disjunction
for `Double.init` where overload choice declaration contexts point
to the closure instead of the enclosing context.

This addresses a long-standing FIXME in `simplifyApplicableFnConstraint`
and helps with disjunction optimizer because its correctness depends on
correct identification of declaration contexts where applications happen.
2025-02-09 15:46:44 -08:00
Pavel Yaskevich
d24f22ec54 [ConstraintSystem] Refactor spots that create ApplicationFunction directly
This is required to make it easier to add "use dc" to the application.
2025-02-09 14:03:43 -08:00
Slava Pestov
5b4218c38d Revert "Sema: Remove ConstraintKind::OneWayEqual"
This reverts commit 385d66f24e.
2025-02-02 00:43:15 -05:00
Slava Pestov
99595e615e Revert "Sema: Split up gatherConstraints() into gatherAllConstraints() and gatherNearbyConstraints()"
This reverts commit 2230c3a17e.
2025-02-02 00:43:15 -05:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Slava Pestov
4ae57acaa2 Sema: Remove ConstraintSystem::ImplicitValueConversions 2025-01-27 17:28:19 -05:00
Slava Pestov
c47ff06a72 Sema: Tiny cleanup for matchTypes() 2025-01-27 16:42:03 -05:00