uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Circular cross-references between WKOs fail in runtime #868

Closed lspigariol closed 8 years ago

lspigariol commented 8 years ago

fails in run time, but editor dont warnings is posible make it run?

object juan {
    var mascota = firulais
}

object firulais {
    var duenio = juan
}
npasserini commented 8 years ago

Could you send more information about the error raised? I guess that the problem is the order of object creation... I think it can be solved.

On Sat, Jul 30, 2016 at 8:19 PM, lspigariol notifications@github.com wrote:

fails in run time, but editor dont warnings is posible make it run?

object juan { var mascota = firulais }

object firulais { var duenio = juan }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/uqbar-project/wollok/issues/868, or mute the thread https://github.com/notifications/unsubscribe-auth/AEa1OZ6q2A320pN76S4jS0zXxAnSugVTks5qa5W0gaJpZM4JY3OQ .

lspigariol commented 8 years ago

fail only if the cross references is defined like example, by assignation in the initialization dont fail if the same cross references is generated later, using messages

javierfernandes commented 8 years ago

This is the failing program

object juan {
            var mascota = firulais
        }

        object firulais {
            var duenio = juan
        }
        program a {
            console.println(juan)
        }

And this is the error.

At least the one that I could reproduce. Evaluating only the objects doesn't produce any error.

java.lang.StackOverflowError
    at java.util.ArrayList.addAll(ArrayList.java:603)
    at org.eclipse.xtend2.lib.StringConcatenation.appendSegments(StringConcatenation.java:290)
    at org.eclipse.xtend2.lib.StringConcatenation.appendSegments(StringConcatenation.java:262)
    at org.eclipse.xtend2.lib.StringConcatenation.append(StringConcatenation.java:134)
    at org.eclipse.xtend2.lib.StringConcatenation.append(StringConcatenation.java:108)
    at org.uqbar.project.wollok.interpreter.WollokInterpreter.resolve(WollokInterpreter.java:280)
    at org.uqbar.project.wollok.interpreter.core.WollokNativeLobby.resolve(WollokNativeLobby.java:65)
    at org.uqbar.project.wollok.interpreter.core.WollokNativeLobby.resolve(WollokNativeLobby.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:252)
    at org.uqbar.project.wollok.interpreter.core.WollokObject.resolve(WollokObject.java:1)
(many many etc)
javierfernandes commented 8 years ago

Where you doing that ? @lspigariol where you printing them ?

Can you please share the exact program that was failing ? Or was it evaluating then in the REPL like

> juan

(that would be the same because it prints them)

javierfernandes commented 8 years ago

This makes me thinks that we need to control stack overflow at intepreter level and rise a "wollok" wollok.lang.StackOverFlow exception. Because we cannot avoid 100% infinite recursion in students code. This will happen eventually. And we need to fail better

lspigariol commented 8 years ago

the code is

object juan {
            var mascota = firulais
        }

        object firulais {
            var duenio = juan
        }

in the REPL

>>> juan
ERROR [main] (WollokChecker.java:89) - 

the infinity recursion problem is at initialization of both objects

the following program work correctly

object juan {
    var mascota

    method mascota(_mascota) {
        mascota = _mascota mascota.duenio(self)
    }
}

object firulais {
    var duenio

    method duenio(_duenio) { duenio = _duenio }

}

in the REPL

>>> juan.mascota(firulais)
>>> juan
juan[mascota=firulais[duenio=juan]]
javierfernandes commented 8 years ago

Fixed in a branch without introducing the stack overflow control. WKO's are now registered before as the first step and then initialized. If an error occurr while initializing they are removed from the scope.

This is of course not thread safe. But enough for the moment.

Eventually it will be hard to make Wollok interpreter multithreading

javierfernandes commented 8 years ago

Waiting to be merged.