Commit Graph

428 Commits

Author SHA1 Message Date
Pavel Yaskevich
a381143495 [CSFix] Fix getConcurrencyFixBehavior to account for non-decl overloads
Adjust the downgrade check for static member references to
account for the fact that argument could come of a tuple or
some other reference that doesn't have a declaration associated
with it.

Resolves: rdar://153083848
(cherry picked from commit 3ae8d5680f)
2025-06-27 13:20:22 -07:00
Hamish Knight
cc66fc886f [CS] Avoid solver-allocated inputs with typesSatisfyConstraint
Escaping solver-allocated types into a nested allocation arena is
problematic since we can e.g lazily compute the `ContextSubMap` for a
`NominalOrBoundGenericNominalType`, which is then destroyed when we
exit the nested arena. Ensure we don't pass any types with type
variables or placeholders to `typesSatisfyConstraint`.

rdar://152763265
2025-06-10 16:08:00 +01:00
Pavel Yaskevich
d517a26f25 [CSFix] SE-0470: Warn about missing @Sendable for unapplied static member references until future Swift version
Static member referenced were marked as `@Sendable` by `InferSendableFromCaptures`
because metatypes used to be always Sendable which is no longer the case, so in
order to maintain the source compatibility we need to downgrade missing `@Sendable`
to a warning for unapplied static member references.

This affects primarily operators at the moment because other static members
form a curry thunk with a call inside and would be diagnosed as a capture.

Resolves: rdar://150777469
(cherry picked from commit a57310b61d)
2025-05-07 09:13:08 -07:00
Doug Gregor
2a7de1b559 Store the conforming type within an abstract ProtocolConformanceRef
An "abstract" ProtocolConformanceRef is a conformance of a type
parameter or archetype to a given protocol. Previously, we would only
store the protocol requirement itself---but not track the actual
conforming type, requiring clients of ProtocolConformanceRef to keep
track of this information separately.

Record the conforming type as part of an abstract ProtocolConformanceRef,
so that clients will be able to recover it later. This is handled by a uniqued
AbstractConformance structure, so that ProtocolConformanceRef itself stays one
pointer.

There remain a small number of places where we create an abstract
ProtocolConformanceRef with a null type. We'll want to chip away at
those and establish some stronger invariants on the abstract conformance
in the future.
2025-03-23 20:53:48 -07:00
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -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
Pavel Yaskevich
13e3269d16 [CSFix] Fix a null pointer dereference in getStructuralTypeContext
First problem - the logic used constraint system, which shouldn't
be required, second - it expects the type to be always present in
`ContextualTypeInfo` but that's not the case for some patterns.

Resolves: rdar://131819800
2025-02-24 13:57:28 -08:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08: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
Hamish Knight
d25bdfa4a3 [CS] Remove hack for rdar://139234188
Now that "is compound" is a separate bit in
FunctionRefInfo, we can correctly track the
application level for an EnumElementPattern.
2024-12-03 11:32:11 +00:00
Hamish Knight
73fb36f371 [AST] Split out "is compound" bit on FunctionRefInfo
FunctionRefKind was originally designed to represent
the handling needed for argument labels on function
references, in which the unapplied and compound cases
are effectively the same. However it has since been
adopted in a bunch of other places where the
spelling of the function reference is entirely
orthogonal to the application level.

Split out the application level from the
"is compound" bit. Should be NFC. I've left some
FIXMEs for non-NFC changes that I'll address in a
follow-up.
2024-12-02 14:11:33 +00:00
Hamish Knight
a4d51419ba [AST] NFC: Rename FunctionRefKind -> FunctionRefInfo 2024-12-02 14:11:32 +00:00
Pavel Yaskevich
7c8000b3a5 [Frontend] Switch -interface-compiler-version to Version
`SWIFT_COMPILER_VERSION` has more than 4 components and it's
easier to use `Version` API over `VersionTuple` as well.
2024-11-18 15:11:36 -08:00
Holly Borla
a31a9d3642 [Concurrency] Downgrade @preconcurrency @Sendable conversion failures
to warnings even in Swift 6.
2024-11-07 16:02:37 -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
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
Amritpan Kaur
8ebc928649 Guard feature behind experimental flag. 2024-09-27 22:42:04 -07:00
Amritpan Kaur
02b9bcbda2 [Sema] Update diagnostics. 2024-09-25 12:54:52 -07:00
Amritpan Kaur
ffb8baf342 [Sema] Remove checks preventing metatype keypaths in Sema. 2024-09-25 12:54:51 -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
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
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
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
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -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
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
Slava Pestov
86d567f95a AST: ModuleDecl::lookupConformance() is a static method 2024-07-06 12:05:47 -04: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
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
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -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
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
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
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
Slava Pestov
d981cf3b77 Sema: De-requestify TypeBase::isNoncopyable() and TypeBase::isEscapable()
And consolidate the logic in ConformanceLookup.cpp.
2024-02-05 11:25:57 -05: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
bd4ee4681b Merge pull request #70007 from xedin/keypath-application-improvements
[ConstraintSystem] Modernization of key path application handling
2023-11-28 12:44:42 -08:00
Slava Pestov
1b1963e904 Sema: Remove 'inferred result type requires explicit coercion' diagnostic 2023-11-27 14:05:36 -05:00