Skip to content

Allow binding instance/internal vars to fields #8804

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

headius
Copy link
Member

@headius headius commented Apr 28, 2025

This is an extension of the existing mechanism for reification of Ruby classes, allowing us to use normal Java fields for either instance or internal variables.

The logic here is largely unchanged from the original reification logic except for enhancements to allow actively requesting a specific binding:

  • Allow specifying a Ruby name to be used in the variable table, so that both instance vars (@var) and internal vars (no @) can be tied to a specific field.
  • Allow the direct field configuration to aggregate a Lookup object so that private fields can bound.

The example usage here binds the "args" internal variable on NoMethodError to the "args" field on RubyNoMethodError, allowing it to be seen by marshal dumping and fixing one of the DRb issues in ruby/drb#36. The reification change was not strictly necessary to fix that issue, but the alternative converts it into a slow-path internal variable lookup which is less than ideal.

Assuming this change is safe, all other instance and internal variables used by concrete JRuby core classes can be converted with the following process:

  • Set the reified class (the real concrete class) at definition time.
  • Request the direct field with a Java name and either the @var or bare var name, providing an appropriate Lookup object if the field shoud be private.

Enhancements to this feature could include:

  • Allow binding read-only variables. Currently both a read and write path are expected.
  • Enhance conversion logic to allow variables to be a more natural Java type. The logic for this exists but has not been heavily tested. See Java logic for treating fields as instance variables.

This is an extension of the existing mechanism for reification of
Ruby classes, allowing us to use normal Java fields for either
instance or internal variables.

The logic here is largely unchanged from the original reification
logic except for enhancements to allow actively requesting a
specific binding:

* Allow specifying a Ruby name to be used in the variable table, so
  that both instance vars (@var) and internal vars (no @) can be
  tied to a specific field.
* Allow the direct field configuration to aggregate a Lookup object
  so that private fields can bound.

The example usage here binds the "args" internal variable on
NoMethodError to the "args" field on RubyNoMethodError, allowing
it to be seen by marshal dumping and fixing one of the DRb issues
in ruby/drb#36. The reification change was not strictly necessary
to fix that issue, but the alternative converts it into a slow-path
internal variable lookup which is less than ideal.

Assuming this change is safe, all other instance and internal
variables used by concrete JRuby core classes can be converted with
the following process:

* Set the reified class (the real concrete class) at definition
  time.
* Request the direct field with a Java name and either the @var or
  bar var name, providing an appropriate Lookup object if the field
  shoud be private.

Enhancements to this feature could include:

* Allow binding read-only variables. Currently both a read and
  write path are expected.
* Enhance conversion logic to allow variables to be a more natural
  Java type. The logic for this exists but has not been heavily
  tested. See Java logic for treating fields as instance variables.
@headius headius force-pushed the reify_normal_fields branch from f9b2c22 to e9e0cb9 Compare April 28, 2025 16:01
@headius
Copy link
Member Author

headius commented Apr 28, 2025

This API should be cleaned up and simplified before applying it elsewhere.

This hides the plumbing of defining an internal or instance
variable accessor that binds directly to a Java instance field. In
NoMethodError, it is used to bind the "args" field so that it is
seen by Marshal.dump. In other classes, it can be used to avoid
the overhead of dynamically retrieving instance variables when a
field would fit the code better.
@headius headius force-pushed the reify_normal_fields branch from 695f9ad to e8f387c Compare May 1, 2025 20:00
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.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy