ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler
@ 2024-02-12 20:06 kddnewton (Kevin Newton) via ruby-core
  2024-02-12 20:07 ` [ruby-core:116682] " kddnewton (Kevin Newton) via ruby-core
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-12 20:06 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been reported by kddnewton (Kevin Newton).

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116682] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
@ 2024-02-12 20:07 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-13 18:30 ` [ruby-core:116709] " ko1 (Koichi Sasada) via ruby-core
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-12 20:07 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


The PR for this work is here: https://github.com/ruby/ruby/pull/9934.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106695

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116709] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
  2024-02-12 20:07 ` [ruby-core:116682] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-13 18:30 ` ko1 (Koichi Sasada) via ruby-core
  2024-02-13 18:58 ` [ruby-core:116712] " kddnewton (Kevin Newton) via ruby-core
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ko1 (Koichi Sasada) via ruby-core @ 2024-02-13 18:30 UTC (permalink / raw
  To: ruby-core; +Cc: ko1 (Koichi Sasada)

Issue #20260 has been updated by ko1 (Koichi Sasada).


I'm okay to change the internal data structure because we can change them in future.

How to change the user facing interface? Changing only `to_a` format?
For example, errror_highlight needs to know the code which comes from.

Endoh-san propose me to raise an error if `RubyVM::AST.of()` is called for ISeqs from prism.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106725

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116712] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
  2024-02-12 20:07 ` [ruby-core:116682] " kddnewton (Kevin Newton) via ruby-core
  2024-02-13 18:30 ` [ruby-core:116709] " ko1 (Koichi Sasada) via ruby-core
@ 2024-02-13 18:58 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-13 20:13 ` [ruby-core:116720] " kddnewton (Kevin Newton) via ruby-core
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-13 18:58 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


Yes, the user-facing part for iseq is only changing `RubyVM::InstructionSequence.to_a` to include `prism: true/false`.

For error highlight to know, we will either need to change `RubyVM::AST.of` to know that it is coming from prism or we will need to add something to `Thread::Backtrace::Location` like `prism?`.

This code here: https://github.com/ruby/error_highlight/blob/80ede6b8ca3219310f30cff42cd17177a7e47f25/lib/error_highlight/base.rb#L55C7-L59 does:

```ruby
return nil unless Thread::Backtrace::Location === loc

node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)

Spotter.new(node, **opts).spot
```

That would need to be either:

```ruby
return nil unless Thread::Backtrace::Location === loc

if loc.prism?
  node = Prism.node_for(loc)
  PrismSpotter.new(node, **opts).spot
else
  node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
  Spotter.new(node, **opts).spot
end
```

or it would need to be:

```ruby
return nil unless Thread::Backtrace::Location === loc

node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)

if node.is_a?(Prism::Node)
  PrismSpotter.new(node, **opts).spot
else
  Spotter.new(node, **opts).spot
end
```

or maybe some other kind of API change. Either way we would need to access the prism flag that is on the iseq associated with the backtrace location. I'm fine with any kind of API that gets us there.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106728

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116720] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (2 preceding siblings ...)
  2024-02-13 18:58 ` [ruby-core:116712] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-13 20:13 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-13 20:25 ` [ruby-core:116721] " kddnewton (Kevin Newton) via ruby-core
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-13 20:13 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


Sorry to respond again, but in thinking about it, I think `Prism.node_for` might not be right. Maybe it should be `RubyVM::PrismSyntaxTree.of`, or something else under `RubyVM` because it is specific to CRuby.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106737

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116721] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (3 preceding siblings ...)
  2024-02-13 20:13 ` [ruby-core:116720] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-13 20:25 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-14 11:47 ` [ruby-core:116743] " mame (Yusuke Endoh) via ruby-core
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-13 20:25 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


Ahh sorry again, but actually if we introduce `Thread::Backtrace::Location#iseq`, all of this can be done in Ruby, because we could make it:

```ruby
return nil unless Thread::Backtrace::Location === loc

if loc.iseq.to_a[4][:prism]
  # reparse with prism
else
  node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
  Spotter.new(node, **opts).spot
end
```

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106738

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116743] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (4 preceding siblings ...)
  2024-02-13 20:25 ` [ruby-core:116721] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-14 11:47 ` mame (Yusuke Endoh) via ruby-core
  2024-02-14 13:00 ` [ruby-core:116745] " mame (Yusuke Endoh) via ruby-core
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-02-14 11:47 UTC (permalink / raw
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20260 has been updated by mame (Yusuke Endoh).


How about the following API?

* Make `RubyVM::AbstractSyntaxTree.of` raise a RuntimeError for objects with iseq complied from Prism.
* Introduce `Thread::Backtrace::Location#node_id`, which returns node_id at the current instruction, regardless of compiled from parse.y or Prism.

```ruby
begin
  node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
  Spotter.new(node, **opt).spot
rescue RuntimeError
  if $!.message =~ /prism/
    node = Prism.parse(loc.path).node_for(loc.node_id)
    PrismSpotter.new(node, **opt).spot
  else
    raise
  end
end
```

The rationale of this API design is as follows.

In principle, we don't want to introduce a temporal method outside of RubyVM that will be useless in the near future. `Location#prism?` will become useless when Prism becomes Ruby's parser successfully. `Ruby VM::InstructionSequence.complied_by_prism?(loc)` is a possible option. However, we need to make `RubyVM::AbstractSyntaxTree.of` raise an exception for the Prism-derived iseq anyway. If so, you can use it to determine if the iseq is compiled from Prism without having any extra methods.

`Location#iseq` is not good because it returns CRuby's internal data structure. `Location#node_id` is not best too, but it seems acceptable and necessary to tell Prism the node_id.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106762

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116745] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (5 preceding siblings ...)
  2024-02-14 11:47 ` [ruby-core:116743] " mame (Yusuke Endoh) via ruby-core
@ 2024-02-14 13:00 ` mame (Yusuke Endoh) via ruby-core
  2024-02-14 13:38 ` [ruby-core:116749] " kddnewton (Kevin Newton) via ruby-core
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-02-14 13:00 UTC (permalink / raw
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20260 has been updated by mame (Yusuke Endoh).


BTW, I prefer to have `ErrorHighlight::Spotter.new` accept both `RubyVM::AST::Node` and `Prism::Node` instead of adding `ErrorHighlight::PrismSpotter`. (I guess you showed it just for clarity.)

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106764

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116749] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (6 preceding siblings ...)
  2024-02-14 13:00 ` [ruby-core:116745] " mame (Yusuke Endoh) via ruby-core
@ 2024-02-14 13:38 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-14 13:52 ` [ruby-core:116751] " Eregon (Benoit Daloze) via ruby-core
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-14 13:38 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


Okay! That makes sense, thank you for the discussion. I'm also fine making `ErrorHighlight::Spotter` handle both, as you say it was just for illustrative purposes. I'll update this ticket when I have updated `RubyVM::AST.of` and `Thread::Backtrace::Location.node_id` in the PR.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106768

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116751] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (7 preceding siblings ...)
  2024-02-14 13:38 ` [ruby-core:116749] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-14 13:52 ` Eregon (Benoit Daloze) via ruby-core
  2024-02-14 15:59 ` [ruby-core:116756] " kddnewton (Kevin Newton) via ruby-core
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-02-14 13:52 UTC (permalink / raw
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #20260 has been updated by Eregon (Benoit Daloze).


It would be great if `ErrorHighlight` can work on other Ruby implementations too, which means not relying on `RubyVM`.

`Thread::Backtrace::Location#node_id` might not be ideal because other Ruby implementations AFAIK don't keep a `node_id` (for footprint reasons).

TruffleRuby OTOH keeps the byte offset and byte length of each node, so this could be used to identify a given call node.
That also seems similar to the 2nd paragraph in https://github.com/ruby/prism/issues/2401.

I think ErrorHighlight could even use the byte offset + byte length to reparse just that part of the file and find where the `.`/`[`/etc is.
Then the generic implementation-agnostic API could be `Thread::Backtrace::Location#{byte_offset,byte_length}` (or `{first_column,first_lineno,last_column,last_lineno}` but it seems less efficient/convenient).
Or even `Thread::Backtrace::Location#code` which would return a String containing the source code of that call node.

@mame WDYT, would one of these be enough for `ErrorHighlight`? If so it sounds ideal because it avoids needing implementation details like `node_id`, `iseq`, etc.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106770

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116756] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (8 preceding siblings ...)
  2024-02-14 13:52 ` [ruby-core:116751] " Eregon (Benoit Daloze) via ruby-core
@ 2024-02-14 15:59 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-15  2:13 ` [ruby-core:116767] " mame (Yusuke Endoh) via ruby-core
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-14 15:59 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


@mame I've made these changes here: https://github.com/ruby/ruby/pull/9934. Could you review? Thanks!

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106779

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116767] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (9 preceding siblings ...)
  2024-02-14 15:59 ` [ruby-core:116756] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-15  2:13 ` mame (Yusuke Endoh) via ruby-core
  2024-02-15 10:48 ` [ruby-core:116777] " Eregon (Benoit Daloze) via ruby-core
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: mame (Yusuke Endoh) via ruby-core @ 2024-02-15  2:13 UTC (permalink / raw
  To: ruby-core; +Cc: mame (Yusuke Endoh)

Issue #20260 has been updated by mame (Yusuke Endoh).


@eregon I don't think it is a good idea to try to guess a node from a code range. To identify a unique node, the Prism AST would have to avoid creating multiple nodes from the exact same code range. It may be possible to carefully design the AST that way, but I am afraid if it will prevent from future syntax extensions.

Though I don't think node_id is super cool, it will no longer be an implementation detail, assuming the Prism AST. Calculating byte_offset + byte_length from node_id is trivial, and the reverse is not.

By the way, is there any advantage of the representation of byte_offset and byte_length? It is larger in size than (or at best equal to) node_id. To display to the user, we need to convert it to lineno + column. It may be useful to blindly extract the corresponding code fragment from a file, but I think such a use case is rare.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106790

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116777] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (10 preceding siblings ...)
  2024-02-15  2:13 ` [ruby-core:116767] " mame (Yusuke Endoh) via ruby-core
@ 2024-02-15 10:48 ` Eregon (Benoit Daloze) via ruby-core
  2024-02-16 16:26 ` [ruby-core:116798] " kddnewton (Kevin Newton) via ruby-core
  2024-02-21 16:46 ` [ruby-core:116900] " kddnewton (Kevin Newton) via ruby-core
  13 siblings, 0 replies; 15+ messages in thread
From: Eregon (Benoit Daloze) via ruby-core @ 2024-02-15 10:48 UTC (permalink / raw
  To: ruby-core; +Cc: Eregon (Benoit Daloze)

Issue #20260 has been updated by Eregon (Benoit Daloze).


mame (Yusuke Endoh) wrote in #note-11:
> @eregon I don't think it is a good idea to try to guess a node from a code range. To identify a unique node, the Prism AST would have to avoid creating multiple nodes from the exact same code range. It may be possible to carefully design the AST that way, but I am afraid if it will prevent from future syntax extensions.

I think for call nodes it would identify uniquely, but it may not be true for all nodes.

> By the way, is there any advantage of the representation of byte_offset and byte_length? It is larger in size than (or at best equal to) node_id. To display to the user, we need to convert it to lineno + column. It may be useful to blindly extract the corresponding code fragment from a file, but I think such a use case is rare.

It's basically byte_offset and byte_length vs line and node_id.
If all 4 are the same integer size then it's the same in memory footprint, but from byte_offset and byte_length we also have precise column information readily available without parsing again (although that means keeping the source code in memory or rereading the file, could be avoided if a file is only US-ASCII characters then only line offsets is enough), which is nice for tools, debugger, etc.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106802

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116798] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (11 preceding siblings ...)
  2024-02-15 10:48 ` [ruby-core:116777] " Eregon (Benoit Daloze) via ruby-core
@ 2024-02-16 16:26 ` kddnewton (Kevin Newton) via ruby-core
  2024-02-21 16:46 ` [ruby-core:116900] " kddnewton (Kevin Newton) via ruby-core
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-16 16:26 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).


@matz The work is done to add support for the flag on the ISEQ, but I think we additionally need your approval on adding `Thread::Backtrace::Location#node_id`.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106821

* Author: kddnewton (Kevin Newton)
* Status: Open
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [ruby-core:116900] [Ruby master Misc#20260] ISEQ flag for prism compiler
  2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
                   ` (12 preceding siblings ...)
  2024-02-16 16:26 ` [ruby-core:116798] " kddnewton (Kevin Newton) via ruby-core
@ 2024-02-21 16:46 ` kddnewton (Kevin Newton) via ruby-core
  13 siblings, 0 replies; 15+ messages in thread
From: kddnewton (Kevin Newton) via ruby-core @ 2024-02-21 16:46 UTC (permalink / raw
  To: ruby-core; +Cc: kddnewton (Kevin Newton)

Issue #20260 has been updated by kddnewton (Kevin Newton).

Status changed from Open to Closed

@mame remembered that we have `RubyVM::AbstractSyntaxTree.node_id_for_backtrace_location(loc)`, so we don't actually need `Thread::Backtrace::Location#node_id`. In this case we've only implemented the flag for the body.

----------------------------------------
Misc #20260: ISEQ flag for prism compiler
https://bugs.ruby-lang.org/issues/20260#change-106938

* Author: kddnewton (Kevin Newton)
* Status: Closed
* Priority: Normal
----------------------------------------
In order to support error highlight, there's needs to be a way to tell which compiler generated an instruction sequence (compile.c or prism_compile.c). That's because when the file is reparsed to find the node based on the node id, we need to know which parser to use. We can't look at the current parser because it may have been dumped to binary and the parser/compile pair might not match up to the current running process.

I would like to add a flag to `rb_iseq_constant_body` that indicates it came from prism, as well as the `:prism` hash key to the misc hash in the array form of iseqs. This will allow us to determine the source of the iseq from both C and Ruby.

Since this is user-facing (albeit from an experimental library that shouldn't be relied upon) I wanted to make sure this way okay before merging.



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-02-21 16:46 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-12 20:06 [ruby-core:116681] [Ruby master Misc#20260] ISEQ flag for prism compiler kddnewton (Kevin Newton) via ruby-core
2024-02-12 20:07 ` [ruby-core:116682] " kddnewton (Kevin Newton) via ruby-core
2024-02-13 18:30 ` [ruby-core:116709] " ko1 (Koichi Sasada) via ruby-core
2024-02-13 18:58 ` [ruby-core:116712] " kddnewton (Kevin Newton) via ruby-core
2024-02-13 20:13 ` [ruby-core:116720] " kddnewton (Kevin Newton) via ruby-core
2024-02-13 20:25 ` [ruby-core:116721] " kddnewton (Kevin Newton) via ruby-core
2024-02-14 11:47 ` [ruby-core:116743] " mame (Yusuke Endoh) via ruby-core
2024-02-14 13:00 ` [ruby-core:116745] " mame (Yusuke Endoh) via ruby-core
2024-02-14 13:38 ` [ruby-core:116749] " kddnewton (Kevin Newton) via ruby-core
2024-02-14 13:52 ` [ruby-core:116751] " Eregon (Benoit Daloze) via ruby-core
2024-02-14 15:59 ` [ruby-core:116756] " kddnewton (Kevin Newton) via ruby-core
2024-02-15  2:13 ` [ruby-core:116767] " mame (Yusuke Endoh) via ruby-core
2024-02-15 10:48 ` [ruby-core:116777] " Eregon (Benoit Daloze) via ruby-core
2024-02-16 16:26 ` [ruby-core:116798] " kddnewton (Kevin Newton) via ruby-core
2024-02-21 16:46 ` [ruby-core:116900] " kddnewton (Kevin Newton) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).