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.



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

def cache_dir
  @cache_dir
end

Class Method Details

.compile_option_updatedObject



103
104
105
106
107
# File 'lib/bootsnap/compile_cache/iseq.rb', line 103

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



63
64
65
66
67
68
69
70
# File 'lib/bootsnap/compile_cache/iseq.rb', line 63

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



80
81
82
# File 'lib/bootsnap/compile_cache/iseq.rb', line 80

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

.input_to_storage(_, path) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bootsnap/compile_cache/iseq.rb', line 31

def self.input_to_storage(_, path)
  iseq = begin
    RubyVM::InstructionSequence.compile_file(path)
  rescue SyntaxError
    return UNCOMPILABLE # syntax error
  end

  begin
    iseq.to_binary
  rescue TypeError
    UNCOMPILABLE # ruby bug #18250
  end
end

.install!(cache_dir) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bootsnap/compile_cache/iseq.rb', line 110

def self.install!(cache_dir)
  Bootsnap::CompileCache::ISeq.cache_dir = cache_dir

  return unless supported?

  Bootsnap::CompileCache::ISeq.compile_option_updated

  class << RubyVM::InstructionSequence
    prepend(InstructionSequenceMixin)
  end
end

.precompile(path) ⇒ Object



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

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

.storage_to_output(binary, _args) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/bootsnap/compile_cache/iseq.rb', line 52

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

.supported?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/bootsnap/compile_cache/iseq.rb', line 16

def supported?
  CompileCache.supported? && defined?(RubyVM)
end