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

experiment: partial fix for for subtyping loop due to polymorphic recursion #4796

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

crusso
Copy link
Contributor

@crusso crusso commented Dec 4, 2024

This is a known issue, but capturing the one @rvanasa found in the wild (that might get in the way of fancy class based libraries)

module {

  public class Iter<T>({next = n : () -> ?T}) = this {

    public let next = n;

    public func map<R>(f : T -> R) : Iter<R> { // NOTE polymorphic recursion on <R> (not <T>)
       loop {}
    };
  }

}
[nix-shell:~/motoko/test/fail]$ moc polyrec.mo 
OOPS! You've triggered a compiler bug.
Please report this at https://github.com/dfinity/motoko/issues/new with the following details:

Motoko (source 0.13.4-30-gcedc663ea-dirty)

Fatal error: exception Stack overflow
Raised by primitive operation at Mo_types__Type.rel_typ in file "mo_types/type.ml", line 980, characters 4-11
Called from Stdlib__list.for_all2 in file "list.ml", line 173, characters 24-31
Called from Mo_types__Type.rel_list in file "mo_types/type.ml", line 911, characters 6-38
Called from Mo_types__Type.rel_typ in file "mo_types/type.ml", line 983, characters 6-81
Called from Mo_types__Type.rel_fields in file "mo_types/type.ml", line 1004, characters 6-36
Called from Stdlib__list.for_all2 in file "list.ml", line 173, characters 24-31
Called from Mo_types__Type.rel_list in file "mo_types/type.ml", line 911, characters 6-38
Called from Mo_types__Type.rel_fields in file "mo_types/type.ml", line 1004, characters 6-36
Called from Stdlib__list.for_all2 in file "list.ml", line 173, characters 24-31
Called from Mo_types__Type.rel_list in file "mo_types/type.ml", line 911, characters 6-38
Called from Mo_types__Type.rel_fields in file "mo_types/type.ml", line 1004, characters 6-36
Called from Stdlib__list.for_all2 in file "list.ml", line 173, characters 24-31
Called from Mo_types__Type.rel_list in file "mo_types/type.ml", line 911, characters 6-38
Called from Mo_types__Type.rel_fields in file "mo_types/type.ml", line 1004, characters 6-36
Called from Stdlib__list.for_all2 in file "list.ml", line 173, characters 24-31
Called from Mo_types__Type.rel_list in file "mo_types/type.ml", line 911, characters 6-38
Called from Mo_types__Type.rel_fields in file "mo_types/type.ml", line 1004, characters 6-36
Called from Stdlib__list.for_all2 in file "list.ml", line 173, characters 24-31
Called from Mo_types__Type.rel_list in file "mo_types/type.ml", line 911, characters 6-38

@crusso crusso changed the title repro for subtyping loop due to polymorhic recursion bug: repro for subtyping loop due to polymorhic recursion Dec 4, 2024
test/fail/polyrec.mo Outdated Show resolved Hide resolved
@ggreif ggreif changed the title bug: repro for subtyping loop due to polymorhic recursion bug: repro for subtyping loop due to polymorphic recursion Dec 4, 2024
OOPS! You've triggered a compiler bug.
Please report this at https://github.com/dfinity/motoko/issues/new with the following details:

Motoko (source 0.13.4-30-gcedc663ea-dirty)
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be normalised, I guess

test/fail/polyrec.mo Outdated Show resolved Hide resolved
Co-authored-by: Gabor Greif <[email protected]>
@crusso crusso marked this pull request as draft December 4, 2024 11:29
…ions of the same constructor as related by subtyping
@crusso crusso changed the title bug: repro for subtyping loop due to polymorphic recursion experiment: partial fix for for subtyping loop due to polymorphic recursion Dec 4, 2024
@crusso
Copy link
Contributor Author

crusso commented Dec 5, 2024

Ok, added counterexample polyrec1.mo that shows why this isn't a good idea. Isomorphic types will still lead to non-termination.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants