Requiring '<file>.rb' then '<file>' results in double load #1788

Closed
nicklewis opened this Issue Jun 27, 2012 · 2 comments

Projects

None yet

3 participants

@nicklewis

Suppose we have some_file.rb in the current directory. This code results in only a single load:

require 'some_file'
require 'some_file.rb'

$LOADED_FEATURES contains ['some_file.rb'].

However, reordering the requires:

require 'some_file.rb'
require 'some_file'

results in two loads, with ['./some_file.rb', 'some_file.rb'] in $LOADED_FEATURES.

I bisected this down to ed6b8a1, which looks to be a refactor gone wrong.

@jc00ke
Member
jc00ke commented Jun 27, 2012

I was unable to reproduce using rubinius 2.0.0dev (1.9.3 0bb5c46b yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]

What version of rbx are you using?

23:28:25 jesse@maynard:~  rbx-head 
∴ cat foo.rb 
require './bar'
require './bar.rb'

puts $LOADED_FEATURES
23:28:45 jesse@maynard:~  rbx-head 
∴ rbx foo.rb 
/home/jesse/.rvm/rubies/rbx-head/lib/ext/melbourne/rbx/melbourne20.so
/home/jesse/.rvm/rubies/rbx-head/runtime/19/melbourne/processor.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/melbourne.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/compiler.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/stages.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/locals.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/node.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/self.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/constants.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/control_flow.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/data.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/definitions.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/encoding.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/exceptions.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/file.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/grapher.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/literals.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/operators.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/sends.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/values.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/variables.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/transforms.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/generator_methods.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/generator.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/iseq.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/opcodes.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/compiled_file.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/evaluator.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/printers.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/runtime.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/defaults.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubinius/build_config.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rbconfig.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/deprecate.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/exceptions.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/platform.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/defaults/rbx.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/custom_require.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems.rb
/home/jesse/bar.rb
23:29:28 jesse@maynard:~  rbx-head 
∴ cat foo.rb 
require './bar.rb'
require './bar'

puts $LOADED_FEATURES
23:29:30 jesse@maynard:~  rbx-head 
∴ rbx foo.rb 
/home/jesse/.rvm/rubies/rbx-head/lib/ext/melbourne/rbx/melbourne20.so
/home/jesse/.rvm/rubies/rbx-head/runtime/19/melbourne/processor.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/melbourne.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/compiler.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/stages.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/locals.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/node.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/self.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/constants.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/control_flow.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/data.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/definitions.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/encoding.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/exceptions.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/file.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/grapher.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/literals.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/operators.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/sends.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/values.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/variables.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast/transforms.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/ast.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/generator_methods.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/generator.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/iseq.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/opcodes.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/compiled_file.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/evaluator.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/printers.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler/runtime.rb
/home/jesse/.rvm/rubies/rbx-head/runtime/19/compiler.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/defaults.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubinius/build_config.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rbconfig.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/deprecate.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/exceptions.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/platform.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/defaults/rbx.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems/custom_require.rb
/home/jesse/.rvm/rubies/rbx-head/lib/rubygems.rb
/home/jesse/bar.rb
@nicklewis

Oops, I should have specified. I'm using master at 18acf20 in 1.8 mode. The bug isn't present in 1.2.4.

I did a bit more experimentation, and gathered a few points:

  • It only occurs in 1.8 mode
  • It doesn't occur if I use an absolute path or a path relative to my current directory (../foo.rb or ./foo.rb)
  • It does occur if I prepend any other directory, (foo/bar.rb)

So it looks like the issue is when it has to search for the file to require (as opposed to being absolute or relative to the local directory). And it's unsurprising it's not present in 1.9 mode, as features are stored as absolute paths.

To avoid the local directory issue, here's a simpler test case:

$ cat test.rb
require 'set.rb'
require 'set'

puts $LOADED_FEATURES

$ rbx test.rb
/Users/nicklewis/projects/rubinius/lib/ext/melbourne/rbx/melbourne20.bundle
/Users/nicklewis/projects/rubinius/runtime/18/melbourne/processor.rb
/Users/nicklewis/projects/rubinius/runtime/18/melbourne.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/compiler.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/stages.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/locals.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/node.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/self.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/constants.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/control_flow.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/data.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/definitions.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/encoding.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/exceptions.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/file.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/grapher.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/literals.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/operators.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/sends.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/values.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/variables.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast/transforms.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/ast.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/generator_methods.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/generator.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/iseq.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/opcodes.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/compiled_file.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/evaluator.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/printers.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler/runtime.rb
/Users/nicklewis/projects/rubinius/runtime/18/compiler.rb
/Users/nicklewis/projects/rubinius/lib/18/set.rb
set.rb
@dbussink dbussink closed this in c520d3b Jul 27, 2012
@Gibheer Gibheer added a commit to Gibheer/rubinius that referenced this issue Aug 14, 2012
@dbussink @Gibheer dbussink + Gibheer Fix path location for code loader in 1.8 mode to prevent double loading
Fixes #1832
Fixes #1788
Fixes #1571
61478c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment