Commit Graph

28382 Commits

Author SHA1 Message Date
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
Saleem Abdulrasool
fc397de5d1 Merge pull request #78776 from compnerd/suppression
lib: simplify some pragma usage
2025-01-22 08:26:01 -08:00
Egor Zhdan
7903bf2684 Merge pull request #78783 from swiftlang/egorzhdan/enum-resilience
[cxx-interop] Assume that plain-C enums are resilient
2025-01-22 15:13:03 +00:00
Allan Shortlidge
fe138e014a AST: Track an unavailable domain instead of platform in AvailabilityContext.
Now that most of the compiler tracks availability in terms of
AvailabilityDomain, it's time to do so in AvailabilityContext as well. This
will ensure that the compiler accurately suppresses diagnostics about a decl
being unavailable in an arbitrary domain when the context of the use is already
unavailable in that domain.

With this change, most of the special-casing for the Embedded Swift availability
domain has been removed from the compiler, outside of parsing and interface
printing.
2025-01-22 06:40:11 -08:00
Allan Shortlidge
ba822d1e23 AST: Eliminate remaining direct access to AvailableAttr's fields.
Most of the compiler should use SemanticAvailableAttr instead. In contexts like
ASTDumper where a semantic attribute is unavailable use accessors on
AvailableAttr.

NFC.
2025-01-21 22:56:07 -08:00
Allan Shortlidge
0f1e301fb8 Merge pull request #78775 from tshortli/replace-unavailability-diagnostic-info
Sema: Replace UnavailabilityDiagnosticInfo with AvailabilityConstraint
2025-01-21 20:28:58 -08:00
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
Pavel Yaskevich
798cd6843e [Diagnostics] Fix generic arguments mismatch diagnostic related to leading-dot syntax
`GenericArgumentsMismatchFailure` missed a case where location
of the failure points to a member spelled with leading-dot syntax.
2025-01-21 11:43:01 -08:00
Egor Zhdan
00e6b360d5 [cxx-interop] Assume that plain-C enums are resilient
This fixes sudden compiler errors that are emitted when trying to use CoreText.framework with C++ interop enabled.

When Swift is trying to rebuild a dependency module from its textual interface, it should not complain on usages of C enums in public Swift APIs.

This still leaves the resilience safety guardrail enabled for C++ scoped enums.

rdar://143215914
2025-01-21 18:57:10 +00:00
Joe Groff
a0a26b8330 Require explicit statement of all Copyable/Escapable requirements for conditional Copyable/Escapable conformances.
As specified by the SE-0446 acceptance, extensions that declare a type's
conditional `Copyable` or `Escapable` ability must reiterate explicitly all
of the `Copyable` and/or `Escapable` requirements, whether required or not
required (by e.g. `~Copyable`) that were suppressed in the original
type declaration.
2025-01-21 09:36:39 -08:00
Saleem Abdulrasool
42af06051d lib: simplify some pragma usage
When suppressing a warning for a single line, prefer to use `suppress`
to avoid the push/pop dance.
2025-01-21 09:15:07 -08:00
Pavel Yaskevich
82e111a276 Merge pull request #78704 from xedin/rdar-142920095
Implement experimental`@execution(concurrent | caller)` attribute
2025-01-21 09:04:39 -08:00
Allan Shortlidge
31fa5fc347 Sema: Replace UnavailabilityDiagnosticInfo with AvailabilityConstraint.
AvailabilityConstraint models a superset of UnavailabilityDiagnosticInfo and
will become the currency type for unsatisfied availability everywhere. NFC.
2025-01-21 08:51:29 -08:00
Allan Shortlidge
fdb182b1a5 Sema: Pass rename to diagnoseExplicitUnavailability() lambda.
This ensures that it doesn't need to be recomputed, which introduces an
opportunity for inconsistency. NFC.
2025-01-21 08:51:29 -08:00
Pavel Yaskevich
d4143ed9bb Merge pull request #78721 from xedin/downgrade-noasync-to-warning-on-preconcurrency-decls
[TypeChecker] Downgrade `noasync` availability to warnings on `@preco…
2025-01-20 15:05:28 -08:00
Allan Shortlidge
691f6fc646 AST: Model Embedded Swift availability with a domain.
Remove the bit on AvailableAttr that previously modeled this.

Resolves rdar://138802876.
2025-01-19 08:52:53 -08:00
Anthony Latsis
6c9bb2a283 Merge pull request #78593 from AnthonyLatsis/cocos-nucifera
OpenedExistentials: Do not attempt to erase existential metatypes wit…
2025-01-19 03:35:22 +00:00
Cal Stephens
8557e234ee Merge branch 'main' into cal--fix-nested-weak-self-issue 2025-01-18 18:36:24 -08:00
Cal Stephens
e6a2230fdf Fix issue where implicit self was unexpectedly not allowed in nested weak self closure in Swift 6 mode 2025-01-18 18:25:23 -08:00
Pavel Yaskevich
c89ba5f58c [Sema] Diagnose clash between inferred global actor isolation and @execution(concurrent) 2025-01-17 15:40:01 -08:00
Pavel Yaskevich
b1e30b22b9 [Sema] Impliment initial validation of @execution(concurrent) attribute 2025-01-17 15:40:01 -08:00