Commit Graph

1216 Commits

Author SHA1 Message Date
Hamish Knight
33b58d25d8 [CS] NFC: Factor out Solution::hasAppliedSelf 2025-07-18 10:54:17 +01:00
Egor Zhdan
01719983dc Merge pull request #82627 from swiftlang/egorzhdan/void-begin-crash
[cxx-interop] Do not crash for `void begin()`
2025-07-01 17:35:16 +01:00
Egor Zhdan
883ff18adb [cxx-interop] Do not crash for void begin()
When importing C++ methods, Swift always assumes that methods named `begin()` and `end()` are unsafe, since these methods commonly return iterator types that are inherently unsafe in Swift.

Some additional logic in Sema tries to diagnose usages of `.begin()` and `.end()` from Swift and suggest safe alternatives. That logic had a null pointer dereference bug.

rdar://153814676 / resolves https://github.com/swiftlang/swift/issues/82361
2025-06-30 16:26:56 +01:00
Hamish Knight
e912eeb2f4 [CS] Use the resolved type in NonOptionalUnwrapFailure::diagnoseAsError
Diagnostics can outlive the ConstraintSystem itself if we have a
diagnostic transaction for e.g `typeCheckParameterDefault`, make sure
we don't try to use a solver-allocated type as an argument.
2025-06-28 12:13:19 +01:00
Anthony Latsis
ad8c52237c Sema: Fix the insertion location for conformances attributes 2025-06-24 14:49:03 +01:00
Slava Pestov
b79f2817f9 Sema: Fix MissingCallFailure::diagnoseAsError() crash with special base names 2025-06-17 09:52:04 -04:00
Pavel Yaskevich
6bbc101a98 [Diagnostics] Correctly diagnose situations when immutable value is passed to inout parameter
Currently the note is going to point to the "callee" but that is
incorrect when the failure is related to an argument of a call.

Detect this situation in `RValueTreatedAsLValueFailure::diagnoseAsNote`
and produce a correct note.

Resolves: rdar://150689994
2025-06-06 14:36:19 -07:00
Pavel Yaskevich
71a8d8d8a4 [CSDiagnostics] Attempt fix-its for contextual generic argument mismatches 2025-06-02 17:39:56 -07:00
Artem Chikin
d8176a7e89 [Compile Time Values] Add syntactic verification of valid expressions in '@const' contexts
Syntactically verify that initializer expressions of '@const' variables and argument expressions to '@const' parameters consist strictly of syntactically-verifiable set of basic values and operations
2025-05-20 09:38:36 -07:00
Becca Royal-Gordon
d48ff3545d [NFC] Give withoutArgumentLabels() a context arg
It will soon need to allocate sometimes.
2025-05-14 11:16:02 -07:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Anthony Latsis
2d899d0e73 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsCommon.def 2025-04-05 12:31:20 +01:00
Anthony Latsis
a0930dec31 AST: Cut down on DescriptiveDeclKind usage in DiagnosticsSema.def 2025-04-05 12:31:19 +01:00
Slava Pestov
00766f7deb AST: Remove type parameter from ProtocolConformanceRef::getTypeWitnessByName() 2025-04-03 17:35:32 -04:00
Pavel Yaskevich
05798e5f45 Revert "Sema: Remove dead diagnostic"
This reverts commit d56d7045a2.
2025-03-31 14:39:44 -07:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00:00
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -07:00
Pavel Yaskevich
552106d536 Merge pull request #80081 from xedin/rdar-143161190
[CSSimplify] Open key path type before assignment to its record requirements
2025-03-19 09:50:11 -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
Pavel Yaskevich
cfad698202 [CSDiagnostics] Tailor diagnostic for Escapable conformance mismatch in key path context 2025-03-18 14:38:40 -07:00
Pavel Yaskevich
6c2b12547b [CSDiagnostics] Tailor diagnostic for Copyable conformance mismatch in key path context 2025-03-18 13:46:56 -07:00
Doug Gregor
c58e22fccc Simplify APIs for accessing conformance isolation
The NormalProtocolConformance APIs for checking for an explicitly-written
isolation on a conformance were easy to get to, and the real semantic
API was buried in the type checker, leading to some unprincipled
checking. Instead, create a central ProtocolConformance::getIsolation()
to get the (semantic) actor isolation, and let that be the only place
that will access the explicitly-written global actor isolation for a
conformance. Update all call sites appropriately.
2025-03-12 23:18:32 -07:00
Doug Gregor
3837661b84 [Isolated conformances] Allow conformance isolation to differ from the type's
With the move to explicitly specifying the global actor for an isolated
conformance, we can now have conformances whose isolation differs from
that of the type, including having actors with global-actor-isolated
conformances. Introduce this generalization to match the proposal, and
update/add tests accordingly.
2025-03-12 23:18:28 -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
Slava Pestov
3a01f206c5 Sema: Rename LocatorPathElt::OptionalPayload to ::OptionalInjection 2025-02-25 17:22:41 -05:00
Slava Pestov
d56d7045a2 Sema: Remove dead diagnostic 2025-02-25 17:22:41 -05:00
fahadnayyar
d8f919778d [cxx-interop] [cxx-interop] Infer SWIFT_SHARED_REFERENCE for types inheriting from a C++ foreign reference type
rdar://97914474
2025-02-20 08:46:57 -08:00
Alejandro Alonso
e4fb1f6761 Rename Slab to InlineArray 2025-02-11 10:26:44 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Pavel Yaskevich
798cd6843e [Diagnostics] Fix generic arguments mismatch diagnostic related to leading-dot syntax
`GenericArgumentsMismatchFailure` missed a case where location
of the failure points to a member spelled with leading-dot syntax.
2025-01-21 11:43:01 -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
4cbe481f82 Merge pull request #78377 from hamishknight/no-simplify-result
[CS] Don't simplify `FunctionResult` in `simplifyLocator`
2025-01-02 17:26:22 +00: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
86e8165569 [CS] Don't simplify FunctionResult in simplifyLocator
Simplifying into the function expression is wrong,
like `FunctionArgument` this isn't an element that
can be simplified. This also means we don't need
to handle it in `MissingCallFailure`, since we
shouldn't be recording that fix in this case.
2024-12-29 12:25:18 +00:00
Doug Gregor
5b90b8851a Generalize protocol conformance options spelled via attribute and incorporate @unsafe
Protocol conformances have a handful attributes that can apply to them
directly, including @unchecked (for Sendable), @preconcurrency, and
@retroactive. Generalize this into an option set that we carry around,
so it's a bit easier to add them, as well as reworking the
serialization logic to deal with an arbitrary number of such options.

Use this generality to add support for @unsafe conformances, which are
needed when unsafe witnesses are used to conform to safe requirements.
Implement general support for @unsafe conformances, including
producing a single diagnostic per missing @unsafe that provides a
Fix-It and collects together all of the unsafe witnesses as notes.
2024-12-20 23:16:23 -08:00
Pavel Yaskevich
c8f3524961 [CSDiagnostics/Tests] Add tests for any Sendable vs. Any interaction in non-strict concurrency contexts 2024-12-13 09:35:34 -08:00
Pavel Yaskevich
a8146d6086 [CSDiagnostics] Generic argument mismatches should always mention the container types 2024-12-12 14:36:10 -08:00
Hamish Knight
0fdb038fc9 Merge pull request #77896 from hamishknight/functionref-split
[AST] Split out "is compound" bit on FunctionRefKind
2024-12-03 09:53:37 +00:00
Pavel Yaskevich
8a0a083a45 Merge pull request #77797 from xedin/locatable-types
[AST/Sema]  Introduce a new type that has associated location in source
2024-12-02 16:33:43 -08:00
Allan Shortlidge
c5398e17d3 AST: Introduce Decl::getDeprecatedAttr().
It replaces `DeclAttr::getDeprecated()` as the designated way to query for the
attribute that makes a decl deprecated.
2024-12-02 07:35:58 -08:00
Allan Shortlidge
2358712870 AST/Sema: Remove DeclAttr::isUnavailable().
Update callers to use `Decl::isUnavailable()` instead.
2024-12-02 07:35:58 -08: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
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