Sha256: 1ce388c96aa166ebaace919e27273b688331d4c1603b9f56f53ce6b66eacca87

Contents?: true

Size: 1.93 KB

Versions: 28

Compression:

Stored size: 1.93 KB

Contents

require 'bootsnap/bootsnap'
require 'zlib'

module Bootsnap
  module CompileCache
    module ISeq
      class << self
        attr_accessor :cache_dir
      end

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

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

      def self.input_to_output(_)
        nil # ruby handles this
      end

      module InstructionSequenceMixin
        def load_iseq(path)
          # Having coverage enabled prevents iseq dumping/loading.
          return nil if defined?(Coverage) && Bootsnap::CompileCache::Native.coverage_running?

          Bootsnap::CompileCache::Native.fetch(
            Bootsnap::CompileCache::ISeq.cache_dir,
            path.to_s,
            Bootsnap::CompileCache::ISeq
          )
        rescue RuntimeError => e
          if e.message =~ /unmatched platform/
            puts "unmatched platform for file #{path}"
          end
          raise
        end

        def compile_option=(hash)
          super(hash)
          Bootsnap::CompileCache::ISeq.compile_option_updated
        end
      end

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

      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
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
bootsnap-1.3.2-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.2 lib/bootsnap/compile_cache/iseq.rb
bootsnap-pr-184-1.3.1.pr.pre.184.1 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.1-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.1 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.0-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.0 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.0.beta2-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.0.beta2 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.0.beta-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.3.0.beta lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.2.1-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.2.1 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.2.0-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.2.0 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.2.0.pre-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.2.0.pre lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.1.8 lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.1.8-java lib/bootsnap/compile_cache/iseq.rb
bootsnap-1.1.7-java lib/bootsnap/compile_cache/iseq.rb