Commit Graph

1689 Commits

Author SHA1 Message Date
Kavon Farvardin
bb78171767 [NFC] forEachMissingConformance doesn't use module 2024-01-10 19:39:07 -08:00
Slava Pestov
597fb216cb Merge pull request #70457 from slavapestov/parameter-pack-open-type
Fix openType() handling of parameter packs
2024-01-10 13:41:08 -05:00
Slava Pestov
5d58a634ad Sema: Clean up openType() and openUnboundGenericType()
Fixes:
- rdar://112785081
- https://github.com/apple/swift/issues/67906
- https://github.com/apple/swift/issues/68160
2024-01-09 15:23:42 -05:00
Saleem Abdulrasool
d36ef3fed1 Merge pull request #63915 from AtariDreams/std-math
Ensure the correct function is called by prepending std:: to the std math functions
2024-01-04 20:30:51 -08:00
Doug Gregor
baaa8f3e5b Merge pull request #70677 from DougGregor/se-0413-typed-throws
Enable SE-0413 "Typed Throws" by default
2024-01-04 16:11:26 -08:00
Doug Gregor
ea836389f7 Suppress warnings about Never error types in catch clauses
Enabling typed throws has introduced some spurious warnings about error
values of `Never` type on top of the custom "unreachable" diagnostics
for catch clauses, so suppress the new warnings---they aren't helpful.
2024-01-04 09:37:35 -08:00
Slava Pestov
8e2aa52f7a Merge pull request #70667 from slavapestov/assorted-small-cleanups
Assorted small cleanups
2024-01-02 19:00:59 -05:00
Doug Gregor
b9c5aca15f Enable SE-0413 "Typed Throws" by default 2024-01-02 15:34:07 -08:00
Slava Pestov
fb3ad9a950 Sema: Tiny cleanup in ConstraintSystem::getTypeOfReference() 2024-01-02 15:41:13 -05: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
a288b1eb76 [CSBindings] Key path cannot be bound to typ erased type even if its existential
Extend existing check to handle type erased versions when they
are wrapped in an existential.
2023-12-19 13:36:46 -08:00
Slava Pestov
2b28cb1647 Sema: Implement missing case in existential erasure
Fixes https://github.com/apple/swift/issues/61934.
2023-12-16 12:24:34 -05:00
Doug Gregor
ab5ab28010 Merge pull request #70454 from DougGregor/full-typed-throws-inference
[Typed throws] Implement thrown type inference for do..catch within closures
2023-12-14 16:09:33 -08:00
Doug Gregor
ae5f66ac11 Record throwing property accesses as potential throw sites 2023-12-13 16:36:14 -08:00
Pavel Yaskevich
2924ce0353 Merge pull request #70409 from xedin/rdar-119001449
[ConstraintSystem] Run `salvage` even if diagnostics are suppressed
2023-12-13 16:16:37 -08:00
Alexis Laferrière
dda7e96503 Merge pull request #70424 from xymus/ambiguity
AST: Specify the module name in errors on ambiguities across modules
2023-12-13 16:07:41 -08:00
Doug Gregor
956c330611 [Constraint solver] Encode thrown error type in references to subscripts
A reference to a subscript (whether instance or static) produces a
function type, which is then applied as part of an application
constraint. Make sure that we encode whether the subscript can throw,
and the thrown error type if present, in that function type. This lets
us correctly treat subscripts as a potential throw sites.
2023-12-13 15:22:21 -08:00
Doug Gregor
8ad137fb51 [Typed throws] Infer thrown error type for do..catch blocks within closures.
Start classifying all potential throw sites within a constraint
system and associate them with the nearest enclosing catch node. Then,
determine the thrown error type for a given catch node by taking the
union of the thrown errors at each potential throw site. Use this to
compute the error type thrown from the body of a `do..catch` block
within a closure.

This behavior is limited to the upcoming feature `FullTypedThrows`.
2023-12-13 14:59:23 -08:00
Alexis Laferrière
72083bf7e3 Diagnostics: Specify the module name on ambiguities across modules
When a file defining an API is included in two modules, clients calling
that API may get an error about the ambiguity on the duplicated API.
That error is not very helpful when it takes into account the
swiftsourceinfo data and points to the source file instead of the
module. In such a case the notes point twice to the same file and line
of code.

Improve this diagnostic by appending the module name to the notes when a
candidate is found outside of the module.

rdar://116255141
2023-12-13 11:12:39 -08:00
Pavel Yaskevich
09a5b99446 [ConstraintSystem] Run salvage even if diagnostics are suppressed
There are some situations where the solver is able to find a valid
solution only during `salvage` (mostly but not limited to unavailable
declarations), which means that we need to keep running `salvage`
even if the diagnostics are suppressed until the underlying issues
in the normal solving mode are fixed.

One of the issues:

```swift
extension Unmanaged {
  @inline(__always)
  internal static func passRetained(_ instance: __owned Instance?) -> Self? {
    guard let instance = instance else { return nil }
    return .passRetained(instance)
  }
}
```

`.passRetained(instance)` is ambiguous during normal solving but
is able to find a solution during `salvage` because it attemtps
more type bindings.

Resolves: rdar://119001449
2023-12-12 10:53:06 -08:00
Pavel Yaskevich
b8d5e4c1c7 [ConstraintSystem] InferSendableFromCaptures: Use of actor isolated members makes key path non-Sendable 2023-12-06 12:21:12 -08:00
Pavel Yaskevich
6f981e5d4b [ConstraintSystem] Forgo checking if key path is already found to be non-Sendable 2023-12-06 10:04:50 -08:00
Pavel Yaskevich
12f02fd37e Merge pull request #70109 from xedin/fixes-for-member-sendability-inference
[ConstraintSystem] A couple of fixes to Sendable inference on functions
2023-12-01 13:36:15 -08:00
Pavel Yaskevich
a86e1eea1a [TypeChecker] Limit @dynamicMemberLookup parameter to compose only with Sendable 2023-12-01 00:25:31 -08:00
Pavel Yaskevich
7d326050f9 [ConstraintSystem] Handle @dynamicMemberLookup subscripts with existential parameters
The parameter should still have a key path type as its superclass
bound (i.e. `KeyPath<...> & Sendable`), this would be verified by
the attribute checker.
2023-11-30 11:28:24 -08:00
Pavel Yaskevich
a8232123c9 [ConstraintSystem] Fix isPartialApplication to properly handle static members
Only instance members require double-apply to be fully applied,
static members apply the base implicitly.
2023-11-29 17:00:38 -08:00
Pavel Yaskevich
40c8da6616 [ConstraintSystem] InferSendableFromCaptures: Start inferring sendability of key path expressions
When `InferSendableFromCaptures` feature is enabled `inferKeyPathLiteralCapability`
should examine subscript arguments to determine whether the key path type is
sendable or not, and if so, inform inference to produce `& Sendable` existential
type as a binding. Binding key path type is delayed until all subscript arguments
are fully resolved.
2023-11-28 13:02:17 -08:00
Pavel Yaskevich
2e1ca0a32a [ConstraintSystem] Extend KeyPathCapability to support sendability 2023-11-28 13:02:14 -08:00
Pavel Yaskevich
bd4ee4681b Merge pull request #70007 from xedin/keypath-application-improvements
[ConstraintSystem] Modernization of key path application handling
2023-11-28 12:44:42 -08:00
Slava Pestov
f89b9817e7 Merge pull request #69950 from slavapestov/clean-up-open-existentials
Cleanups and fixes for opened existentials
2023-11-28 10:45:19 -05:00
Alex Hoppen
6ac7915dae Merge pull request #70013 from ahoppen/ahoppen/remove-leaveclosurebodiesunchecked
[Sema] Remove `LeaveClosureBodiesUnchecked`
2023-11-27 14:03:18 -08:00
Pavel Yaskevich
420e0af776 Merge pull request #69939 from xedin/issue-69936
[ConstraintSystem] Key path literals with completion tokens should be…
2023-11-27 13:16:48 -08:00
Slava Pestov
6fb5b94675 Sema: Simplify recursion in typeEraseExistentialSelfReferences() 2023-11-27 14:05:36 -05:00
Slava Pestov
81723435b6 Sema: Extract duplication between typeEraseOpenedExistentialReference() and typeEraseOpenedArchetypesWithRoot() 2023-11-27 14:05:36 -05:00
Slava Pestov
c0f9d290fa AST: Move TypeBase::typeEraseOpenedArchetypesWithRoot() into ConstraintSystem.cpp 2023-11-27 14:05:36 -05:00
Slava Pestov
04577febf5 Sema: Simplify typeEraseExistentialSelfReferences() 2023-11-27 14:05:36 -05:00
Slava Pestov
5bb82f754e Sema: Don't need to pass parent signature to OpenedArchetypeType::get() 2023-11-27 14:05:36 -05:00
Slava Pestov
f5e250551d AST: Merge GenericSignature::get{Non,}DependentUpperBounds() 2023-11-27 14:05:36 -05:00
Slava Pestov
c298997e1e AST: Use ArchetypeType::getExistentialType() in a couple of places 2023-11-27 14:05:36 -05:00
Slava Pestov
1b1963e904 Sema: Remove 'inferred result type requires explicit coercion' diagnostic 2023-11-27 14:05:36 -05:00
Slava Pestov
ef6630f0ac Sema: Strip off LValueType from opened existential accesses with an erased result type
- Fixes https://github.com/apple/swift/issues/62219
- Fixes https://github.com/apple/swift/issues/60619,
- Fixes rdar://104230391
- Fixes rdar://118247162.
2023-11-27 14:05:36 -05:00
Alex Hoppen
b603a5e9a0 [Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based.

rdar://91403086
2023-11-23 11:41:29 -08:00
Pavel Yaskevich
1a011c3bde [ConstraintSystem] Adjust locator for key path project value type variable
Previous `FunctionArgument` locator didn't make sense because
this type variable doesn't actually represent a parameter but
rather a value generic parameter of the key path subscript index
parameter.
2023-11-20 00:24:30 -08:00
Pavel Yaskevich
47b4d70540 [ConstraintSystem] Remove unused r-value key path type element type variable
The resulting type is no longer in use so there is no need to create
a type variable and a constraint to perform the operation.
2023-11-17 16:19:32 -08:00
Pavel Yaskevich
76046ba712 [ConstraintSystem] Key path subscript index cannot be inferred as inout
Subscripts do not support inout parameters.
2023-11-17 16:18:15 -08:00
Pavel Yaskevich
f440dd8e37 [ConstraintSystem] Update key path subscript index type variable to use new locator element 2023-11-17 15:47:44 -08:00
Pavel Yaskevich
d542ab99f0 [ConstraintSystem] Add a new locator for key path subscript parameter 2023-11-17 13:21:42 -08:00
Pavel Yaskevich
72bb74aa4f [ConstraintSystem] Key path literals with completion tokens should be marked as invalid
Capability couldn't be determined for expressions like that which
means that inference should be delayed until root becomes available.

Resolves: https://github.com/apple/swift/issues/69936
2023-11-16 15:48:46 -08:00
Pavel Yaskevich
34a0b09889 [ConstraintSystem] NFC: Format code related to InferSendableFromCaptures feature 2023-11-16 10:47:55 -08:00
Pavel Yaskevich
8d7b1a44c4 [ConstraintSystem] NFC: Remove unused reference to ASTContext 2023-11-16 10:47:55 -08:00