class Bootsnap::CompileCache::ISeq::Compiler

Attributes

namespace[R]

Public Class Methods

new(namespace = nil, compile_options = nil) click to toggle source
# File lib/bootsnap/compile_cache/iseq.rb, line 26
def initialize(namespace = nil, compile_options = nil)
  @namespace = namespace
  @options = compile_options.freeze
  update_options
end

Public Instance Methods

input_to_output(source, path, _kwargs) click to toggle source
# File lib/bootsnap/compile_cache/iseq.rb, line 110
def input_to_output(source, path, _kwargs)
  if @compile_options
    if source
      RubyVM::InstructionSequence.compile(
        source.force_encoding(Encoding.default_external),
        path,
        path,
        nil,
        @compile_options,
      )
    else
      RubyVM::InstructionSequence.compile_file(path, @compile_options)
    end
  end
end
input_to_storage(_, path) click to toggle source
# File lib/bootsnap/compile_cache/iseq.rb, line 83
def input_to_storage(_, path)
  iseq = RubyVM::InstructionSequence.compile_file(path, @compile_options)
  iseq.to_binary
rescue TypeError, SyntaxError # Ruby [Bug #18250] & [Bug #22023]
  UNCOMPILABLE
end
storage_to_output(binary, _args) click to toggle source
# File lib/bootsnap/compile_cache/iseq.rb, line 97
def storage_to_output(binary, _args)
  iseq = RubyVM::InstructionSequence.load_from_binary(binary)
  binary.clear
  iseq
rescue RuntimeError => error
  if error.message == "broken binary format"
    $stderr.puts("[Bootsnap::CompileCache] warning: rejecting broken binary")
    nil
  else
    raise
  end
end
update_options() click to toggle source
# File lib/bootsnap/compile_cache/iseq.rb, line 32
def update_options
  @compile_options = if @options.nil? || @options < RubyVM::InstructionSequence.compile_option
    nil
  else
    RubyVM::InstructionSequence.compile_option.merge(@options).freeze
  end
end