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

Potential infinite loop in type checking #190

Closed
Meowcolm024 opened this issue Nov 10, 2023 · 3 comments
Closed

Potential infinite loop in type checking #190

Meowcolm024 opened this issue Nov 10, 2023 · 3 comments

Comments

@Meowcolm024
Copy link
Collaborator

In cb89a08

:NewDefs
:GADTs

abstract class Foo[type T]: Bar | Baz
class Bar extends Foo[Int]
class Baz[T](val x: Foo[T]) extends Foo[[T]]

fun foo[T](f: Foo[T]): Int = if f is
    Bar then 0
    Baz(x) then foo(x : Foo[x.T])
//│ ╔══[ERROR] Subtyping constraint of the form `([?a]) -> ?b <: ?c -> ?d` exceeded recursion depth limit (250)
//│ ║  l.14: 	fun foo[T](f: Foo[T]): Int = if f is
//│ ║        	                                ^^^^
//│ ║  l.15: 	    Bar then 0
//│ ║        	^^^^^^^^^^^^^^
//│ ║  l.16: 	    Baz(x) then foo(x : Foo[x.T])
//│ ║        	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//│ ╙── Note: use flag `:ex` to see internal error info.
// (some more errors)
@Meowcolm024
Copy link
Collaborator Author

Update: an even smaller example:

class Box[type A](val get: A)
abstract class F[type A]: MkF
class MkF[T](t: T) extends F[Box[T]]

fun f[T](x: F[T]): T = if x is MkF(t) then Box(t) as x.A
//│ ╔══[ERROR] Subtyping constraint of the form `?a <: ?b` exceeded recursion depth limit (250)
//│ ╙── Note: use flag `:ex` to see internal error info.
//│ fun f: forall 'T. (x: F['T]) -> 'T

@LPTK
Copy link
Contributor

LPTK commented Jan 15, 2024

So as we've discussed before, this seems to be happening during reconstraining after type extrusion. Recornstraining is basically a hacky plug on top of extrusion to detect type mismatches introduced by approximated skolems (in the context of first-class polymorphism).

The solution is not a low-hanging fruit. We need to rearchitect extrusion so it's done in a more principled way, accumulating all level-mismatched bounds first and extruding them all together, only reconstraining what's actually neede.

@LPTK
Copy link
Contributor

LPTK commented Feb 2, 2024

Ok so it turns out the issue was not what I thought it was. There was a bug in extrusion, fixed in 55ae363.

@LPTK LPTK closed this as completed Feb 2, 2024
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

No branches or pull requests

2 participants