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

Allow free vars in types for coercion. #6828

Merged
merged 6 commits into from
Jul 3, 2024
Merged

Conversation

cristianoc
Copy link
Collaborator

See #6821

Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time.

There's probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt.

This just marks the place where one could investigate.

cristianoc added a commit that referenced this pull request Jun 25, 2024
There are two forms of type coercion:
1 `e: t0 :> t`
2 `e :> t`

The first form was never supported in .res syntax, and is now removed from parsed and typed tree.

That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation.

See #6828
@zth
Copy link
Collaborator

zth commented Jun 25, 2024

So, this enables you to use free variables when coercing...? I guess I don't fully understand the change.

@cristianoc
Copy link
Collaborator Author

So, this enables you to use free variables when coercing...? I guess I don't fully understand the change.

This just disables the check for free variables.
The consequences are not clear: it could introduce some issues.
This is old code without explanation.

@zth
Copy link
Collaborator

zth commented Jun 26, 2024

I wonder what types of issues it could cause..

@cristianoc
Copy link
Collaborator Author

Tried to run all tests in the ocaml repo, and they work after this change.

Here's a bunch of new things that type check:

module NoFreeVars = {
  type t = private int

  let f = (x: t) => (x :> int)

  let g = (y: t) => ()

  let h = x => (g(x), (x :> int))

  let h2 = x => ((x :> int), g(x))
}

module WithTypeArg = {
  type t<'a> = private int

  let f = (x: t<_>) => (x :> int)
}

module FunctionType = {
  type t = private int
  let f = _ => (Obj.magic(3) : t)
  let _ = f :> (_ => int)
}

module Contravariant = {
  type t = private int
  let f1 = (_:int) => ()
  let _ = f1 :> (t => unit)
  let f2 = (_:int, _) => ()
  let _ = f2 :> ((t, _) => unit)
}

module Totallypoly = {
  let f = x => (x :> int)
  let idint = (x:int) => x
  let _ = f == idint
}

@cristianoc cristianoc force-pushed the coercion_free_vars branch from 915cf36 to 16ae754 Compare July 2, 2024 09:11
cristianoc added a commit that referenced this pull request Jul 2, 2024
There are two forms of type coercion:
1 `e: t0 :> t`
2 `e :> t`

The first form was never supported in .res syntax, and is now removed from parsed and typed tree.

That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation.

See #6828
cristianoc added a commit that referenced this pull request Jul 2, 2024
…6829)

* Remove coercion with 2 types, which is only supported in ml syntax.

There are two forms of type coercion:
1 `e: t0 :> t`
2 `e :> t`

The first form was never supported in .res syntax, and is now removed from parsed and typed tree.

That said, coercion 1 is the only one that ever supported coercion with free variables. So this is subject to more investigation.

See #6828

* Cleanup and indent.

* Make Texp_coerce compatible with old runtime representation.

By adding a unit argument to the payload.
See #6821

Free variables are not allowed in coercion, and if that happens, simple unification is performed without ever attempting coercion. This seems to go back a very long time.

There's  probably a good reason why free vars were not allowed. At the same time, there are no objects/classes supported in the language anymore, so it's not clear how those reasons would adapt.

This just marks the place where one could investigate.
@cristianoc cristianoc force-pushed the coercion_free_vars branch from 3312be7 to 7a4b87f Compare July 2, 2024 09:31
@cristianoc cristianoc requested a review from zth July 2, 2024 20:07
@cristianoc cristianoc changed the title Test: allow free vars in types for coercion. Allow free vars in types for coercion. Jul 3, 2024
@cristianoc cristianoc merged commit 938db06 into master Jul 3, 2024
19 checks passed
@cristianoc cristianoc deleted the coercion_free_vars branch July 3, 2024 06:43
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