Commit Graph

28352 Commits

Author SHA1 Message Date
Pavel Yaskevich
aff0f455cf Merge pull request #79026 from xedin/rdar-143474313
[CSBindings] Allow optional subtype inference when closure result is …
2025-01-30 00:37:46 -08:00
Pavel Yaskevich
f5158f8427 Merge pull request #79023 from xedin/rdar-143799118
[CSOptimizer] Disjunctions with IUO overload choices are unsupported
2025-01-30 00:37:33 -08:00
Anthony Latsis
9fb198ff71 Sema: Do not diagnose preconcurrency redundancy in implied conformances 2025-01-30 06:35:43 +00:00
Michael Gottesman
37720323d2 Merge pull request #78997 from gottesmm/wire-up-execution
[concurrency] Wire up execution(concurrent)/execution(caller)
2025-01-29 16:53:11 -08:00
Pavel Yaskevich
654d39b736 Merge pull request #79004 from xedin/rdar-143582881
[CSOptimizer] MemberImportVisibility: Don't consider overloads that c…
2025-01-29 14:23:47 -08:00
Pavel Yaskevich
c922ab5634 [CSBindings] Allow optional subtype inference when closure result is not yet resolved
Similar to `Void?` we need to unwrap `$T?` because it could be later
bound to `Void` from context.

Resolves: rdar://143474313
2025-01-29 13:12:56 -08:00
Michael Gottesman
28826b107c Remove some dead code and remove an unneeded comment. 2025-01-29 12:22:57 -08:00
Pavel Yaskevich
471ee21535 [CSOptimizer] Disjunctions with IUO overload choices are unsupported
They form a follow-up disjunction to determine whether force unwrap
is necessary and `getEffectiveType` cannot handle that.

Resolves: rdar://143799118
2025-01-29 10:36:16 -08:00
Pavel Yaskevich
aa4a2b9071 [CSOptimizer] MemberImportVisibility: Don't consider overloads that come from implicit imports
Ignore declarations that come from implicitly imported modules
when `MemberImportVisibility` feature is enabled otherwise
we might end up favoring an overload that would be diagnosed
as unavailable later.

Resolves: rdar://143582881
2025-01-29 10:09:39 -08:00
Michael Gottesman
d79fcb6d84 [caller-isolation] Teach Sema how to handle isolation of explicit @execution({concurrent,caller}). 2025-01-28 13:48:44 -08:00
Allan Shortlidge
36c6c7fc68 AST: Add a DeclContext to AvailabilityDomain::builtinDomainForString().
A context is needed to customize the behavior of lookup in downstream versions
of Swift.
2025-01-28 13:47:42 -08:00
Allan Shortlidge
4fa8c559da Sema: Fix diagnostics for @available(noasync, swift). 2025-01-28 13:47:42 -08:00
Michael Gottesman
6a9afa53f7 [concurrency] Add back support for checking if we have a global actor/execution together. 2025-01-28 13:44:23 -08:00
Michael Gottesman
3415189442 [concurrency] Change execution to override inferred global actor isolation to match nonisolated.
Specifically, we were attempting to diagnose cases like the following:

```swift
@MainActor protocol P {
  func foo() async
}

struct S : P {
  @execution(concurrent) func foo() async {}
}
```

This was just an attempt to be more conservative. After some conversations, it
came up that nonisolated does not work that way... that is the compiler will
accept the following and just hop in the protocol witness thunk:

```swift
@MainActor protocol P {
  func foo() async
}

struct S : P {
  nonisolated func foo() async {}
}
```
2025-01-28 12:46:20 -08:00
Michael Gottesman
527616d105 [sema] Move some extra type checking from getIsolationFromAttribute to the attribute checker.
This never belonged in ActorIsolationRequest since it fits perfectly in the
attribute checker. This also simplifies the logic before I add code to
getIsolationFromAttribute to handle ExecutionAttribute.
2025-01-28 12:39:05 -08:00
Konrad `ktoso` Malawski
a2b3c488a7 [Distributed] ban typed throws in distributed funcs
They don't yield a correct error type as we didn't implement it, so
rather allow it and risk crashes, ban it until we get the time to
implement it.

The real solution is to adjust typed throws error inference to do an
union of the thrown error of the func and the type thrown by the
distributed actor system remote call -- which today always would be (E |
Error) -> Error...

We could add a new associated type to DAS and then we could make it more
proper...

resolves rdar://136467528
2025-01-28 17:07:21 +00:00
Slava Pestov
852e3f5f94 Merge pull request #78957 from slavapestov/cgfloat-double-cleanup
Sema: Clean up CSApply for CGFloat <-> Double conversion
2025-01-28 08:06:32 -05:00
Anthony Latsis
b97682adc9 [NFC] Sema: Minor optimizations to TypeChecker::checkConformancesInContext 2025-01-28 08:12:41 +00:00
Pavel Yaskevich
248c0260f0 Merge pull request #78949 from xedin/rdar-143475850-part-2
[CSOptimizer] Don't consider CGFloat widening when explicit initializ…
2025-01-28 00:04:18 -08:00
Allan Shortlidge
e019a32122 AST: Introduce and adopt DeclContext::isInSwiftinterface().
Checking whether a declaration is in a `.swiftinterface` is a very common query
that is made somewhat awkward because declarations are not always in source
files. To make these checks more ergonomic, expose a convenience on
DeclContext.
2025-01-27 19:25:41 -08:00
Slava Pestov
5cbe8cbf56 Sema: Handle CGFloat <-> Double conversion in getOptionalEvaluationDepth() 2025-01-27 17:28:20 -05:00
Slava Pestov
4ae57acaa2 Sema: Remove ConstraintSystem::ImplicitValueConversions 2025-01-27 17:28:19 -05:00
Slava Pestov
0c2887db5b Sema: Simplify CSApply for Double<->CGFloat conversion 2025-01-27 16:42:03 -05:00
Slava Pestov
c47ff06a72 Sema: Tiny cleanup for matchTypes() 2025-01-27 16:42:03 -05:00
Slava Pestov
5ee97c5275 Merge pull request #78888 from slavapestov/fix-rdar143340082
Sema: Ignore inactive type variables in addTypeVariableConstraintsToWorkList()
2025-01-27 16:40:59 -05:00
Allan Shortlidge
45b5050c23 Merge pull request #78937 from tshortli/allow-overrides-as-available-as-their-context
Sema: Always allow method overrides to be as available as the context
2025-01-27 13:34:47 -08:00
Pavel Yaskevich
3cc76eacdd [CSOptimizer] Don't consider CGFloat widening when explicit initializer is used
Disable implicit `CGFloat` -> `Double` widening conversion if
argument is an explicit call to `CGFloat` initializer.
2025-01-27 09:57:47 -08:00
Slava Pestov
2230c3a17e 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-01-27 10:27:00 -05:00
Slava Pestov
881c4f775b Sema: Ignore inactive type variables in addTypeVariableConstraintsToWorkList()
Fixes a regression from commit 0c128e5db7.

The old depthFirstSearch() walked all adjacencies via the constraint graph,
and thus it would visit type variables that are currently inactive because
we're solving a conjunction element.

This was inconsistent with the new union-find which only formed the
connected components from the currently active type variables; adjacencies
involving inactive type variables are no longer considered.

Fix the inconsistency by changing gatherConstraints(), which used from
addTypeVariableConstraintsToWorkList(), to also skip inactive type
variables.

Fixes rdar://problem/143340082.
2025-01-27 10:26:59 -05:00
Pavel Yaskevich
e8fe5c3769 Merge pull request #78906 from xedin/rdar-143475850-part-1
[CSBindings] Allow subtype inference from `Void?` for closure result …
2025-01-27 00:30:19 -08:00
Allan Shortlidge
174e57cdad Sema: Always allow method overrides to be as available as the context.
When a method override is as available as the class it's a member of, then it
can't be any more available. It doesn't make sense to diagnose such a method as
less available than the method it overrides. This regressed recently for
methods belonging to classes that are nested inside extensions. The
availability of the derived class may be defined by its context, but the
compiler was only checking the availability attributes directly on the class.

Resolves rdar://143600638.
2025-01-26 22:34:53 -08:00
Allan Shortlidge
1284001e45 Sema: Canonicalize platform versions in SemanticAvailableAttrRequest.
This should really be done on-demand during version remapping, but for now the
goal of this change is to be as NFC as possible.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
904518088a Sema: Diagnose @available attibutes that cannot be noasync.
Instead of asserting.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
bd79424039 Sema: Move domain-specific @available attr diagnostics to type checking.
Since the domain is now resolved by SemanticAvailableAttrRequest, diagnosing
attributes with invalid combinations of fields for a specific domains needs to
be delayed.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
a5d60ce35e AST/Sema: Resolve AvailabilityDomain in SemanticAvailableAttrRequest.
Look up the AvailabilityDomain given its name during type checking, instead of
parsing.
2025-01-26 13:50:56 -08:00
Allan Shortlidge
7b8cbd7109 AST: Store unresolved domain strings in AvailableAttr.
This is the first step towards resolving the AvailabilityDomain associated with
an AvailableAttr during type checking instead of parsing.
2025-01-26 13:50:56 -08:00
Slava Pestov
70d6257e8c Merge pull request #78893 from slavapestov/fix-issue-77315
Sema: Fix crash in type resolution when tuple type contains type variables
2025-01-25 10:09:59 -05:00
Pavel Yaskevich
116d1af911 [CSBindings] Allow subtype inference from Void? for closure result types
We don't want to do that in general because injection should happen
only in one place but Void is special because it allows conversions
in that position.
2025-01-25 00:18:31 -08:00
Slava Pestov
9ddfc9e47b Sema: Fix crash in type resolution when tuple type contains type variables
This can happen when we're generating constraints and resolving the
type annotations written in a closure expression. Just skip the
non-copyable check in this case.

Fixes rdar://problem/143031466.
2025-01-24 17:05:20 -05:00
Michael Gottesman
7cb6581560 [caller-isolation] Move "interception" of Nonisolated from attribute to a more logical place.
Specifically, rather than performing the interception in ActorIsolationRequest
itself after we have returned an actor isolation from
getIsolationFromAttributes, just do it in getIsolationFromAttributes.

The reason I am doing this is then the code around how we infer isolation in
such a case is centralized in getIsolationFromAttributes instead of being in
both places.

This is a NFC change.
2025-01-24 12:03:21 -08:00
Doug Gregor
720240254b Enusre that we cannot infinite-loop when finding expression parent 2025-01-23 07:47:20 -08:00
Doug Gregor
b3f2f00588 Suggest both @unsafe and @safe Fix-Its for unsafe types in signature 2025-01-23 07:47:19 -08:00
Doug Gregor
4395537fa0 Introduce the @safe attribute as described in the opt-in safety checking proposal 2025-01-23 07:47:17 -08:00
Allan Shortlidge
9796d1b1f3 Merge pull request #78832 from tshortli/downgrade-more-available-than-enclosing-for-different-domain
Sema: Loosen the decl more available than enclosing diagnostic
2025-01-23 00:24:02 -08:00
Allan Shortlidge
3b7ff19630 Sema: Loosen the decl more available than enclosing diagnostic.
Downgrade the `cannot be more available than enclosing scope` error to a
warning when the attribute making the decl too available is specified for a
less specific platform.

Resolves rdar://143423070.
2025-01-22 17:02:37 -08:00
Allan Shortlidge
2908520841 AST: Introduce SemanticAvailableAttrRequest.
This request will finish type checking an AvailableAttr by resolving its domain
and then enforcing any restrictions that the domain has on the attribute, like
disallowing version specifications.

This change just introduces the request and plumbs it through. NFC.
2025-01-22 16:01:19 -08:00
Pavel Yaskevich
ab8b1cd869 Merge pull request #78789 from xedin/fix-generic-arg-mismatch-with-leading-dot-syntax
[Diagnostics] Fix generic arguments mismatch diagnostic related to le…
2025-01-22 14:32:05 -08:00
Anthony Latsis
499146df88 Merge pull request #78739 from AnthonyLatsis/hatzegopteryx
TypeCheckType: Rework IUO diagnostics using behavior limitation
2025-01-22 19:12:02 +00:00
Allan Shortlidge
190779ecd4 Merge pull request #78797 from tshortli/availability-context-unavailable-domain
AST: Track an unavailable domain instead of platform in AvailabilityContext
2025-01-22 10:31:51 -08:00
Joe Groff
5d0fe0a156 Merge pull request #78705 from jckarter/explicit-conditional-invertible-extension-requirements
Require explicit statement of all `Copyable`/`Escapable` requirements for conditional `Copyable`/`Escapable` conformances.
2025-01-22 09:52:26 -08:00