Skip to content
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

Exclusion of location fields in serialize for execution #807

Closed
enebo opened this issue Apr 11, 2023 · 8 comments · Fixed by #1450
Closed

Exclusion of location fields in serialize for execution #807

enebo opened this issue Apr 11, 2023 · 8 comments · Fixed by #1450
Assignees
Labels
enhancement New feature or request

Comments

@enebo
Copy link
Collaborator

enebo commented Apr 11, 2023

Execution does not need all info contained in Nodes defined in config.yml. In particular, they do not need any Tokens or Location fields. We should allow templates for serialization and loading to not include those in the blob or in the generated AST.

Towards this goal issues will get opened we encounter places where we DO currently need tokens (e.g. CallNode.call_operator (. vs &.) or RegularExpressionNode.closing (/ix).

@eregon
Copy link
Member

eregon commented Apr 11, 2023

Towards this goal issues will get opened we encounter places where we DO currently need tokens

For those I suggest we annotate them with serialize: true or keep_in_serialization: true or so in config.yml, until that info is available through other fields.

@enebo
Copy link
Collaborator Author

enebo commented Apr 11, 2023

Here is an interesting case where I am not sure how this should be structured if you remove the token:

  - name: BlockParameterNode
    child_nodes:
      - name: name
        type: token?
      - name: operator_loc
        type: location
        java_exclude: true
    comment: |
      Represents a block parameter to a method, block, or lambda definition.

          def a(&b)
                ^^
          end

If the token is removed then it will be pointing at '&b' and not 'b'. I think the solution would be to assume first char is '&'? Today I use the name token.

@enebo
Copy link
Collaborator Author

enebo commented Apr 11, 2023

@jemmaissroff Is this layout/strategy ok? I open up individual issues where excluding the token would lead to loss of information and mention this issue in the description? I am willing to audit all in config.yml but don't want know if this is how it should be done.

@eregon
Copy link
Member

eregon commented Apr 12, 2023

For BlockParameterNode it seems best to keep the token for serialization for now (to get the identifier name).
Notably there can be spacing around there and it's still valid Ruby: ruby -e 'def m( & a ); a; end; p m {}'.
But we wouldn't want a space in the variable name (would break for references to a in the method).

Such identifiers should most likely use the constant pool long term, and then they're pretty short in serialized form + avoids rereading the same identifier multiple times (and to convert from byte[] to java.lang.String or so).

So I'd say use serialize: true for that token until we have another way.

@enebo
Copy link
Collaborator Author

enebo commented Apr 12, 2023

@eregon I am going with the assumption the goal is to replace anything which is token and is needed to what we want to read. You are correct we can add a temporary serialize: true but I am asking how should we do it. If you were to read this node from TR how would you want to see this node?

@eregon
Copy link
Member

eregon commented Apr 12, 2023

Yeah, agreed. I think an interned identifier in the constant pool is the way to go here (but we don't have a constant pool yet in YARP).

@kddnewton kddnewton self-assigned this Jun 5, 2023
@kddnewton
Copy link
Collaborator

I'm going to close this once #997 is merged. At that point all tokens are off the tree and only locations remain.

I think going forward we can operate as if there is a future where all location fields on nodes are removed from the serialization. In that case if there is anything that y'all need for compilation that isn't serviced by just the name of the node and its fields that aren't locations, we should add flags.

The only one I know of at the moment is the range node where we need to indicate exclusivity. Other than that I think we have all the information we need? We certainly will find out pretty soon once we integrate into CRuby and start our own compilation work.

@eregon eregon changed the title Exclusion of Tokens in serialize for execution Exclusion of location fields in serialize for execution Sep 6, 2023
@eregon
Copy link
Member

eregon commented Sep 6, 2023

Let me reopen this with the original intent, i.e. the possibility to have no token and no location fields in serialization, and also no location fields in Java nodes.

@eregon eregon reopened this Sep 6, 2023
@kddnewton kddnewton added the enhancement New feature or request label Sep 6, 2023
@eregon eregon self-assigned this Sep 12, 2023
eregon added a commit to eregon/yarp that referenced this issue Sep 12, 2023
* Add a include_location_fields argument for serialize functions.
* Add a byte in the header to indicate whether location fields are included.
* Fixes ruby#807
eregon added a commit to eregon/yarp that referenced this issue Sep 12, 2023
* Add a include_location_fields argument for serialize functions.
* Add a byte in the header to indicate whether location fields are included.
* Fixes ruby#807
eregon added a commit to eregon/yarp that referenced this issue Sep 13, 2023
* Add a include_location_fields argument for serialize functions.
* Add a byte in the header to indicate whether location fields are included.
* Fixes ruby#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
eregon added a commit to eregon/yarp that referenced this issue Sep 14, 2023
* Add a include_location_fields argument for serialize functions.
* Add a byte in the header to indicate whether location fields are included.
* Fixes ruby#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
eregon added a commit to eregon/yarp that referenced this issue Sep 15, 2023
* Add $YARP_SERIALIZE_ONLY_SEMANTICS_FIELDS to control where to serialize location fields at templating time,
  this way there is no overhead for either case and nothing to check at runtime.
* Add a byte in the header to indicate whether location fields are included as expected.
* Fixes ruby#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
* Support keeping some location fields which are still needed until there is a replacement
eregon added a commit to eregon/yarp that referenced this issue Sep 15, 2023
* Add $YARP_SERIALIZE_ONLY_SEMANTICS_FIELDS to control where to serialize location fields at templating time,
  this way there is no overhead for either case and nothing to check at runtime.
* Add a byte in the header to indicate whether location fields are included as expected.
* Fixes ruby#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
* Support keeping some location fields which are still needed until there is a replacement
eregon added a commit to eregon/yarp that referenced this issue Sep 16, 2023
* Add $YARP_SERIALIZE_ONLY_SEMANTICS_FIELDS to control where to serialize location fields at templating time,
  this way there is no overhead for either case and nothing to check at runtime.
* Add a byte in the header to indicate whether location fields are included as expected.
* Fixes ruby#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
* Support keeping some location fields which are still needed until there is a replacement
eregon added a commit to eregon/yarp that referenced this issue Sep 19, 2023
* Add a include_location_fields argument for serialize functions.
* Add a byte in the header to indicate whether location fields are included.
* Fixes ruby#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
matzbot pushed a commit to ruby/ruby that referenced this issue Sep 19, 2023
* Add $YARP_SERIALIZE_ONLY_SEMANTICS_FIELDS to control where to serialize location fields at templating time,
  this way there is no overhead for either case and nothing to check at runtime.
* Add a byte in the header to indicate whether location fields are included as expected.
* Fixes ruby/prism#807
* Simplify the build-java CI job now that the FFI backend is available so JRuby can serialize.
* Support keeping some location fields which are still needed until there is a replacement

ruby/prism@fc5cf2df12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants