rbs 3.2.2 → 3.3.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +1 -1
  3. data/.github/workflows/ruby.yml +7 -2
  4. data/CHANGELOG.md +85 -0
  5. data/Gemfile.lock +14 -14
  6. data/README.md +11 -2
  7. data/Rakefile +10 -7
  8. data/Steepfile +7 -7
  9. data/core/basic_object.rbs +7 -7
  10. data/core/binding.rbs +3 -3
  11. data/core/builtin.rbs +171 -5
  12. data/core/constants.rbs +17 -17
  13. data/core/dir.rbs +3 -3
  14. data/core/encoding.rbs +434 -628
  15. data/core/enumerator.rbs +37 -0
  16. data/core/exception.rbs +11 -11
  17. data/core/false_class.rbs +5 -11
  18. data/core/fiber.rbs +3 -3
  19. data/core/file_test.rbs +28 -26
  20. data/core/kernel.rbs +900 -21
  21. data/core/marshal.rbs +24 -14
  22. data/core/match_data.rbs +8 -8
  23. data/core/math.rbs +57 -53
  24. data/core/method.rbs +3 -1
  25. data/core/module.rbs +38 -36
  26. data/core/nil_class.rbs +7 -13
  27. data/core/object.rbs +3 -966
  28. data/core/process.rbs +3 -3
  29. data/core/ractor.rbs +2 -2
  30. data/core/rb_config.rbs +64 -43
  31. data/core/regexp.rbs +3 -3
  32. data/core/signal.rbs +10 -4
  33. data/core/struct.rbs +1 -1
  34. data/core/thread.rbs +7 -7
  35. data/core/thread_group.rbs +9 -9
  36. data/core/true_class.rbs +5 -11
  37. data/core/unbound_method.rbs +56 -7
  38. data/core/warning.rbs +33 -0
  39. data/docs/collection.md +56 -6
  40. data/docs/data_and_struct.md +57 -0
  41. data/docs/stdlib.md +61 -2
  42. data/docs/syntax.md +123 -2
  43. data/ext/rbs_extension/lexer.c +624 -569
  44. data/ext/rbs_extension/lexer.h +1 -0
  45. data/ext/rbs_extension/lexer.re +1 -0
  46. data/ext/rbs_extension/lexstate.c +1 -0
  47. data/ext/rbs_extension/parser.c +6 -0
  48. data/goodcheck.yml +2 -2
  49. data/lib/rbs/annotate/formatter.rb +13 -3
  50. data/lib/rbs/annotate/rdoc_source.rb +10 -1
  51. data/lib/rbs/cli/colored_io.rb +48 -0
  52. data/lib/rbs/cli/diff.rb +80 -0
  53. data/lib/rbs/cli.rb +151 -16
  54. data/lib/rbs/collection/config/lockfile.rb +0 -25
  55. data/lib/rbs/collection/config/lockfile_generator.rb +0 -6
  56. data/lib/rbs/collection/installer.rb +1 -1
  57. data/lib/rbs/collection/sources/git.rb +6 -4
  58. data/lib/rbs/collection/sources/local.rb +7 -5
  59. data/lib/rbs/diff.rb +104 -0
  60. data/lib/rbs/environment.rb +1 -1
  61. data/lib/rbs/method_type.rb +23 -0
  62. data/lib/rbs/prototype/rb.rb +2 -9
  63. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  64. data/lib/rbs/prototype/runtime/value_object_generator.rb +236 -0
  65. data/lib/rbs/prototype/runtime.rb +234 -150
  66. data/lib/rbs/sorter.rb +144 -117
  67. data/lib/rbs/test/guaranteed.rb +31 -0
  68. data/lib/rbs/test/type_check.rb +4 -4
  69. data/lib/rbs/test.rb +3 -0
  70. data/lib/rbs/types.rb +184 -3
  71. data/lib/rbs/version.rb +1 -1
  72. data/lib/rbs/writer.rb +4 -4
  73. data/lib/rbs.rb +1 -0
  74. data/rbs.gemspec +1 -0
  75. data/sig/annotate/formatter.rbs +2 -2
  76. data/sig/annotate/rdoc_annotater.rbs +1 -1
  77. data/sig/cli/colored_io.rbs +15 -0
  78. data/sig/cli/diff.rbs +21 -0
  79. data/sig/cli.rbs +2 -0
  80. data/sig/collection/config/lockfile.rbs +0 -6
  81. data/sig/diff.rbs +23 -0
  82. data/sig/errors.rbs +1 -5
  83. data/sig/method_types.rbs +6 -0
  84. data/sig/prototype/runtime.rbs +108 -0
  85. data/sig/rdoc/rbs.rbs +4 -0
  86. data/sig/shims/bundler.rbs +5 -0
  87. data/sig/sorter.rbs +23 -5
  88. data/sig/types.rbs +29 -0
  89. data/stdlib/benchmark/0/benchmark.rbs +1 -1
  90. data/stdlib/cgi/0/core.rbs +2 -2
  91. data/stdlib/did_you_mean/0/did_you_mean.rbs +2 -2
  92. data/stdlib/digest/0/digest.rbs +1 -1
  93. data/stdlib/fileutils/0/fileutils.rbs +1 -1
  94. data/stdlib/forwardable/0/forwardable.rbs +4 -4
  95. data/stdlib/io-console/0/io-console.rbs +1 -1
  96. data/stdlib/json/0/json.rbs +37 -0
  97. data/stdlib/logger/0/logger.rbs +2 -2
  98. data/stdlib/net-http/0/manifest.yaml +1 -1
  99. data/stdlib/net-http/0/net-http.rbs +16 -63
  100. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  101. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  102. data/stdlib/openssl/0/openssl.rbs +1 -1
  103. data/stdlib/pp/0/manifest.yaml +2 -0
  104. data/stdlib/pp/0/pp.rbs +301 -0
  105. data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
  106. data/stdlib/psych/0/manifest.yaml +3 -0
  107. data/stdlib/psych/0/psych.rbs +391 -0
  108. data/stdlib/{yaml → psych}/0/store.rbs +2 -2
  109. data/stdlib/rdoc/0/code_object.rbs +55 -0
  110. data/stdlib/rdoc/0/comment.rbs +60 -0
  111. data/stdlib/rdoc/0/context.rbs +153 -0
  112. data/stdlib/rdoc/0/markup.rbs +119 -0
  113. data/stdlib/rdoc/0/parser.rbs +56 -0
  114. data/stdlib/rdoc/0/rdoc.rbs +0 -372
  115. data/stdlib/rdoc/0/ri.rbs +17 -0
  116. data/stdlib/rdoc/0/store.rbs +48 -0
  117. data/stdlib/rdoc/0/top_level.rbs +97 -0
  118. data/stdlib/socket/0/basic_socket.rbs +1 -1
  119. data/stdlib/socket/0/socket.rbs +1 -1
  120. data/stdlib/uri/0/common.rbs +1 -1
  121. data/stdlib/yaml/0/manifest.yaml +1 -2
  122. data/stdlib/yaml/0/yaml.rbs +1 -199
  123. metadata +46 -9
  124. data/sig/shims/pp.rbs +0 -3
  125. data/sig/shims.rbs +0 -47
data/core/builtin.rbs CHANGED
@@ -1,60 +1,172 @@
1
+ # A type that's convertible to a `Complex`.
2
+ #
1
3
  interface _ToC
4
+ # Convert `self` to a `Complex`.
5
+ #
2
6
  def to_c: () -> Complex
3
7
  end
4
8
 
9
+ # A type that's convertible to a `Rational`.
10
+ #
5
11
  interface _ToR
12
+ # Convert `self` to a `Complex`.
13
+ #
6
14
  def to_r: () -> Rational
7
15
  end
8
16
 
17
+ # A type that's convertible to a `Float`.
18
+ #
9
19
  interface _ToF
20
+ # Convert `self` to a `Float`.
21
+ #
10
22
  def to_f: () -> Float
11
23
  end
12
24
 
25
+ # A type that's convertible to an `Integer`.
26
+ #
13
27
  interface _ToI
28
+ # Convert `self` to an `Integer`.
29
+ #
14
30
  def to_i: () -> Integer
15
31
  end
16
32
 
33
+ # A type that's implicitly convertible to an `Integer`.
34
+ #
35
+ # Implicit `.to_int` conversions are usable all over Ruby's stdlib, such as `Kernel#exit`,
36
+ # `File#chmod`, and `Array#take`. Virtually anywhere that accepts an `Integer` will also accept
37
+ # something that defines `.to_int`.
38
+ #
39
+ # Interestingly, types that define `.to_int` aren't immediately converted in math operations on
40
+ # `Integers` (eg `1 + defines_to_int`): Instead, `.coerce` must be defined on the right-hand-side
41
+ # value.
42
+ #
17
43
  interface _ToInt
44
+ # Converts `self` to an `Integer`.
45
+ #
18
46
  def to_int: () -> Integer
19
47
  end
20
48
 
49
+ # A type that's convertible to a `String`.
50
+ #
21
51
  interface _ToS
52
+ # Converts `self` to a `String`.
53
+ #
22
54
  def to_s: () -> String
23
55
  end
24
56
 
57
+ # A type that's implicitly convertible to a `String`.
58
+ #
59
+ # Implicit `.to_str` conversions are usable all over Ruby's stdlib, such as `Kernel#abort`,
60
+ # `String#+`, and `Object#send`. Virtually anywhere that accepts a `String` will also accept
61
+ # something that defines `.to_Str`.
62
+ #
63
+ # Types that define `.to_str` are also usable wherever paths are expected (See the `path` type
64
+ # alias).
65
+ #
25
66
  interface _ToStr
67
+ # Converts `self` to a `String`.
68
+ #
26
69
  def to_str: () -> String
27
70
  end
28
71
 
72
+ # A type that's explicitly convertible to a `String`.
73
+ #
74
+ # Interestingly enough, most methods that accept `Symbol` in the standard library _do not_ accept
75
+ # an object that defines `.to_sym` (unlike `String` and `.to_str`).
76
+ #
77
+ # There are only two places that `Symbol | _ToSym`, and they're quite obscure:
78
+ # - `Kernel#warn`'s `category:` optional parameter. (Oddly enough, not for `Warning.warn`, though.)
79
+ # - `TracePoint#trace`'s `event`s parameter.
80
+ # Additionally, the `rb_iseq_load` C function, only accessible through `Fiddle`, uses `.to_sym`
81
+ # internally.
82
+ #
29
83
  interface _ToSym
84
+ # Converts `self` to a `Symbol`.
85
+ #
30
86
  def to_sym: () -> Symbol
31
87
  end
32
88
 
89
+ # A type that's convertible to a `Hash`.
90
+ #
33
91
  interface _ToH[K, V]
92
+ # Converts `self` to a `Hash`.
93
+ #
34
94
  def to_h: () -> Hash[K, V]
35
95
  end
36
96
 
97
+ # A type that's implicitly convertible to a `Hash`.
98
+ #
99
+ # Implicit `.to_hash` conversions are usable infrequently in Ruby's stdlib, such as `Io#popen`,
100
+ # `Kernel#sprintf`, and `Enumerable#tally`. It's also used with the `**` "splatsplat" operator.
101
+ #
37
102
  interface _ToHash[K, V]
103
+ # Converts `self` to a `Hash`.
104
+ #
38
105
  def to_hash: () -> Hash[K, V]
39
106
  end
40
107
 
108
+ # A type that's convertible to an `Array`.
109
+ #
41
110
  interface _ToA[T]
111
+ # Converts `self` to an `Array`.
112
+ #
42
113
  def to_a: () -> Array[T]
43
114
  end
44
115
 
116
+ # A type that's implicitly convertible to an `Array`.
117
+ #
118
+ # Implicit `.to_ary` conversions are usable semi-frequently in Ruby's stdlib, such as `Dir#glob`,
119
+ # `Regex#union`, and `Class#private`. It's also used with the `*` "splat" operator.
120
+ #
45
121
  interface _ToAry[T]
122
+ # Converts `self` to an `Array`.
123
+ #
46
124
  def to_ary: () -> Array[T]
47
125
  end
48
126
 
127
+ # A type that's convertible to a `Proc`.
128
+ #
129
+ # This is implicitly called when the `&` "block-passing" operator is used, in addition to a handful
130
+ # of other places, such as `Hash#default_proc=`.
131
+ #
49
132
  interface _ToProc
133
+ # Converts `self` to a `Proc.`
134
+ #
50
135
  def to_proc: () -> Proc
51
136
  end
52
137
 
138
+ # A type that's convertible to a `String` that contains a filepath.
139
+ #
140
+ # Implicit `.to_path` conversions are usable throughout Ruby's stdlib, whenever a file path is
141
+ # expected, such as `Dir#mkdir`, `File#open`, and `UNIXSocket#read`. These functions, however, also
142
+ # accept types that define `.to_str`. See the `path` type alias.
143
+ #
53
144
  interface _ToPath
145
+ # Converts `self` to a `String` containing a filepath.
146
+ #
54
147
  def to_path: () -> String
55
148
  end
56
149
 
150
+ # A type that's convertible to an `IO`.
151
+ #
152
+ # Implicit `.to_io` conversions are usuable infrequently in Ruby's stdlib, such as `IO#reopen`,
153
+ # `File.exist?`, and `Kernel#select`.
154
+ #
155
+ interface _ToIO
156
+ # Converts `self` to an `IO` object.
157
+ #
158
+ def to_io: () -> IO
159
+ end
160
+
161
+ # A type that defines the `.inspect` method.
162
+ #
163
+ # Since `Object` defines `.inspect`, nearly every object in Ruby has it defined: Only those that
164
+ # derive from `BasicObject`, or `undef inspect` won't have it. It's used in a few locations,
165
+ # such as `Kernel#p` and `Array#join`.
166
+ #
57
167
  interface _Inspect
168
+ # Returns a debugging representation of `self`.
169
+ #
58
170
  def inspect: () -> String
59
171
  end
60
172
 
@@ -76,6 +188,7 @@ end
76
188
 
77
189
  interface _Writer
78
190
  # Writes the +data+ string. Returns the number of bytes written
191
+ #
79
192
  def write: (*_ToS data) -> Integer
80
193
  end
81
194
 
@@ -85,8 +198,20 @@ interface _Rewindable
85
198
  def rewind: () -> Integer
86
199
  end
87
200
 
88
- interface _ToIO
89
- def to_io: () -> IO
201
+ # A type that's usable like a `Range[T]`.
202
+ #
203
+ # Implicit `_Range` usage is usable frequently in ruby's stdlib, such as `Comparable#clamp`,
204
+ # `String#[]`, and `Kernel#rand`.
205
+ #
206
+ interface _Range[T]
207
+ # The beginning value, `nil` if there is no beginning.
208
+ def begin: () -> T?
209
+
210
+ # The ending value, `nil` if there is no ending.
211
+ def end: () -> T?
212
+
213
+ # Whether or not to include the end in the range.
214
+ def exclude_end?: () -> bool
90
215
  end
91
216
 
92
217
  interface _Exception
@@ -94,15 +219,56 @@ interface _Exception
94
219
  | (String arg0) -> Exception
95
220
  end
96
221
 
222
+ # Represents an `Integer`, or a type convertible to it (via `.to_int`).
223
+ #
97
224
  type int = Integer | _ToInt
98
- type real = Integer | Float | Rational
99
225
 
226
+ # Represents a `Float`, or a type convertible to it (via `.to_f`).
227
+ #
228
+ type float = Float | _ToF
229
+
230
+ # Represents a `Range[T]`, or a type that acts like it (via `.begin`, `.end`, and `.exclude_end?`).
231
+ #
232
+ type range[T] = Range[T] | _Range[T]
233
+
234
+ # Represents a `String`, or a type convertible to it (via `.to_str`).
235
+ #
100
236
  type string = String | _ToStr
101
- type encoding = Encoding | string
102
- type path = string | _ToPath
103
237
 
238
+ # Represents an `Array[T]`, or a type convertible to it (via `.to_ary`).
239
+ #
240
+ type array[T] = Array[T] | _ToAry[T]
241
+
242
+ # Represents a `Hash[K, V]`, or a type convertible to it (via `.to_hash`).
243
+ #
244
+ type hash[K, V] = Hash[K, V] | _ToHash[K, V]
245
+
246
+ # Represents an `IO`, or a type convertible to it (via `.to_io`).
247
+ #
104
248
  type io = IO | _ToIO
105
249
 
250
+ # A filesystem path: Either something that defines `.to_path`, or a `String` (or a type that is
251
+ # convertible to a string via `.to_str`).
252
+ #
253
+ # If a type defines both `.to_path` and `.to_str`, the `.to_path` function is called.
254
+ #
255
+ type path = string | _ToPath
256
+
257
+ # An `Encoding`, or a `String` (or type that defines `.to_str`) that represents it.
258
+ #
259
+ type encoding = Encoding | string
260
+
261
+ # A real number, ie not a `Complex`.
262
+ #
263
+ type real = Integer | Float | Rational
264
+
265
+ # Represents a `Symbol` or a `string`.
266
+ #
267
+ # A lot of builtin functions accept either a Symbol, a String, or something which has `.to_str`
268
+ # defined.
269
+ #
270
+ type interned = Symbol | string
271
+
106
272
  # `boolish` is a type for documentation.
107
273
  # It means the value of this type is only for testing a condition.
108
274
  # Unlike `bool` type, it doesn't require the value is one of `true` or `false`.
data/core/constants.rbs CHANGED
@@ -4,16 +4,16 @@
4
4
  #
5
5
  # See ARGF (the class) for more details.
6
6
  #
7
- ::ARGF: RBS::Unnamed::ARGFClass
7
+ ARGF: RBS::Unnamed::ARGFClass
8
8
 
9
9
  # <!-- rdoc-file=ruby.c -->
10
10
  # ARGV contains the command line arguments used to run ruby.
11
11
  #
12
12
  # A library like OptionParser can be used to process command-line arguments.
13
13
  #
14
- ::ARGV: Array[String]
14
+ ARGV: Array[String]
15
15
 
16
- ::CROSS_COMPILING: NilClass
16
+ CROSS_COMPILING: true?
17
17
 
18
18
  # <!-- rdoc-file=ruby.c -->
19
19
  # DATA is a File that contains the data section of the executed file. To create
@@ -27,70 +27,70 @@
27
27
  # $ ruby t.rb
28
28
  # hello world!
29
29
  #
30
- ::DATA: File
30
+ DATA: File
31
31
 
32
32
  # <!-- rdoc-file=version.c -->
33
33
  # The copyright string for ruby
34
34
  #
35
- ::RUBY_COPYRIGHT: String
35
+ RUBY_COPYRIGHT: String
36
36
 
37
37
  # <!-- rdoc-file=version.c -->
38
38
  # The full ruby version string, like `ruby -v` prints
39
39
  #
40
- ::RUBY_DESCRIPTION: String
40
+ RUBY_DESCRIPTION: String
41
41
 
42
42
  # <!-- rdoc-file=version.c -->
43
43
  # The engine or interpreter this ruby uses.
44
44
  #
45
- ::RUBY_ENGINE: String
45
+ RUBY_ENGINE: String
46
46
 
47
47
  # <!-- rdoc-file=version.c -->
48
48
  # The version of the engine or interpreter this ruby uses.
49
49
  #
50
- ::RUBY_ENGINE_VERSION: String
50
+ RUBY_ENGINE_VERSION: String
51
51
 
52
52
  # <!-- rdoc-file=version.c -->
53
53
  # The patchlevel for this ruby. If this is a development build of ruby the
54
54
  # patchlevel will be -1
55
55
  #
56
- ::RUBY_PATCHLEVEL: Integer
56
+ RUBY_PATCHLEVEL: Integer
57
57
 
58
58
  # <!-- rdoc-file=version.c -->
59
59
  # The platform for this ruby
60
60
  #
61
- ::RUBY_PLATFORM: String
61
+ RUBY_PLATFORM: String
62
62
 
63
63
  # <!-- rdoc-file=version.c -->
64
64
  # The date this ruby was released
65
65
  #
66
- ::RUBY_RELEASE_DATE: String
66
+ RUBY_RELEASE_DATE: String
67
67
 
68
68
  # <!-- rdoc-file=version.c -->
69
69
  # The GIT commit hash for this ruby.
70
70
  #
71
- ::RUBY_REVISION: Integer
71
+ RUBY_REVISION: String
72
72
 
73
73
  # <!-- rdoc-file=version.c -->
74
74
  # The running version of ruby
75
75
  #
76
- ::RUBY_VERSION: String
76
+ RUBY_VERSION: String
77
77
 
78
78
  # <!-- rdoc-file=io.c -->
79
79
  # Holds the original stderr
80
80
  #
81
- ::STDERR: IO
81
+ STDERR: IO
82
82
 
83
83
  # <!-- rdoc-file=io.c -->
84
84
  # Holds the original stdin
85
85
  #
86
- ::STDIN: IO
86
+ STDIN: IO
87
87
 
88
88
  # <!-- rdoc-file=io.c -->
89
89
  # Holds the original stdout
90
90
  #
91
- ::STDOUT: IO
91
+ STDOUT: IO
92
92
 
93
93
  # <!-- rdoc-file=vm.c -->
94
94
  # The Binding of the top level scope
95
95
  #
96
- ::TOPLEVEL_BINDING: Binding
96
+ TOPLEVEL_BINDING: Binding
data/core/dir.rbs CHANGED
@@ -241,7 +241,7 @@ class Dir
241
241
  # -->
242
242
  # Returns `true` if the named file is a directory, `false` otherwise.
243
243
  #
244
- def self.exist?: (path | _ToIO file_name) -> bool
244
+ def self.exist?: (path | io file_name) -> bool
245
245
 
246
246
  # <!--
247
247
  # rdoc-file=dir.c
@@ -371,8 +371,8 @@ class Dir
371
371
  #
372
372
  # Dir.glob("**/lib/*.rb") #=> ["lib/song.rb"]
373
373
  #
374
- def self.glob: (_ToAry[path] | path pattern, ?int flags, ?base: path?, ?sort: bool) -> Array[String]
375
- | (_ToAry[path] | path pattern, ?int flags, ?base: path?, ?sort: bool) { (String pathname) -> void } -> nil
374
+ def self.glob: (array[path] | path pattern, ?int flags, ?base: path?, ?sort: bool) -> Array[String]
375
+ | (array[path] | path pattern, ?int flags, ?base: path?, ?sort: bool) { (String pathname) -> void } -> nil
376
376
 
377
377
  # <!--
378
378
  # rdoc-file=dir.c