backports 3.18.0 → 3.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +435 -292
  3. data/Gemfile +3 -16
  4. data/README.md +306 -156
  5. data/backports.gemspec +1 -1
  6. data/lib/backports/2.0.0.rb +1 -1
  7. data/lib/backports/2.1.0/module/singleton_class.rb +8 -0
  8. data/lib/backports/2.1.0.rb +1 -1
  9. data/lib/backports/2.2.0/string/unicode_normalize.rb +3 -3
  10. data/lib/backports/2.2.0.rb +1 -1
  11. data/lib/backports/2.3.0/queue/close.rb +48 -0
  12. data/lib/backports/2.3.0/string.rb +3 -0
  13. data/lib/backports/2.3.0/struct/dig.rb +2 -0
  14. data/lib/backports/2.3.0.rb +1 -1
  15. data/lib/backports/2.4.0/bignum/dup.rb +5 -0
  16. data/lib/backports/2.4.0/bignum.rb +3 -0
  17. data/lib/backports/2.4.0/string/unpack1.rb +7 -0
  18. data/lib/backports/2.4.0.rb +1 -1
  19. data/lib/backports/2.5.0/dir/children.rb +4 -0
  20. data/lib/backports/2.5.0/dir/each_child.rb +7 -0
  21. data/lib/backports/2.5.0/hash/transform_keys.rb +10 -3
  22. data/lib/backports/2.5.0/string/undump.rb +2 -2
  23. data/lib/backports/2.5.0.rb +1 -1
  24. data/lib/backports/2.5.rb +1 -1
  25. data/lib/backports/2.6.0/enumerable/chain.rb +2 -0
  26. data/lib/backports/2.6.0.rb +2 -2
  27. data/lib/backports/2.6.rb +1 -1
  28. data/lib/backports/2.7.0/complex/{comparision.rb → comparison.rb} +0 -0
  29. data/lib/backports/2.7.0/enumerable/tally.rb +4 -3
  30. data/lib/backports/2.7.0/symbol/end_with.rb +9 -0
  31. data/lib/backports/2.7.0/symbol.rb +3 -0
  32. data/lib/backports/2.7.0.rb +2 -2
  33. data/lib/backports/3.0.0/env/except.rb +10 -0
  34. data/lib/backports/3.0.0/env.rb +3 -0
  35. data/lib/backports/3.0.0/hash/except.rb +10 -0
  36. data/lib/backports/3.0.0/hash/transform_keys.rb +48 -0
  37. data/lib/backports/3.0.0/hash.rb +3 -0
  38. data/lib/backports/3.0.0/ractor.rb +19 -0
  39. data/lib/backports/3.0.0/symbol/name.rb +21 -0
  40. data/lib/backports/3.0.0/symbol.rb +3 -0
  41. data/lib/backports/3.0.0.rb +3 -0
  42. data/lib/backports/3.0.rb +1 -0
  43. data/lib/backports/3.1.0/array/intersect.rb +16 -0
  44. data/lib/backports/3.1.0/array.rb +3 -0
  45. data/lib/backports/3.1.0/class/descendants.rb +11 -0
  46. data/lib/backports/3.1.0/class/subclasses.rb +11 -0
  47. data/lib/backports/3.1.0/class.rb +3 -0
  48. data/lib/backports/3.1.0/enumerable/compact.rb +5 -0
  49. data/lib/backports/3.1.0/enumerable/tally.rb +18 -0
  50. data/lib/backports/3.1.0/enumerable.rb +3 -0
  51. data/lib/backports/3.1.0/file/dirname.rb +16 -0
  52. data/lib/backports/3.1.0/file.rb +3 -0
  53. data/lib/backports/3.1.0/integer/try_convert.rb +7 -0
  54. data/lib/backports/3.1.0/integer.rb +3 -0
  55. data/lib/backports/3.1.0/match_data/match.rb +5 -0
  56. data/lib/backports/3.1.0/match_data/match_length.rb +6 -0
  57. data/lib/backports/3.1.0/match_data.rb +3 -0
  58. data/lib/backports/3.1.0/struct/keyword_init.rb +5 -0
  59. data/lib/backports/3.1.0/struct.rb +3 -0
  60. data/lib/backports/3.1.0.rb +3 -0
  61. data/lib/backports/3.1.rb +1 -0
  62. data/lib/backports/latest.rb +1 -1
  63. data/lib/backports/ractor/cloner.rb +103 -0
  64. data/lib/backports/ractor/errors.rb +20 -0
  65. data/lib/backports/ractor/filtered_queue.rb +205 -0
  66. data/lib/backports/ractor/queues.rb +66 -0
  67. data/lib/backports/ractor/ractor.rb +272 -0
  68. data/lib/backports/ractor/sharing.rb +97 -0
  69. data/lib/backports/version.rb +1 -1
  70. metadata +51 -8
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Backports
2
- VERSION = "3.18.0" unless Backports.constants.include? :VERSION # the guard is against a redefinition warning that happens on Travis
2
+ VERSION = "3.23.0" 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.18.0
4
+ version: 3.23.0
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: 2020-06-22 00:00:00.000000000 Z
11
+ date: 2021-12-28 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.
@@ -391,6 +391,7 @@ files:
391
391
  - lib/backports/2.1.0/fixnum/bit_length.rb
392
392
  - lib/backports/2.1.0/module.rb
393
393
  - lib/backports/2.1.0/module/include.rb
394
+ - lib/backports/2.1.0/module/singleton_class.rb
394
395
  - lib/backports/2.1.rb
395
396
  - lib/backports/2.2.0.rb
396
397
  - lib/backports/2.2.0/enumerable.rb
@@ -425,12 +426,16 @@ files:
425
426
  - lib/backports/2.3.0/numeric.rb
426
427
  - lib/backports/2.3.0/numeric/negative.rb
427
428
  - lib/backports/2.3.0/numeric/positive.rb
429
+ - lib/backports/2.3.0/queue/close.rb
430
+ - lib/backports/2.3.0/string.rb
428
431
  - lib/backports/2.3.0/string/uminus.rb
429
432
  - lib/backports/2.3.0/string/uplus.rb
430
433
  - lib/backports/2.3.0/struct.rb
431
434
  - lib/backports/2.3.0/struct/dig.rb
432
435
  - lib/backports/2.3.rb
433
436
  - lib/backports/2.4.0.rb
437
+ - lib/backports/2.4.0/bignum.rb
438
+ - lib/backports/2.4.0/bignum/dup.rb
434
439
  - lib/backports/2.4.0/comparable.rb
435
440
  - lib/backports/2.4.0/comparable/clamp.rb
436
441
  - lib/backports/2.4.0/enumerable.rb
@@ -451,6 +456,7 @@ files:
451
456
  - lib/backports/2.4.0/regexp/match.rb
452
457
  - lib/backports/2.4.0/string.rb
453
458
  - lib/backports/2.4.0/string/match.rb
459
+ - lib/backports/2.4.0/string/unpack1.rb
454
460
  - lib/backports/2.4.0/true_class.rb
455
461
  - lib/backports/2.4.0/true_class/dup.rb
456
462
  - lib/backports/2.4.rb
@@ -519,15 +525,46 @@ files:
519
525
  - lib/backports/2.7.0/comparable.rb
520
526
  - lib/backports/2.7.0/comparable/clamp.rb
521
527
  - lib/backports/2.7.0/complex.rb
522
- - lib/backports/2.7.0/complex/comparision.rb
528
+ - lib/backports/2.7.0/complex/comparison.rb
523
529
  - lib/backports/2.7.0/enumerable.rb
524
530
  - lib/backports/2.7.0/enumerable/filter_map.rb
525
531
  - lib/backports/2.7.0/enumerable/tally.rb
526
532
  - lib/backports/2.7.0/enumerator.rb
527
533
  - lib/backports/2.7.0/enumerator/produce.rb
534
+ - lib/backports/2.7.0/symbol.rb
535
+ - lib/backports/2.7.0/symbol/end_with.rb
528
536
  - lib/backports/2.7.0/time/ceil.rb
529
537
  - lib/backports/2.7.0/time/floor.rb
530
538
  - lib/backports/2.7.rb
539
+ - lib/backports/3.0.0.rb
540
+ - lib/backports/3.0.0/env.rb
541
+ - lib/backports/3.0.0/env/except.rb
542
+ - lib/backports/3.0.0/hash.rb
543
+ - lib/backports/3.0.0/hash/except.rb
544
+ - lib/backports/3.0.0/hash/transform_keys.rb
545
+ - lib/backports/3.0.0/ractor.rb
546
+ - lib/backports/3.0.0/symbol.rb
547
+ - lib/backports/3.0.0/symbol/name.rb
548
+ - lib/backports/3.0.rb
549
+ - lib/backports/3.1.0.rb
550
+ - lib/backports/3.1.0/array.rb
551
+ - lib/backports/3.1.0/array/intersect.rb
552
+ - lib/backports/3.1.0/class.rb
553
+ - lib/backports/3.1.0/class/descendants.rb
554
+ - lib/backports/3.1.0/class/subclasses.rb
555
+ - lib/backports/3.1.0/enumerable.rb
556
+ - lib/backports/3.1.0/enumerable/compact.rb
557
+ - lib/backports/3.1.0/enumerable/tally.rb
558
+ - lib/backports/3.1.0/file.rb
559
+ - lib/backports/3.1.0/file/dirname.rb
560
+ - lib/backports/3.1.0/integer.rb
561
+ - lib/backports/3.1.0/integer/try_convert.rb
562
+ - lib/backports/3.1.0/match_data.rb
563
+ - lib/backports/3.1.0/match_data/match.rb
564
+ - lib/backports/3.1.0/match_data/match_length.rb
565
+ - lib/backports/3.1.0/struct.rb
566
+ - lib/backports/3.1.0/struct/keyword_init.rb
567
+ - lib/backports/3.1.rb
531
568
  - lib/backports/basic_object.rb
532
569
  - lib/backports/force/array_map.rb
533
570
  - lib/backports/force/enumerable_map.rb
@@ -535,6 +572,12 @@ files:
535
572
  - lib/backports/force/string_length.rb
536
573
  - lib/backports/force/string_size.rb
537
574
  - lib/backports/latest.rb
575
+ - lib/backports/ractor/cloner.rb
576
+ - lib/backports/ractor/errors.rb
577
+ - lib/backports/ractor/filtered_queue.rb
578
+ - lib/backports/ractor/queues.rb
579
+ - lib/backports/ractor/ractor.rb
580
+ - lib/backports/ractor/sharing.rb
538
581
  - lib/backports/rails.rb
539
582
  - lib/backports/rails/array.rb
540
583
  - lib/backports/rails/enumerable.rb
@@ -566,10 +609,10 @@ homepage: http://github.com/marcandre/backports
566
609
  licenses:
567
610
  - MIT
568
611
  metadata:
569
- changelog_uri: https://github.com/marcandre/backports/blob/master/CHANGELOG.rdoc
612
+ changelog_uri: https://github.com/marcandre/backports/blob/master/CHANGELOG.md
570
613
  source_code_uri: https://github.com/marcandre/backports
571
614
  bug_tracker_uri: https://github.com/marcandre/backports/issues
572
- post_install_message:
615
+ post_install_message:
573
616
  rdoc_options: []
574
617
  require_paths:
575
618
  - lib
@@ -584,8 +627,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
584
627
  - !ruby/object:Gem::Version
585
628
  version: '0'
586
629
  requirements: []
587
- rubygems_version: 3.1.2
588
- signing_key:
630
+ rubygems_version: 3.3.3
631
+ signing_key:
589
632
  specification_version: 4
590
633
  summary: Backports of Ruby features for older Ruby.
591
634
  test_files: []