backports 3.18.1 → 3.20.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +47 -1
- data/Gemfile +2 -2
- data/README.md +34 -14
- data/lib/backports/2.0.0.rb +1 -1
- data/lib/backports/2.1.0.rb +1 -1
- data/lib/backports/2.2.0.rb +1 -1
- data/lib/backports/2.2.0/string/unicode_normalize.rb +3 -3
- data/lib/backports/2.3.0.rb +1 -1
- data/lib/backports/2.3.0/queue/close.rb +48 -0
- data/lib/backports/2.3.0/string.rb +3 -0
- data/lib/backports/2.4.0.rb +1 -1
- data/lib/backports/2.4.0/bignum.rb +3 -0
- data/lib/backports/2.4.0/bignum/dup.rb +5 -0
- data/lib/backports/2.5.0.rb +1 -1
- data/lib/backports/2.5.0/hash/transform_keys.rb +10 -3
- data/lib/backports/2.5.0/string/undump.rb +2 -2
- data/lib/backports/2.5.rb +1 -1
- data/lib/backports/2.6.0.rb +2 -2
- data/lib/backports/2.6.0/enumerable/chain.rb +2 -0
- data/lib/backports/2.6.rb +1 -1
- data/lib/backports/2.7.0.rb +2 -2
- data/lib/backports/3.0.0.rb +3 -0
- data/lib/backports/3.0.0/env.rb +3 -0
- data/lib/backports/3.0.0/env/except.rb +10 -0
- data/lib/backports/3.0.0/hash.rb +3 -0
- data/lib/backports/3.0.0/hash/except.rb +10 -0
- data/lib/backports/3.0.0/hash/transform_keys.rb +48 -0
- data/lib/backports/3.0.0/ractor.rb +19 -0
- data/lib/backports/3.0.0/symbol.rb +3 -0
- data/lib/backports/3.0.0/symbol/name.rb +11 -0
- data/lib/backports/3.0.rb +1 -0
- data/lib/backports/ractor/cloner.rb +94 -0
- data/lib/backports/ractor/errors.rb +20 -0
- data/lib/backports/ractor/filtered_queue.rb +205 -0
- data/lib/backports/ractor/queues.rb +66 -0
- data/lib/backports/ractor/ractor.rb +272 -0
- data/lib/backports/ractor/sharing.rb +97 -0
- data/lib/backports/version.rb +1 -1
- metadata +26 -6
@@ -0,0 +1,97 @@
|
|
1
|
+
# shareable_constant_value: literal
|
2
|
+
|
3
|
+
module Backports
|
4
|
+
class Ractor
|
5
|
+
class << self
|
6
|
+
# @api private
|
7
|
+
def ractor_isolate(val, move = false)
|
8
|
+
return val if move
|
9
|
+
|
10
|
+
Cloner.deep_clone(val)
|
11
|
+
end
|
12
|
+
|
13
|
+
private def ractor_check_shareability?(obj, freeze_all)
|
14
|
+
ractor_shareable_self?(obj, freeze_all) do
|
15
|
+
visited = {}
|
16
|
+
|
17
|
+
return false unless ractor_shareable_parts?(obj, freeze_all, visited)
|
18
|
+
|
19
|
+
ractor_mark_set_shareable(visited)
|
20
|
+
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# yield if shareability can't be determined without looking at its parts
|
26
|
+
def ractor_shareable_self?(obj, freeze_all)
|
27
|
+
return true if @ractor_shareable.key?(obj)
|
28
|
+
return true if ractor_shareable_by_nature?(obj, freeze_all)
|
29
|
+
if obj.frozen? || (freeze_all && obj.freeze)
|
30
|
+
yield
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private def ractor_shareable_parts?(obj, freeze_all, visited)
|
37
|
+
return true if visited.key?(obj)
|
38
|
+
visited[obj] = true
|
39
|
+
|
40
|
+
ractor_traverse(obj) do |part|
|
41
|
+
return false unless ractor_shareable_self?(part, freeze_all) do
|
42
|
+
ractor_shareable_parts?(part, freeze_all, visited)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def ractor_mark_set_shareable(visited)
|
50
|
+
visited.each do |key|
|
51
|
+
@ractor_shareable[key] = Ractor
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private def ractor_traverse(obj, &block)
|
56
|
+
case obj
|
57
|
+
when ::Hash
|
58
|
+
Hash obj.default
|
59
|
+
yield obj.default_proc
|
60
|
+
obj.each do |key, value|
|
61
|
+
yield key
|
62
|
+
yield value
|
63
|
+
end
|
64
|
+
when ::Range
|
65
|
+
yield obj.begin
|
66
|
+
yield obj.end
|
67
|
+
when ::Array, ::Struct
|
68
|
+
obj.each(&block)
|
69
|
+
when ::Complex
|
70
|
+
yield obj.real
|
71
|
+
yield obj.imaginary
|
72
|
+
when ::Rational
|
73
|
+
yield obj.numerator
|
74
|
+
yield obj.denominator
|
75
|
+
end
|
76
|
+
obj.instance_variables.each do |var|
|
77
|
+
yield obj.instance_variable_get(var)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private def ractor_shareable_by_nature?(obj, freeze_all)
|
82
|
+
case obj
|
83
|
+
when ::Module, Ractor
|
84
|
+
true
|
85
|
+
when ::Regexp, ::Range, ::Numeric
|
86
|
+
!freeze_all # Assume that these are literals that would have been frozen in 3.0
|
87
|
+
# unless we're making them shareable, in which case we might as well
|
88
|
+
# freeze them for real.
|
89
|
+
when ::Symbol, false, true, nil # Were only frozen in Ruby 2.3+
|
90
|
+
true
|
91
|
+
else
|
92
|
+
false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/backports/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Backports
|
2
|
-
VERSION = "3.
|
2
|
+
VERSION = "3.20.2" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
|
3
3
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: backports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.20.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc-André Lafortune
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Essential backports that enable many of the nice features of Ruby for
|
14
14
|
earlier versions.
|
@@ -425,12 +425,16 @@ files:
|
|
425
425
|
- lib/backports/2.3.0/numeric.rb
|
426
426
|
- lib/backports/2.3.0/numeric/negative.rb
|
427
427
|
- lib/backports/2.3.0/numeric/positive.rb
|
428
|
+
- lib/backports/2.3.0/queue/close.rb
|
429
|
+
- lib/backports/2.3.0/string.rb
|
428
430
|
- lib/backports/2.3.0/string/uminus.rb
|
429
431
|
- lib/backports/2.3.0/string/uplus.rb
|
430
432
|
- lib/backports/2.3.0/struct.rb
|
431
433
|
- lib/backports/2.3.0/struct/dig.rb
|
432
434
|
- lib/backports/2.3.rb
|
433
435
|
- lib/backports/2.4.0.rb
|
436
|
+
- lib/backports/2.4.0/bignum.rb
|
437
|
+
- lib/backports/2.4.0/bignum/dup.rb
|
434
438
|
- lib/backports/2.4.0/comparable.rb
|
435
439
|
- lib/backports/2.4.0/comparable/clamp.rb
|
436
440
|
- lib/backports/2.4.0/enumerable.rb
|
@@ -528,6 +532,16 @@ files:
|
|
528
532
|
- lib/backports/2.7.0/time/ceil.rb
|
529
533
|
- lib/backports/2.7.0/time/floor.rb
|
530
534
|
- lib/backports/2.7.rb
|
535
|
+
- lib/backports/3.0.0.rb
|
536
|
+
- lib/backports/3.0.0/env.rb
|
537
|
+
- lib/backports/3.0.0/env/except.rb
|
538
|
+
- lib/backports/3.0.0/hash.rb
|
539
|
+
- lib/backports/3.0.0/hash/except.rb
|
540
|
+
- lib/backports/3.0.0/hash/transform_keys.rb
|
541
|
+
- lib/backports/3.0.0/ractor.rb
|
542
|
+
- lib/backports/3.0.0/symbol.rb
|
543
|
+
- lib/backports/3.0.0/symbol/name.rb
|
544
|
+
- lib/backports/3.0.rb
|
531
545
|
- lib/backports/basic_object.rb
|
532
546
|
- lib/backports/force/array_map.rb
|
533
547
|
- lib/backports/force/enumerable_map.rb
|
@@ -535,6 +549,12 @@ files:
|
|
535
549
|
- lib/backports/force/string_length.rb
|
536
550
|
- lib/backports/force/string_size.rb
|
537
551
|
- lib/backports/latest.rb
|
552
|
+
- lib/backports/ractor/cloner.rb
|
553
|
+
- lib/backports/ractor/errors.rb
|
554
|
+
- lib/backports/ractor/filtered_queue.rb
|
555
|
+
- lib/backports/ractor/queues.rb
|
556
|
+
- lib/backports/ractor/ractor.rb
|
557
|
+
- lib/backports/ractor/sharing.rb
|
538
558
|
- lib/backports/rails.rb
|
539
559
|
- lib/backports/rails/array.rb
|
540
560
|
- lib/backports/rails/enumerable.rb
|
@@ -569,7 +589,7 @@ metadata:
|
|
569
589
|
changelog_uri: https://github.com/marcandre/backports/blob/master/CHANGELOG.md
|
570
590
|
source_code_uri: https://github.com/marcandre/backports
|
571
591
|
bug_tracker_uri: https://github.com/marcandre/backports/issues
|
572
|
-
post_install_message:
|
592
|
+
post_install_message:
|
573
593
|
rdoc_options: []
|
574
594
|
require_paths:
|
575
595
|
- lib
|
@@ -584,8 +604,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
584
604
|
- !ruby/object:Gem::Version
|
585
605
|
version: '0'
|
586
606
|
requirements: []
|
587
|
-
rubygems_version: 3.1.
|
588
|
-
signing_key:
|
607
|
+
rubygems_version: 3.1.4
|
608
|
+
signing_key:
|
589
609
|
specification_version: 4
|
590
610
|
summary: Backports of Ruby features for older Ruby.
|
591
611
|
test_files: []
|