Skip to content

Sema: Respect TVO_CanBindToPack #61777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

slavapestov
Copy link
Contributor

No description provided.

// can't merge these two type variables.
if (rep1->getImpl().canBindToPack()
!= rep2->getImpl().canBindToPack())
return getTypeMatchFailure(locator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of failing should this just from an unsolved constraint and wait until one of type variables is resolved so it could be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TVO_CanBindToPack should never change. It's set when the type variable is created in CSGen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable but we cannot diagnose here and at the same time cannot fail right away either I think, we need to waiting into more is know about one of the types or it's marked as a placeholder...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we can't unconditionally fail. When Pavel says "so it could be fixed", I think he means that this constraint needs to ultimately return SolutionKind::Solved in diagnostic mode with some kind of fix recorded. The solver should never fail solving a constraint in diagnostic mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should never fail solving a constraint in diagnostic mode

Shouldn't fail unless it leads to a worse solution i.e. if the impact of the fix is greater than previous solutions that have been discovered.

@@ -4307,6 +4307,14 @@ ConstraintSystem::matchTypesBindTypeVar(
}
}

if (type->is<PackType>() || type->is<PackArchetypeType>()) {
if (!typeVar->getImpl().canBindToPack())
return getTypeMatchFailure(locator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a bi-directional fix here similar to fixReferenceMismatch otherwise constraint solver is just going to fail with "failed to produce a diagnostic" because it wouldn't be able to form a valid solution due to this binding always failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let @hborla handle this one :) I was just rebasing this PR so that she could finish it off.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm going to pick this up and address the feedback about diagnostics!

@hborla
Copy link
Member

hborla commented Mar 21, 2023

Subsumed by #64498

@hborla hborla closed this Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants