Frege / frege-repl

Frege REPL
78 stars 17 forks source link

Endless loop/memory allocation when using type aliases #2

Closed talios closed 11 years ago

talios commented 11 years ago

Whilst working on some code samples for a presentation, I found the following code will cause the FregeREPL to dive into an endless loop when trying to call show cust.

type Currency = String
data Customer = Customer { name :: String, currency :: Currency }
derive Show Customer
cust = Customer "Mark" "NZD"

show cust

A sampling of a thread dump is at https://gist.github.com/talios/ec13155910ab52a54ce2 .

Ingo60 commented 11 years ago

The function deepdep that occurs often in the stack trace is local to Utilities.tsort (topological sort). This function is used frequently on classes, type aliases and top level functions to detect mutual recursivity, which is forbidden for superclass relationships and type aliases, e.g. you can't have:

type A = B type B = A

Since the error seems to manifest itself when there are type declarations, I guess it is called in the "check type aliases" pass (TAlias.pass). The same code does work in the compiler, so it would be useful to somehow see what the REPL is doing there. I hope @mmhelloworld can help us here.

mmhelloworld commented 11 years ago

The problem is that the REPL will call show to print the result if the expression is not of type String. The code that returns the type in this case returns the type alias (Currency) which is in fact String but REPL couldn't unify that so it keeps on calling show and ends up in a loop.

I am working on it. The REPL changes for the latest Frege are also done so I will upload a new jar along with this fix in few hours.

Ingo60 commented 11 years ago

The type unaliasing takes only place if you use "nicer", maybe you can use "nice" only and check if it is StringJ Char

mmhelloworld commented 11 years ago

Thanks Ingo. I tried that but It still returns the type alias name.

mmhelloworld commented 11 years ago

My mistake! I explicitly called unAlias. It works now after removing unAlias.

mmhelloworld commented 11 years ago

This issue is fixed and the fix is available in the latest REPL for Frege 3.21.232-g7b05453. The REPL is available in the releases page here.

talios commented 11 years ago

You rock ;-)

On 6/10/2013, at 7:44 PM, Marimuthu Madasamy notifications@github.com wrote:

This issue is fixed and the fix is available in the latest REPL for Frege 3.21.232-g7b05453. The REPL is available in the releases page here.

— Reply to this email directly or view it on GitHub.

mmhelloworld commented 11 years ago

Thanks! :)