Module: Bootsnap::CompileCache::ISeq

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

Defined Under Namespace

Modules: InstructionSequenceMixin Classes: Compiler

Constant Summary collapse

DEFAULT =
Compiler.new
FROZEN_STRING_LITERAL =
Compiler.new("-fstr", {frozen_string_literal: true}.freeze)
MUTABLE_STRING_LITERAL =
Compiler.new("-no-fstr", {frozen_string_literal: false}.freeze)

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

.compiler_selectorObject

Returns the value of attribute compiler_selector.



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

def compiler_selector
  @compiler_selector
end

.default_compilerObject

Returns the value of attribute default_compiler.



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

def default_compiler
  @default_compiler
end

Class Method Details

.compile_option_updatedObject



118
119
120
121
122
# File 'lib/bootsnap/compile_cache/iseq.rb', line 118

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



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

def self.fetch(path, cache_dir: ISeq.cache_dir)
  compiler = compiler_selector&.call(path) || default_compiler
  Bootsnap::CompileCache::Native.fetch(
    cache_dir,
    compiler.namespace,
    path.to_s,
    compiler,
    nil,
  )
end

.install!(cache_dir) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
# File 'lib/bootsnap/compile_cache/iseq.rb', line 125

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



89
90
91
92
93
94
95
96
97
# File 'lib/bootsnap/compile_cache/iseq.rb', line 89

def self.precompile(path)
  compiler = compiler_selector&.call(path) || default_compiler
  Bootsnap::CompileCache::Native.precompile(
    cache_dir,
    compiler.namespace,
    path.to_s,
    compiler,
  )
end

.supported?Boolean

Returns:

  • (Boolean)


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

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