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

Segmentation fault: 11 when trying to define a method which returns a new “instance” of a class #3057

Closed
paulyoung opened this issue Jan 12, 2022 · 10 comments · Fixed by #4798

Comments

@paulyoung
Copy link
Contributor

paulyoung commented Jan 12, 2022

I’m sure I brought this up before but I ran into it again and couldn’t find anything about it.

Here’s a fairly minimal example that reproduces the issue when run with --check:

module {
  public class Id<A>(x : A) {
    public func map<B>(f : A -> B) : Id<B> {
      Id(f(x));
    };
  };
};
@ggreif
Copy link
Contributor

ggreif commented Jan 12, 2022

Heh, if the good old identity functor fails, then all bets are off! ;-)

ggreif added a commit that referenced this issue Jan 12, 2022
@ggreif
Copy link
Contributor

ggreif commented Jan 12, 2022

I bet this is a mutual recursion problem. I have seen OCaml segfaulting when exhausting the stack several times.

@crusso
Copy link
Contributor

crusso commented Jan 12, 2022

Interesting...

@paulyoung
Copy link
Contributor Author

If anyone has any suggestions on how to tackle this I can try to take a look.

@ggreif
Copy link
Contributor

ggreif commented Jan 19, 2022

@paulyoung is this a curiosity problem ("let's code up some Haskell idioms in Motoko") or appearing in your production code?

@ggreif
Copy link
Contributor

ggreif commented Jan 19, 2022

@nomeata you have squashed "not lazy enough reference" bugs in the past. Maybe this rings a bell?

@nomeata
Copy link
Collaborator

nomeata commented Jan 19, 2022

Not in the typechecker… :-)

@paulyoung
Copy link
Contributor Author

is this a curiosity problem ("let's code up some Haskell idioms in Motoko") or appearing in your production code?

@ggreif I’m trying to do the former to see if there’s something interesting to write about and perhaps promote Motoko, but bugs like this are preventing me from reaching the latter.

mergify bot pushed a commit that referenced this issue Feb 15, 2022
Reproduces the infinite recursion.

Also speeds up the normalisation by passing various `-e` to `sed`.
@crusso
Copy link
Contributor

crusso commented Mar 3, 2022

I think this type should actually be rejected as expansive since it involves polymorphic recursion.

c.f.

module {
 /*
  public class Id<A>(x : A) {
    public func map<B>(f : A -> B) : Id<B> = Id(f x)
  }
  */

 type Id<A> = object { map : <B>(A->B) -> Id<B> }; // note polymorphic recursion
}

Hacky branch investigating the bug with sad attempts to alter the expansiveness check here are in branch
#3134

@ggreif
Copy link
Contributor

ggreif commented Mar 3, 2022

I think this type should actually be rejected as expansive since it involves polymorphic recursion.

By which definition of polymorphic recursion? It would be polymorphic recursion when the type variable (A or B) were wrapped (nested) in a different type constructor, like Id<?B> or Id<(B, A)>. But Id<> applied to a tyvar isn't polymorphic recursion.

EDIT: Maybe you are right, after re-reading the wikipedia article — "where the type parameter changes with each recursive invocation" I can see that data Foo a b = Bar (Foo b a) in Haskell would also fall under polymorphic recursion. The question now is whether we can disregard the map method in some way to make the definition valid...

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 a pull request may close this issue.

4 participants