Skip to content

Warnings emitted by requiring 'ostruct' #8200

Closed

Description

@PragTob

👋 Hello my friends! Long time no see, some might say the not seeing level is over 9000 ;)

Environment

tobi@qiqi:~/github/simplecov(ci-madness)$ jruby -v
jruby 9.4.6.0 (3.1.4) 2024-02-20 576fab2c51 OpenJDK 64-Bit Server VM 11.0.22+7-post-Ubuntu-0ubuntu222.04.1 on 11.0.22+7-post-Ubuntu-0ubuntu222.04.1 +jit [x86_64-linux]
tobi@qiqi:~/github/simplecov(ci-madness)$ uname -a
Linux qiqi 6.5.0-27-generic #28~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 15 10:51:06 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Behaviour

Just requiring open struct yields the following warnings with warnings turned on

tobi@qiqi:~/github/simplecov(ci-madness)$ cat wtwas.rb 
require 'ostruct'
tobi@qiqi:~/github/simplecov(ci-madness)$ jruby -w wtwas.rb 
/home/tobi/.asdf/installs/ruby/jruby-9.4.6.0/lib/ruby/stdlib/ostruct.rb:466: warning: OpenStruct#public_send accesses caller method's state and should not be aliased
/home/tobi/.asdf/installs/ruby/jruby-9.4.6.0/lib/ruby/stdlib/ostruct.rb:466: warning: OpenStruct#method accesses caller method's state and should not be aliased

Expected Behavior

No warnings :)

More context

FWIW the simplecov CI is failing because of this, I'll work around it for now somehow. We have a test that just makes sure we don't emit warnings.

Cheers, and thanks for all your work 💚

Activity

  1. headius commented on Apr 22, 2024

    @headius
    Member

    This is related to #7524 which added additional whitelisted methods for which we won't warn.

    The problem here is that JRuby wants to warn users when they alias "special" methods that access the caller's frame, since those aliases are often wrapped with another method that breaks that frame access. For example, you can't alias and wrap eval because the eval won't actually execute in the method that calls the wrapper.

    These two methods access the caller's frame in order to get the scope for refinement lookups. If called via a wrapper, they won't work properly, because they'll use the wrapper method's scope.

    The fix I proposed in #7524 whitelists these names so they won't be aliased, since we know that openstruct does this. In other cases we have worked with @marcandre to reduce the number of methods it aliases in this way, but neither solution is really very good.

  2. headius commented on Apr 22, 2024

    @headius
    Member

    Further clarification of why we warn: In order to optimize method bodies by eliminating extra frame and scope information, we gather a list of all method names known to access the caller's frame or scope. When one of these methods gets aliased, that becomes a method name that also needs caller access, and any code already compiled to call that new name may not have the right context set up. So we warn to indicate these methods may not behave like the user expects.

  3. headius commented on Apr 22, 2024

    @headius
    Member

    I pushed #8206 with a new sort of fix: eagerly add all frame-aware names with an additional bang-suffixed version in expectation that this will be an ongoing problem with ostruct.

    This could probably be reduced to just Kernel, Object, and BasicObject names but that is a messier fix.

  4. added this to the JRuby 9.4.7.0 milestone on Apr 22, 2024
  5. PragTob commented on Apr 23, 2024

    @PragTob
    Author

    Thanks for all the work as always Charlie! 💚

    IMG_20220705_184557

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions