Skip to content

Fix double execution in JSR223 Implementation #7010

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

Merged
merged 1 commit into from
Dec 8, 2019
Merged

Conversation

rjolly
Copy link
Contributor

@rjolly rjolly commented Aug 7, 2019

The reason for this change is that currently, statements in the
JSR223 script engine are evaluated twice. Once when the "run" method
is called, and once when the value of the result is extracted.
The first one needs not be, it exists solely due to displayDefinitions
being called. If we put it behind a flag, the problem is solved.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@smarter
Copy link
Member

smarter commented Aug 8, 2019

I'm confused, what's the method that gets called twice exactly, and by whom ? Why is there a difference between scripting and non-scripting ?

@rjolly
Copy link
Contributor Author

rjolly commented Aug 8, 2019

See in https://github.com/rjolly/dotty/blob/master/compiler/src/dotty/tools/repl/ScriptEngine.scala . In the eval method, first the method "run" is called, which at the end calls DisplayDefinitions which does a reflective method invocation (on something like rs$line$1.res0). Then, still in eval, I do a second reflective method invocation (and this is specific to the script engine) to extract the value, which is returned by the eval method.

@rjolly
Copy link
Contributor Author

rjolly commented Aug 14, 2019

How to reproduce:

user@debian:~/dotty-0.17.0-RC1/lib$ jrunscript -J-Djava.class.path=dotty-compiler_0.17-0.17.0-RC1.jar:dotty-doc_0.17-0.17.0-RC1.jar:dotty-interfaces-0.17.0-RC1.jar:dotty-library_0.17-0.17.0-RC1.jar:scala-library-2.12.8.jar:scala-asm-6.0.0-scala-1.jar -l scala
scala> def fn = println("hello world")
def fn: Unit

scala> fn
hello world

hello world
()
scala>

The reason for this change is that currently, statements in the
JSR223 script engine are evaluated twice. Once when the "run" method
is called, and once when the value of the result is extracted.
The first one needs not be, it exists solely due to displayDefinitions
being called. If we put it behind a flag, the problem is solved.
@rjolly rjolly changed the title Introduce option not to display definitions in repl driver Fix double execution in JSR223 Implementation Nov 18, 2019
@rjolly
Copy link
Contributor Author

rjolly commented Nov 18, 2019

@smarter Is there something I can do to help this PR going forward ?

@smarter
Copy link
Member

smarter commented Nov 18, 2019

Very sorry about the delay, I'll try to review this properly this week!

@rjolly
Copy link
Contributor Author

rjolly commented Dec 2, 2019

Is it alright to add a command line argument "repl-disable-display" ? The alternative is a constructor argument to ReplDriver, which is not perfect either.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Finally had time to look at this :). I think this is fine as is since it doesn't affect the code too much, but maybe in the future we could instead refactor ReplDriver slightly so you could override the method that run and print the definitions?

@rjolly
Copy link
Contributor Author

rjolly commented Dec 7, 2019

Thanks ! Yes, override would be fine, but indeed it requires some refactoring. I'll think about it.

@smarter smarter merged commit 122d759 into scala:master Dec 8, 2019
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 this pull request may close these issues.

3 participants