module Kernel

def load(path, wrap = false)

def load(path, wrap = false)
  if resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)
    return load_without_bootsnap(resolved, wrap)
  end
  # load also allows relative paths from pwd even when not in $:
  if File.exist?(relative = File.expand_path(path))
    return load_without_bootsnap(relative, wrap)
  end
  raise Bootsnap::LoadPathCache::CoreExt.make_load_error(path)
rescue Bootsnap::LoadPathCache::ReturnFalse
  return false
rescue Bootsnap::LoadPathCache::FallbackScan
  load_without_bootsnap(path, wrap)
end

def require(path)

def require(path)
  return false if Bootsnap::LoadPathCache.loaded_features_index.key?(path)
  if resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)
    return require_with_bootsnap_lfi(path, resolved)
  end
  raise Bootsnap::LoadPathCache::CoreExt.make_load_error(path)
rescue Bootsnap::LoadPathCache::ReturnFalse
  return false
rescue Bootsnap::LoadPathCache::FallbackScan
  require_with_bootsnap_lfi(path)
end

def require_with_bootsnap_lfi(path, resolved = nil)

Note that require registers to $LOADED_FEATURES while load does not.
def require_with_bootsnap_lfi(path, resolved = nil)
  Bootsnap::LoadPathCache.loaded_features_index.register(path, resolved) do
    require_without_bootsnap(resolved || path)
  end
end