Module: Bootsnap::CompileCache::ISeq

Defined in:
lib/bootsnap/compile_cache/iseq.rb

Defined Under Namespace

Modules: InstructionSequenceMixin

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_dirObject

Returns the value of attribute cache_dir.



9
10
11
# File 'lib/bootsnap/compile_cache/iseq.rb', line 9

def cache_dir
  @cache_dir
end

Class Method Details

.compile_option_updatedObject



71
72
73
74
75
# File 'lib/bootsnap/compile_cache/iseq.rb', line 71

def self.compile_option_updated
  option = RubyVM::InstructionSequence.compile_option
  crc = Zlib.crc32(option.inspect)
  Bootsnap::CompileCache::Native.compile_option_crc32 = crc
end

.fetch(path, cache_dir: ISeq.cache_dir) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/bootsnap/compile_cache/iseq.rb', line 29

def self.fetch(path, cache_dir: ISeq.cache_dir)
  Bootsnap::CompileCache::Native.fetch(
    cache_dir,
    path.to_s,
    Bootsnap::CompileCache::ISeq,
    nil,
  )
end

.input_to_output(_data, _kwargs) ⇒ Object



46
47
48
# File 'lib/bootsnap/compile_cache/iseq.rb', line 46

def self.input_to_output(_data, _kwargs)
  nil # ruby handles this
end

.input_to_storage(_, path) ⇒ Object



12
13
14
15
16
# File 'lib/bootsnap/compile_cache/iseq.rb', line 12

def self.input_to_storage(_, path)
  RubyVM::InstructionSequence.compile_file(path).to_binary
rescue SyntaxError
  raise(Uncompilable, 'syntax error')
end

.install!(cache_dir) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/bootsnap/compile_cache/iseq.rb', line 78

def self.install!(cache_dir)
  Bootsnap::CompileCache::ISeq.cache_dir = cache_dir
  Bootsnap::CompileCache::ISeq.compile_option_updated
  class << RubyVM::InstructionSequence
    prepend(InstructionSequenceMixin)
  end
end

.precompile(path, cache_dir: ISeq.cache_dir) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/bootsnap/compile_cache/iseq.rb', line 38

def self.precompile(path, cache_dir: ISeq.cache_dir)
  Bootsnap::CompileCache::Native.precompile(
    cache_dir,
    path.to_s,
    Bootsnap::CompileCache::ISeq,
  )
end

.storage_to_output(binary, _args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/bootsnap/compile_cache/iseq.rb', line 18

def self.storage_to_output(binary, _args)
  RubyVM::InstructionSequence.load_from_binary(binary)
rescue RuntimeError => e
  if e.message == 'broken binary format'
    STDERR.puts("[Bootsnap::CompileCache] warning: rejecting broken binary")
    nil
  else
    raise
  end
end