Commit Graph

490 Commits

Author SHA1 Message Date
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
a96b780a28 [Sema] Diagnose method arg captures that are not Hashable/Equatable. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
970159c09d [CSDiagnostics] Block async, throws and mutating methods. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
7ff563eb0c [CSDiagnostics] Remove checks preventing method/initializer keypaths. 2025-03-19 08:56:03 -07:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Doug Gregor
6a4d1a41c4 Prohibit isolated conformances with Sendable(Metatype) constraints
Within the constraint system, introduce a new kind of conformance constraint,
a "nonisolated conforms-to" constraint, which can only be satisfied by
nonisolated conformances. Introduce this constraint instead of the normal
conforms-to constraint whenever the subject type is a type parameter that
has either a `Sendable` or `SendableMetatype` constraint, i.e., when the type
or its values can escape the current isolation domain.
2025-03-01 08:19:42 -08:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Anthony Latsis
87cf1179ff [NFC] Sema: Add Solution::getCalleeOverloadChoice 2025-01-16 02:35:26 +00:00
Alejandro Alonso
f76d841540 Rename to Slab 2025-01-09 10:39:45 -08:00
Alejandro Alonso
61702fb813 Implement Vector literals 2025-01-08 10:35:55 -08:00
Hamish Knight
2fd6863b1d [CS] Remove AutoClosureForwarding fix
The fix is currently unused, and the
FailureDiagnostic can be inlined into
MissingCallFailure.
2024-12-29 12:25:19 +00:00
Pavel Yaskevich
e3b1f341f0 [CSDiagnostics] Adjust conformance failure diagnostic to check for locatable types
If conformance failure is associated with a `LocatableType`, use
its location to anchor the failure.
2024-11-21 14:13:16 -08: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
Amritpan Kaur
02b9bcbda2 [Sema] Update diagnostics. 2024-09-25 12:54:52 -07:00
James Brown
f0eef0f583 [CS] Diagnose misuse of CheckedCastExpr with ~=
Using an unwrap operator with 'as' or the wrong keyword (i.e. `is`)
when already checking a cast via ~= results in error:
'pattern variable binding cannot appear in an expression'.
Add a diagnostic that provides more guidance and a fix-it
for the removal of ?/! or replacement of 'is' with 'as'.
2024-09-24 01:45:51 -04: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
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
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
Allan Shortlidge
bbea88eb6b Sema: Remove unused method from FailureDiagnostic. 2024-08-06 20:38:27 -07: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
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
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
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
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
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
Anthony Latsis
d18a7fd073 Sema: Require CS to certify conversions associated w/ existential member accesses 2024-04-18 22:54:19 +03:00
Konrad `ktoso` Malawski
54229549b3 [Distributed] Offer fixit for import Distributed when it is required (#72948) 2024-04-12 18:05:32 -07:00
Li, Zhen
b44fbf60c6 [CSDiagnostics] Add diags for holes in generic parameter pack 2024-02-21 23:25:25 -05:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Pavel Yaskevich
4c604b479b Merge pull request #70777 from xedin/diagnostic-improvements-for-closures
[ConstraintSystem] Closure type-checking improvements
2024-01-10 11:13:49 -08:00
Slava Pestov
d08b6446c6 Sema: Add a missing call to resolveType() with shape mismatch diagnostic 2024-01-09 14:43:16 -05:00
Pavel Yaskevich
859106eed1 [Diagnostics] Expand trailing closure failure to handle all closure arguments 2024-01-08 14:09:18 -08:00
Sima Nerush
b6d0afba1f Merge pull request #67594 from simanerush/simanerush/pack-iteration-impl
[SE-0408] Enable Pack Iteration
2023-12-07 17:09:48 -08:00
Sima Nerush
23485990e5 Diagnose that where clause is not supported 2023-12-03 21:51:41 -08:00
Pavel Yaskevich
8a0d61faac [CSDiagnostics] Add a diagnostic for an invalid key path subscript index argument 2023-11-21 14:53:46 -08:00
Doug Gregor
4b3d2f47d9 [Typed throws] Handle function conversions involving different thrown errors
Teach the constraint solver about the subtyping rule that permits
converting one function type to another when the effective thrown error
type of one is a subtype of the effective thrown error type of the
other, using `any Error` for untyped throws and `Never` for
non-throwing.

With minor other fixes, this allows us to use typed throws for generic
functions that carry a typed error from their arguments through to
themselves, which is in effect a typed `rethrows`:

```swift
func mapArray<T, U, E: Error>(_ array: [T], body: (T) throws(E) -> U)
throws(E) -> [U] {
  var resultArray: [U] = .init()
  for value in array {
    resultArray.append(try body(value))
  }
  return resultArray
}
```
2023-10-05 11:55:05 -07:00
Becca Royal-Gordon
78127ce5ee Diagnose possible enum common-prefix mistakes
Clang Importer strips prefixes from enum and option set case names. The logic to do this computes a common prefix from the type name and all non-deprecated case names (to oversimplify), which means that adding, removing, or changing one case can change the prefix that is removed from *all* cases. This typically causes the prefix to become shorter, meaning that additional words are prepended to each existing case name.

Existing diagnostics make it look like the case has disappeared, when in fact it still exists under a different name. A little more information may help developers to figure out what happened.

Add a tailored diagnostic for this scenario which kicks in when (a) a missing member is diagnosed, (b) the base is an imported enum or option set’s metatype, and (c) an enum case or static property exists which has the name we attempted to look up as a suffix.

Fixes rdar://116251319.
2023-10-02 16:50:54 -07:00
Hamish Knight
c0ae9b950b Move out-of-place ThenStmt checking to constraint generation 2023-09-01 14:32:15 +01:00
Becca Royal-Gordon
fc2c66f674 [NFC] Adopt %kind for Sema ValueDecl diagnostics 2023-07-19 13:08:11 -07:00
Pavel Yaskevich
c50263c730 Merge pull request #66971 from xedin/fix-specialization-issues
[ConstraintSystem] Fix a couple of issues related to generic specialization
2023-06-29 12:25:11 -07:00
Pavel Yaskevich
be4df5afd2 [CSDiagnostics] Diagnose attempts to specialize with invalid number of generic arguments
```swift
struct Test<T, U> {}
_ = Test<Int>() // error
```
2023-06-27 17:24:39 -07:00
Pavel Yaskevich
40169c74ee [CSDiagnostics] Add a diagnostic for an attempt to specialize a concrete type
Diagnose attempts to specialize a concrete type or its alias:

```swift
struct Test {}
typealias X = Test

_ = X<Int>() // error
```
2023-06-27 17:24:38 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Kavon Farvardin
66bf3c03fc describe illegal casts to existentials 2023-06-23 20:15:01 -07:00
Hamish Knight
f10d0df62f Merge pull request #66593 from hamishknight/pattern-error 2023-06-16 18:06:47 +01:00