Commit Graph

2632 Commits

Author SHA1 Message Date
Slava Pestov
8ee4eeee55 Sema: Migrate SavedTypeVariableBindings to SolverTrail 2024-09-26 23:15:27 -04:00
Egor Zhdan
c126bab3ae Merge pull request #74185 from swiftlang/egorzhdan/frt-test-nonobjc
[cxx-interop] C++ reference types are not `AnyObject`s
2024-09-26 12:54:45 +01:00
Egor Zhdan
82c076c9d3 [cxx-interop] C++ reference types are not AnyObjects
C++ foreign reference types have custom reference counting mechanisms, so they cannot conform to `AnyObject`.

Currently Swift's type system treats C++ FRTs as `AnyObject`s on non-Darwin platforms, which is incorrect. This change makes sure the behavior is consistent with Darwin platform, i.e. a cast of C++ FRT to `AnyObject` is rejected by the typechecker.

rdar://136664617
2024-09-25 15:15:11 +01:00
Slava Pestov
fca570ca91 Sema: Don't use ExistentialLayout for DeepEquality matching 2024-09-24 19:12:44 -04:00
Pavel Yaskevich
0276a33de5 [CSSimplify] Forego any contextual score increases while checking erased member type
`resolveOverload` introduces a conversion if there were any adjustments
to a member type on existential base. This conversion exists only to
check adjustments in the member type, so the fact that adjustments also
cause a function conversion is unrelated.

Resolves: rdar://135974645
2024-09-13 16:30:09 -07:00
Pavel Yaskevich
b1d9ae01ed [CSSimplify] Delay inout type to pointer conversion until inout is sufficiently resolved
If left-hand side of any conversion constraint is `inout` type
and right is a pointer (or optional thereof), delay simplification
until `inout` is at least partially structurally resolved (cannot
be a type variable or dependent member) because eager simplification
won't record all of the possible conversions.
2024-09-12 13:46:02 -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
7e71641707 Merge pull request #76397 from xedin/rdar-135610320
[CSSimplify] Specialization: Fix a crash when specialized declaration…
2024-09-11 09:30:22 -07:00
Pavel Yaskevich
efd43b0f7d [CSSimplify] Specialization: Fix a crash when specialized declaration is not generic
Check whether there are any opened generic parameters associated
with a declaration and if not, produce a fix which would be later
diagnosed as either a warning (in Swift 5 mode) or an error (if it
was a concrete type or the compiler is in Swift 6 language mode).

Resolves: rdar://135610320
2024-09-10 21:06:59 -07:00
Pavel Yaskevich
564155e74d Merge pull request #76377 from xedin/dont-discriminate-against-any-and-anyobject
[CSSimplify] Don't increase impact if member doesn't exist on Any/Any…
2024-09-10 17:41:41 -07:00
Pavel Yaskevich
97f284aa76 [CSSimplify] Don't increase impact if member doesn't exist on Any/AnyObject
`Any` used to be the type used to indicate placeholders before
and that's reflected in the score of the `DefineMemberBasedOnUse`,
this is no longer the same and the impact increase should be dropped.
2024-09-10 10:38:32 -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
Pavel Yaskevich
55b8d9538d [CSSimplify] Rework how/when mismatches between optional types are fixed
- Don't attempt to insert fixes if there are restrictions present, they'd inform the failures.

  Inserting fixes too early doesn't help the solver because restriction matching logic would
  record the same fixes.

- Adjust impact of the fixes.

  Optional conversions shouldn't impact the score in any way because
  they are not the source of the issue.

- Look through one level of optional when failure is related to optional injection.

  The diagnostic is going to be about underlying type, so there is no reason to print
  optional on right-hand side.
2024-09-10 10:35:05 -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
Allan Shortlidge
c868378d96 ConstraintSystem: Use scoring to implement MemberImportVisibility.
Previously, the constraint solver would first attempt member lookup that
excluded members from transitively imported modules. If there were no viable
candidates, it would perform a second lookup that included the previously
excluded members, treating any candidates as unviable. This meant that if the
member reference did resolve to one of the unviable candidates the resulting
AST would be broken, which could cause unwanted knock-on diagnostics.

Now, members from transitively imported modules are always returned in the set
of viable candidates. However, scoring will always prioritize candidates from
directly imported modules over members from transitive imports. This solves the
ambiguities that `MemberImportVisibility` is designed to prevent. If the only
viable candidates are from transitively imported modules, though, then the
reference will be resolved successfully and diagnosed later in
`MiscDiagnostics.cpp`. The resulting AST will not contain any errors, which
ensures that necessary access levels can be computed correctly for the imports
suggested by `MemberImportVisibility` fix-its.

Resolves rdar://126637855.
2024-09-10 09:47:42 -07:00
Alejandro Alonso
45d7ea39a5 Merge pull request #75518 from Azoy/integer-generics
Implement Value generics
2024-09-05 15:33:46 -07:00
Pavel Yaskevich
c069e6a84a Merge pull request #76268 from xedin/rdar-134504519
[TypeChecker] Warn if witness mismatches only on sendability until Sw…
2024-09-05 13:37:43 -07:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Alejandro Alonso
0df42e9841 Lower UDRE to TypeValue if it references a value generic 2024-09-04 15:13:29 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Pavel Yaskevich
6c1fc03c87 [TypeChecker] Limit sendability downgrade to preconcurrency requirements only 2024-09-04 14:54:41 -07:00
Pavel Yaskevich
9a3d1b7eb4 [TypeChecker] Warn if witness mismatches only on sendability until Swift 6 mode
This expands the downgrade for Objective-C requirements to all requirements
until strict concurrency checking is enabled (either via a flag in Swift 5
language mode or by switching to Swift 6 language mode).

Resolves: rdar://134503878
2024-09-04 14:38:06 -07:00
Slava Pestov
851a829063 Sema: Consolidate logic for opening existentials in OpenedExistentials.cpp 2024-09-04 14:57:38 -04:00
Pavel Yaskevich
f9e08bc6ec Merge pull request #76174 from xedin/remodel-constraint-generation-for-assignment
[ConstraintSystem] Introduce `LValueObject` constraint to replace direct l-value assignments
2024-09-04 09:27:59 -07:00
Slava Pestov
ba585fd6c0 Merge pull request #76206 from slavapestov/existential-signature-rework-part-1
AST: Add new implementation of getOpenedExistentialSignature()
2024-09-03 10:05:29 -04:00
Slava Pestov
39d77b81b3 Sema: Rework shouldOpenExistentialCallArgument() 2024-09-02 21:42:04 -04:00
Slava Pestov
2ebef08f7e AST: Generalize findGenericParameterReferences() 2024-09-02 21:42:04 -04:00
Slava Pestov
56cefdc83f AST: Clean up findGenericParameterReferences() 2024-09-02 16:12:31 -04:00
Pavel Yaskevich
bd313deae5 Merge pull request #76136 from xedin/rdar-131321053
[ConstraintSystem] InferSendableFromCaptures: Mark unapplied operator references as `@Sendable`
2024-09-02 08:29:56 -07:00
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