Commit Graph

28382 Commits

Author SHA1 Message Date
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Pavel Yaskevich
d01c9cbaee [CSBindings] Revert changes in BindingSet::isViable
This change although correct cases performance issues
in some scenarios.
2024-11-15 15:46:29 -08:00
Slava Pestov
3b5c2a18b7 Sema: Fix yet another call to SubstitutionMap::getProtocolSubstitutions()
The conforming type didn't match the conformance, which is going to
be flagged by SubstitutionMap::verify().
2024-11-15 17:26:34 -05:00
Slava Pestov
4d87f25c81 Sema: Fix another call to SubstitutionMap::getProtocolSubstitutions()
The conforming type didn't match the conformance, which is going to
be flagged by SubstitutionMap::verify().
2024-11-15 17:26:34 -05:00
Slava Pestov
5d40673112 Sema: Fix call to SubstitutionMap::getProtocolSubstitutions()
The conforming type didn't match the conformance, which is going to
be flagged by SubstitutionMap::verify().
2024-11-15 17:26:33 -05:00
Slava Pestov
1fc2cd9fad Sema: Remove some pointless passing around of ModuleDecl 2024-11-15 17:26:33 -05:00
Pavel Yaskevich
30c196118e [CSSimplify] Handle invalid type specializations
If the base type of the specialization is invalid,
the AST node is going to be replaced with `ErrorExpr`.

We need to handle that gracefully when attempting
to apply specialization in such situations.

Resolves: https://github.com/swiftlang/swift/issues/77644
2024-11-15 11:10:51 -08:00
Slava Pestov
47196614e6 Merge pull request #77595 from slavapestov/fix-rdar139747886
Sema: Fix request cycle due to unnecessary Sendable check with static method
2024-11-15 12:02:16 -05:00
Rintaro Ishizaki
0f1b650716 [AST] MacroRoleAttr accept any 'Expr *' as the conformances arguments 2024-11-14 15:10:11 -08:00
nate-chandler
6b43670258 Merge pull request #77603 from nate-chandler/general-coro/20241113/1
[CoroutineAccessors] Several small fixes.
2024-11-14 07:06:35 -08:00
Nate Chandler
430307a29d [CoroutineAccessors] Don't synthesize overrides.
Such storage decls don't actually have entries in the wtable.
2024-11-13 21:33:08 -08:00
Nate Chandler
9bbb8e8e70 [CoroutineAccessors] Set field on RequirementMatch
The WitnessSubstitutions field must be set to the appropriate
substitution map.
2024-11-13 21:33:07 -08:00
Doug Gregor
11ed132614 [Clang importer + macros] Handle name lookup and type checking for expanded macros
Introduce a number of fixes to allow us to fully use declarations that
are produced by applying a peer macro to an imported declarations.
These changes include:
* Ensuring that we have the right set of imports in the source file
containing the macro expansion, because it depends only on the module
it comes from
* Ensuring that name lookup looks in that file even when the
DeclContext hierarchy doesn't contain the source file (because it's
based on the Clang module structure)

Expand testing to be sure that we're getting the right calls,
diagnostics, and generated IR symbols.
2024-11-13 21:21:56 -08:00
Pavel Yaskevich
7c35c881a9 [CSSimplify] CGFloat-Double: Fix ambiguity when assigning CGFloat to double property/variable
Situations like:
```
  let _: Double = <<CGFloat>>
  <var/property of type Double> = <<CGFloat>>
```

Used to be supported due to an incorrect fix added in
diagnostic mode. Lower impact here means that right-hand
side of the assignment is allowed to maintain CGFloat
until the very end which minimizes the number of conversions
used and keeps literals as Double when possible.

Resolves: rdar://139675914
2024-11-13 13:45:56 -08:00
Slava Pestov
59ba1a0294 Sema: Fix request cycle due to unnecessary Sendable check with static method
Fixes rdar://139747886.
2024-11-13 15:16:28 -05:00
Hamish Knight
1965f96aff Merge pull request #77554 from hamishknight/statement-misc-diags
[Sema] A couple more MiscDiagnostics cleanups/fixes
2024-11-13 18:04:46 +00:00
nate-chandler
11f9ea7529 Merge pull request #77572 from nate-chandler/rdar139759304
[BitwiseCopyable] Permit conformance in overlay.
2024-11-13 00:07:56 -08:00
Meghana Gupta
184058e4ac Merge pull request #76588 from meg-gupta/lifetimeremovefeatureguardincompiler
Remove feature guard on lifetime dependence inference
2024-11-12 18:38:41 -08:00
Nate Chandler
80390ce1d1 [BitwiseCopyable] Permit conformance in overlay.
rdar://139759304
2024-11-12 16:54:16 -08:00
Hamish Knight
9e5a105644 Merge pull request #77561 from hamishknight/completion-feedback
[Sema] NFC: Address review feedback on #77537
2024-11-13 00:25:41 +00:00
Allan Shortlidge
1e6effd0aa Merge pull request #77563 from tshortli/rename-type-refinement-context
AST: Rename TypeRefinementContext to AvailabilityScope
2024-11-12 15:21:19 -08:00
Alexis Laferrière
b5bf21758e Merge pull request #77538 from xymus/dont-warn-submodules-reexport
Sema: fix reporting reexporting submodules imports as unused in API
2024-11-12 13:59:39 -08:00
Allan Shortlidge
239720897a AST: Rename TypeRefinementContext to AvailabilityScope. 2024-11-12 11:34:25 -08:00
nate-chandler
359f898bbf Merge pull request #77546 from nate-chandler/general-coro/20241110/1
[CoroutineAccessors] Ban read+_read and modify+_modify.
2024-11-12 10:40:52 -08:00
Hamish Knight
d8ec851c93 [Sema] NFC: Address review feedback on #77537 2024-11-12 18:35:17 +00:00
Hamish Knight
b644cd87a9 [Sema] Ensure performStmtDiagnostics is called for CaseStmts
Previously we would check if we have a SwitchStmt,
and apply diagnostics such as `checkExistentialTypes`
to the CaseStmts individually. This however would
have been missed for `catch` statements. The change
to consistently call `performStmtDiagnostics` in
closures fixed this for `do-catch`'s in closures,
this commit fixes it for those outside of closures.
Because this is source breaking, the existential
diagnostic is downgraded to a warning until Swift
7 for catch statements specifically.

While here, also apply the ambiguous where clause
diagnostic to `catch` statements.
2024-11-12 18:26:54 +00:00
Hamish Knight
964ba731bb [Sema] Inherit ExprAvailabilityWalker from BaseDiagnosticWalker
Simplifies things a tiny amount, and ensures we
don't attempt to walk into non-PatternBindingDecls,
same as other MiscDiagnostic passes. I don't think
this currently makes a difference since I don't
believe we have any interesting cases where a Decl
is nested in an Expr without an intermediate Stmt,
but it's the right thing to do regardless.
2024-11-12 18:26:53 +00:00
Hamish Knight
6e09a4e2ae [Sema] NFC: Remove shouldWalkIntoClosure
This used to have some logic when multi-statement
closures were type-checked differently, it's always
true now.
2024-11-12 18:26:53 +00:00
Hamish Knight
9a339d937e [Sema] Clean up diagnoseStmtAvailability a bit
The walker here is really doing 2 completely
separate things, split it into 2 walkers. For
ExprAvailabilityWalker, we just want to recursively
continue walking looking for any sub-expressions
to diagnose. For StmtAvailabilityWalker we only
want to walk the top-level statement, and are
only interested in any TypeReprs it has. This lets
us get rid of the special handling for BraceStmt.
2024-11-12 18:26:53 +00:00
Hamish Knight
d2b298bd4b [CS] Avoid doing performStmtDiagnostics in CSApply
Instead, ensure we walk into expressions in
SyntacticDiagnosticWalker, allowing
`performStmtDiagnostics` to be called there for
all statements present in the target. This avoids
a case where we'd double diagnose.

While here, inherit the walker from
BaseDiagnosticWalker.
2024-11-12 18:26:53 +00:00
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