Commit Graph

28352 Commits

Author SHA1 Message Date
Hamish Knight
b1c90feb52 [CS] Sink closure property wrapper application into applySolution
We need to make sure property wrappers are
applied before `checkParameterList`.
2024-09-14 15:37:21 +01:00
Hamish Knight
2d6a38b2cd [CS] Call checkParameterList for single-expr closures
Previously we would only call this in the delayed
application logic, which is currently run for
multi-statement closures. I'm planning on
removing that code path, which uncovered this
issue.
2024-09-14 15:37:21 +01:00
Slava Pestov
c997778e0f Merge pull request #76467 from slavapestov/fix-rdar135607071
SIL: Fix lowering of local functions with explicit isolated parameter
2024-09-14 08:45:30 -04:00
Slava Pestov
f35c90a6b7 Merge pull request #76445 from slavapestov/maptypeintocontext
Overhaul mapTypeIntoContext()
2024-09-14 08:45:20 -04:00
Slava Pestov
6fb66db6da Merge pull request #76318 from slavapestov/favored-over-disjunction-heuristic
Sema: Generalize heuristic in favoredOverDisjunction()
2024-09-14 08:45:09 -04:00
Pavel Yaskevich
0276a33de5 [CSSimplify] Forego any contextual score increases while checking erased member type
`resolveOverload` introduces a conversion if there were any adjustments
to a member type on existential base. This conversion exists only to
check adjustments in the member type, so the fact that adjustments also
cause a function conversion is unrelated.

Resolves: rdar://135974645
2024-09-13 16:30:09 -07:00
Slava Pestov
e0377fb9c4 SIL: Fix lowering of local functions with explicit isolated parameter
When the isolated parameter is the function's own parameter, it is
not a capture.

Fixes rdar://135607071.
2024-09-13 19:26:42 -04:00
Allan Shortlidge
02dbb96b94 AST: Rename AvailabilityContext to AvailabilityRange.
The generality of the `AvailabilityContext` name made it seem like it
encapsulates more than it does. Really it just augments `VersionRange` with
additional set algebra operations that are useful for availability
computations. The `AvailabilityContext` name should be reserved for something
pulls together more than just a single version.
2024-09-13 16:25:18 -07:00
Becca Royal-Gordon
cd8d3adab0 Mimic old objcImpl behavior for early adopters
Before the update to support the new syntax, the decl checker treated private and fileprivate members of objcImpl extensions as non-@objc by default. But SE-0436 specified that private and fileprivate members should be implicitly @objc unless opted out, so when support for the final syntax was added, this behavior was changed retroactively.

Unfortunately, we’ve found that some early adopters depended on the old behavior. Restore some logic deleted by #73309 for early adopter syntax *only*, with a warning telling the developer to put `final` or `@nonobjc` on the declaration if they want to preserve the behavior after updating it.

Also tweaks the ObjCImplementationChecker to ensure this logic will actually be run in time for it to suppress the “upgrade to @objc @implementation” warning, and corrects a couple of regressions arising from that change.

Fixes rdar://135747897.
2024-09-13 14:55:16 -07:00
Slava Pestov
4923521227 AST: Re-implement GenericEnvironment::mapTypeIntoContext() using TypeTransform 2024-09-13 15:19:48 -04:00
Pavel Yaskevich
22b9dd7f7b [Concurrency] Allow global actor mismatches while overriding @preconcurrency members in Swift 5 mode
Downgrade a mismatch on global actor attributes to a warning until
Swift 6 to enable class authors to introduce concurrency annotations
to overridable members.

Resolves: rdar://131347583
2024-09-13 11:28:47 -07:00
Pavel Yaskevich
16244b327d Merge pull request #76439 from xedin/delay-implicit-pointer-conversions-for-unknown-inout
[CSSimplify] Delay `inout` type to pointer conversion until `inout` is sufficiently resolved
2024-09-13 11:06:28 -07:00
Slava Pestov
eaf06eae0e Sema: Fix call to mapTypeIntoContext() with wrong environment 2024-09-13 08:12:51 -04:00
Slava Pestov
40641f5e91 Sema: Fix dodgy logic in findMissingGenericRequirementForSolutionFix()
'type' and 'missingType' are contextual types in the generic environment
of the witness thunk. We cannot simply map them into the environment of
the conformance, because if the conforming type is a class, the witness
thunk has an extra generic parameter at depth=0, index=0 and all other
generic parameters are shifted down by one depth.
2024-09-13 08:12:51 -04:00
Pavel Yaskevich
279ef7de2d [CSBindings] Infer bindings through inout in some cases
Allow inferring type of `inout` from a pointer type
(or optional thereof) but delay the binding set because
it might not be complete and object type of `inout` could
also be an Array or C-style pointer type.
2024-09-13 05:08:26 -07:00
Pavel Yaskevich
b1d9ae01ed [CSSimplify] Delay inout type to pointer conversion until inout is sufficiently resolved
If left-hand side of any conversion constraint is `inout` type
and right is a pointer (or optional thereof), delay simplification
until `inout` is at least partially structurally resolved (cannot
be a type variable or dependent member) because eager simplification
won't record all of the possible conversions.
2024-09-12 13:46:02 -07:00
Allan Shortlidge
21837e9fde Sema: Reject @available on observing accessors.
Marking an observer unavailable (or potentially unavailable) has no effect
since the compiler emits calls to them unconditionally.

Resolves rdar://80337141.
2024-09-11 16:42:48 -07:00
Allan Shortlidge
a860b02360 Sema: Diagnose unavailability of associated type decls.
It should not be possible to mark an associated type declaration unavailable
since doing so does not have an effect on how a conformance interacts with its
associated types.
2024-09-11 16:42:47 -07:00
Allan Shortlidge
23e9719b2b Sema: Refactor "cannot be marked unavailable" diagnostics.
Make it possible to share the diagnostics string for common case.
2024-09-11 16:42:47 -07:00
Becca Royal-Gordon
4dae9eea5a Merge pull request #76270 from beccadax/objcimpl-serialization-2 2024-09-11 10:53:17 -07:00
Pavel Yaskevich
c49aeaf177 Merge pull request #76354 from xedin/improve-mismatch-diagnostics-in-optional-context
[CSSimplify] Rework how/when mismatches between optional types are fixed
2024-09-11 10:14:19 -07:00
Pavel Yaskevich
7e71641707 Merge pull request #76397 from xedin/rdar-135610320
[CSSimplify] Specialization: Fix a crash when specialized declaration…
2024-09-11 09:30:22 -07:00
Alexis Laferrière
5ac817e338 Merge pull request #76386 from xymus/public-import-of-private-fixit
Sema: Use `internal import` in fixits on public imports of private modules
2024-09-11 08:59:12 -07:00
Pavel Yaskevich
efd43b0f7d [CSSimplify] Specialization: Fix a crash when specialized declaration is not generic
Check whether there are any opened generic parameters associated
with a declaration and if not, produce a fix which would be later
diagnosed as either a warning (in Swift 5 mode) or an error (if it
was a concrete type or the compiler is in Swift 6 language mode).

Resolves: rdar://135610320
2024-09-10 21:06:59 -07:00
Meghana Gupta
0dde044e89 Merge pull request #76256 from meg-gupta/lifetimeattrsyntax
Introduce @lifetime attribute to specify lifetime dependence on function declarations
2024-09-10 19:49:32 -07:00
Pavel Yaskevich
564155e74d Merge pull request #76377 from xedin/dont-discriminate-against-any-and-anyobject
[CSSimplify] Don't increase impact if member doesn't exist on Any/Any…
2024-09-10 17:41:41 -07:00
Alexis Laferrière
2aabffa8a0 Merge pull request #76358 from xymus/authoritative-import
Sema: Pick the most relevant import for diagnostics about the source of a decl
2024-09-10 16:25:06 -07:00
Alexis Laferrière
4fe88c2720 Sema: Use internal import instead of @_implementationOnly on public imports of a private module
The error about a public import of a private module is raised when
a library-level API module imports a library-level SPI module without
a non-public access-level, `@_implementationOnly` attribute or
`@_spiOnly` attribute. Update the fixit to insert an `internal` instead
of a `@_implementationOnly`.
2024-09-10 13:22:57 -07:00
Pavel Yaskevich
97f284aa76 [CSSimplify] Don't increase impact if member doesn't exist on Any/AnyObject
`Any` used to be the type used to indicate placeholders before
and that's reflected in the score of the `DefineMemberBasedOnUse`,
this is no longer the same and the impact increase should be dropped.
2024-09-10 10:38:32 -07:00
Pavel Yaskevich
8fca2c5110 [CSDiagnostics] Look into tuple expressions to find requirement failure location
If the requirement failure is related to an assignment destination
analyze the source of the assignment and if it's a tuple, find the
element and return its type.
2024-09-10 10:35:33 -07:00
Pavel Yaskevich
890e45d1e1 [CSSimplify] Increase impact of treat r-value as l-value fix in certain situations
If location (member) isn't mutable in the current context
or there are other problems at this location, increase impact
of the fix since it compounds the problem.
2024-09-10 10:35:28 -07:00
Pavel Yaskevich
55b8d9538d [CSSimplify] Rework how/when mismatches between optional types are fixed
- Don't attempt to insert fixes if there are restrictions present, they'd inform the failures.

  Inserting fixes too early doesn't help the solver because restriction matching logic would
  record the same fixes.

- Adjust impact of the fixes.

  Optional conversions shouldn't impact the score in any way because
  they are not the source of the issue.

- Look through one level of optional when failure is related to optional injection.

  The diagnostic is going to be about underlying type, so there is no reason to print
  optional on right-hand side.
2024-09-10 10:35:05 -07:00
Allan Shortlidge
58a77206c4 ConstraintSystem: Remove UnviableReason::UR_MissingImport.
Now that `MemberImportVisibility` behavior is implemented using ranking there
is no need to support the `UR_MissingImport` unviability reason.
2024-09-10 09:47:42 -07:00
Allan Shortlidge
c868378d96 ConstraintSystem: Use scoring to implement MemberImportVisibility.
Previously, the constraint solver would first attempt member lookup that
excluded members from transitively imported modules. If there were no viable
candidates, it would perform a second lookup that included the previously
excluded members, treating any candidates as unviable. This meant that if the
member reference did resolve to one of the unviable candidates the resulting
AST would be broken, which could cause unwanted knock-on diagnostics.

Now, members from transitively imported modules are always returned in the set
of viable candidates. However, scoring will always prioritize candidates from
directly imported modules over members from transitive imports. This solves the
ambiguities that `MemberImportVisibility` is designed to prevent. If the only
viable candidates are from transitively imported modules, though, then the
reference will be resolved successfully and diagnosed later in
`MiscDiagnostics.cpp`. The resulting AST will not contain any errors, which
ensures that necessary access levels can be computed correctly for the imports
suggested by `MemberImportVisibility` fix-its.

Resolves rdar://126637855.
2024-09-10 09:47:42 -07:00
Jan
6236b258d2 [Sema] Fixes for mutability handling in property wrappers (#76357)
Prevents a crash when a parameter references an invalid property wrapper. The original code assumed that mutability information would always be available, but this assumption fails when the property wrapper is invalid

Resolves https://github.com/swiftlang/swift/issues/65640
2024-09-10 00:20:29 -07:00
Meghana Gupta
e61d87c01c Add support for parsing @lifetime attribute to specify lifetime dependencies on declarations 2024-09-09 22:02:42 -07:00
Anthony Latsis
faf2bccec1 Sema: Resolve result builder type in innermost decl context 2024-09-10 04:44:21 +03:00
Alexis Laferrière
9751be9e75 Diagnostics: Ignore public-module-name for warnings about unused imports 2024-09-09 16:57:46 -07:00
Allan Shortlidge
2ec8efea91 Sema: Allow some @_implementationOnly imports in stdlib modules.
The `_Concurrency` module imports a C module that is not available in the
toolchain or SDK, which means that `@_implementationOnly` must be used to hide
the dependency on this module from clients.
2024-09-09 12:48:28 -07:00
Allan Shortlidge
99fd29c3b9 Sema: Refactor @_implementationOnly deprecation warning suppression. 2024-09-09 12:24:25 -07:00
Slava Pestov
73aa029a8b Sema: Generalize heuristic in favoredOverDisjunction() 2024-09-09 11:18:58 -04:00
Hamish Knight
ee0e408a8c [Sema] Remove separate closure type-checking logic
`participatesInInference` is now always true for
a non-empty body, remove it along with the separate
type-checking logic such that empty bodies are
type-checked together with the context.
2024-09-08 16:17:11 +01:00
Hamish Knight
72fe29f7f4 [CS] Add custom diagnostic for missing result builder element
If we have a single missing argument for an empty
`buildBlock` call, emit a custom diagnostic.
2024-09-08 16:17:11 +01:00
Doug Gregor
42809af51e Merge pull request #76327 from DougGregor/suppress-warnings-in-inactive-regions-without-ifconfigdecl
Suppress certain warnings in inactive `#if` regions without relying on `IfConfigDecl`
2024-09-07 10:16:20 -07:00
Doug Gregor
48db8767b5 Suppress the warning for inactive try/throw in do..catch
In the warning about having no try/throw within the body of a do..catch,
replace the walk of the inactive clauses of IfConfigDecl with a syntactic
check of inactive and unparsed regions to look for 'try' and 'throw'
keywords.

This both eliminates a dependency on IfConfigDecl and expands the
usefulness of this warning suppression to unparsed code.
2024-09-06 22:38:04 -07:00
Doug Gregor
4a4c0f68f1 Teach the "unused variable / value" diagnostics to use SwiftIfConfig
Rather than walking into the inactive regions of IfConfigDecls looking for
references to a declaration before we diagnose it, go to the syntax
tree and look through inactive *and unparsed* regions for identifier
tokens that match. If we find one, suppress the diagnostic.

This reduces our dependency on IfConfigDecl in the AST, and also makes
the same suppression work with code in unparsed regions that had no
representation in IfConfigDecl.
2024-09-06 22:14:52 -07:00
Holly Borla
0312054dae [Concurrency] Handle implicitly async operator expressions in the actor
isolation checker.

Previously, the actor isolation checker would crash when attempting to
mark an operator call as implicitly async, because it was specifically
expecting to see a CallExpr. Instead, accept all ApplyExprs except for
SelfApplyExpr.
2024-09-06 22:03:12 -07:00
Hamish Knight
1caaeeb83e Merge pull request #76295 from hamishknight/capturent
Remove `shouldWalkCaptureInitializerExpressions`
2024-09-06 21:39:51 +01:00
Pavel Yaskevich
23577af715 Merge pull request #76299 from xedin/rdar-135203192
Revert "[CSBindings] Mark generic parameter type vars as complete if they don't have any adjacent vars"
2024-09-06 13:08:32 -07:00
Allan Shortlidge
85068f0d4d Merge pull request #76300 from tshortli/module-interface-patterns-with-opaque-results
ModuleInterface: Print patterns with opaque result types using `some` keyword
2024-09-05 22:45:37 -07:00