crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.35k stars 1.62k forks source link

Metaissue: Improve the interpreter #11555

Open straight-shoota opened 2 years ago

straight-shoota commented 2 years ago

What's missing for the interpreter:

Feel free to post comments for additional items here.

No discussion on individual items. Thank you πŸ™‡β€β™‚οΈ

That should be moved to dedicated issues. If none exists, please open one or start an informal discussion at https://forum.crystal-lang.org/

asterite commented 2 years ago

I think pry doesn't work well in many cases. For example, block arguments are not visible. In general, I feel that pry has still a long way to go

asterite commented 2 years ago

After https://github.com/crystal-lang/crystal/pull/11578 is merged, the first thing I would do is to write at least one spec for debugger and pry. There's a lot to fix and improve there, and without tests it's going to be tough.

My idea was to have tests specify three things:

For example:

assert_interpreter_debugger(
  code: "a = 1; debugger; a",
  input: "a",
  expected_output: "1",
)

That is, after debugger is reached, the user types "a" on the console, and they expect to get "1" as the output.

This will require adapting the interpreter so that the input and output are not tied to STDIN and STDERR, which might also eventually make it possible to hook the interpreter into code editors.

These tests will also be independent of the underlying implementation, so they will be extremely useful and resilient to changes.

With those tests in place, I could start working on some of them to fix existing bugs, like https://github.com/crystal-lang/crystal/issues/11555#issuecomment-989295051

beta-ziliani commented 2 years ago

@asterite just to clarify, each of the lines stating BUG: missing handling... is a TODO waiting to be completed, right? (Just stumble across one of this).

asterite commented 2 years ago

That's it! Maybe I should have put a TODO there πŸ˜…

watzon commented 2 years ago

I assume the issue that happens when attempting to require "openssl" or anything that relies on openssl is included in one of these subtasks? The issue seems to be different based on whether you require openssl in the repl or in a file the interpreter is running, but both break.

If other people aren't having this problem for some reason I'll gladly make a new issue.

HertzDevil commented 2 years ago

That is, after debugger is reached, the user types "a" on the console, and they expect to get "1" as the output.

12119 does this for LLDB. We could probably use FileCheck here or even share the same test source files for multiple CLI debuggers (another one I have in my mind is GDB).

mwgkgk commented 2 years ago

https://github.com/Ivo-Balbaert/programming_crystal/blob/master/exercises/crystal_new/fibers.cr

Something really slow about channels. crystal i <filename> this thing grinds my computer to a halt i barely Ctrl-c'd at 1507 out of 10000 iterations. crystal r <filename> completes smoothly in a blink of an eye. Linux x86-64

# START:p1
chan = Channel(String).new
i = 0
num = 10000
num.times do
  spawn do
    chan.send "fiber #{i}: I like crystals!"
  end
  i += 1
  puts chan.receive
end
# =>
# fiber 1: I like crystals!
# fiber 2: I like crystals!
# fiber 3: I like crystals!
# fiber 4: I like crystals!
# ...
# fiber 10000: I like crystals!
# END:p1
mdwagner commented 2 years ago

Can confirm similar results on MacOS (Intel) with Crystal 1.5.0

asterite commented 2 years ago

Yes, the interpreter is slower than compiled mode. And I have no immediate plans to improve its speed.