Commit Graph

28382 Commits

Author SHA1 Message Date
Allan Shortlidge
54e6900c36 Sema: Skip diagnosing witness availability for unavailable conformances.
If a conformance is unavailable then checking for the potential unavailability
of a witness doesn't make sense so skip it. This is necessary now because
availability scopes no longer constrain the platform introduction version for a
source range in that is annotated in source to be simultaneously unavailable
and also introduced in a later version.

This fixes a regression caused by https://github.com/swiftlang/swift/pull/79249.

Resolves rdar://145255592.
2025-02-20 22:42:00 -08:00
Allan Shortlidge
b20f2c0e4e Merge pull request #79517 from tshortli/availability-scope-decl-context
AST: Store the active `DeclContext` in `AvailabilityScope`
2025-02-20 20:07:57 -08:00
Allan Shortlidge
3db2b97a83 Merge pull request #79520 from tshortli/sink-semantic-available-attr-request
AST/Sema: Sink `SemanticAvailableAttrRequest` from Sema into AST
2025-02-20 20:00:13 -08:00
Pavel Yaskevich
18a9987e16 Merge pull request #79497 from xedin/execution-attr-diagnostics
[Sema] Either variant of `@execution` is incompatible with other isol…
2025-02-20 14:00:57 -08:00
Slava Pestov
3a722210bb Merge pull request #79507 from slavapestov/assert-constraint-types
Sema: Assert that certain type kinds do not appear in constraints
2025-02-20 16:54:28 -05:00
fahadnayyar
9782eae585 Merge pull request #77522 from fahadnayyar/cxx-frt-inheritance-diagnostics
[cxx-interop] Infer SWIFT_SHARED_REFERENCE for types inheriting from a C++ foreign reference type
2025-02-20 13:46:28 -08: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
0b57ca6d56 [CS] Use dumpAnchor in SolverTrail::Change::dump
Resolve a couple of FIXMEs by using `dumpAnchor` to
dump a couple of ASTNodes. This uses the same
compact representation as used in ConstraintLocator
dumping.
2025-02-20 21:31:46 +00:00
Hamish Knight
9c04fd8cd3 [CS] NFC: Factor out matchPackElementType 2025-02-20 21:31:46 +00:00
Hamish Knight
29e9f429e3 [CS] NFC: Rename PackEnvironments -> PackElementExpansions
IMO "environment" is confusable for GenericEnvironment,
make it clearer it's referring to the parent
PackExpansionExpr.
2025-02-20 21:31:46 +00:00
Holly Borla
be035a65fb Merge pull request #78652 from jamieQ/static-actor-safety-hole
[Sema]: Fix data race safety hole with mutable statics within actors
2025-02-20 12:04:16 -08:00
Allan Shortlidge
f4f9d85503 AST/Sema: Sink SemanticAvailableAttrRequest from Sema into AST.
Unblocks some work on the `@abi` attribute.
2025-02-20 10:29:38 -08:00
Rintaro Ishizaki
8833ff58a2 [AST] Sink the flag collection logic from Parse to AST
* Collect flag in `ParamDecl::setTypeRepr()`.

* [ASTGen] Separate `BridgedParamDecl.setTypeRepr(_:)` from
`BridgedParamDecl.createParsed(_:)` aligning with C++ API. The majority
of the creations don't set the typerepr.

* Update `ParamSpecifierRequest::evaluate` to handle non-implicit
`ParamDecl` without `TypeRepr` (i.e. untyped closure parameter), instead
of `setSpecifier(::Default)` manually in Parse.
2025-02-20 10:04:49 -08:00
Slava Pestov
cd77027675 Sema: Banish GenericTypeParamType from the constraint system 2025-02-20 12:06:21 -05:00
Slava Pestov
209e266b47 Sema: Banish UnboundGenericType from the constraint system
These should have been opened already, and the logic in
simplifyConstraint(), matchTypes(), etc is just going to do
undefined things if they end up there, so let's guard
against it happening.
2025-02-20 12:06:21 -05:00
Allan Shortlidge
1ff1a8d7bc AST: Store the active DeclContext in AvailabilityScope.
In the future, the `DeclContext` for a given scope will be needed as an input
in order to query for the `AvailabilityDomain` associated with an
`AvailabilitySpec`.
2025-02-20 08:57:45 -08:00
fahadnayyar
d8f919778d [cxx-interop] [cxx-interop] Infer SWIFT_SHARED_REFERENCE for types inheriting from a C++ foreign reference type
rdar://97914474
2025-02-20 08:46:57 -08:00
Doug Gregor
c308cfd26a Fix declaration context for unsafe storage checking
Fix a compiler crash involving checking of generic types for unsafe
storage.
2025-02-19 21:31:20 -10:00
Slava Pestov
668928e591 Merge pull request #79475 from slavapestov/issue-a-retraction
Sema: Clean up odd bit of dead code in binding inference
2025-02-19 23:55:36 -05:00
Slava Pestov
a7b50c0b62 Merge pull request #79489 from slavapestov/fix-rdar145092838
Sema: Don't record constraints containing UnboundGenericType from shrink()
2025-02-19 23:42:09 -05:00
Pavel Yaskevich
613fbaf76e [Sema] Either variant of @execution is incompatible with other isolation
According to the proposal both variants cannot be used together
with other forms of isolation i.e. isolated parameters, global
actors, `@isolated(any)` attributes.
2025-02-19 20:06:15 -08:00
Konrad `ktoso` Malawski
e8668684a1 Merge pull request #79411 from amartini51/typo_144059094
Remove double word ("a a" and "the the")
2025-02-20 13:05:06 +09:00
Pavel Yaskevich
e2ff3308be [Frontend] NFC: Rename NonIsolatedAsyncInheritsIsolationFromContext feature
New name is `AsyncCallerExecution` as stated by the proposal.
2025-02-19 20:00:56 -08:00
Michael Gottesman
3ef18eaf1d Merge pull request #79300 from gottesmm/pr-12bede947a34719b34b1aa8ea6c126a6126d6dd6
[concurrency] Implement serialization for execution(caller)/execution(concurrent).
2025-02-19 18:29:02 -08:00
Allan Shortlidge
ff17263e56 Merge pull request #79480 from tshortli/exclude-parser-diags
Parse: Avoid including `DiagnosticsParse.h` in `Parser.h`
2025-02-19 18:19:29 -08:00
Allan Shortlidge
7492e961dc Merge pull request #79494 from tshortli/type-check-availability-spec
Parse/Sema: Move some `AvailabilitySpec` diagnostics from Parse to Sema
2025-02-19 17:07:24 -08:00
Rintaro Ishizaki
e5d5026992 Merge pull request #79456 from rintaro/astgen-paramdecl
[ASTGen] ParamDecl generation improvements
2025-02-19 14:05:55 -08:00
Allan Shortlidge
e90530990a Parse/Sema: Move some AvailabilitySpec diagnostics from Parse to Sema.
Eventually, querying the `AvailabilityDomain` associated with an
`AvailabilitySpec` will require invoking a request that takes a `DeclContext`.
This means that any diagnostics related to the domain identified by an
`AvailabilitySpec` need to be emitted during type-checking rather than parsing.
This change migrates several `AvailabilitySpec` diagnostics from Parse to Sema
to unblock further work.
2025-02-19 11:40:56 -08:00
Slava Pestov
521ea46d15 Sema: Don't record constraints containing UnboundGenericType from shrink()
Something changed here between the removal of shrink() and it's
re-introduction, and we now record constraints that contain
UnboundGenericType, which crashes in matchTypes().

As a narrow workaround, let's just ignore the contextual type if
contains an UnboundGenericType.

Fixes rdar://145092838.
2025-02-19 13:27:33 -05:00
Allan Shortlidge
e8329d292b Parse: Avoid including DiagnosticsParse.h in Parser.h.
This prevents the include of DiagnosticsParse.h from leaking into `.cpp` files
in libraries besides Parse.
2025-02-19 07:56:38 -08:00
Slava Pestov
2cf365fa19 Sema: Fold ConstraintGraph::updateFixedType() into its last caller 2025-02-18 17:53:30 -05:00
Slava Pestov
58fdc4f805 Sema: ConstraintGraph::retractFromInference() doesn't need the new fixed type 2025-02-18 17:52:59 -05:00
Rintaro Ishizaki
6980509f8c [ASTGen] Generate DefaultArgumentInitializer
Rework ParamDecl contextualization.
2025-02-18 11:13:39 -08:00
Hamish Knight
11a4415ce7 [CS] Fix DeclContext for multi-statement closure captures
Make sure we set the correct DeclContext for CSGen
of multi-statement closure captures, since
otherwise the DeclContext is set to the closure
itself, which is wrong.
2025-02-18 11:30:22 +00:00
Hamish Knight
fd5346fee3 [CS] Ensure DeclContext is switched for if/switch expressions
Similar to multi-statement closures, we need to
make sure we change the DeclContext of the
ConstraintSystem when solving a conjunction for an
if/switch expression. This is unfortunately needed
for cases within single-expression closures since
they can't switch the system's DeclContext (as
they're solved together with the rest of the system).
2025-02-17 12:02:16 +00:00
Allan Shortlidge
9c15342d08 Sema: Allow unavailable stored properties in swiftinterfaces.
In a swiftinterface a declaration could be unavailable because it was written
in source with an `@_spi_available` attribute so it isn't possible to safely
reject unavailable stored properties in that context.

Resolves rdar://144958440.
2025-02-16 21:04:19 -08:00
Doug Gregor
c2e36decfe Merge pull request #79424 from DougGregor/se-0458-match-proposal
[SE-0458] Bring implementation in line with the latest proposal revision
2025-02-16 19:15:27 -08:00
Hamish Knight
d11f7c9ed6 Merge pull request #79422 from hamishknight/remove-init-ty
[AST] NFC: Remove `InitRetType`
2025-02-17 00:56:12 +00:00
Hamish Knight
1e8dc55b7f [AST] NFC: Remove InitRetType
This is no longer used.
2025-02-16 18:52:23 +00:00
Allan Shortlidge
e804c937eb Sema: Retire ExportContext::shouldDiagnoseDeclAsUnavailable().
NFC.
2025-02-16 07:44:45 -08:00
Allan Shortlidge
949a6c68d7 AST/Sema: Retire SemanticAvailableAttr::getVersionAvailability().
Query for availability constraints instead of calling getVersionAvailability().
2025-02-16 07:44:45 -08:00
Allan Shortlidge
7d4ab8d66d Sema: Adopt getAvailabilityConstraintsForDecl().
Replaces `getUnsatisfiedAvailabilityConstraint()`.

NFC.
2025-02-16 07:44:45 -08:00
Allan Shortlidge
3c8a57f86d AST: Use consolidated availability constraint query for diagnostics.
Switch to calling `swift::getAvailabilityConstraintsForDecl()` to get the
unsatisfied availability constraints that should be diagnosed.

This was intended to be NFC, but it turns out it fixed a bug in the recently
introduced objc_implementation_direct_to_storage.swift test. In the test,
the stored properties are as unavailable as the context that is accessing them
so the accesses should not be diagnosed. However, this test demonstrates a
bigger issue with `@objc @implementation`, which is that it allows the
implementations of Obj-C interfaces to be less available than the interface,
which effectively provides an availability checking loophole that can be used
to invoke unavailable code.
2025-02-16 07:44:45 -08:00
Doug Gregor
4313f6790c [Strict memory safety] Diagnose unsafe types in the superclass of a class 2025-02-15 22:57:54 -08:00
Doug Gregor
c9cfed2007 [Strict safety] Diagnose types with unsafe storage
When a type definition involves unsafe types in its storage, require it
to be explicitly marked @unsafe or @safe.
2025-02-15 22:42:07 -08:00
Doug Gregor
2de9f4a8f5 [Strict safety] Stop complaining about unsafe signatures
Since we infer unsafety from a use of a declaration that involves unsafe types
in its signature, there isn't a reason to require @unsafe on declaration to
restate it. This matches recent revisions of SE-0458.
2025-02-15 22:02:22 -08:00
Holly Borla
34cc3e88b3 Merge pull request #79406 from hborla/type-eraser-availability
[ConstraintSystem] Always choose an available type eraser type.
2025-02-15 10:49:34 -08:00
Jamie
f1a1998071 [gardening]: refactor checkGlobalIsolation function & add comments 2025-02-15 10:38:48 -06:00
Jamie
96ee7a0ffb [Sema]: Fix data race safety hole with mutable statics within actors
Update the concurrency typechecking logic to remove a check that allowed
mutable static variable declarations nested within an Actor type to be
ignored when diagnosing mutable non-Sendable state.
2025-02-15 10:29:40 -06: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