bootsnap 1.10.1 → 1.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c66adff2d954aee5f0f0b6beae724c2ec1a2abedb6cc6ffd1b3eb84a0481acf
4
- data.tar.gz: 91a512ba361da721632679a2942d84128fe301bfc0750b48ec3c98989433072b
3
+ metadata.gz: 22aca6043d2a55eb7747cb38aec8365879c37e3fbdbd0cdfdd040098dd945fdd
4
+ data.tar.gz: 69085ad28c61b3dbffeab8e50a49f0655d05c9639cae9e4ba0a9cc2f2b7c9051
5
5
  SHA512:
6
- metadata.gz: 74613cfa0f4b1b337cf60c2e60f8f51c8726321953addfc1166708af567bdae486ea38b5ff9f1ad63ec13bee2c7142be0cde9fd9d68bf2eca4c044936b575f17
7
- data.tar.gz: 9449f4e75ebe813e5df1fd2c71c1e334853c67feaa0a4e5351a0bcc53d6479993ffc59b37412f81853dce6154e36a165e5e5fb6c311c2ef5cf561afc889a51e2
6
+ metadata.gz: f63a81e86c721f737e5f29b9696abbcbc118e5bf703bf994dbf275d9939203d1eb6aebabc8ccad927f818b2bf9311d4174dde0338b7cd74f4e71e7e9727e6692
7
+ data.tar.gz: 3209a8fcdbb446c0f32738f2f580e7adc573d556da298560718c23d25963dc3f9dcf8fd5794a79864bac203089aef6be3da7743fde8bcc906f469b20461bb7aa
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
1
  # Unreleased
2
2
 
3
+ # 1.10.2
4
+
5
+ * Reduce the `Kernel.require` extra stack frames some more. Now bootsnap should only add one extra frame per `require` call.
6
+
7
+ * Better check `freeze` option support in JSON compile cache.
8
+ Previously `JSON.load_file(..., freeze: true)` would be cached even when the msgpack version is missing support for it.
9
+
3
10
  # 1.10.1
4
11
 
5
- * Fix `Kernel#autoload`'s fallback path always bing executed.
12
+ * Fix `Kernel#autoload`'s fallback path always being executed.
13
+
6
14
  * Consider `unlink` failing with `ENOENT` as a success.
7
15
 
8
16
  # 1.10.0
@@ -52,7 +52,9 @@ module Bootsnap
52
52
  self.msgpack_factory = MessagePack::Factory.new
53
53
  self.supported_options = [:symbolize_names]
54
54
  if ::JSON.parse('["foo"]', freeze: true).first.frozen?
55
- self.supported_options = [:freeze]
55
+ if MessagePack.load(MessagePack.dump("foo"), freeze: true).frozen?
56
+ self.supported_options = [:freeze]
57
+ end
56
58
  end
57
59
  supported_options.freeze
58
60
  end
@@ -65,7 +65,7 @@ module Bootsnap
65
65
  # returns false as if it were already loaded; however, there is no
66
66
  # file to find on disk. We've pre-built a list of these, and we
67
67
  # return false if any of them is loaded.
68
- raise(LoadPathCache::ReturnFalse, "", []) if BUILTIN_FEATURES.key?(feature)
68
+ return false if BUILTIN_FEATURES.key?(feature)
69
69
 
70
70
  # The feature wasn't found on our preliminary search through the index.
71
71
  # We resolve this differently depending on what the extension was.
@@ -89,7 +89,7 @@ module Bootsnap
89
89
  else
90
90
  # other, unknown extension. For example, `.rake`. Since we haven't
91
91
  # cached these, we legitimately need to run the load path search.
92
- raise(LoadPathCache::FallbackScan, "", [])
92
+ return FALLBACK_SCAN
93
93
  end
94
94
  end
95
95
 
@@ -97,7 +97,7 @@ module Bootsnap
97
97
  # cases where the file doesn't appear to be on the load path. We should
98
98
  # be able to detect newly-created files without rebooting the
99
99
  # application.
100
- raise(LoadPathCache::FallbackScan, "", []) if @development_mode
100
+ return FALLBACK_SCAN if @development_mode
101
101
  end
102
102
 
103
103
  def unshift_paths(sender, *paths)
@@ -1,55 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Bootsnap
4
- module LoadPathCache
5
- module CoreExt
6
- def self.make_load_error(path)
7
- err = LoadError.new(+"cannot load such file -- #{path}")
8
- err.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
9
- err.define_singleton_method(:path) { path }
10
- err
11
- end
12
- end
13
- end
14
- end
15
-
16
3
  module Kernel
17
4
  module_function
18
5
 
19
6
  alias_method(:require_without_bootsnap, :require)
20
7
 
21
8
  def require(path)
22
- fallback = false
23
9
  string_path = path.to_s
24
10
  return false if Bootsnap::LoadPathCache.loaded_features_index.key?(string_path)
25
11
 
26
- if (resolved = Bootsnap::LoadPathCache.load_path_cache.find(string_path))
27
- # Note that require registers to $LOADED_FEATURES while load does not.
28
- ret = require_without_bootsnap(resolved)
29
- Bootsnap::LoadPathCache.loaded_features_index.register(string_path, resolved)
30
- return ret
31
- end
32
-
33
- raise(Bootsnap::LoadPathCache::CoreExt.make_load_error(path))
34
- rescue LoadError => error
35
- error.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
36
- raise(error)
37
- rescue Bootsnap::LoadPathCache::ReturnFalse
38
- false
39
- rescue Bootsnap::LoadPathCache::FallbackScan
40
- fallback = true
41
- ensure
42
- # We raise from `ensure` so that any further exception don't have FallbackScan as a cause
43
- # See: https://github.com/Shopify/bootsnap/issues/250
44
- if fallback
12
+ resolved = Bootsnap::LoadPathCache.load_path_cache.find(string_path)
13
+ if Bootsnap::LoadPathCache::FALLBACK_SCAN.equal?(resolved)
45
14
  if (cursor = Bootsnap::LoadPathCache.loaded_features_index.cursor(string_path))
46
15
  ret = require_without_bootsnap(path)
47
16
  resolved = Bootsnap::LoadPathCache.loaded_features_index.identify(string_path, cursor)
48
17
  Bootsnap::LoadPathCache.loaded_features_index.register(string_path, resolved)
49
- ret
50
- else # If we're not given a cursor, it means we don't need to register the path (likely an absolute path)
51
- require_without_bootsnap(path)
18
+ return ret
19
+ else
20
+ return require_without_bootsnap(path)
52
21
  end
22
+ elsif false == resolved
23
+ return false
24
+ elsif resolved.nil?
25
+ error = LoadError.new(+"cannot load such file -- #{path}")
26
+ error.instance_variable_set(:@path, path)
27
+ raise error
28
+ else
29
+ # Note that require registers to $LOADED_FEATURES while load does not.
30
+ ret = require_without_bootsnap(resolved)
31
+ Bootsnap::LoadPathCache.loaded_features_index.register(string_path, resolved)
32
+ return ret
53
33
  end
54
34
  end
55
35
 
@@ -75,7 +55,6 @@ end
75
55
  class Module
76
56
  alias_method(:autoload_without_bootsnap, :autoload)
77
57
  def autoload(const, path)
78
- fallback = false
79
58
  # NOTE: This may defeat LoadedFeaturesIndex, but it's not immediately
80
59
  # obvious how to make it work. This feels like a pretty niche case, unclear
81
60
  # if it will ever burn anyone.
@@ -83,19 +62,13 @@ class Module
83
62
  # The challenge is that we don't control the point at which the entry gets
84
63
  # added to $LOADED_FEATURES and won't be able to hook that modification
85
64
  # since it's done in C-land.
86
- autoload_without_bootsnap(const, Bootsnap::LoadPathCache.load_path_cache.find(path) || path)
87
- rescue LoadError => error
88
- error.instance_variable_set(Bootsnap::LoadPathCache::ERROR_TAG_IVAR, true)
89
- raise(error)
90
- rescue Bootsnap::LoadPathCache::ReturnFalse
91
- false
92
- rescue Bootsnap::LoadPathCache::FallbackScan
93
- fallback = true
94
- ensure
95
- # We raise from `ensure` so that any further exception don't have FallbackScan as a cause
96
- # See: https://github.com/Shopify/bootsnap/issues/250
97
- if fallback
65
+ resolved = Bootsnap::LoadPathCache.load_path_cache.find(path)
66
+ if Bootsnap::LoadPathCache::FALLBACK_SCAN.equal?(resolved)
98
67
  autoload_without_bootsnap(const, path)
68
+ elsif resolved == false
69
+ return false
70
+ else
71
+ autoload_without_bootsnap(const, resolved || path)
99
72
  end
100
73
  end
101
74
  end
@@ -92,7 +92,7 @@ module Bootsnap
92
92
  # entry:
93
93
  #
94
94
  # If the user asked for e.g. `require 'bundler'`, and we went through the
95
- # `FallbackScan` pathway in `kernel_require.rb` and therefore did not
95
+ # `FALLBACK_SCAN` pathway in `kernel_require.rb` and therefore did not
96
96
  # pass `long` (the full expanded absolute path), then we did are not able
97
97
  # to confidently add the `bundler.rb` form to @lfi.
98
98
  #
@@ -2,18 +2,12 @@
2
2
 
3
3
  module Bootsnap
4
4
  module LoadPathCache
5
- ReturnFalse = Class.new(StandardError)
6
- FallbackScan = Class.new(StandardError)
5
+ FALLBACK_SCAN = BasicObject.new
7
6
 
8
7
  DOT_RB = ".rb"
9
8
  DOT_SO = ".so"
10
9
  SLASH = "/"
11
10
 
12
- # If a NameError happens several levels deep, don't re-handle it
13
- # all the way up the chain: mark it once and bubble it up without
14
- # more retries.
15
- ERROR_TAG_IVAR = :@__bootsnap_rescued
16
-
17
11
  DL_EXTENSIONS = ::RbConfig::CONFIG
18
12
  .values_at("DLEXT", "DLEXT2")
19
13
  .reject { |ext| !ext || ext.empty? }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bootsnap
4
- VERSION = "1.10.1"
4
+ VERSION = "1.10.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.1
4
+ version: 1.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack