Commit Graph

28382 Commits

Author SHA1 Message Date
Pavel Yaskevich
8d4038dacd Merge pull request #77461 from xedin/rdar-139237088
[CSBindings] Don't favor application result types before application …
2024-11-11 08:34:16 -08:00
Hamish Knight
26b827de29 [Sema] NFC: Remove diagnoseMoveOnlyPatternMatchSubject
This appears to be a dead function now.
2024-11-11 16:09:52 +00:00
Doug Gregor
f64189043a Merge pull request #77517 from DougGregor/rtc-macro-expansion
Teach the TypeRefinementContext not to skip declarations within macro expansions
2024-11-10 16:43:15 -08:00
Allan Shortlidge
b97e27279e Sema: Fix opaque type accessors with inactive availability conditions.
Opaque type metadata accessor functions could be miscompiled for functions that
contain `if #available` checks for inactive platforms. For example, this
function will always return `A` when compiled for macOS, but the opaque type
accessor would instead return the type metadata for `B`:

```
func f() -> some P {
  if #available(iOS 99, *) {
    return A() // Returns an A on macOS
  } else {
    return B()
  }
}
```

Resolves rdar://139487970.
2024-11-10 09:23:39 -08:00
nate-chandler
aab880da05 Merge pull request #77429 from nate-chandler/general-coro/20241104/1
[CoroutineAccessors] Synthesize default requirement implementations.
2024-11-10 07:43:11 -08:00
Doug Gregor
de4d4a4244 Teach the TypeRefinementContext not to skip declarations within macro expansions
The construction of type refinement contexts performs lazy expansion
for the contents of macro expansions, so that TRC creation doesn't
force all macros to be expanded. However, the logic that skips macro
expansions would *also* skip some declarations produced within a macro
expansion, even when building the TRC specifically for that macro
expansion buffer. This manifest as missing some availability
information within the TRC, rejecting some well-formed code.

Tune the logic for "don't visit macro expansions when building a TRC"
to recognize when we're building a TRC for that macro expansion.

Fixes rdar://128400301.
2024-11-10 07:32:00 -08:00
Allan Shortlidge
0d581c4261 NFC: Use VersionRange::all() to represent "always available".
It doesn't make sense to use `VersionRange::empty()` to represent "universally
available" since something that is available in an empty version range is
effectively never available.
2024-11-09 19:36:03 -08:00
Holly Borla
f6cd19a01a [Concurrency] Handle self apply exprs when computing @preconcurency in the
availability checker.
2024-11-09 10:14:29 -08:00
Holly Borla
dc01137314 Merge pull request #77459 from hborla/preconcurrency-downgrade
[Concurrency] Fix preconcurrency downgrade behavior for `Sendable` closures and generic requirements.
2024-11-09 07:18:50 -08:00
Holly Borla
7331c5e543 [Concurrency] Downgrade preconcurrency errors about unavailable conformances
to `Sendable`.
2024-11-08 17:44:22 -08:00
Slava Pestov
b5af518638 Merge pull request #77491 from slavapestov/fix-rdar139237671
Sema: Allow closure parameter lists to reference opaque parameter declarations
2024-11-08 19:31:43 -05:00
Hamish Knight
9c3b8a6256 [CS] Delay macro expansion until end of CSApply
Attempting to expand macros in the middle of
CSApply can result in attempting to run
MiscDiagnostics within a closure that hasn't yet
had the solution applied to the AST, which can
crash the implicit-self diagnostic logic. Move
the expansion to the end of CSApply such that
expansions are type-checked along with local
decls, ensuring it's run after the solution has
been applied to the AST.

rdar://138997009
2024-11-09 00:24:53 +00:00
Hamish Knight
be94e5d305 [CS] NFC: Sink LocalDeclsToTypeCheck into ExprRewriter 2024-11-09 00:24:53 +00:00
Hamish Knight
caceca6530 [CS] NFC: Move some code
Always bothered me the constructor for
ExprRewriter is buried in the middle of the class.
2024-11-09 00:24:53 +00:00
Hamish Knight
6352b01635 [Sema] Avoid double-diagnosing in macro expansions
Avoid walking into macro expansions for
MiscDiagnostics, the expansions will instead be
visited when they're type-checked on their own.
2024-11-09 00:24:52 +00:00
Pavel Yaskevich
bc949c3680 [CSBindings] Don't favor application result types before application happens
Until `ApplicableFunction` constraint is simplified result type
associated with it cannot be bound because the binding set if
incomplete.

Resolves: rdar://139237088
2024-11-08 14:00:01 -08:00
Slava Pestov
f702e46751 Merge pull request #77475 from slavapestov/fix-rdar139237781
Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
2024-11-08 15:15:27 -05:00
Slava Pestov
e9ff8ad889 Sema: Allow closure parameter lists to reference opaque parameter declarations
A function declaration cannot have an opaque parameter type appearing in
consuming position:

    func f(_: (some P) -> ()) {}

However, we should skip this check for a closure, because if the
closure's parameter list references an opaque parameter declaration,
it means something else: namely, the inferred type of the closure
refers to an opaque parameter from an outer scope. That's allowed.

This unnecessary prohibition has been there ever since the check was
added, but only for multi-statement closures, so nobody seemed to
notice.

When https://github.com/swiftlang/swift/pull/76473 made it so we always
call TypeChecker::checkParameterList(), this exposed the problem in a
single-expression closure in an existing project.

Fixes rdar://139237671.
2024-11-08 14:59:15 -05:00
Holly Borla
806de5a90a [Concurrency] Downgrade Sendable requirement failures in existential
erasure expressions for arguments to `@preconcurrency` functions in Swift
6 mode.
2024-11-08 10:01:13 -08:00
Pavel Yaskevich
4be399003e Merge pull request #77434 from xedin/rdar-134503878-other-way-around
[Concurrency] Allow witnesses to adopt concurrency before requirements
2024-11-08 09:22:14 -08:00
Pavel Yaskevich
fc90551f8f Merge pull request #77473 from xedin/rdar-139314763
[CSSolver] DynamicMemberLookup: Ignore disabled choices while filteri…
2024-11-08 09:15:40 -08:00
Slava Pestov
d67e89d89c Sema: Fix handling of appliedPropertyWrappers in ConstraintSystem::replaySolution()
When we replay a solution, we must record changes in the trail, so fix the
logic to do that. This fixes the first assertion failure with this test case.

The test case also exposed a second issue. We synthesize a CustomAttr in
applySolutionToClosurePropertyWrappers() with a type returned by simplifyType().
Eventually, CustomAttrNominalRequest::evaluate() looks at this type, and passes
it to directReferencesForType(). Unfortunately, this entry point does not
understand type aliases whose underlying type is a type parameter.
However, directReferencesForType() is the wrong thing to use here, and we
can just call getAnyNominal() instead.

Fixes rdar://139237781.
2024-11-08 10:46:07 -05:00
Doug Gregor
e34226714e Merge pull request #77477 from DougGregor/result-builder-empty-case-crash
[Result builder transform] Don't abort when we encounter a case with no statements
2024-11-08 04:15:24 -08:00
Doug Gregor
f89218941b [Result builder transform] Don't abort when we encounter a case with no statements
Remove code that aborts the result builder transform when we encounter
a case that has no statements in it. This can occur when the only
statements were behind a `#if` that evaluataed empty, so it should not
cause an abort.

Previously, the presence of an IfConfigDecl within the case statement
would have prevented us from aborting the traversal here. However, the
removal of IfConfigDecl from the AST turned this previously-accepted
code into a compiler crash.

Fixes rdar://139312426.
2024-11-07 22:58:18 -08:00
Pavel Yaskevich
392dac41f1 [CSSolver] DynamicMemberLookup: Ignore disabled choices while filtering disjunctions
`filterDisjunction` should ignore the choices that are already
disabled while attempting to optimize disjunctions related to
dynamic member lookup.

Resolves: rdar://139314763
2024-11-07 18:31:52 -08:00
Holly Borla
e21bf2ffb4 [Concurrency] Downgrade @preconcurrency conformance requirement failures to
warnings in Swift 6 mode.
2024-11-07 17:32:30 -08:00
Nate Chandler
da71271d8f [CoroutineAccessors] Synthesize default req impls.
When a protocol which has a read (or modify) requirement is built with
the CoroutineAccessors feature, it gains a read2 (or modify2,
respectively) requirement.  For this to be compatible with binaries
built without the feature, a default implementation for these new
requirements must be provided.  Cause these new accessor requirements to
have default implementations by returning `true` from
`doesAccessorHaveBody` when the context is a `ProtocolDecl` and the
relevant availability check passes.
2024-11-07 16:47:09 -08:00
Konrad `ktoso` Malawski
b5964a05a5 Merge branch 'main' into revert-77364-mpokhylets/non-experimental-isolated-deinit 2024-11-08 09:03:21 +09:00
Holly Borla
a31a9d3642 [Concurrency] Downgrade @preconcurrency @Sendable conversion failures
to warnings even in Swift 6.
2024-11-07 16:02:37 -08:00
Holly Borla
d2d317a3d7 [Concurrency] Fix preconcurrency downgrade behavior for Sendable closures.
Sendable violations inside `@preconcurrency @Sendable` closures should be
suppressed in minimal checking, and diagnosed as warnings under complete
checking, including the Swift 6 language mode.
2024-11-07 16:02:37 -08:00
Alexis Laferrière
321f9aa707 Merge pull request #77454 from xymus/public-imports-of-private-as-error
Sema: Report public imports of private modules as errors by default
2024-11-07 15:47:07 -08:00
Gábor Horváth
88c2269e69 Merge pull request #77323 from swiftlang/gaborh/use-imported-locs
[cxx-interop] Use the locations imported from C++
2024-11-07 17:44:07 +00:00
Alexis Laferrière
d90664c7f1 Sema: Report public imports of private modules as errors by default
Align the behavior between release and debug compilers to always report
this as an error. Downstream compilers already make this an error.

rdar://136041870
2024-11-07 09:41:33 -08:00
Allan Shortlidge
817e4517de Merge pull request #77442 from tshortli/disable-availability-checking 2024-11-07 00:47:04 -08:00
Doug Gregor
7a43b44a2e Merge pull request #77440 from DougGregor/no-fallback-diag-in-transaction
[Constraint solver] Disable fallback diagnostic when error emitted into a transaction
2024-11-06 21:39:59 -08:00
Nate Chandler
8995602107 [NFC] Promote static to member function. 2024-11-06 20:52:21 -08:00
Nate Chandler
76dc6e12a8 [NFC] Cache preexisting synthesized accessor.
Move the bailout from getSynthesizedAccessor from the wrapper function
into the evaluate body.  Will enable the request to do work on
non-synthesized accessors, which is required to provide a default
implementation for modify2 and read2 members.
2024-11-06 20:52:21 -08:00
Nate Chandler
f1f0ccdeff [NFC] Improved predicate names. 2024-11-06 20:52:21 -08:00
Nate Chandler
953aca419d [Gardening] Accessor name spelling in comment. 2024-11-06 20:52:21 -08:00
Nate Chandler
11db6766be [Gardening] Deleted duplicated word in comment. 2024-11-06 20:52:21 -08:00
Doug Gregor
64e08d7e47 Merge pull request #77436 from DougGregor/parse-expression-macro-buffer-as-expression 2024-11-06 20:25:49 -08:00
Allan Shortlidge
d8be24b395 Sema: Fix -disable-availability-checking.
Suppression of diagnostics about use of unavailable declarations in
equivalently unavailable contexts now relies on querying the
`TypeRefinementContext` hierarchy. Generation of the TypeRefinementContext tree
was suppressed when `-disable-availability-checking` was specified, though,
causing some unavailability diagnostics to be emitted when they ought to be
suppressed.

Instead of refusing to generate a `TypeRefinementContext` hierarchy, instead
just avoid populating nodes for `if #available` checks for OS versions since
these checks are meant to have no effect when `-disable-availability-checking`
is specified.

Resolves rdar://138987918.
2024-11-06 17:20:31 -08:00
Doug Gregor
720429daf4 [Constraint solver] Disable fallback diagnostic when error emitted into a transaction
When we are using diagnostic transactions to disable immediate emission
of diagnostics, `DiagnosticEngine::hadAnyError()` no longer accurately
reports whether an error occurred. Thread the DiagnosticTransaction
into the ConstraintSystem so we can also check whether it contains an
error before emitting the fallback diagnostic.

Fixes rdar://128272346.
2024-11-06 17:07:13 -08:00
Konrad `ktoso` Malawski
aadc67ec0e Revert "Make IsolatedDeinit non-experimental" 2024-11-07 09:59:00 +09:00
Doug Gregor
78b89b201c Parse expression macro expansion buffers as expressions
This started out as a crash, where an expression macro could not be
defined in terms of one of the builtin macros (e.g., `#line`), because
we were expecting a macro expansion expression but didn't get one.
Easy fix.

However, this uncovered a second bug, which is that we couldn't handle
an expression macro expansino to `#line`. This is because we were
parsing the macro expansion buffer as "top level items", which treats
`#line` at the start of a line as a deprecated alias of
`#sourceLocation`. Switch over to parsing a single expression in these
contexts, and fix up an issue where `#isolation` didn't even have that
expression.

Fixes rdar://139372780.
2024-11-06 15:55:38 -08:00
Pavel Yaskevich
73d658ae5a [Concurrency] Allow witnesses to adopt concurrency before requirements
Allow witnesses to introduce `any Sendable` types into their interface
before requirements (predicated on presence of `@preconcurrency` and
Swift 5 language mode) as a pathway for concurrency adoption.

Resolves: rdar://134503878
2024-11-06 15:24:36 -08:00
Hamish Knight
4faabc9111 Merge pull request #77417 from hamishknight/duplicate-macro
[CS] Filter out invalid macros from overload set
2024-11-06 18:46:18 +00:00
Allan Shortlidge
b345418eca Merge pull request #77408 from tshortli/revert-package-fixes
Revert removal of `-package-name` from swiftinterfaces
2024-11-06 10:31:34 -08:00
Chris Miles
f7f6cd144e Merge pull request #77350 from swiftlang/eng/chrismiles/Instrumenter-buildPatternAndVariable-crash
Fixes build logger call crashing with ImplicitOpenExistentials.
2024-11-06 10:21:10 -08:00
Hamish Knight
4e7a119235 [CS] Filter out invalid macros from overload set
This matches how we handle OverloadSetRefExpr and
avoids a crash for e.g redeclared macros.
2024-11-06 12:43:41 +00:00