Skip to content
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

Coerce polyvariant to variant #6981

Merged
merged 6 commits into from
Aug 27, 2024
Merged

Coerce polyvariant to variant #6981

merged 6 commits into from
Aug 27, 2024

Conversation

zth
Copy link
Collaborator

@zth zth commented Aug 26, 2024

This makes it possible to coerce from polyvariant to variant when we can guarantee the runtime representations will match.

  • Checks that the polyvariant is closed.
  • Checks that there's a variant case that would match for each polyvariant label

@zth zth requested a review from cristianoc August 26, 2024 21:54
@@ -3701,6 +3701,14 @@ let rec subtype_rec env trace t1 t2 cstrs =
with Exit ->
(trace, t1, t2, !univar_pairs)::cstrs
end
| (Tvariant {row_closed=true; row_fields}, Tconstr (_, [], _))
when extract_concrete_typedecl_opt env t2 |> Variant_coercion.type_is_variant ->
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if there's a better way to do this. I had to check that it's an actual variant, or the case under would be blocked, which broke a coercion test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@cristianoc anything else we should check for here? Private?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Private does not change the internal representation, so I would not bother.

Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

Looks good so far

@zth zth force-pushed the coerce-polyvariant-to-variant branch from e1ddefd to 40a31f1 Compare August 27, 2024 07:59
@zth zth force-pushed the coerce-polyvariant-to-variant branch from 40a31f1 to 0eb44ef Compare August 27, 2024 08:30
@zth zth requested a review from cristianoc August 27, 2024 08:33
@zth
Copy link
Collaborator Author

zth commented Aug 27, 2024

@cristianoc ready for review.

@@ -3701,6 +3701,14 @@ let rec subtype_rec env trace t1 t2 cstrs =
with Exit ->
(trace, t1, t2, !univar_pairs)::cstrs
end
| (Tvariant {row_closed=true; row_fields}, Tconstr (_, [], _))
when extract_concrete_typedecl_opt env t2 |> Variant_coercion.type_is_variant ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Private does not change the internal representation, so I would not bother.

@zth zth merged commit c8ed227 into master Aug 27, 2024
20 checks passed
@zth zth deleted the coerce-polyvariant-to-variant branch August 27, 2024 08:50
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.

2 participants