Commit Graph

28352 Commits

Author SHA1 Message Date
Hamish Knight
ed1589de4c [Sema] Walk MacroExpansionDecls in BaseDiagnosticWalker
I missed this in my previous PR, but this is needed
to ensure we visit macro arguments for macro expansion
exprs that have substitute MacroExpansionDecls since
we prefer to visit the arguments on the decl once
the expression has been expanded.
2024-11-12 18:26:53 +00:00
Alexis Laferrière
a4fcdefc8f Sema: fix reporting reexporting submodules imports as unused in API
Importing a clang submodule from Swift implies importing the top-level
module too. We make sure we don't warn on the import of the top-level
module as being unused when the submodule is used by associating all
references to the top-level module instead of submodules. This change
applies the same logic for transitive imports, marking the import of the
top-level module as used instead of the submodule with the `export *`.

In the updated test, this silences the following warning:
```
public import of 'ClangReexportedSubmodulePublic' was not used in public
declarations or inlinable code
```

rdar://139492772
2024-11-12 09:35:19 -08:00
Egor Zhdan
6943986c71 [cxx-interop] Import private fields of C++ structs
While private and protected fields coming from C++ cannot be accessed from Swift, they can affect Swift typechecking.

For instance, the Swift typechecker mechanism that adds implicit `Sendable` conformances works by iterating over all of the struct's fields and checking whether all of them are `Sendable`. This logic was broken for C++ types with private fields, since they were never accounted for. This resulted in erroneous implicit `Sendable` confromances being added.

Same applies for `BitwiseCopyable`.

In addition to this, ClangImporter used to mistakenly mark all C++ structs that have private fields as types with unreferenceable storage, which hampered optimizations.

As a side effect of this change, we now also provide a better diagnostic when someone tries to access a private C++ field from Swift.

rdar://134430857
2024-11-12 12:47:26 +00:00
Hamish Knight
b2dcf1ef05 Merge pull request #77534 from hamishknight/i-take-issue-with-your-argument
[Sema] Consistently run MiscDiagnostics on macro arguments
2024-11-12 10:42:10 +00:00
Hamish Knight
36a9628b9e Merge pull request #77537 from hamishknight/complete-func
[Completion] Type-check parent closures for local functions
2024-11-12 10:40:53 +00:00
Meghana Gupta
a39bf7d338 [NFC] Rename helper function for @_noImplicitCopy and @_eagerMove 2024-11-11 23:18:29 -08:00
Nate Chandler
de86cc037c [CoroutineAccessors] Tweak diags for old accessors
When the feature is enabled, refer to the old accessors as they are
actually spelled (i.e. `_read` and `_modify`).
2024-11-11 18:34:01 -08:00
Doug Gregor
531a1ab4c4 Temporarily put uses of "Span" and "RawSpan" behind an experimental feature flag
While Span is present, we don't yet have an official way to create Span
instances. Until then, put uses of Span and RawSpan behind an
experimental feature flag (`Span`) that must be set to use these.

Addresses rdar://139308307.
2024-11-11 16:18:33 -08:00
Doug Gregor
cf68d28400 Merge pull request #76951 from kovdan01/issue60102
[AutoDiff] Enhance performance of custom derivatives lookup
2024-11-11 14:55:54 -08:00
Doug Gregor
1bdffc31fe Merge pull request #77528 from DougGregor/macro-expansion-rtc-comment-fix
Finish thought in comment
2024-11-11 13:44:32 -08:00
Hamish Knight
f8ca3975fe Merge pull request #77526 from hamishknight/remove-dead-func
[Sema] NFC: Remove `diagnoseMoveOnlyPatternMatchSubject`
2024-11-11 20:00:13 +00:00
Hamish Knight
27995eed19 [Completion] Type-check parent closures for local functions
Local functions can capture variables from parent
closures, so we need to make sure we type-check
parent closures when doing completion in a local
function. Ideally we ought to be able to be more
selective about the elements of the parent closure
that we type-check, but that's a more complex change
I'm leaving as future work for now.
2024-11-11 19:34:21 +00:00
Hamish Knight
7beceb0e4b [AST] Generalize getInnermostClosureForSelfCapture
Really this applies to any capture, not just
`self`. Also refactor to make it clear that
parent closures and functions are really the only
cases that matter here.
2024-11-11 19:34:21 +00:00
Hamish Knight
eef4716731 [Completion] Avoid doing extra type-checking in CSApply
Avoid type-checking local decls and macros, the
type-checking here should instead be handled by
TypeCheckASTNodeAtLocRequest.
2024-11-11 19:34:21 +00:00
Hamish Knight
1b5ed65a57 [Sema] Consistently run MiscDiagnostics on macro arguments
Previously we would only run MiscDiagnostics
passes on macro arguments for some statement
diagnostics, update the expression walkers that
inherit from BaseDiagnosticWalker such that we
consistently do MiscDiagnostics on macro arguments.
2024-11-11 19:29:59 +00:00
Hamish Knight
146e95c76a [Sema] Use BaseDiagnosticWalker consistently in MiscDiagnostics
None of these walkers ought to be walking into
non-PatternBinding decls, this avoids duplicate
diagnostics in nested local decls in closures.
2024-11-11 19:29:59 +00:00
Hamish Knight
fab09c50a0 Merge pull request #77479 from hamishknight/macro-misc-diag-fixes
[Sema] A couple of fixes for MiscDiagnostics on macro expansions
2024-11-11 19:27:58 +00:00
Doug Gregor
9abb9cf8e5 Finish thought in comment 2024-11-11 09:30:58 -08:00
Holly Borla
f8bb5d1c16 Merge pull request #77510 from hborla/preconcurrency-downgrade
[Concurrency] Handle self apply exprs when computing `@preconcurency` in the availability checker.
2024-11-11 09:26:22 -08:00
Allan Shortlidge
600ed07c88 Merge pull request #77519 from tshortli/fix-conditional-opaque-type-miscompile
Sema: Fix opaque type accessors with inactive availability conditions
2024-11-11 09:22:09 -08:00
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