Commit Graph

28352 Commits

Author SHA1 Message Date
Pavel Yaskevich
d721b6e074 Merge pull request #77302 from xedin/se-0438-enhancements
[Frontend/ConstraintSystem] NFC: SE-0438 implementation enhancements
2024-11-01 09:45:03 -07:00
Allan Shortlidge
7c75b26f1b Sema: Make suppression of availability checking for types more consistent.
Availability checking for types was only suppressed when the immediate context
for the use of the type was explicitly marked unavailable. Availability is
lexical so the checking should be suppressed in the entire scope instead.
2024-11-01 08:18:13 -07:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
Allan Shortlidge
85ded8549c Sema: TypeRefinementContextBuilder must not skip defer blocks.
https://github.com/swiftlang/swift/pull/76621 caused a regression by skipping
the AST nodes nested under `defer` blocks. The node associated with a `defer`
block is implicit because it is a kind of closure context synthesized by the
compiler. However, the nodes it contains are not implicit and so they must be
visited by the `TypeRefinementContextBuilder`.

Resolves rdar://139012152
2024-10-31 23:13:08 -07:00
Pavel Yaskevich
70ac657a46 [CSBindings] Don't delay bindings inferred through inout conversion
Delaying such bindings is too restrictive and leads to subpar selections.

For `$T1` to be array or C-style pointer it would have to be
connected either to a type variable that could be bound to
array/pointer or directly to array/pointer type which would
result in the solver either selecting the other type variable
first (because it appears in adjacent variables of `$T1`) or
provide an additional binding(s) for `$T1` (including literals).

Consider the following constraint system:

```
$T2 arg conv $T1
$T2 conforms ExpressibleByIntegerLiteral

inout $T1 arg conv UnsafeMutablePointer<UInt8>?
```

If `$T1` and `$T2` are the only viable type variables delaying
`$T1` would mean that `$T2` is picked to attempt its default
type `Int` which is incorrect (it doesn't get `UInt8` because
there is no transitive inference through conversions).
2024-10-31 11:58:55 -07:00
Hamish Knight
2d7500eda6 [AST] Remove ParenType
Today ParenType is used:

1. As the type of ParenExpr
2. As the payload type of an unlabeled single
   associated value enum case (and the type of
   ParenPattern).
3. As the type for an `(X)` TypeRepr

For 1, this leads to some odd behavior, e.g the
type of `(5.0 * 5).squareRoot()` is `(Double)`. For
2, we should be checking the arity of the enum case
constructor parameters and the presence of
ParenPattern respectively. Eventually we ought to
consider replacing Paren/TuplePattern with a
PatternList node, similar to ArgumentList.

3 is one case where it could be argued that there's
some utility in preserving the sugar of the type
that the user wrote. However it's really not clear
to me that this is particularly desirable since a
bunch of diagnostic logic is already stripping
ParenTypes. In cases where we care about how the
type was written in source, we really ought to be
consulting the TypeRepr.
2024-10-31 11:32:40 +00:00
Hamish Knight
08920da2a1 [Sema] Avoid relying on ParenType in coercePatternToType
I missed this in my other Sema ParenType PR, avoid
relying on ParenType here.
2024-10-31 11:32:14 +00:00
Hamish Knight
5bda774bbb [Sema] Make explicit that resolveInverseType doesn't look through parens
Check for `isParenType` on the TypeRepr to avoid
relying on getting that behavior by casting the
type pointer.
2024-10-31 11:32:14 +00:00
Gábor Horváth
09c89fb983 Merge pull request #77204 from swiftlang/gaborh/diagnostic-location
[cxx-interop] Import more C++ source locations into Swift
2024-10-31 11:06:11 +00:00
Allan Shortlidge
2e02ef2004 Merge pull request #77307 from tshortli/round-trip-unavailable-in-embedded
Embedded: Distinguish `@_unavailableInEmbedded` from `@availble(*, unavailable)`
2024-10-30 20:16:39 -07:00
JanBaig
9dce7c5f43 [Diagnostics] Extend fix-it if no parenthesis and no args 2024-10-30 21:32:57 -04:00
nate-chandler
65a6d03805 Merge pull request #77265 from nate-chandler/general-coro/20241024/1
[CoroutineAccessors] Key table membership off availability.
2024-10-30 18:01:38 -07:00
Allan Shortlidge
0e4c881eb3 AST: Store the IsSPI bit of AvailableAttr inline in DecAttribute.
Reduces the layout requirements for `AvailableAttr` by one byte.
2024-10-30 14:29:45 -07:00
Tony Allevato
97186b0738 Merge pull request #69460 from dylansturg/indexstore
Enable indexing for refs to implicit declarations.
2024-10-30 16:38:37 -04:00
Sophia Poirier
e8d98047db Merge pull request #77057 from sophiapoirier/preconcurrency_import_warning_for_suppressed_sendable_diagnostic
[Concurrency] fix erroneous "@preconcurrency import" diagnostic
2024-10-30 13:20:33 -05:00
Pavel Yaskevich
9dc1403a3c [CSDiagnostics] SE-0438: Add a tailored diagnostic for unsupported static member references
Libraries of modules built with older compilers (< 6.1) don't have
symbols required to enable staitc member support in key path context.
2024-10-30 10:53:42 -07:00
Pavel Yaskevich
e68e4ea1b1 [CSFix] Add a new kind of invalid ref in key path - unsupported static members
Replaces feature flag check with module compiler version check
which implements the behavior discussed in the SE-0438.
2024-10-30 10:53:42 -07:00
Gabor Horvath
86e708a39b [cxx-interop] Import more C++ source locations into Swift
Occasionally, when the Swift compiler emits a diagnostic for a construct
that was imported from C++ we get a diagnostic with unknown location.
This is a bad user experience. It is particularly bad with the
borrow-checker related diagnostics. This patch extends the source
location importing to declarations in ClangImporter. There are some
invariants enforced by the Swift compile, e.g., a source range is
comprised of two valid source locations or two invalid ones. As a
result, this patch adds approximate source locations to some separators
like braces or parens that are not maintained by Clang. Having slightly
incorrect ranges in this case is better than emitting unknown source
locations.
2024-10-30 10:58:26 +00:00
Hamish Knight
5f5c9dd23e Merge pull request #77284 from hamishknight/for-in
[CS] Fix source range for `for` loop result builder transform
2024-10-30 02:33:42 +00:00
Nate Chandler
b87b42cd1e [CoroutineAccessors] If available, provide old ABI
If the feature is enabled, base the requirement for the underscored
accessors on the availability of the non-underscored accessors.  If the
(non-underscored) accessor's was available earlier than the feature,
interpret that to mean that the underscored version was available in
that earlier version, and require the underscored version.  The goal is
to ensure that the ABI is preserved, so long as the simplest migration
is done (namely, deleting the underscores from the old accessors).

For modify2, cache the required-ness in the same way that it is cached
for modify.
2024-10-29 14:24:36 -07:00
Nate Chandler
2801076a22 [CoroutineAccessors] Synthesize modify2 bodies.
Adding a synthesis routine for modify2 separate from that for modify was
inadverently omitted during the initial inadverently.  Fix that here.
2024-10-29 14:24:36 -07:00
Hamish Knight
2bcffc56d0 [CS] Fix source range for for loop result builder transform
Ensure the implicit `do` statement has a source
range that covers the `for` loop by changing the
source location for the initial binding. This ensures
we correctly detect the code completion child and
avoid skipping it.
2024-10-29 20:35:40 +00:00
Pavel Yaskevich
a7336e86f8 Merge pull request #77266 from xedin/fix-name-of-expr-time-threshold-param
[ConstraintSystem] NFC: Rename threshold in `ExpressionTimer` to clar…
2024-10-29 07:47:10 -07:00
Daniil Kovalev
0d7e37e4ec [AutoDiff] Enhance performance of custom derivatives lookup
In #58965, lookup for custom derivatives in non-primary source files was
introduced. It required triggering delayed members parsing of nominal types in
a file if the file was compiled with differential programming enabled.

This patch introduces `CustomDerivativesRequest` to address the issue.
We only parse delayed members if tokens `@` and `derivative` appear
together inside skipped nominal type body (similar to how member operators
are handled).

Resolves #60102
2024-10-29 12:45:14 +03:00
Hamish Knight
b4b99e9d28 Merge pull request #77248 from hamishknight/regex-avail-diag
[Sema] Add logic to diagnose regex feature availability
2024-10-29 09:45:00 +00:00
Daniil Kovalev
194199643f [AutoDiff] Fix assert on missing struct decl on cross-file derivative search (#77183)
Consider:

1. File struct.swift defining `struct Struct` with `static func max` member
2. File derivatives.swift defining `extension Struct` with custom derivative of the `max` function
3. File error.swift defining a differentiable function which uses `Struct.max`.

Previously, when passing error.swift as primary file and derivatives.swift as a secondary file to swift-frontend (and forgetting to pass struct.swift as a secondary file as well), an assertion failure was triggered.

This patch fixes the issue by adding a check against `ErrorType` in `findAutoDiffOriginalFunctionDecl` before calling `lookupMember`.

Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
2024-10-29 02:20:50 -07:00
Allan Shortlidge
1499229bab Merge pull request #77254 from tshortli/extract-clang-enum-element-versioned-availability
Sema: Only diagnose explicit unavailable Clang enum elements
2024-10-28 19:45:15 -07:00
Pavel Yaskevich
6109463cce [ConstraintSystem] NFC: Rename threshold in ExpressionTimer to clarify granularity
The variable was named incorrectly, it's actually expressed in seconds.
2024-10-28 17:29:01 -07:00
Gábor Horváth
708782d40b Merge pull request #77100 from swiftlang/gaborh/empty-value-type-diagnostic
[cxx-interop] Mark some zero-sized value types as unavailable
2024-10-28 18:08:40 +00:00
Allan Shortlidge
c2a7b086a0 Sema: Only diagnose explicit unavailable Clang enum elements.
https://github.com/swiftlang/swift/pull/77236 caused a source compatibility
regression because `extractEnumElement()` does not suppress its diagnostics in
the context of pattern matching. Potentially unavailable enum elements should
not be diagnosed when pattern matching since the generated code will not
retrieve the potentially unavailable element value on versions where it is
unavailable.

Fixes rdar://138771328.
2024-10-28 11:02:03 -07:00
Hamish Knight
9d4a78678a [Sema] Add logic to diagnose regex feature availability
Add the necessary compiler-side logic to allow
the regex parsing library to hand back a set of
features for a regex literal, which can then be
diagnosed by ExprAvailabilityWalker if the
availability context isn't sufficient. No tests
as this only adds the necessary infrastructure,
we don't yet hand back the features from the regex
parsing library.
2024-10-28 17:09:47 +00:00
Dylan Sturgeon
a1e888785d Enable indexing for refs to synthesized declarations.
Based on feedback in PR https://github.com/swiftlang/swift/pull/69460, enabling indexing for synthesized decls because they are usable by users and make sense to appear in the indexstore.

Sets `synthesized` on some additional decls:

  - derived `hashInto(...)`
  - Objc properties and methods derived from Objc protocols

https://github.com/apple/swift/issues/67446
2024-10-28 10:07:27 -07:00
Hamish Knight
e07fda5c43 [Sema] Factor out callback version of TypeChecker::checkAvailability
Allow the caller to use their own diagnostic
logic.
2024-10-28 15:42:54 +00:00
Gabor Horvath
22b46d3c9c [cxx-interop] Mark some zero-sized value types as unavailable
Currently, we do not support exporting zero-sized value types from Swift
to C++. It needs some work on our end as these types are not part of the
lowered signature. In the meantime, this PR makes sure that common (but
not all) zero sized types are properly marked as unavailable. This is
important as the proper diagnostic will give users a hint how to work
around this problem. Moreover, it is really easy to hit this when
someone is experimenting with interop, so it is important to not have a
cryptic failure mode.

rdar://138122545
2024-10-28 14:00:35 +00:00
Allan Shortlidge
d0506e1905 Merge pull request #77237 from tshortli/fix-resilience-diagnostic
Sema: Correct the decl kind in a resilience diagnostic
2024-10-27 18:28:52 -07:00
Hamish Knight
f4bea5f7c0 Merge pull request #77203 from hamishknight/wrapping-paper-sema
[Sema] Avoid relying on ParenType in a couple of places
2024-10-26 21:25:17 +01:00
Allan Shortlidge
ac8aec32ea Sema: Correct the decl kind in a resilience diagnostic.
Not everything is a type, type checker.
2024-10-26 09:26:39 -07:00
Allan Shortlidge
7e6e8ed7b5 Sema: Fully check the availability of wrappedValue.
Call `checkDeclarationAvailability()`, instead of just diagnosing
unavailability.
2024-10-25 16:50:20 -07:00
Allan Shortlidge
40695188c0 Sema: Fully check the availability of extracted enum elements.
Call `checkDeclarationAvailability()`, instead of just diagnosing
unavailability.
2024-10-25 14:25:13 -07:00
JanBaig
099eb46e82 [Diagnostics] Improve insertion location check when handling a missing argument 2024-10-25 13:05:03 -04:00
Allan Shortlidge
5c7509bef5 Merge pull request #77218 from tshortli/unmet-availability-requirement 2024-10-25 00:18:44 -07:00
Ben Barham
65f7c9eeb5 Merge pull request #77214 from slavapestov/fix-ub
Sema: Fix access of wrong union member
2024-10-24 21:49:05 -07:00
Allan Shortlidge
c02dccf622 Sema: Introduce UnmetAvailabilityRequirement.
This class is used to represent the reason a declaration is unavailable in a
specific context.
2024-10-24 20:07:42 -07:00
Allan Shortlidge
e1adee173a Sema: Use AvailabilityContext to compute compatible unavailability. 2024-10-24 20:06:35 -07:00
Allan Shortlidge
40f1556cc7 Merge pull request #77207 from tshortli/inaccessable-accessor-unavailable-storage
Sema: Diagnose accessor exportability even if storage is unavailable
2024-10-24 15:50:24 -07:00
Slava Pestov
a40d4c79ea Sema: Fix access of wrong union member 2024-10-24 18:17:52 -04:00
Slava Pestov
5190d98e1b Merge pull request #77178 from slavapestov/misc-solver-cleanups
Miscellaneous solver cleanups
2024-10-24 16:52:01 -04:00
Allan Shortlidge
df6b339c44 Sema: Diagnose accessor exportability even if storage is unavailable.
It is invalid to reference an internal setter from a fragile function
regardless of whether the storage is unavailable. The swiftinterface generated
for this code would not typecheck since the setter is not known to exist
outside the module.
2024-10-24 11:38:41 -07:00
Hamish Knight
b9646da26d [Sema] Refactor repairTupleOrAssociatedValuePatternIfApplicable
Avoid relying on the modeling of single unlabeled
associated values as ParenType, instead check the
case constructor parameters. Also refactor to
early return in more cases.
2024-10-24 15:29:49 +01:00
Hamish Knight
3c8921aa69 [Sema] Avoid relying on ParenType in space engine
Refactor `decomposeDisjuncts` to avoid relying on
the modeling of single unlabeled associated values
as ParenTypes.
2024-10-24 15:29:48 +01:00