rbs 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +12 -0
  6. data/README.md +86 -47
  7. data/Rakefile +54 -21
  8. data/bin/rbs-prof +9 -0
  9. data/bin/run_in_md.rb +49 -0
  10. data/lib/rbs.rb +2 -0
  11. data/lib/rbs/ast/declarations.rb +62 -7
  12. data/lib/rbs/ast/members.rb +41 -17
  13. data/lib/rbs/cli.rb +299 -121
  14. data/lib/rbs/constant.rb +4 -4
  15. data/lib/rbs/constant_table.rb +50 -44
  16. data/lib/rbs/definition.rb +175 -59
  17. data/lib/rbs/definition_builder.rb +647 -603
  18. data/lib/rbs/environment.rb +338 -209
  19. data/lib/rbs/environment_walker.rb +14 -23
  20. data/lib/rbs/errors.rb +141 -3
  21. data/lib/rbs/parser.y +14 -9
  22. data/lib/rbs/prototype/rb.rb +100 -112
  23. data/lib/rbs/prototype/rbi.rb +4 -2
  24. data/lib/rbs/prototype/runtime.rb +10 -6
  25. data/lib/rbs/substitution.rb +8 -1
  26. data/lib/rbs/test/hook.rb +2 -2
  27. data/lib/rbs/test/setup.rb +3 -1
  28. data/lib/rbs/test/test_helper.rb +2 -5
  29. data/lib/rbs/test/type_check.rb +1 -2
  30. data/lib/rbs/type_name_resolver.rb +58 -0
  31. data/lib/rbs/types.rb +94 -2
  32. data/lib/rbs/validator.rb +51 -0
  33. data/lib/rbs/variance_calculator.rb +12 -2
  34. data/lib/rbs/version.rb +1 -1
  35. data/lib/rbs/writer.rb +125 -89
  36. data/rbs.gemspec +0 -10
  37. data/schema/decls.json +15 -0
  38. data/schema/members.json +3 -0
  39. data/stdlib/benchmark/benchmark.rbs +151 -151
  40. data/stdlib/builtin/enumerable.rbs +1 -1
  41. data/stdlib/builtin/file.rbs +0 -3
  42. data/stdlib/builtin/io.rbs +4 -4
  43. data/stdlib/builtin/thread.rbs +2 -2
  44. data/stdlib/csv/csv.rbs +4 -6
  45. data/stdlib/fiber/fiber.rbs +1 -1
  46. data/stdlib/json/json.rbs +1 -1
  47. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  48. data/stdlib/pathname/pathname.rbs +6 -6
  49. data/stdlib/prime/integer-extension.rbs +1 -1
  50. data/stdlib/prime/prime.rbs +44 -44
  51. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  52. metadata +8 -129
@@ -374,7 +374,7 @@ module Enumerable[unchecked out Elem, out Return]: _Each[Elem, Return]
374
374
  | [T] (?T arg0) -> (Elem | T)
375
375
  | [U] (?U arg0) { (Elem arg0) -> U } -> U
376
376
 
377
- def filter_map: [U] () { (Elem arg0) -> U? } -> ::Array[U]
377
+ def filter_map: [U] () { (Elem elem) -> (nil | false | U) } -> ::Array[U]
378
378
  | () -> ::Enumerator[Elem, Return]
379
379
 
380
380
  def chain: (*self enumerables) -> ::Enumerator::Chain[Elem, ::Array[self]]
@@ -60,9 +60,6 @@ class File < IO
60
60
  #
61
61
  # File.absolute_path?("c:/foo") #=> false (on Linux), true (on Windows)
62
62
  #
63
- # # arglists 💪👽🚨 << Delete this section
64
- # File.absolute_path?(file_name) -> true or false
65
- #
66
63
  def self.absolute_path?: (string | _ToPath file_name) -> bool
67
64
 
68
65
  # Returns the last access time for the named file as a Time object.
@@ -480,7 +480,7 @@ class IO < Object
480
480
 
481
481
  def sysseek: (Integer amount, ?Integer whence) -> Integer
482
482
 
483
- def syswrite: (String arg0) -> Integer
483
+ def syswrite: (_ToS arg0) -> Integer
484
484
 
485
485
  # Returns the current offset (in bytes) of *ios* .
486
486
  #
@@ -508,11 +508,11 @@ class IO < Object
508
508
 
509
509
  def ungetc: (String arg0) -> NilClass
510
510
 
511
- def write: (String arg0) -> Integer
511
+ def write: (*_ToS arg0) -> Integer
512
512
 
513
513
  def self.binread: (String name, ?Integer length, ?Integer offset) -> String
514
514
 
515
- def self.binwrite: (String name, String arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
515
+ def self.binwrite: (String name, _ToS arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
516
516
 
517
517
  def self.copy_stream: (String | IO src, String | IO dst, ?Integer copy_length, ?Integer src_offset) -> Integer
518
518
 
@@ -528,7 +528,7 @@ class IO < Object
528
528
 
529
529
  def self.try_convert: (untyped arg0) -> IO?
530
530
 
531
- def self.write: (String name, String arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
531
+ def self.write: (String name, _ToS arg0, ?Integer offset, ?external_encoding: String external_encoding, ?internal_encoding: String internal_encoding, ?encoding: String encoding, ?textmode: untyped textmode, ?binmode: untyped binmode, ?autoclose: untyped autoclose, ?mode: String mode) -> Integer
532
532
 
533
533
  def self.for_fd: (Integer fd, ?Integer mode, ?Integer opt) -> self
534
534
 
@@ -898,7 +898,7 @@ class Thread::ConditionVariable < Object
898
898
  #
899
899
  # If `timeout` is given, this method returns after `timeout` seconds
900
900
  # passed, even if no other thread doesn't signal.
901
- def wait: (Mutex mutex, ?Integer timeout) -> self
901
+ def wait: (Thread::Mutex mutex, ?Integer timeout) -> self
902
902
  end
903
903
 
904
904
  # [Mutex](Mutex) implements a simple semaphore that
@@ -1078,7 +1078,7 @@ class Thread::SizedQueue < Thread::Queue
1078
1078
  # Alias for: [push](SizedQueue.downloaded.ruby_doc#method-i-push)
1079
1079
  alias enq push
1080
1080
 
1081
- def initialize: (Integer max) -> SizedQueue
1081
+ def initialize: (Integer max) -> void
1082
1082
 
1083
1083
  # Returns the maximum size of the queue.
1084
1084
  def max: () -> Integer
@@ -159,7 +159,7 @@
159
159
  # with it.
160
160
  #
161
161
  class CSV < Object
162
- include Enumerable
162
+ include Enumerable[untyped, untyped]
163
163
 
164
164
  # This method is intended as the primary interface for reading CSV files. You
165
165
  # pass a `path` and any `options` you wish to set for the read. Each row of file
@@ -407,7 +407,7 @@ CSV::VERSION: String
407
407
  # processing is activated.
408
408
  #
409
409
  class CSV::Row < Object
410
- include Enumerable
410
+ include Enumerable[untyped, untyped]
411
411
 
412
412
  # If a two-element Array is provided, it is assumed to be a header and field and
413
413
  # the pair is appended. A Hash works the same way with the key being the header
@@ -544,8 +544,6 @@ class CSV::Row < Object
544
544
 
545
545
  def size: (*untyped args) { (*untyped) -> untyped } -> untyped
546
546
 
547
- alias to_ary to_a
548
-
549
547
  # Returns the row as a CSV String. Headers are not used. Equivalent to:
550
548
  #
551
549
  # csv_row.fields.to_csv( options )
@@ -564,7 +562,7 @@ class CSV::Row < Object
564
562
  alias values_at fields
565
563
  end
566
564
 
567
- class CSV::FieldInfo < Struct
565
+ class CSV::FieldInfo < Struct[untyped]
568
566
  end
569
567
 
570
568
  # The error thrown when the parser encounters illegal CSV formatting.
@@ -580,7 +578,7 @@ end
580
578
  # processing is activated.
581
579
  #
582
580
  class CSV::Table[out Elem] < Object
583
- include Enumerable
581
+ include Enumerable[untyped, untyped]
584
582
 
585
583
  # Constructs a new CSV::Table from `array_of_rows`, which are expected to be
586
584
  # CSV::Row objects. All rows are assumed to have the same headers.
@@ -54,7 +54,7 @@
54
54
  # 1000000
55
55
  # FiberError: dead fiber called
56
56
  #
57
- extension Fiber (Fiber)
57
+ class Fiber
58
58
  # Returns the current fiber. You need to `require 'fiber'` before using this
59
59
  # method. If you are not running in the context of a fiber this method will
60
60
  # return the root fiber.
@@ -326,7 +326,7 @@ JSON::SAFE_STATE_PROTOTYPE: json_state
326
326
  #
327
327
  JSON::VERSION: String
328
328
 
329
- JSON::VERSION_ARRAY: Array
329
+ JSON::VERSION_ARRAY: Array[Integer]
330
330
 
331
331
  JSON::VERSION_BUILD: Integer
332
332
 
@@ -0,0 +1,77 @@
1
+ # # mutex_m.rb
2
+ #
3
+ # When 'mutex_m' is required, any object that extends or includes Mutex_m will
4
+ # be treated like a Mutex.
5
+ #
6
+ # Start by requiring the standard library Mutex_m:
7
+ #
8
+ # require "mutex_m.rb"
9
+ #
10
+ # From here you can extend an object with Mutex instance methods:
11
+ #
12
+ # obj = Object.new
13
+ # obj.extend Mutex_m
14
+ #
15
+ # Or mixin Mutex_m into your module to your class inherit Mutex instance methods
16
+ # --- remember to call super() in your class initialize method.
17
+ #
18
+ # class Foo
19
+ # include Mutex_m
20
+ # def initialize
21
+ # # ...
22
+ # super()
23
+ # end
24
+ # # ...
25
+ # end
26
+ # obj = Foo.new
27
+ # # this obj can be handled like Mutex
28
+ #
29
+ module Mutex_m
30
+ def self.append_features: (Module cl) -> untyped
31
+
32
+ def self.define_aliases: (Module cl) -> untyped
33
+
34
+ def self.extend_object: (Object obj) -> untyped
35
+
36
+ public
37
+
38
+ def mu_extended: () -> untyped
39
+
40
+ # See Mutex#lock
41
+ #
42
+ def mu_lock: () -> Thread::Mutex
43
+
44
+ # See Mutex#locked?
45
+ #
46
+ def mu_locked?: () -> bool
47
+
48
+ # See Mutex#synchronize
49
+ #
50
+ def mu_synchronize: [T] () { () -> T } -> T
51
+
52
+ # See Mutex#try_lock
53
+ #
54
+ def mu_try_lock: () -> bool
55
+
56
+ # See Mutex#unlock
57
+ #
58
+ def mu_unlock: () -> Thread::Mutex
59
+
60
+ # See Mutex#sleep
61
+ #
62
+ def sleep: (?Numeric timeout) -> Integer
63
+
64
+ alias locked? mu_locked?
65
+ alias lock mu_lock
66
+ alias unlock mu_unlock
67
+ alias try_lock mu_try_lock
68
+ alias synchronize mu_synchronize
69
+
70
+ private
71
+
72
+ def initialize: (*untyped args) -> untyped
73
+
74
+ def mu_initialize: () -> untyped
75
+ end
76
+
77
+ Mutex_m::VERSION: String
@@ -1066,17 +1066,17 @@ class Pathname
1066
1066
  def prepend_prefix: (untyped prefix, untyped relpath) -> untyped
1067
1067
 
1068
1068
  def split_names: (untyped path) -> untyped
1069
- end
1070
1069
 
1071
- Pathname::SAME_PATHS: Proc
1070
+ SAME_PATHS: Proc
1072
1071
 
1073
- Pathname::SEPARATOR_LIST: String
1072
+ SEPARATOR_LIST: String
1074
1073
 
1075
- Pathname::SEPARATOR_PAT: Regexp
1074
+ SEPARATOR_PAT: Regexp
1076
1075
 
1077
- Pathname::TO_PATH: Symbol
1076
+ TO_PATH: Symbol
1077
+ end
1078
1078
 
1079
- extension Kernel (Pathname)
1079
+ module Kernel
1080
1080
  # Creates a new Pathname object from the given string, `path`, and returns
1081
1081
  # pathname object.
1082
1082
  #
@@ -1,4 +1,4 @@
1
- extension Integer (Prime)
1
+ class Integer
2
2
  # Iterates the given block over all prime numbers.
3
3
  #
4
4
  # See Prime#each for more details.
@@ -129,60 +129,60 @@ class Prime
129
129
  # Returns the singleton instance.
130
130
  #
131
131
  def self.instance: () -> Prime
132
- end
133
132
 
134
- # An abstract class for enumerating pseudo-prime numbers.
135
- #
136
- # Concrete subclasses should override succ, next, rewind.
137
- #
138
- class Prime::PseudoPrimeGenerator
139
- def initialize: (?Integer?) -> void
133
+ # An abstract class for enumerating pseudo-prime numbers.
134
+ #
135
+ # Concrete subclasses should override succ, next, rewind.
136
+ #
137
+ class PseudoPrimeGenerator
138
+ def initialize: (?Integer?) -> void
140
139
 
141
- include Enumerable[Integer, void]
140
+ include Enumerable[Integer, void]
142
141
 
143
- attr_accessor upper_bound (): Integer?
142
+ attr_accessor upper_bound (): Integer?
144
143
 
145
- # Iterates the given block for each prime number.
146
- #
147
- def each: () { (Integer) -> void } -> void
144
+ # Iterates the given block for each prime number.
145
+ #
146
+ def each: () { (Integer) -> void } -> void
148
147
 
149
- # alias of `succ`.
150
- #
151
- def next: () -> Integer
148
+ # alias of `succ`.
149
+ #
150
+ def next: () -> Integer
152
151
 
153
- # Rewinds the internal position for enumeration.
154
- #
155
- # See `Enumerator`#rewind.
156
- #
157
- def rewind: () -> void
152
+ # Rewinds the internal position for enumeration.
153
+ #
154
+ # See `Enumerator`#rewind.
155
+ #
156
+ def rewind: () -> void
158
157
 
159
- def size: () -> Float
158
+ def size: () -> Float
160
159
 
161
- # returns the next pseudo-prime number, and move the internal position forward.
160
+ # returns the next pseudo-prime number, and move the internal position forward.
161
+ #
162
+ # `PseudoPrimeGenerator`#succ raises `NotImplementedError`.
163
+ #
164
+ def succ: () -> Integer
165
+ end
166
+
167
+ # An implementation of `PseudoPrimeGenerator`.
162
168
  #
163
- # `PseudoPrimeGenerator`#succ raises `NotImplementedError`.
169
+ # Uses `EratosthenesSieve`.
164
170
  #
165
- def succ: () -> Integer
166
- end
167
-
168
- # An implementation of `PseudoPrimeGenerator`.
169
- #
170
- # Uses `EratosthenesSieve`.
171
- #
172
- class Prime::EratosthenesGenerator < PseudoPrimeGenerator
173
- end
171
+ class EratosthenesGenerator < PseudoPrimeGenerator
172
+ end
174
173
 
175
- # An implementation of `PseudoPrimeGenerator` which uses a prime table generated
176
- # by trial division.
177
- #
178
- class Prime::TrialDivisionGenerator < PseudoPrimeGenerator
179
- end
174
+ # An implementation of `PseudoPrimeGenerator` which uses a prime table generated
175
+ # by trial division.
176
+ #
177
+ class TrialDivisionGenerator < PseudoPrimeGenerator
178
+ end
180
179
 
181
- # Generates all integers which are greater than 2 and are not divisible by
182
- # either 2 or 3.
183
- #
184
- # This is a pseudo-prime generator, suitable on checking primality of an integer
185
- # by brute force method.
186
- #
187
- class Prime::Generator23 < PseudoPrimeGenerator
180
+ # Generates all integers which are greater than 2 and are not divisible by
181
+ # either 2 or 3.
182
+ #
183
+ # This is a pseudo-prime generator, suitable on checking primality of an integer
184
+ # by brute force method.
185
+ #
186
+ class Generator23 < PseudoPrimeGenerator
187
+ end
188
188
  end
@@ -1,4 +1,4 @@
1
- extension Dir (tmpdir)
1
+ class Dir
2
2
  # Returns the operating system's temporary file path.
3
3
  #
4
4
  def self.tmpdir: () -> String
metadata CHANGED
@@ -1,141 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-15 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '13.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '13.0'
41
- - !ruby/object:Gem::Dependency
42
- name: minitest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '5.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '5.0'
55
- - !ruby/object:Gem::Dependency
56
- name: racc
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 1.4.16
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 1.4.16
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rubycw
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: minitest-reporters
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: 1.3.6
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: 1.3.6
111
- - !ruby/object:Gem::Dependency
112
- name: json
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: 2.3.0
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: 2.3.0
125
- - !ruby/object:Gem::Dependency
126
- name: json-schema
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '2.8'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '2.8'
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
+ dependencies: []
139
13
  description: RBS is the language for type signatures for Ruby and standard library
140
14
  definitions.
141
15
  email:
@@ -157,6 +31,8 @@ files:
157
31
  - bin/annotate-with-rdoc
158
32
  - bin/console
159
33
  - bin/query-rdoc
34
+ - bin/rbs-prof
35
+ - bin/run_in_md.rb
160
36
  - bin/setup
161
37
  - bin/sort
162
38
  - bin/test_runner.rb
@@ -198,7 +74,9 @@ files:
198
74
  - lib/rbs/test/test_helper.rb
199
75
  - lib/rbs/test/type_check.rb
200
76
  - lib/rbs/type_name.rb
77
+ - lib/rbs/type_name_resolver.rb
201
78
  - lib/rbs/types.rb
79
+ - lib/rbs/validator.rb
202
80
  - lib/rbs/variance_calculator.rb
203
81
  - lib/rbs/vendorer.rb
204
82
  - lib/rbs/version.rb
@@ -279,6 +157,7 @@ files:
279
157
  - stdlib/find/find.rbs
280
158
  - stdlib/ipaddr/ipaddr.rbs
281
159
  - stdlib/json/json.rbs
160
+ - stdlib/mutex_m/mutex_m.rbs
282
161
  - stdlib/pathname/pathname.rbs
283
162
  - stdlib/prime/integer-extension.rbs
284
163
  - stdlib/prime/prime.rbs