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

Kernel#autoload? returns true after the file has been required #3585

Closed
judofyr opened this issue Jan 8, 2016 · 6 comments
Closed

Kernel#autoload? returns true after the file has been required #3585

judofyr opened this issue Jan 8, 2016 · 6 comments
Assignees
Milestone

Comments

@judofyr
Copy link

judofyr commented Jan 8, 2016

test.rb:

$LOAD_PATH << 'lib'
Object.autoload :Tilt, 'tilt'
p Object.autoload?(:Tilt)
require 'tilt'
p Object.autoload?(:Tilt)

Different behaviour from MRI:

$ ruby -v test.rb
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
"tilt"
nil
$ ruby -v test.rb
jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) 64-Bit Server VM 24.45-b08 on 1.7.0_45-b18 +jit [darwin-x86_64]
"tilt"
"tilt"

This is failing for Tilt: https://travis-ci.org/rtomayko/tilt/builds/101022917

@kares kares self-assigned this Jan 12, 2016
kares added a commit to kares/jruby that referenced this issue Jan 12, 2016
…appened (jrubyGH-3585)

in this case the finishAutolog never gets called and thus autoload-map is not cleared!
kares added a commit that referenced this issue Jan 13, 2016
…appened (GH-3585)

in this case the finishAutolog never gets called and thus autoload-map is not cleared!
@kares
Copy link
Member

kares commented Jan 14, 2016

now working with 75ee995#diff-b0dc42ec523c3c3de1ac9ff40bc56852R213 - leaving open as in case of explicit require for an autoload feature the module's internal constant retrieval never gets rid of Autoload as the finishAutoload gets never called and I am not (yet) sure how to deal with the case.

kares added a commit that referenced this issue Jan 15, 2016
* master: (35 commits)
  [Truffle] Remove redundant checks for the type in Array nodes.
  [Truffle] Consistently name Array nodes.
  [Truffle] Add a few layout guards in ShapeCachingGuards.
  [Truffle] Some refactoring in Hash#[]=.
  [Truffle] Use helpers in Hash#[] for eql?/equal?
  deprecate IAutoloadMethod in favor of interface at RubyModule
  cleanup imports
  remove dead method
  handle autoload? returning nil when an explicit require of the file happened (GH-3585)
  loop through module hierarchy when checking autoload? - now behaving as MRI's
  update getConstant lookup to avoid auto-loading constant on a const_defined? check
  avoid replaceAll regexp due load service '.so' library '.jar' substitution + null warnings
  cleanup & align const_defined? + const_get impl methods
  [test] import ruby/test_autoload.rb from MRI 2.2.4
  make RubyKernel's autoload Ruby method receive a thread-context
  use isUTF8() where possible
  update to latest jcodings
  [Truffle] Off-by-one.
  [Truffle] Have a much simpler Array#fill for compilation.
  [Truffle] Make our Entry class final.
  ...
@headius
Copy link
Member

headius commented Jan 21, 2016

@kares Does MRI handle that case?

@headius
Copy link
Member

headius commented Jan 21, 2016

Oh nevermind...that's what this bug originally reported. Yeah, weird.

@headius
Copy link
Member

headius commented Jan 21, 2016

It looks like MRI does this through an additional check. After they lookup and find an autoload for the given constant, they go back to loaded features and see if the autoload file has been loaded in some form.

@kares
Copy link
Member

kares commented Jan 22, 2016

so it sounds that we should additionally trigger a finishAutoload when a feature has been loaded explicitly to get the internal constant replaced : 75ee995#diff-b0dc42ec523c3c3de1ac9ff40bc56852R213

@headius headius added this to the JRuby 9.3.0.0 milestone Jul 1, 2021
@headius headius modified the milestones: JRuby 9.3.0.0, JRuby 9.3.1.0 Aug 19, 2021
@headius
Copy link
Member

headius commented Oct 11, 2021

Not sure why we never re-tested this but it appear to be working fine in 9.3.

$ cat blah.rb
$LOAD_PATH << '.'
Object.autoload :Foo, 'foo'
p Object.autoload?(:Foo)
require 'foo'
p Object.autoload?(:Foo)

$ cat foo.rb
Foo = 1

$ jruby blah.rb
"foo"
nil

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

No branches or pull requests

3 participants