Commit Graph

28382 Commits

Author SHA1 Message Date
Doug Gregor
5a3327c829 Merge pull request #79264 from DougGregor/unsafe-yield
Handle unsafe expressions in yield statements
2025-02-10 10:51:38 -08:00
Slava Pestov
17d8c820dc Merge pull request #79220 from slavapestov/fix-rdar143950572
AST: Source range of FuncDecl/ConstructorDecl should include the thrown type
2025-02-10 13:49:37 -05:00
Cal Stephens
14632b7c3e Update tests after pulling fix from master 2025-02-10 08:13:27 -08:00
Doug Gregor
54124193cf Look past autoclosures when determining where to insert "unsafe" in a Fix-It
Otherwise, we'll end up inserting the "unsafe" on the right-hand side of an &&
2025-02-10 06:54:17 -08:00
Doug Gregor
1cbeee6fed Fix Fix-It location for "unsafe" when calling an initializer
The implicit reference to the initializer was tripping up the logic
for finding the appropriate place to insert "unsafe", and it was ending
up in the middle of the expression.
2025-02-10 06:54:15 -08:00
Cal Stephens
64fc43e19b Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2025-02-06-a' of github.com:swiftlang/swift into cal--fix-nested-weak-self-issue
Tag build swift-DEVELOPMENT-SNAPSHOT-2025-02-06-a
2025-02-10 06:31:27 -08:00
Cal Stephens
31528da906 Further simplify conditions 2025-02-10 06:29:27 -08:00
Doug Gregor
4a9e8906fb Handle unsafe expressions in yield statements 2025-02-10 06:22:41 -08:00
Slava Pestov
e9266c25d3 Sema: Fix accepts-invalid with throwing function types
We can't unconditionally skip the conformance check if the type contains type
parameters; instead, we only want to skip it in the structural resolution
stage. In interface resolution stage, we proceed by mapping the type into
the generic environment first.
2025-02-10 09:17:40 -05:00
Slava Pestov
8400b43388 Sema: Don't diagnose thrown error type that contains errors
If we have error types here, type resolution already diagnosed an
error; don't diagnose again.
2025-02-10 09:17:40 -05:00
Slava Pestov
92d8bf715f Sema: Remove unused variable 2025-02-10 09:17:40 -05: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
Doug Gregor
8463e2a606 Merge pull request #79240 from DougGregor/safe-cover-unsafe-arguments
@safe functions, properties, and subscripts "cover" certain unsafe arguments
2025-02-08 14:50:20 -08:00
Doug Gregor
4139430560 @safe functions, properties, and subscripts "cover" certain unsafe arguments
When calling an explicitly-@safe function or subscript, or accessing an
explicitly-@safe property, the direct arguments to that operation can be
considered safe if they are references to local variables or are references
to types.

This brings the implementation in line with the recent adjustments to the
proposal within the review.
2025-02-08 10:18:12 -08:00
Becca Royal-Gordon
6e9d386d9e Fix indexing crasher with implicit objcImpl inits
Implicit initializers are given a source location within the type they belong to. This works poorly for @objc @implementation classes, because the class they belong to is imported and so those SourceLocs are in a different source buffer from the extension they’re inside, breaking an invariant enforced by index-while-building features.

Fix these SourceLocs to come from the implementation context, so they’ll come from the extension for an objcImpl class and the type itself otherwise.
2025-02-07 13:22:43 -08:00
Hamish Knight
5af928216e [CS] Avoid penalizing holes for placeholder vars for completion
When doing completion in a result builder, we avoid
solving unrelated expressions by replacing them with
unbound placeholder variables. Avoid penalizing
assigning holes to these placeholders, since
otherwise we end up unnecessarily exploring the
entire solution space, and bailing due to too
complex.

rdar://144382123
2025-02-07 17:37:35 +00:00
Hamish Knight
b03e989280 [CS] NFC: Factor out shouldIgnoreHoleForCodeCompletion 2025-02-07 17:37:35 +00:00
Michael Gottesman
8c5b49e65a Merge pull request #79204 from gottesmm/undo-concurrent-for-now
[concurrency] For now undo ActorIsolation::Concurrent refactoring.
2025-02-06 23:06:15 -08:00
kibeom lee
2311794184 Fix typo in comments 2025-02-07 15:12:11 +09:00
Allan Shortlidge
3ce2449b8d Merge pull request #79190 from tshortli/availability-context-unit-tests
AST: Introduce `AvailabilityContext::containsUnavailableDomain()`
2025-02-06 20:58:35 -08:00
Doug Gregor
3637e69ca1 Merge pull request #79195 from DougGregor/expand-conformances-member-ordering
[Macros] Eliminate ordering dependency that suppressed conformingTo protocols
2025-02-06 19:32:48 -08:00
Michael Gottesman
d33371a51a Merge pull request #79178 from xedin/execution-attr-in-type-context
[AST/Parse] Initial implementation of `@execution(concurrent | caller)` in type context
2025-02-06 18:44:00 -08:00
Michael Gottesman
7e350bb4ce Revert "[concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated."
This reverts commit 0cb64638d0.
2025-02-06 14:05:06 -08:00
Michael Gottesman
f05f08c2c0 Revert "[concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting."
This reverts commit 543b1e6ca3.
2025-02-06 14:04:30 -08:00
Michael Gottesman
c12a1410bf Revert "[concurrency] Split out the default inferred actor isolation computation into a helper from ActorIsolationRequest::evaluate."
This reverts commit 5d6131e16b.
2025-02-06 14:04:25 -08:00
Doug Gregor
d276006648 [Macros] Eliminate ordering dependency that suppressed conformingTo protocols
When a macro that has both 'member' and 'extension' roles is on a type,
and both list conforming protocols, the order in which those roles were
evaluated in the compiler could change the set of protocols passed to
the macro expansion function (via `conformingTo:`). Specifically, if
the extension macro was expanded first, the member macro would see the
extension providing the conformance to one of its protocols, and not
pass down that protocol to the member macro's `conformingTo:`.

Ensure that we account for already-expanded extension macros that
define conformances.

Fixes rdar://137080876.
2025-02-06 11:07:20 -08:00
Allan Shortlidge
ddb5f23306 AST: Add AvailabilityContext::containsUnavailableDomain().
Replaces AvailabilityContext::getUnavailableDomain().
2025-02-06 09:50:07 -08:00
Cal Stephens
041c68519c Simplify diagnostics 2025-02-06 08:38:13 -08:00
Anton Korobeynikov
1e7a1d91fc Emit reabstraction thunks for implicit conversions between T.TangentType and Optional<T>.TangentType (#78076) 2025-02-05 20:57:52 -08:00
Slava Pestov
4937d0a242 Merge pull request #79134 from slavapestov/smaller-potential-bindings
Sema: More accurate undo() of PotentialBindings::retract()
2025-02-05 14:05:05 -05:00
Pavel Yaskevich
aad858d66c [Sema] Implement validation of @execution(...) in type context 2025-02-05 10:11:38 -08:00
Doug Gregor
246e130584 Merge pull request #79144 from DougGregor/distributed-typed-throws
Ensure that distributed functions with typed throws can be called from outside the actor
2025-02-05 01:21:22 -08:00
Michael Gottesman
c846306f63 Merge pull request #79145 from gottesmm/pr-4f8d798bbab9e98210dd45e18e92720f7c73cc7d
[concurrency] Split out the default inferred actor isolation computation into a helper from ActorIsolationRequest::evaluate.
2025-02-04 23:09:38 -08:00
Cal Stephens
684c908564 Prevent nested closure in 'extension Optional' from unexpectedly being allowed 2025-02-04 18:49:42 -08:00
Michael Gottesman
5d6131e16b [concurrency] Split out the default inferred actor isolation computation into a helper from ActorIsolationRequest::evaluate.
NFC.
2025-02-04 17:30:05 -08:00
Slava Pestov
8a3300baa1 Sema: We no longer call PotentialBindings::infer() from undo() 2025-02-04 20:26:53 -05:00
Slava Pestov
09f78bfd95 Sema: Remove now-unused ConstraintGraph::inferBindings() 2025-02-04 20:26:12 -05:00
Slava Pestov
cda3cda132 Sema: Rework change recording in PotentialBindings::retract()
Instead of making an undo() do an infer(), let's record fine-grained
changes about what was retracted, and directly re-insert the same
elements into the data structures.
2025-02-04 20:26:12 -05:00
Allan Shortlidge
8534f29ef5 Merge pull request #79122 from tshortli/loosen-more-available-than-enclosing-extension
Sema: Loosen more available than enclosing extension diagnostic
2025-02-04 16:31:20 -08:00
Doug Gregor
84ed66f3be Ensure that distributed functions with typed throws can be called from outside
When calling a distributed function for an actor that might not be local,
the call can throw due to the distributed actor system producing an
error. The function might, independently, also throw. When the
function uses typed throws, we incorrectly treated the call is if it
would always throw the error type specified by the function. This
leads to incorrectly accepting invalid code, and compiler crashes in
SILGen.

The change here is to always mark calls to distributed functions
outside the actor as "implicitly throwing", which makes sure that we
treat the call sites as throwing 'any Error'. The actual handling of
the typed throw (from the local function) and the untyped throw (from
the distributed actor system) occurs in thunk generation in SILGen,
and was already handled correctly.

Fixes rdar://144093249, and undoes the ban introduced by rdar://136467528
2025-02-04 16:06:51 -08:00
Slava Pestov
b09c6733d3 Sema: Change a few fields of PotentialBindings from SmallDenseSet to SmallVector
These are not going to have duplicates by construction.
2025-02-04 16:38:55 -05:00
Allan Shortlidge
4d94d55fc8 Merge pull request #79098 from tshortli/consolidate-unexpected-available-versions-diagnostic
Parse/Sema: Consolidate diagnostics for unexpected versions
2025-02-04 10:05:58 -08:00
Slava Pestov
4b1cb12b6c Sema: Sink PotentialBindings::Defaults down into BindingSet 2025-02-03 20:38:06 -05:00
Slava Pestov
6ea39d2415 Sema: Sink PotentialBindings::Literals down into BindingSet 2025-02-03 17:19:22 -05:00
Slava Pestov
466c7708e2 Sema: Sink PotentialBindings::Protocols down into BindingSet 2025-02-03 17:19:22 -05:00
Slava Pestov
baa1ee9fb9 Sema: Move BindingSet::BindingSet to CSBindings.cpp 2025-02-03 17:19:22 -05:00
Allan Shortlidge
aed1a013e4 Sema: Loosen more available than enclosing extension diagnostic.
When diagnosing a declaration that is more available than its context, to
preserve source compatibility we need to downgrade the diagnostic to a warning
when the outermost declaration is an extension. This logic regressed with
https://github.com/swiftlang/swift/pull/77950 and my earlier attempt to fix
this (https://github.com/swiftlang/swift/pull/78832) misidentified what had
regressed.

Really resolves rdar://143423070.
2025-02-03 14:07:27 -08:00
Michael Gottesman
543b1e6ca3 [concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting. 2025-02-03 10:56:08 -08:00
Michael Gottesman
0cb64638d0 [concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated.
This is just the first part of a larger transition.
2025-02-03 10:56:06 -08:00