Commit Graph

2753 Commits

Author SHA1 Message Date
Pavel Yaskevich
05b0adac5d [ConstraintSystem] Use getNumApplications + ValueDecl::getNumCurryLevels to detect partial applications
We used to detect partial applications based on member locators
and parent expressions, but using function reference kind +
check to see if self is applied is such simpler and hits both
uses of `isPartialApplication`.
2024-08-30 17:04:46 -07:00
Pavel Yaskevich
427e7bc196 [CSSimplify] Adjust impact assessment of l-value mismatch based on member settability
Increases the default score of the `treat r-value as l-value`
and decrease the impact if the immediate member is settable
because that means that the problem is somewhere in the "base".
2024-08-30 15:39:25 -07:00
Pavel Yaskevich
d8750a83f8 [CSSimplify] Allow l-value object simplication if l-value type is a placeholder
Placeholders propagate but we still can allow contextual inference,
to facilitate that the solver should consider `l-value object` constraint
to be solved and allow placeholders on "object" type.
2024-08-30 15:39:18 -07:00
Pavel Yaskevich
2e53bc26cd [CSSimplify] Implement LValueObject constraint simplification 2024-08-29 10:10:14 -07:00
Pavel Yaskevich
5a93255133 [ConstraintSystem] Introduce new LValueObject constraint 2024-08-29 10:10:14 -07:00
Pavel Yaskevich
2a6cc12a63 [ConstraintSystem] Downgrade some invalid specialization uses to a warning until Swift 6 language mode
Some invalid specializations were previously allowed by the compiler
and we found some existing code that used that (albeit invalid) syntax,
so we need to stage that error as a warning until Swift 6 language mode
to avoid source compatibility break.

Resolves: rdar://134740240
2024-08-29 00:15:08 -07:00
Pavel Yaskevich
815699d21a [Diagnostics] Produce a diagnostic for existential mismatch in same-type constraint
Previously this would result in a fallback diagnostic because
type mismatches associated with `ExistentialConstraintType`
locations weren't handled at all.
2024-08-22 16:51:48 -07:00
Pavel Yaskevich
d151118833 [CSSimplify] Don't erase sugar while forming locators for generic types during matching
Fixes retrieve information form locators which means that we
need to preserve the original form for diagnostics.
2024-08-22 14:46:36 -07:00
Slava Pestov
69bd0f0f1f AST: Remove OpaqueTypeArchetypeType::getCanonicalInterfaceType() 2024-08-20 17:00:25 -04:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Kavon Farvardin
6331381199 Ownership: infer from contextual parameter's type
We were not carrying-over the ownership specifier in the constraint
solver when forming the closure's inferred type from its contextual
type.

resolves rdar://118133048
2024-08-06 16:06:53 -07:00
Slava Pestov
fdfeb0e2d0 Merge pull request #75647 from slavapestov/fix-issue-74858
Sema: Fix crash with SpecializeExpr around something that's not a type
2024-08-02 18:42:17 -04:00
Slava Pestov
43d673c51b Sema: Fix crash with SpecializeExpr around something that's not a type
Unfortunately the diagnostic is terrible.

Fixes https://github.com/swiftlang/swift/issues/74858
2024-08-02 15:12:52 -04:00
Greg Titus
d87e049cde Improve diagnoses of generic specializations
Always add constraints, find fixes during simplify.
New separate fix for allow generic function specialization.
Improve parse heuristic for isGenericTypeDisambiguatingToken.
Degrade concrete type specialization fix to warning for macros.
2024-07-30 18:51:34 -07:00
Pavel Yaskevich
0343bb18af Revert "[Sema] Add specialization constraints for func and variable types, then diagnose w/fixes." 2024-07-25 15:43:15 -07:00
Greg Titus
47acc09e11 Merge pull request #74909 from gregomni/generic-arg
[Sema] Add specialization constraints for func and variable types, then diagnose w/fixes.
2024-07-24 19:38:11 -07:00
Greg Titus
6e917b567a Improve diagnoses of generic specializations
Always add constraints, find fixes during simplify.
New separate fix for allow generic function specialization.
Improve parse heuristic for isGenericTypeDisambiguatingToken.
2024-07-24 14:25:11 -07:00
Hamish Knight
22b08da0dd [Sema] Remove replaceInvalidRefsWithErrors param
Doesn't seem like anything is relying on setting
this to `false` anymore, remove it.
2024-07-21 15:27:15 +01:00
Hamish Knight
d6d8d08608 [CS] Better diagnose conformance failures for EnumElementPatterns
Previously we could end up with a
ContextualMismatch fix and a MissingConformance fix
for different elements of the `matchTypes` disjunction,
leading to an ambiguity. Instead, avoid recording
the ContextualMismatch if we're matching an
existential, and tweak the MissingConformance
failure to have a custom diagnostic for
EnumElementPattern matching.
2024-07-15 12:47:50 +01:00
Allan Shortlidge
5d6f6947ed Merge pull request #75158 from tshortli/member-import-visibility-package
AST: Add a `IgnoreMissingImports` option to name lookup
2024-07-11 11:07:39 -07:00
Allan Shortlidge
d002da0ef2 AST: Add a IgnoreMissingImports option to name lookup.
Control enforcement of member import visibility requirements via a new option,
instead of piggy-backing on the existing IgnoreAccessControl option. Adopt the
option when doing fallback lookups for unviable members so that the compiler
can diagnose the reason that a member is inaccessible more reliably.
Previously, with MemberImportVisibility enabled decls with the package access
level could be mis-diagnosed as inaccessible due to their access level when
really they were inaccessible due to a missing import.

Resolves rdar://131501862.
2024-07-10 22:57:15 -07:00
Meghana Gupta
076d70acbb Update getLifetimeDependenceInfo to getLifetimeDependencies in CSSimplify 2024-07-10 14:48:34 -07:00
Meghana Gupta
a91cb2819a Ban conversion between function types of different lifetime dependencies 2024-07-09 09:12:18 -07:00
Hamish Knight
4beaaf32ad [CS] Improve placeholder diagnostics slightly
Make sure `CouldNotInferPlaceholderType` can
produce a diagnostic for a `PlaceholderType`
locator element, and avoid emitting an extra
diagnostic for a placeholder type in an invalid
position.
2024-07-07 23:42:33 +01:00
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04:00
Slava Pestov
3fcda140bb AST: ModuleDecl::checkConformance() is a static method 2024-07-06 12:05:46 -04:00
Slava Pestov
fae01d9776 AST: Remove ModuleDecl parameter from more places 2024-07-06 12:05:46 -04:00
Greg Titus
8a40393287 Merge pull request #74692 from gregomni/adding-member
[Sema] Raise impact of DefineMemberBasedOnUse to match RemoveInvalidCall
2024-06-28 15:33:36 -07:00
Greg Titus
50333b6104 Raise impact of DefineMemberBasedOnUse to 4, lower RemoveInvalidCall to 3. 2024-06-25 11:29:24 -07:00
Michael Gottesman
56cb980540 Merge pull request #74564 from gottesmm/pr-9be87019f95149167c2e03043b7a86b82f9d282c
Follow up fixes with feedback from #74129
2024-06-25 10:24:26 -07:00
Tim Kientzle
598e5104ef Merge pull request #74184 from tbkka/tbkka-assertions2
Add `#include "swift/Basic/Assertions.h"` to a lot of source files
2024-06-20 12:13:28 -07:00
Michael Gottesman
9b0e0f5010 Follow up fixes with feedback from #74129
Didn't need to modify any tests since this shouldn't have any functional
change. Just a slight cleanup.
2024-06-19 20:04:05 -07:00
Pavel Yaskevich
adaaf5a522 Merge pull request #74542 from gregomni/issue-74463
[Sema] Tuple mismatch with argument locator should be handled by ArgumentMismatch
2024-06-19 14:39:14 -07:00
Greg Titus
6266564700 Tuple mismatch with argument locator should be handled by ArgumentMismatch 2024-06-18 21:58:39 -07:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Greg Titus
3e7f323276 Merge pull request #74464 from gregomni/issue-46902
[Sema] Fix hole where missing_nullary_call wasn't diagnosed in ternary condition.
2024-06-17 08:49:44 -07:00
Greg Titus
10138d8390 Fix hole where missing_nullary_call wasn't diagnosed in ternary condition. 2024-06-16 22:19:48 -07:00
Greg Titus
fb2d667e45 Merge pull request #74243 from gregomni/rvalue-ambiguous
[Sema] Score non-settable overload choices higher in RValueToLValue fix
2024-06-15 15:35:39 -07:00
Greg Titus
843ce585a3 Set fix impact for non-settable overload choices higher, so we get diagnoses from better choices. 2024-06-15 11:43:21 -07:00
Michael Gottesman
f9954181ae Merge pull request #74129 from gottesmm/pr-d17a3faab1ceab8b831d7649c1005be9c49d771c
[region-isolation] Implement function sub typing rules
2024-06-14 12:53:22 -07:00
Michael Gottesman
16d0194d77 [sending] Improve the sending mismatch errors and make them warnings when not in swift 6.
This will ensure that we do not break anyone who has adopted APIs like
CheckedContinuation.resume that now have sending parameters.

An example of where this can come up is shown by the ProcessType in SwiftToolsCore:

```swift
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
@discardableResult
public func waitUntilExit() async throws -> ProcessResult {
    try await withCheckedThrowingContinuation { continuation in
        DispatchQueue.processConcurrent.async {
            self.waitUntilExit(continuation.resume(with:))
        }
    }
}
```

This fails to compile since self.waitUntilExit doesn't expect a function that
takes a sending parameter. We want to give people time to fix such issues.
2024-06-13 22:23:08 -07:00
Michael Gottesman
2ac874e8e3 [sending] Fix a few bugs around closure inference of sending parameters and results.
I found this while writing tests for the earlier part of this work. Since this
is also type checking work, I am just folding this work into that work.
2024-06-12 16:13:05 -07:00
Michael Gottesman
3c166b5d96 [sending] Implement non-protocol function subtyping rules.
rdar://127675288
2024-06-12 16:13:05 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Kavon Farvardin
79075e900d Merge pull request #73927 from kavon/ncgenerics-diagnostics-improved
NCGenerics: improve diagnostics
2024-06-04 21:47:01 -07:00
Kavon Farvardin
c9cfe28e6d NCGenerics: improve diagnostics
Removing the old, ad-hoc diagnostics code improves the diagnostics we
emit, since the existing diagnostics for missing conformances is already
pretty good.

rdar://127369509
2024-06-04 15:06:32 -07:00
Pavel Yaskevich
243cc1641d [CSSimplify] Don't pile up fixes for incorrect optional chaining
If the contextual type propagated into the optional chain mismatches with
the inner type formed from its member references and that inner type
is a result of some fix, let's consider that un-salvageable and avoid
producing additional "ignore contextual type" fixes which only lead
to subpar solutions.
2024-05-28 15:52:53 -07:00
Slava Pestov
33071e2525 Sema: Use getNextDepth()/getMaxDepth() 2024-05-01 12:09:01 -04:00