Class: Bootsnap::CompileCache::ISeq::Compiler
- Inherits:
-
Object
- Object
- Bootsnap::CompileCache::ISeq::Compiler
- Includes:
- PatchRubyBug22023
- Defined in:
- lib/bootsnap/compile_cache/iseq.rb
Defined Under Namespace
Modules: PatchRubyBug22023
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
-
#initialize(namespace = nil, compile_options = nil) ⇒ Compiler
constructor
A new instance of Compiler.
- #input_to_output(source, path, _kwargs) ⇒ Object
- #input_to_storage(_, path) ⇒ Object
- #storage_to_output(binary, _args) ⇒ Object
- #update_options ⇒ Object
Methods included from PatchRubyBug22023
#compile_file, #compile_file_prism
Constructor Details
#initialize(namespace = nil, compile_options = nil) ⇒ Compiler
Returns a new instance of Compiler.
26 27 28 29 30 |
# File 'lib/bootsnap/compile_cache/iseq.rb', line 26 def initialize(namespace = nil, = nil) @namespace = namespace @options = .freeze end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
24 25 26 |
# File 'lib/bootsnap/compile_cache/iseq.rb', line 24 def namespace @namespace end |
Instance Method Details
#input_to_output(source, path, _kwargs) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/bootsnap/compile_cache/iseq.rb', line 108 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) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/bootsnap/compile_cache/iseq.rb', line 81 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) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/bootsnap/compile_cache/iseq.rb', line 95 def storage_to_output(binary, _args) iseq = RubyVM::InstructionSequence.load_from_binary(binary) binary.clear iseq rescue RuntimeError => error if error. == "broken binary format" $stderr.puts("[Bootsnap::CompileCache] warning: rejecting broken binary") nil else raise end end |
#update_options ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/bootsnap/compile_cache/iseq.rb', line 32 def @compile_options = if @options.nil? || @options < RubyVM::InstructionSequence.compile_option nil else RubyVM::InstructionSequence.compile_option.merge(@options).freeze end end |