rbs 4.0.0.dev.4 → 4.0.0.dev.5
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 +4 -4
- data/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +11 -8
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +17 -34
- data/.github/workflows/typecheck.yml +2 -2
- data/.github/workflows/valgrind.yml +42 -0
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +1 -1
- data/README.md +1 -1
- data/Rakefile +32 -5
- data/config.yml +46 -0
- data/core/array.rbs +96 -46
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/comparable.rbs +13 -6
- data/core/complex.rbs +55 -41
- data/core/dir.rbs +4 -4
- data/core/encoding.rbs +7 -10
- data/core/enumerable.rbs +90 -3
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +63 -1
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +40 -20
- data/core/file.rbs +108 -78
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +225 -69
- data/core/gc.rbs +417 -281
- data/core/hash.rbs +1023 -727
- data/core/integer.rbs +104 -110
- data/core/io/buffer.rbs +21 -10
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +82 -19
- data/core/kernel.rbs +70 -59
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +63 -27
- data/core/module.rbs +103 -26
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +43 -35
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +21 -15
- data/core/pathname.rbs +1272 -0
- data/core/proc.rbs +30 -25
- data/core/process.rbs +4 -2
- data/core/ractor.rbs +361 -509
- data/core/random.rbs +17 -0
- data/core/range.rbs +113 -16
- data/core/rational.rbs +56 -85
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -113
- data/core/regexp.rbs +25 -20
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +488 -359
- data/core/signal.rbs +24 -14
- data/core/string.rbs +3171 -1241
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +17 -11
- data/core/thread.rbs +95 -33
- data/core/time.rbs +35 -9
- data/core/trace_point.rbs +7 -4
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +470 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +33 -4
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +77 -3
- data/ext/rbs_extension/ast_translation.h +3 -0
- data/ext/rbs_extension/class_constants.c +8 -2
- data/ext/rbs_extension/class_constants.h +4 -0
- data/ext/rbs_extension/extconf.rb +5 -1
- data/ext/rbs_extension/legacy_location.c +5 -5
- data/ext/rbs_extension/main.c +37 -20
- data/include/rbs/ast.h +85 -38
- data/include/rbs/defines.h +27 -0
- data/include/rbs/lexer.h +30 -11
- data/include/rbs/parser.h +6 -6
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +137 -0
- data/lib/rbs/ast/ruby/comment_block.rb +24 -0
- data/lib/rbs/ast/ruby/declarations.rb +198 -3
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/members.rb +159 -1
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +20 -15
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -51
- data/lib/rbs/cli.rb +52 -19
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -0
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +20 -0
- data/lib/rbs/definition_builder.rb +91 -2
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +227 -74
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -7
- data/lib/rbs/inline_parser.rb +341 -5
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +2 -2
- data/lib/rbs/prototype/rbi.rb +2 -0
- data/lib/rbs/prototype/runtime.rb +8 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +116 -38
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +16 -2
- data/lib/rbs/type_name.rb +1 -1
- data/lib/rbs/types.rb +27 -27
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +3 -2
- data/schema/typeParam.json +17 -1
- data/sig/ast/ruby/annotations.rbs +124 -0
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +87 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +13 -4
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -1
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser.rbs +39 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -1
- data/sig/method_builder.rbs +3 -1
- data/sig/method_types.rbs +1 -1
- data/sig/parser.rbs +16 -2
- data/sig/resolver/type_name_resolver.rbs +35 -7
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/types.rbs +4 -4
- data/src/ast.c +80 -1
- data/src/lexer.c +1392 -1313
- data/src/lexer.re +3 -0
- data/src/lexstate.c +58 -37
- data/src/location.c +4 -4
- data/src/parser.c +412 -145
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -71
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -10
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/bigdecimal/0/big_decimal.rbs +100 -82
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/date/0/date.rbs +67 -59
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +20 -14
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +82 -28
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +9 -27
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/open3/0/open3.rbs +459 -1
- data/stdlib/openssl/0/openssl.rbs +331 -228
- data/stdlib/optparse/0/optparse.rbs +8 -3
- data/stdlib/pathname/0/pathname.rbs +9 -1379
- data/stdlib/psych/0/psych.rbs +4 -4
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +2 -2
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +6 -19
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +1176 -85
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +16 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +24 -16
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/gzip_writer.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +30 -4
data/core/struct.rbs
CHANGED
|
@@ -130,7 +130,7 @@ class Struct[Elem]
|
|
|
130
130
|
# Foo = Struct.new('Foo', :foo, :bar) # => Struct::Foo
|
|
131
131
|
# f = Foo.new(0, 1) # => #<struct Struct::Foo foo=0, bar=1>
|
|
132
132
|
#
|
|
133
|
-
#
|
|
133
|
+
# **Class Name**
|
|
134
134
|
#
|
|
135
135
|
# With string argument `class_name`, returns a new subclass of `Struct` named
|
|
136
136
|
# `Struct::*class_name`*:
|
data/core/symbol.rbs
CHANGED
|
@@ -130,19 +130,25 @@ class Symbol
|
|
|
130
130
|
|
|
131
131
|
# <!--
|
|
132
132
|
# rdoc-file=string.c
|
|
133
|
-
# -
|
|
133
|
+
# - self <=> other -> -1, 0, 1, or nil
|
|
134
134
|
# -->
|
|
135
|
-
#
|
|
136
|
-
# object.to_s`:
|
|
135
|
+
# Compares `self` and `other`, using String#<=>.
|
|
137
136
|
#
|
|
138
|
-
#
|
|
139
|
-
# :foo <=> :foo # => 0
|
|
140
|
-
# :foo <=> :bar # => 1
|
|
137
|
+
# Returns:
|
|
141
138
|
#
|
|
142
|
-
#
|
|
139
|
+
# * `self.to_s <=> other.to_s`, if `other` is a symbol.
|
|
140
|
+
# * `nil`, otherwise.
|
|
143
141
|
#
|
|
142
|
+
# Examples:
|
|
143
|
+
#
|
|
144
|
+
# :bar <=> :foo # => -1
|
|
145
|
+
# :foo <=> :foo # => 0
|
|
146
|
+
# :foo <=> :bar # => 1
|
|
144
147
|
# :foo <=> 'bar' # => nil
|
|
145
148
|
#
|
|
149
|
+
# Class Symbol includes module Comparable, each of whose methods uses Symbol#<=>
|
|
150
|
+
# for comparison.
|
|
151
|
+
#
|
|
146
152
|
# Related: String#<=>.
|
|
147
153
|
#
|
|
148
154
|
def <=>: (Symbol object) -> (-1 | 0 | 1)
|
|
@@ -188,7 +194,7 @@ class Symbol
|
|
|
188
194
|
|
|
189
195
|
# <!--
|
|
190
196
|
# rdoc-file=string.c
|
|
191
|
-
# - capitalize(
|
|
197
|
+
# - capitalize(mapping) -> symbol
|
|
192
198
|
# -->
|
|
193
199
|
# Equivalent to `sym.to_s.capitalize.to_sym`.
|
|
194
200
|
#
|
|
@@ -268,7 +274,7 @@ class Symbol
|
|
|
268
274
|
|
|
269
275
|
# <!--
|
|
270
276
|
# rdoc-file=string.c
|
|
271
|
-
# - downcase(
|
|
277
|
+
# - downcase(mapping) -> symbol
|
|
272
278
|
# -->
|
|
273
279
|
# Equivalent to `sym.to_s.downcase.to_sym`.
|
|
274
280
|
#
|
|
@@ -413,7 +419,7 @@ class Symbol
|
|
|
413
419
|
|
|
414
420
|
# <!--
|
|
415
421
|
# rdoc-file=string.c
|
|
416
|
-
# - swapcase(
|
|
422
|
+
# - swapcase(mapping) -> symbol
|
|
417
423
|
# -->
|
|
418
424
|
# Equivalent to `sym.to_s.swapcase.to_sym`.
|
|
419
425
|
#
|
|
@@ -462,7 +468,7 @@ class Symbol
|
|
|
462
468
|
|
|
463
469
|
# <!--
|
|
464
470
|
# rdoc-file=string.c
|
|
465
|
-
# - upcase(
|
|
471
|
+
# - upcase(mapping) -> symbol
|
|
466
472
|
# -->
|
|
467
473
|
# Equivalent to `sym.to_s.upcase.to_sym`.
|
|
468
474
|
#
|
data/core/thread.rbs
CHANGED
|
@@ -265,7 +265,10 @@ class Thread < Object
|
|
|
265
265
|
# -->
|
|
266
266
|
# Terminates `thr` and schedules another thread to be run, returning the
|
|
267
267
|
# terminated Thread. If this is the main thread, or the last thread, exits the
|
|
268
|
-
# process.
|
|
268
|
+
# process. Note that the caller does not wait for the thread to terminate if the
|
|
269
|
+
# receiver is different from the currently running thread. The termination is
|
|
270
|
+
# asynchronous, and the thread can still run a small amount of ruby code before
|
|
271
|
+
# exiting.
|
|
269
272
|
#
|
|
270
273
|
def kill: () -> Thread?
|
|
271
274
|
|
|
@@ -334,7 +337,10 @@ class Thread < Object
|
|
|
334
337
|
# <!-- rdoc-file=thread.c -->
|
|
335
338
|
# Terminates `thr` and schedules another thread to be run, returning the
|
|
336
339
|
# terminated Thread. If this is the main thread, or the last thread, exits the
|
|
337
|
-
# process.
|
|
340
|
+
# process. Note that the caller does not wait for the thread to terminate if the
|
|
341
|
+
# receiver is different from the currently running thread. The termination is
|
|
342
|
+
# asynchronous, and the thread can still run a small amount of ruby code before
|
|
343
|
+
# exiting.
|
|
338
344
|
#
|
|
339
345
|
def exit: () -> Thread?
|
|
340
346
|
|
|
@@ -364,9 +370,9 @@ class Thread < Object
|
|
|
364
370
|
|
|
365
371
|
# <!--
|
|
366
372
|
# rdoc-file=thread.c
|
|
367
|
-
# - Thread.new { ... }
|
|
368
|
-
# - Thread.new(*args, &proc)
|
|
369
|
-
# - Thread.new(*args) { |args| ... }
|
|
373
|
+
# - Thread.new { ... } -> thread
|
|
374
|
+
# - Thread.new(*args, &proc) -> thread
|
|
375
|
+
# - Thread.new(*args) { |args| ... } -> thread
|
|
370
376
|
# -->
|
|
371
377
|
# Creates a new thread executing the given block.
|
|
372
378
|
#
|
|
@@ -660,7 +666,10 @@ class Thread < Object
|
|
|
660
666
|
# <!-- rdoc-file=thread.c -->
|
|
661
667
|
# Terminates `thr` and schedules another thread to be run, returning the
|
|
662
668
|
# terminated Thread. If this is the main thread, or the last thread, exits the
|
|
663
|
-
# process.
|
|
669
|
+
# process. Note that the caller does not wait for the thread to terminate if the
|
|
670
|
+
# receiver is different from the currently running thread. The termination is
|
|
671
|
+
# asynchronous, and the thread can still run a small amount of ruby code before
|
|
672
|
+
# exiting.
|
|
664
673
|
#
|
|
665
674
|
def terminate: () -> Thread?
|
|
666
675
|
|
|
@@ -947,12 +956,11 @@ class Thread < Object
|
|
|
947
956
|
|
|
948
957
|
# <!--
|
|
949
958
|
# rdoc-file=thread.c
|
|
950
|
-
# -
|
|
951
|
-
# -
|
|
952
|
-
# - thr.raise(exception [, string [, array]])
|
|
959
|
+
# - raise(exception, message = exception.to_s, backtrace = nil, cause: $!)
|
|
960
|
+
# - raise(message = nil, cause: $!)
|
|
953
961
|
# -->
|
|
954
962
|
# Raises an exception from the given thread. The caller does not have to be
|
|
955
|
-
# `thr`. See Kernel#raise for more information.
|
|
963
|
+
# `thr`. See Kernel#raise for more information on arguments.
|
|
956
964
|
#
|
|
957
965
|
# Thread.abort_on_exception = true
|
|
958
966
|
# a = Thread.new { sleep(200) }
|
|
@@ -965,8 +973,8 @@ class Thread < Object
|
|
|
965
973
|
# from prog.rb:2:in `new'
|
|
966
974
|
# from prog.rb:2
|
|
967
975
|
#
|
|
968
|
-
def raise: (?String message) -> nil
|
|
969
|
-
| (_Exception, ?_ToS message, ?Array[Thread::Backtrace::Location] | Array[String] | nil backtrace) -> nil
|
|
976
|
+
def raise: (?String message, ?cause: Exception?) -> nil
|
|
977
|
+
| (_Exception, ?_ToS message, ?Array[Thread::Backtrace::Location] | Array[String] | nil backtrace, ?cause: Exception?) -> nil
|
|
970
978
|
|
|
971
979
|
# <!--
|
|
972
980
|
# rdoc-file=thread.c
|
|
@@ -1378,28 +1386,80 @@ end
|
|
|
1378
1386
|
# <!-- rdoc-file=thread_sync.c -->
|
|
1379
1387
|
# ConditionVariable objects augment class Mutex. Using condition variables, it
|
|
1380
1388
|
# is possible to suspend while in the middle of a critical section until a
|
|
1381
|
-
# resource becomes available.
|
|
1389
|
+
# condition is met, such as a resource becomes available.
|
|
1390
|
+
#
|
|
1391
|
+
# Due to non-deterministic scheduling and spurious wake-ups, users of condition
|
|
1392
|
+
# variables should always use a separate boolean predicate (such as reading from
|
|
1393
|
+
# a boolean variable) to check if the condition is actually met before starting
|
|
1394
|
+
# to wait, and should wait in a loop, re-checking the condition every time the
|
|
1395
|
+
# ConditionVariable is waken up. The idiomatic way of using condition variables
|
|
1396
|
+
# is calling the `wait` method in an `until` loop with the predicate as the loop
|
|
1397
|
+
# condition.
|
|
1398
|
+
#
|
|
1399
|
+
# condvar.wait(mutex) until condition_is_met
|
|
1400
|
+
#
|
|
1401
|
+
# In the example below, we use the boolean variable `resource_available` (which
|
|
1402
|
+
# is protected by `mutex`) to indicate the availability of the resource, and use
|
|
1403
|
+
# `condvar` to wait for that variable to become true. Note that:
|
|
1404
|
+
#
|
|
1405
|
+
# 1. Thread `b` may be scheduled before thread `a1` and `a2`, and may run so
|
|
1406
|
+
# fast that it have already made the resource available before either `a1`
|
|
1407
|
+
# or `a2` starts. Therefore, `a1` and `a2` should check if
|
|
1408
|
+
# `resource_available` is already true before starting to wait.
|
|
1409
|
+
# 2. The `wait` method may spuriously wake up without signalling. Therefore,
|
|
1410
|
+
# thread `a1` and `a2` should recheck `resource_available` after the `wait`
|
|
1411
|
+
# method returns, and go back to wait if the condition is not actually met.
|
|
1412
|
+
# 3. It is possible that thread `a2` starts right after thread `a1` is waken up
|
|
1413
|
+
# by `b`. Thread `a2` may have acquired the `mutex` and consumed the
|
|
1414
|
+
# resource before thread `a1` acquires the `mutex`. This necessitates
|
|
1415
|
+
# rechecking after `wait`, too.
|
|
1382
1416
|
#
|
|
1383
1417
|
# Example:
|
|
1384
1418
|
#
|
|
1385
1419
|
# mutex = Thread::Mutex.new
|
|
1386
|
-
# resource = Thread::ConditionVariable.new
|
|
1387
1420
|
#
|
|
1388
|
-
#
|
|
1389
|
-
#
|
|
1390
|
-
#
|
|
1391
|
-
#
|
|
1392
|
-
#
|
|
1393
|
-
#
|
|
1421
|
+
# resource_available = false
|
|
1422
|
+
# condvar = Thread::ConditionVariable.new
|
|
1423
|
+
#
|
|
1424
|
+
# a1 = Thread.new {
|
|
1425
|
+
# # Thread 'a1' waits for the resource to become available and consumes
|
|
1426
|
+
# # the resource.
|
|
1427
|
+
# mutex.synchronize {
|
|
1428
|
+
# condvar.wait(mutex) until resource_available
|
|
1429
|
+
# # After the loop, 'resource_available' is guaranteed to be true.
|
|
1430
|
+
#
|
|
1431
|
+
# resource_available = false
|
|
1432
|
+
# puts "a1 consumed the resource"
|
|
1433
|
+
# }
|
|
1434
|
+
# }
|
|
1435
|
+
#
|
|
1436
|
+
# a2 = Thread.new {
|
|
1437
|
+
# # Thread 'a2' behaves like 'a1'.
|
|
1438
|
+
# mutex.synchronize {
|
|
1439
|
+
# condvar.wait(mutex) until resource_available
|
|
1440
|
+
# resource_available = false
|
|
1441
|
+
# puts "a2 consumed the resource"
|
|
1442
|
+
# }
|
|
1394
1443
|
# }
|
|
1395
1444
|
#
|
|
1396
1445
|
# b = Thread.new {
|
|
1397
|
-
#
|
|
1398
|
-
#
|
|
1399
|
-
#
|
|
1400
|
-
#
|
|
1446
|
+
# # Thread 'b' periodically makes the resource available.
|
|
1447
|
+
# loop {
|
|
1448
|
+
# mutex.synchronize {
|
|
1449
|
+
# resource_available = true
|
|
1450
|
+
#
|
|
1451
|
+
# # Notify one waiting thread if any. It is possible that neither
|
|
1452
|
+
# # 'a1' nor 'a2 is waiting on 'condvar' at this moment. That's OK.
|
|
1453
|
+
# condvar.signal
|
|
1454
|
+
# }
|
|
1455
|
+
# sleep 1
|
|
1456
|
+
# }
|
|
1401
1457
|
# }
|
|
1402
1458
|
#
|
|
1459
|
+
# # Eventually both 'a1' and 'a2' will have their resources, albeit in an
|
|
1460
|
+
# # unspecified order.
|
|
1461
|
+
# [a1, a2].each {|th| th.join}
|
|
1462
|
+
#
|
|
1403
1463
|
class Thread::ConditionVariable < Object
|
|
1404
1464
|
# <!--
|
|
1405
1465
|
# rdoc-file=thread_sync.c
|
|
@@ -1426,6 +1486,8 @@ class Thread::ConditionVariable < Object
|
|
|
1426
1486
|
# If `timeout` is given, this method returns after `timeout` seconds passed,
|
|
1427
1487
|
# even if no other thread doesn't signal.
|
|
1428
1488
|
#
|
|
1489
|
+
# This method may wake up spuriously due to underlying implementation details.
|
|
1490
|
+
#
|
|
1429
1491
|
# Returns the slept result on `mutex`.
|
|
1430
1492
|
#
|
|
1431
1493
|
def wait: (Thread::Mutex mutex, ?Time::_Timeout? timeout) -> Integer?
|
|
@@ -1453,7 +1515,7 @@ end
|
|
|
1453
1515
|
#
|
|
1454
1516
|
class Thread::Mutex < Object
|
|
1455
1517
|
# <!--
|
|
1456
|
-
# rdoc-file=thread_sync.
|
|
1518
|
+
# rdoc-file=thread_sync.rb
|
|
1457
1519
|
# - mutex.lock -> self
|
|
1458
1520
|
# -->
|
|
1459
1521
|
# Attempts to grab the lock and waits if it isn't available. Raises
|
|
@@ -1462,7 +1524,7 @@ class Thread::Mutex < Object
|
|
|
1462
1524
|
def lock: () -> self
|
|
1463
1525
|
|
|
1464
1526
|
# <!--
|
|
1465
|
-
# rdoc-file=thread_sync.
|
|
1527
|
+
# rdoc-file=thread_sync.rb
|
|
1466
1528
|
# - mutex.locked? -> true or false
|
|
1467
1529
|
# -->
|
|
1468
1530
|
# Returns `true` if this lock is currently held by some thread.
|
|
@@ -1470,7 +1532,7 @@ class Thread::Mutex < Object
|
|
|
1470
1532
|
def locked?: () -> bool
|
|
1471
1533
|
|
|
1472
1534
|
# <!--
|
|
1473
|
-
# rdoc-file=thread_sync.
|
|
1535
|
+
# rdoc-file=thread_sync.rb
|
|
1474
1536
|
# - mutex.owned? -> true or false
|
|
1475
1537
|
# -->
|
|
1476
1538
|
# Returns `true` if this lock is currently held by current thread.
|
|
@@ -1478,7 +1540,7 @@ class Thread::Mutex < Object
|
|
|
1478
1540
|
def owned?: () -> bool
|
|
1479
1541
|
|
|
1480
1542
|
# <!--
|
|
1481
|
-
# rdoc-file=thread_sync.
|
|
1543
|
+
# rdoc-file=thread_sync.rb
|
|
1482
1544
|
# - mutex.synchronize { ... } -> result of the block
|
|
1483
1545
|
# -->
|
|
1484
1546
|
# Obtains a lock, runs the block, and releases the lock when the block
|
|
@@ -1487,7 +1549,7 @@ class Thread::Mutex < Object
|
|
|
1487
1549
|
def synchronize: [X] () { () -> X } -> X
|
|
1488
1550
|
|
|
1489
1551
|
# <!--
|
|
1490
|
-
# rdoc-file=thread_sync.
|
|
1552
|
+
# rdoc-file=thread_sync.rb
|
|
1491
1553
|
# - mutex.try_lock -> true or false
|
|
1492
1554
|
# -->
|
|
1493
1555
|
# Attempts to obtain the lock and returns immediately. Returns `true` if the
|
|
@@ -1496,11 +1558,11 @@ class Thread::Mutex < Object
|
|
|
1496
1558
|
def try_lock: () -> bool
|
|
1497
1559
|
|
|
1498
1560
|
# <!--
|
|
1499
|
-
# rdoc-file=thread_sync.
|
|
1500
|
-
# - mutex.
|
|
1561
|
+
# rdoc-file=thread_sync.rb
|
|
1562
|
+
# - mutex.lock -> self
|
|
1501
1563
|
# -->
|
|
1502
|
-
#
|
|
1503
|
-
# current thread.
|
|
1564
|
+
# Attempts to grab the lock and waits if it isn't available. Raises
|
|
1565
|
+
# `ThreadError` if `mutex` was locked by the current thread.
|
|
1504
1566
|
#
|
|
1505
1567
|
def unlock: () -> self
|
|
1506
1568
|
end
|
data/core/time.rbs
CHANGED
|
@@ -47,24 +47,30 @@
|
|
|
47
47
|
#
|
|
48
48
|
# ## Time Internal Representation
|
|
49
49
|
#
|
|
50
|
-
# Time
|
|
51
|
-
#
|
|
52
|
-
#
|
|
50
|
+
# Conceptually, Time class uses a rational value to represent the number of
|
|
51
|
+
# seconds from *Epoch*, 1970-01-01 00:00:00 UTC. There are no boundary or
|
|
52
|
+
# resolution limitations. The value can be obtained using Time#to_r.
|
|
53
|
+
#
|
|
54
|
+
# The Time class always uses the Gregorian calendar. I.e. the proleptic
|
|
55
|
+
# Gregorian calendar is used. Other calendars, such as Julian calendar, are not
|
|
56
|
+
# supported.
|
|
57
|
+
#
|
|
58
|
+
# The implementation uses a signed 63 bit integer, Integer (Bignum) object or
|
|
59
|
+
# Ratoinal object to represent a rational value. (The signed 63 bit integer is
|
|
60
|
+
# used regardless of 32 and 64 bit environments.) The value represents the
|
|
61
|
+
# number of nanoseconds from *Epoch*. The signed 63 bit integer can represent
|
|
62
|
+
# 1823-11-12 to 2116-02-20. When Integer or Rational object is used (before
|
|
53
63
|
# 1823, after 2116, under nanosecond), Time works slower than when the signed 63
|
|
54
64
|
# bit integer is used.
|
|
55
65
|
#
|
|
56
66
|
# Ruby uses the C function `localtime` and `gmtime` to map between the number
|
|
57
67
|
# and 6-tuple (year,month,day,hour,minute,second). `localtime` is used for local
|
|
58
|
-
# time and
|
|
68
|
+
# time and `gmtime` is used for UTC.
|
|
59
69
|
#
|
|
60
70
|
# Integer and Rational has no range limit, but the localtime and gmtime has
|
|
61
71
|
# range limits due to the C types `time_t` and `struct tm`. If that limit is
|
|
62
72
|
# exceeded, Ruby extrapolates the localtime function.
|
|
63
73
|
#
|
|
64
|
-
# The Time class always uses the Gregorian calendar. I.e. the proleptic
|
|
65
|
-
# Gregorian calendar is used. Other calendars, such as Julian calendar, are not
|
|
66
|
-
# supported.
|
|
67
|
-
#
|
|
68
74
|
# `time_t` can represent 1901-12-14 to 2038-01-19 if it is 32 bit signed
|
|
69
75
|
# integer, -292277022657-01-27 to 292277026596-12-05 if it is 64 bit signed
|
|
70
76
|
# integer. However `localtime` on some platforms doesn't supports negative
|
|
@@ -72,7 +78,7 @@
|
|
|
72
78
|
#
|
|
73
79
|
# `struct tm` has *tm_year* member to represent years. (`tm_year = 0` means the
|
|
74
80
|
# year 1900.) It is defined as `int` in the C standard. *tm_year* can represent
|
|
75
|
-
# between -2147481748 to 2147485547 if `int` is 32 bit.
|
|
81
|
+
# years between -2147481748 to 2147485547 if `int` is 32 bit.
|
|
76
82
|
#
|
|
77
83
|
# Ruby supports leap seconds as far as if the C function `localtime` and
|
|
78
84
|
# `gmtime` supports it. They use the tz database in most Unix systems. The tz
|
|
@@ -984,10 +990,20 @@ class Time < Object
|
|
|
984
990
|
# now = Time.now
|
|
985
991
|
# # => 2022-08-18 10:24:13.5398485 -0500
|
|
986
992
|
# now.utc? # => false
|
|
993
|
+
# now.getutc.utc? # => true
|
|
987
994
|
# utc = Time.utc(2000, 1, 1, 20, 15, 1)
|
|
988
995
|
# # => 2000-01-01 20:15:01 UTC
|
|
989
996
|
# utc.utc? # => true
|
|
990
997
|
#
|
|
998
|
+
# `Time` objects created with these methods are considered to be in UTC:
|
|
999
|
+
#
|
|
1000
|
+
# * Time.utc
|
|
1001
|
+
# * Time#utc
|
|
1002
|
+
# * Time#getutc
|
|
1003
|
+
#
|
|
1004
|
+
# Objects created in other ways will not be treated as UTC even if the
|
|
1005
|
+
# environment variable "TZ" is "UTC".
|
|
1006
|
+
#
|
|
991
1007
|
# Related: Time.utc.
|
|
992
1008
|
#
|
|
993
1009
|
def gmt?: () -> bool
|
|
@@ -1560,10 +1576,20 @@ class Time < Object
|
|
|
1560
1576
|
# now = Time.now
|
|
1561
1577
|
# # => 2022-08-18 10:24:13.5398485 -0500
|
|
1562
1578
|
# now.utc? # => false
|
|
1579
|
+
# now.getutc.utc? # => true
|
|
1563
1580
|
# utc = Time.utc(2000, 1, 1, 20, 15, 1)
|
|
1564
1581
|
# # => 2000-01-01 20:15:01 UTC
|
|
1565
1582
|
# utc.utc? # => true
|
|
1566
1583
|
#
|
|
1584
|
+
# `Time` objects created with these methods are considered to be in UTC:
|
|
1585
|
+
#
|
|
1586
|
+
# * Time.utc
|
|
1587
|
+
# * Time#utc
|
|
1588
|
+
# * Time#getutc
|
|
1589
|
+
#
|
|
1590
|
+
# Objects created in other ways will not be treated as UTC even if the
|
|
1591
|
+
# environment variable "TZ" is "UTC".
|
|
1592
|
+
#
|
|
1567
1593
|
# Related: Time.utc.
|
|
1568
1594
|
#
|
|
1569
1595
|
def utc?: () -> bool
|
data/core/trace_point.rbs
CHANGED
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
# change. Instead, it is recommended to specify the types of events you want to
|
|
26
26
|
# use.
|
|
27
27
|
#
|
|
28
|
-
# To filter what is traced, you can pass any of the following as
|
|
28
|
+
# To filter what is traced, you can pass any number of the following as
|
|
29
|
+
# `events`:
|
|
29
30
|
#
|
|
30
31
|
# `:line`
|
|
31
32
|
# : Execute an expression or statement on a new line.
|
|
@@ -107,8 +108,8 @@ class TracePoint
|
|
|
107
108
|
#
|
|
108
109
|
# A block must be given; otherwise, an ArgumentError is raised.
|
|
109
110
|
#
|
|
110
|
-
# If the trace method isn't
|
|
111
|
-
# is raised.
|
|
111
|
+
# If the trace method isn't supported for the given event(s) filter, a
|
|
112
|
+
# RuntimeError is raised.
|
|
112
113
|
#
|
|
113
114
|
# TracePoint.trace(:line) do |tp|
|
|
114
115
|
# p tp.raised_exception
|
|
@@ -122,7 +123,9 @@ class TracePoint
|
|
|
122
123
|
# end
|
|
123
124
|
# $tp.lineno #=> access from outside (RuntimeError)
|
|
124
125
|
#
|
|
125
|
-
# Access from other threads is
|
|
126
|
+
# Access from other ractors, threads or fibers is forbidden. TracePoints are
|
|
127
|
+
# active per-ractor so if you enable a TracePoint in one ractor, other ractors
|
|
128
|
+
# will not be affected.
|
|
126
129
|
#
|
|
127
130
|
def self.new: (*_ToSym events) { (instance tp) -> void } -> instance
|
|
128
131
|
|
data/core/unbound_method.rbs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# <!-- rdoc-file=proc.c -->
|
|
2
|
-
# Ruby supports two forms of objectified methods. Class Method is used to
|
|
2
|
+
# Ruby supports two forms of objectified methods. Class `Method` is used to
|
|
3
3
|
# represent methods that are associated with a particular object: these method
|
|
4
4
|
# objects are bound to that object. Bound method objects for an object can be
|
|
5
5
|
# created using Object#method.
|
|
@@ -287,10 +287,18 @@ class UnboundMethod
|
|
|
287
287
|
|
|
288
288
|
# <!--
|
|
289
289
|
# rdoc-file=proc.c
|
|
290
|
-
# - meth.source_location -> [String, Integer]
|
|
290
|
+
# - meth.source_location -> [String, Integer, Integer, Integer, Integer]
|
|
291
291
|
# -->
|
|
292
|
-
# Returns the
|
|
293
|
-
#
|
|
292
|
+
# Returns the location where the method was defined. The returned Array
|
|
293
|
+
# contains:
|
|
294
|
+
# (1) the Ruby source filename
|
|
295
|
+
# (2) the line number where the definition starts
|
|
296
|
+
# (3) the column number where the definition starts
|
|
297
|
+
# (4) the line number where the definition ends
|
|
298
|
+
# (5) the column number where the definitions ends
|
|
299
|
+
#
|
|
300
|
+
# This method will return `nil` if the method was not defined in Ruby (i.e.
|
|
301
|
+
# native).
|
|
294
302
|
#
|
|
295
303
|
def source_location: () -> [String, Integer]?
|
|
296
304
|
|
|
@@ -298,8 +306,8 @@ class UnboundMethod
|
|
|
298
306
|
# rdoc-file=proc.c
|
|
299
307
|
# - meth.super_method -> method
|
|
300
308
|
# -->
|
|
301
|
-
# Returns a Method of superclass which would be called when super is used or
|
|
302
|
-
# if there is no method on superclass.
|
|
309
|
+
# Returns a `Method` of superclass which would be called when super is used or
|
|
310
|
+
# nil if there is no method on superclass.
|
|
303
311
|
#
|
|
304
312
|
def super_method: () -> UnboundMethod?
|
|
305
313
|
|
data/docs/aliases.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Aliases
|
|
2
|
+
|
|
3
|
+
This document explains module/class aliases and type aliases.
|
|
4
|
+
|
|
5
|
+
## Module/class alias
|
|
6
|
+
|
|
7
|
+
Module/class aliases give another name to a module/class.
|
|
8
|
+
This is useful for some syntaxes that has lexical constraints.
|
|
9
|
+
|
|
10
|
+
```rbs
|
|
11
|
+
class C
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class D = C # ::D is an alias for ::C
|
|
15
|
+
|
|
16
|
+
class E < D # ::E inherits from ::D, which is actually ::C
|
|
17
|
+
end
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Note that module/class aliases cannot be recursive.
|
|
21
|
+
|
|
22
|
+
So, we can define a *normalization* of aliased module/class names.
|
|
23
|
+
Normalization follows the chain of alias definitions and resolves them to the original module/class defined with `module`/`class` syntax.
|
|
24
|
+
|
|
25
|
+
```rbs
|
|
26
|
+
class C
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class D = C
|
|
30
|
+
class E = D
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`::E` is defined as an alias, and it can be normalized to `::C`.
|
|
34
|
+
|
|
35
|
+
## Type alias
|
|
36
|
+
|
|
37
|
+
The biggest difference from module/class alias is that type alias can be recursive.
|
|
38
|
+
|
|
39
|
+
```rbs
|
|
40
|
+
# cons_cell type is defined recursively
|
|
41
|
+
type cons_cell = nil
|
|
42
|
+
| [Integer, cons_cell]
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This means type aliases *cannot be* normalized generally.
|
|
46
|
+
So, we provide another operation for type alias, `DefinitionBuilder#expand_alias` and its family.
|
|
47
|
+
It substitutes with the immediate right hand side of a type alias.
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
cons_cell ===> nil | [Integer, cons_cell] (expand 1 step)
|
|
51
|
+
===> nil | [Integer, nil | [Integer, cons_cell]] (expand 2 steps)
|
|
52
|
+
===> ... (expand will go infinitely)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Note that the namespace of a type alias *can be* normalized, because they are module names.
|
|
56
|
+
|
|
57
|
+
```rbs
|
|
58
|
+
module M
|
|
59
|
+
type t = String
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
module N = M
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
With the type definition above, a type `::N::t` can be normalized to `::M::t`.
|
|
66
|
+
And then it can be expanded to `::String`.
|
|
67
|
+
|
|
68
|
+
> [!NOTE]
|
|
69
|
+
> This is something like an *unfold* operation in type theory.
|
|
70
|
+
|
|
71
|
+
## Type name resolution
|
|
72
|
+
|
|
73
|
+
Type name resolution in RBS usually rewrites *relative* type names to *absolute* type names.
|
|
74
|
+
`Environment#resolve_type_names` converts all type names in the RBS type definitions, and returns a new `Environment` object.
|
|
75
|
+
|
|
76
|
+
It also *normalizes* modules names in type names.
|
|
77
|
+
|
|
78
|
+
- If the type name can be resolved and normalized successfully, the AST has *absolute* type names.
|
|
79
|
+
- If the type name resolution/normalization fails, the AST has *relative* type names.
|
data/docs/collection.md
CHANGED
|
@@ -159,9 +159,9 @@ For example:
|
|
|
159
159
|
# manifest.yaml
|
|
160
160
|
|
|
161
161
|
dependencies:
|
|
162
|
-
# If your gem depends on
|
|
162
|
+
# If your gem depends on logger but the gemspec doesn't include logger,
|
|
163
163
|
# you need to write the following.
|
|
164
|
-
- name:
|
|
164
|
+
- name: logger
|
|
165
165
|
```
|
|
166
166
|
|
|
167
167
|
If the gem's RBS is managed with [ruby/gem_rbs_collection](https://github.com/ruby/gem_rbs_collection), put it as `gems/GEM_NAME/VERSION/manifest.yaml`. For example, `gems/activesupport/6.0/manifest.yaml`.
|
data/docs/encoding.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# RBS File Encoding
|
|
2
|
+
|
|
3
|
+
## Best Practice
|
|
4
|
+
|
|
5
|
+
**Use UTF-8** for both file encoding and your system locale.
|
|
6
|
+
|
|
7
|
+
## Supported Encodings
|
|
8
|
+
|
|
9
|
+
RBS parser supports ASCII-compatible encodings (similar to Ruby's script encoding support).
|
|
10
|
+
|
|
11
|
+
**Examples**: UTF-8, US-ASCII, Shift JIS, EUC-JP, ...
|
|
12
|
+
|
|
13
|
+
## Unicode Codepoint Symbols
|
|
14
|
+
|
|
15
|
+
String literal types in RBS can contain Unicode codepoint escape sequences (`\uXXXX`).
|
|
16
|
+
|
|
17
|
+
When the file encoding is UTF-8, the parser translates Unicode codepoint symbols:
|
|
18
|
+
|
|
19
|
+
```rbs
|
|
20
|
+
# In UTF-8 encoded files
|
|
21
|
+
|
|
22
|
+
type t = "\u0123" # Translated to the actual Unicode character ģ
|
|
23
|
+
type s = "\u3042" # Translated to the actual Unicode character あ
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
When the file encoding is not UTF-8, Unicode escape sequences are interpreted literally as the string `\uXXXX`:
|
|
27
|
+
|
|
28
|
+
```rbs
|
|
29
|
+
# In non-UTF-8 encoded files
|
|
30
|
+
|
|
31
|
+
type t = "\u0123" # Remains as the literal string "\u0123"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Implementation
|
|
35
|
+
|
|
36
|
+
RBS gem currently doesn't do anything for file encoding. It relies on Ruby's encoding handling, specifically `Encoding.default_external` and `Encoding.default_internal`.
|
|
37
|
+
|
|
38
|
+
`Encoding.default_external` is the encoding Ruby assumes when it reads external resources like files. The Ruby interpreter sets it based on the locale. `Encoding.default_internal` is the encoding Ruby converts the external resources to. The default is `nil` (no conversion.)
|
|
39
|
+
|
|
40
|
+
When your locale is set to use `UTF-8` encoding, `default_external` is `Encoding::UTF_8`. So the RBS file content read from the disk will have UTF-8 encoding.
|
|
41
|
+
|
|
42
|
+
### Parsing non UTF-8 RBS source text
|
|
43
|
+
|
|
44
|
+
If you want to work with another encoding, ensure the source string has ASCII compatible encoding.
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
source = '"日本語"'
|
|
48
|
+
RBS::Parser.parse_type(source.encode(Encoding::EUC_JP)) # => Parses successfully
|
|
49
|
+
RBS::Parser.parse_type(source.encode(Encoding::UTF_32)) # => Returns `nil` since UTF-32 is not ASCII compatible
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Specifying file encoding
|
|
53
|
+
|
|
54
|
+
Currently, RBS doesn't support specifying file encoding directly.
|
|
55
|
+
|
|
56
|
+
You can use `Encoding.default_external` while the gem loads RBS files from the storage.
|