Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Handle inline_const_cache=false
  • Loading branch information
kddnewton committed Nov 22, 2022
commit be9465d49edf5fe71b470aefeff1893289d68070
4 changes: 4 additions & 0 deletions lib/syntax_tree/yarv/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def visit_unsupported(_node)
# These options mirror the compilation options that we currently support
# that can be also passed to RubyVM::InstructionSequence.compile.
attr_reader :frozen_string_literal,
:inline_const_cache,
:operands_unification,
:specialized_instruction

Expand All @@ -217,10 +218,12 @@ def visit_unsupported(_node)

def initialize(
frozen_string_literal: false,
inline_const_cache: true,
operands_unification: true,
specialized_instruction: true
)
@frozen_string_literal = frozen_string_literal
@inline_const_cache = inline_const_cache
@operands_unification = operands_unification
@specialized_instruction = specialized_instruction

Expand Down Expand Up @@ -1374,6 +1377,7 @@ def visit_program(node)
nil,
node.location,
frozen_string_literal: frozen_string_literal,
inline_const_cache: inline_const_cache,
operands_unification: operands_unification,
specialized_instruction: specialized_instruction
)
Expand Down
32 changes: 24 additions & 8 deletions lib/syntax_tree/yarv/instruction_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def change_by(value)

# These are various compilation options provided.
attr_reader :frozen_string_literal,
:inline_const_cache,
:operands_unification,
:specialized_instruction

Expand All @@ -86,6 +87,7 @@ def initialize(
parent_iseq,
location,
frozen_string_literal: false,
inline_const_cache: true,
operands_unification: true,
specialized_instruction: true
)
Expand All @@ -104,6 +106,7 @@ def initialize(
@stack = Stack.new

@frozen_string_literal = frozen_string_literal
@inline_const_cache = inline_const_cache
@operands_unification = operands_unification
@specialized_instruction = specialized_instruction
end
Expand Down Expand Up @@ -192,6 +195,7 @@ def child_iseq(type, name, location)
self,
location,
frozen_string_literal: frozen_string_literal,
inline_const_cache: inline_const_cache,
operands_unification: operands_unification,
specialized_instruction: specialized_instruction
)
Expand Down Expand Up @@ -434,23 +438,35 @@ def opt_aset_with(object, calldata)
end

def opt_getconstant_path(names)
if RUBY_VERSION < "3.2"
cache = inline_storage
getinlinecache = opt_getinlinecache(-1, cache)

if names[0] == :""
if RUBY_VERSION < "3.2" || !inline_const_cache
cache = nil
getinlinecache = nil

if inline_const_cache
cache = inline_storage
getinlinecache = opt_getinlinecache(-1, cache)

if names[0] == :""
names.shift
pop
putobject(Object)
end
elsif names[0] == :""
names.shift
pop
putobject(Object)
else
putnil
end

names.each_with_index do |name, index|
putobject(index == 0)
getconstant(name)
end

opt_setinlinecache(cache)
getinlinecache.patch!(self)
if inline_const_cache
opt_setinlinecache(cache)
getinlinecache.patch!(self)
end
else
push(OptGetConstantPath.new(names))
end
Expand Down
1 change: 1 addition & 0 deletions test/compiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class CompilerTest < Minitest::Test
{ frozen_string_literal: true },
{ operands_unification: false },
{ specialized_instruction: false },
{ inline_const_cache: false },
{ operands_unification: false, specialized_instruction: false }
]

Expand Down