Commit Graph

1731 Commits

Author SHA1 Message Date
Hamish Knight
1f32f7f5ac Merge pull request #85525 from hamishknight/yeet
[CS] Remove `getImplicitValueConversionLocator` & `ImplicitConversion`
2025-11-17 14:03:13 +00:00
Hamish Knight
61a5ae8e01 [CS] Eagerly bind hole in recordInvalidNode
We know this is where the issue is so we can immediately bind to a hole,
ensuring we don't produce unnecessary downstream diagnostics from
things we can't infer.
2025-11-16 11:47:21 +00:00
Hamish Knight
6dfff1ce9c [CS] Remove getImplicitValueConversionLocator & ImplicitConversion
These are now unused.
2025-11-15 19:26:46 +00:00
Slava Pestov
819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
Anthony Latsis
bda6edb85c AST: Rename GenericContext::isGeneric to hasGenericParamList
`isGeneric` is a misleading name because this method checks for the
existence of a `GenericParamList`, which is not implied by genericity.
2025-11-11 15:55:16 +00:00
Hamish Knight
260d10f6b8 [CS] Fix a couple of fixPropertyWrapperFailure crashers
Make sure we query the constraint system for a type if we have a local
property wrapper in a closure to avoid kicking interface type
computation outside the closure, and make sure we map into context if
we need to.
2025-11-04 00:56:01 +00:00
Hamish Knight
3b57a7cd91 [CS] Clean up some property wrapper logic
These methods can be simplified a bunch since the returned decl is
always the input decl and we can refactor the lambdas to just return
the auxiliary variable and have the type computation in the caller.
2025-11-04 00:56:01 +00:00
Slava Pestov
69c8d15570 Sema: Fix a fuzzer crash
This test case crashes when prepared overloads are disabled, but passes
when enabled. To avoid messing up tests if we have to turn the flag on
and off, fix the crash.
2025-10-24 16:20:21 -04:00
Hamish Knight
977246e0da [CS] Use inSalvageMode instead of phase in a couple of places
This seems to better match what the conditions are checking for.
2025-10-19 13:14:00 +01:00
Tim Kientzle
41f680cb93 Merge pull request #84826 from tbkka/tbkka-revert-revert-floatingpointdescription
Re-land new Floating-poing `debugDescription`
2025-10-12 20:19:12 -07:00
Tim Kientzle
4c0b58096e Make _InlineArray subject to the same optimizations as InlineArray 2025-10-10 14:06:14 -07:00
Slava Pestov
8600cdcc2a Sema: Remove ConstraintSystemPhase::{Diagnostics,Finalization} 2025-10-10 16:06:42 -04:00
Hamish Knight
48ac5126d9 [AST] Fold away nested ErrorTypes
Remove the now-unnecessary hack where we could build recursive
ErrorTypes.
2025-10-08 21:16:02 +01:00
Hamish Knight
9e4208b69b [CS] Remove custom logic from simplifyTypeForCodeCompletion
We ought to be able to just use `simplifyType` with an additional
parameter to tell it to produce archetypes.
2025-10-04 12:56:52 +01:00
Hamish Knight
669a2ce9b0 [CS] Sink placeholder handling logic into Solution::simplifyType
Move the logic from `FailureDiagnostic::resolveType` into
`Solution::simplifyType` to allow completion to use it too. While
here, also handle cases where the placeholder is from a different
member of the equivalence class to the generic parameter.
2025-10-04 12:56:52 +01:00
Hamish Knight
5171b84dba [CS] Replace UnresolvedType with ErrorType in simplifyType/resolveType
This means we now either produce a bare ErrorType, or an ErrorType
with a generic parameter original type for a generic parameter hole.
We ought to further consolidate this logic by sinking the generic
parameter original type replacement into `simplifyType` itself, but
I'm leaving that for a future patch since it affects completion
results and I want to try keep this close to NFC.
2025-10-03 09:50:42 +01:00
Allan Shortlidge
2467b931a7 ConstraintSystem: Move key path type utilities to AST. 2025-09-25 07:13:17 -07:00
Slava Pestov
7f8c4e08a8 Sema: Correctly thread PreparedOverloadBuilder through InferableTypeOpener 2025-09-18 14:54:16 -04:00
Slava Pestov
9dea72579a Sema: Record ASTNode type changes in PreparedOverload
Also, move some methods from ConstraintSystem.h to ConstraintSystem.cpp.
2025-09-18 14:54:16 -04:00
Slava Pestov
4ea2f1706b Sema: Simplify getConcreteReplacementForProtocolSelfType() 2025-09-18 11:31:59 -04:00
Doug Gregor
7d21bc332a [Embedded] Diagnose untyped throws as an Embedded Swift restriction
Untyped throws depends on existentials (`any Error`), and is therefore
not available in Embedded Swift. Introduce a diagnostic that diagnoses
any use of untyped throws, suggesting that one use typed throws
instead.

Make this an opt-in diagnostic enabled with `-Wwarning
EmbeddedRestrictions`, whether in Embedded Swift or not, using the
"default ignore" flag on these new warnings. Document this new
diagnostic group, and put the existing Embedded Swift error about
weak/unowned references in it as well.

Part of the general push to have the type checker identify code that
will not compile as Embedded Swift earlier, rdar://133874555.
2025-09-14 21:48:50 -07:00
Slava Pestov
13b4b03aca Sema: Fix crash in IgnoreAssignmentDestinationType::diagnoseForAmbiguity() 2025-09-09 18:58:10 -04:00
Hamish Knight
5b8dfc70ab [CS] Emit fallback diagnostic if needed for IgnoreInvalidASTNode
If no other error has been emitted, make sure we emit a fallback
diagnostic rather than crashing in the ASTVerifier or SILGen.
2025-08-28 15:31:48 +01:00
Hamish Knight
9c898206e8 Merge pull request #83870 from hamishknight/overrun
[CS] Open generic requirements for types with unbound + placeholder types
2025-08-27 23:20:33 +01:00
Hamish Knight
2e0be5afd7 [CS] Open generic requirements for types with unbound + placeholder types
- Introduce a generic requirements opening function for type resolution,
  which is used by the constraint system in cases where we need to
  impose requirements on opened type variables.
- Refactor `replaceInferableTypesWithTypeVars` to use this function
  when opening generic types that contain either placeholder or unbound
  generic types.

Together these changes ensure that we don't drop generic requirements
when an unbound generic or placeholder type is used as a generic
argument.
2025-08-26 12:16:54 +01:00
Slava Pestov
1972c4845f Sema: Cache result of getUnsatisfiedAvailabilityConstraint()
This query is expensive and we call it a lot.
2025-08-25 17:14:35 -04:00
Hamish Knight
5c3f6703a0 Remove diag::type_of_expression_is_ambiguous
This is a diagnostic that is only really emitted as a fallback when
the constraint system isn't able to better diagnose the expression.
It's not particulary helpful for the user, and can be often be
misleading since the underlying issue might not actually be an
ambiguity, and the user may well already have a type annotation. Let's
instead just emit the fallback diagnostic that we emit in all other
cases, asking the user to file a bug.
2025-08-19 17:14:23 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Pavel Yaskevich
94b0b55837 Merge pull request #83286 from xedin/treat-std-string-as-default-literal-type
[ConstraintSystem] C++ Interop: Binding a string literal to `std.stri…
2025-07-25 00:05:14 -07:00
Pavel Yaskevich
cd9c37cac6 [ConstraintSystem] C++ Interop: Binding a string literal to std.string shouldn't increase the score
Since this is a C++ stdlib type we need make sure that any overloads
that use it are preferred over custom types that also conform to
`ExpressibleByStringLiteral` when argument is a string literal.

This is important for operators like `==` which could be heterogenous
and have a custom C++ type that conforms to `ExpressibleByStringLiteral`
on either side together with `std.string` i.e.
`==(std.string, const CustomString &)`, such overloads should only
be selected if argument passed to `CustomString` is non-literal because
literals are convered by a stdlib `==(std.string, std.string)` overload.
2025-07-24 14:08:15 -07:00
Hamish Knight
33b58d25d8 [CS] NFC: Factor out Solution::hasAppliedSelf 2025-07-18 10:54:17 +01:00
Allan Shortlidge
59b136ccc4 Merge pull request #83054 from tshortli/unavailable-setters-require-read-only-key-paths
ConstraintSystem: Make key paths for properties with unavailable setters read-only
2025-07-16 21:31:41 -07:00
Anthony Latsis
d7ec3a34bb Merge pull request #83094 from swiftlang/jepa-main
Sema: Make `@concurrent` not imply `async` on closures
2025-07-17 01:54:04 +01:00
Anthony Latsis
58d5059617 Sema: Make @concurrent not imply async on closures
The present approach is not prudent because `@concurrent` synchronous
functions, a natural extension, are a likely-to-happen future direction,
whereas the current inference rule is entirely grounded on `@concurrent`
being exclusive to async functions.

If we were to ship this rule, we would have to keep the promise for
backwards compatibility when implementing the aforementioned future
direction, replacing one inconsistency with another, and possibly
introducing new bug-prone expression checking code.

```swift
func foo(_: () -> Void) {}
func foo(_: () async -> Void) {}

// In a future without this change and  `@concurrent` synchronous
// functions accepted, the first call resolves to the first overload,
// and the second call resolves to the second, despite `@concurrent` no
// longer implying `async`.
foo { }
foo { @concurrent in }
```

This change also drops the fix-it for removing `@concurrent` when used
on a synchronous closure. With the inference rule gone, and the
diagnosis delayed until after solution application, this error raises a
fairly balanced choice between removing the attribute and being
explicit about the effect, where a unilateral suggestion is quite
possibly more harmful than useful.
2025-07-16 20:46:29 +01:00
Allan Shortlidge
4076fa6b2e ConstraintSystem: Make key paths for properties with unavailable setters read-only.
Previously, only conditional unavailability was considered, but setters that
are always unavailable must also make a keypath read-only.

Resolves rdar://155832511.
2025-07-15 10:33:44 -07:00
Slava Pestov
44750115f0 Sema: You can't simplify types while preparing an overload 2025-07-11 19:57:29 -04:00
Slava Pestov
f7a552385c Sema: PreparedOverload => PreparedOverloadBuilder 2025-07-10 19:53:18 -04:00
Slava Pestov
751edee921 Sema: Rework PreparedOverload to store a list of changes 2025-07-09 15:00:10 -04:00
Slava Pestov
2a0b11a22e Sema: Collect property wrappers in PreparedOverload 2025-07-09 15:00:03 -04:00
Slava Pestov
c5741e31ed Sema: Stash the existential archetype in PreparedOverload 2025-07-09 15:00:02 -04:00
Slava Pestov
b9256307b5 Sema: Stub out PreparedOverload 2025-07-09 15:00:02 -04:00
Hamish Knight
d6037049b1 [CS] Ensure type variables are eliminated by Solution::simplifyType
`TypeSimplifier` may not eliminate type variables from e.g the
pattern types of pattern expansion types since they can remain
unresolved due to e.g having a placeholder count type. Make sure we
eliminate any remaining type variables along with the placeholders.
There's probably a more principled fix here, but this is a quick and
low risk fix we can hopefully take for 6.2.

rdar://154954995
2025-07-03 16:24:31 +01:00
Slava Pestov
487918f07b Sema: Fix -warn-long-expression-type-checking when expression timer is turned off
My change 983b75e1cf broke
-warn-long-expression-type-checking because now the
ExpressionTimer is not instantiated by default and that
entire code path is skipped.

Change it so that if -warn-long-expression-type-checking
is passed in, we still start the timer, we just don't
ever consider it to have 'expired'.

Fixes rdar://problem/152998878.
2025-06-25 22:07:23 -04:00
Pavel Yaskevich
622475bf15 [ConstraintSystem] Look through ArgumentAttribute element when computing a callee
This element is used purely for diagnostic purposes and locator
should behavior as if it's completely transparent.
2025-06-05 22:30:46 -07:00
Pavel Yaskevich
cda9866b26 [CSGen] Prevent @concurrent on closures from skipping throws inference
Introduction of `@concurrent` attribute caused an unintended
side-effect in `ClosureEffectsRequest` since the attribute
could only be used on `async` types setting `async` too early
prevented body analysis for `throws` from running.

Resolves: rdar://151421590
2025-05-15 17:17:02 -07:00
Alejandro Alonso
e68b398d41 Rename isArrayType and split the InlineArray portion 2025-04-29 15:57:10 -07:00
Anthony
c9b17383c8 Grammatical corrections for compound modifiers 2025-04-24 09:21:32 +02:00
Nate Chandler
347689fb30 [NFC] AST: Extract helper method.
Several callers of `AbstractStorageDecl::getAccessStrategy` only cared
about whether the the access would be via physical storage.  Before
adding more arguments to `getAccessStrategy` for which such callers
would have to pass a sentinel value, add a convenience method for this.
2025-04-15 20:45:37 -07:00
Pavel Yaskevich
07ff063ae3 [AST/ASTGen/Sema/Serialization] Remove @execution attribute
Complete the transition from `@execution` to `@concurrent` and `nonisolated(nonsending)`
2025-04-11 15:59:25 -07:00
Pavel Yaskevich
2704ab7337 [AST/ASTGen] Introduce @concurrent attribute to replace @execution(concurrent) spelling 2025-04-11 12:08:29 -07:00