rbs 1.1.1 → 1.3.1

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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -1
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +81 -0
  5. data/README.md +1 -1
  6. data/Rakefile +11 -0
  7. data/Steepfile +1 -0
  8. data/core/array.rbs +2 -2
  9. data/core/basic_object.rbs +1 -1
  10. data/core/enumerable.rbs +1 -1
  11. data/core/hash.rbs +13 -5
  12. data/core/io.rbs +4 -4
  13. data/core/kernel.rbs +2 -2
  14. data/core/marshal.rbs +4 -3
  15. data/core/module.rbs +1 -1
  16. data/core/numeric.rbs +10 -0
  17. data/core/proc.rbs +1 -1
  18. data/core/random.rbs +4 -2
  19. data/core/range.rbs +2 -2
  20. data/core/struct.rbs +3 -2
  21. data/core/thread.rbs +1 -1
  22. data/docs/CONTRIBUTING.md +5 -3
  23. data/docs/rbs_by_example.md +328 -0
  24. data/docs/sigs.md +21 -2
  25. data/docs/stdlib.md +1 -1
  26. data/docs/syntax.md +11 -14
  27. data/lib/rbs.rb +1 -0
  28. data/lib/rbs/ast/annotation.rb +2 -2
  29. data/lib/rbs/ast/comment.rb +2 -2
  30. data/lib/rbs/ast/declarations.rb +37 -22
  31. data/lib/rbs/ast/members.rb +26 -26
  32. data/lib/rbs/cli.rb +3 -0
  33. data/lib/rbs/constant_table.rb +4 -1
  34. data/lib/rbs/definition.rb +1 -1
  35. data/lib/rbs/definition_builder.rb +16 -18
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +10 -2
  37. data/lib/rbs/definition_builder/method_builder.rb +4 -2
  38. data/lib/rbs/errors.rb +36 -0
  39. data/lib/rbs/location.rb +106 -2
  40. data/lib/rbs/locator.rb +205 -0
  41. data/lib/rbs/method_type.rb +2 -2
  42. data/lib/rbs/parser.rb +1315 -962
  43. data/lib/rbs/parser.y +411 -75
  44. data/lib/rbs/prototype/rb.rb +7 -3
  45. data/lib/rbs/prototype/runtime.rb +118 -42
  46. data/lib/rbs/test/hook.rb +8 -2
  47. data/lib/rbs/type_name.rb +2 -3
  48. data/lib/rbs/type_name_resolver.rb +1 -1
  49. data/lib/rbs/types.rb +36 -34
  50. data/lib/rbs/version.rb +1 -1
  51. data/lib/rbs/writer.rb +4 -2
  52. data/rbs.gemspec +1 -1
  53. data/sig/ancestor_builder.rbs +2 -0
  54. data/sig/annotation.rbs +1 -1
  55. data/sig/cli.rbs +31 -21
  56. data/sig/comment.rbs +1 -1
  57. data/sig/declarations.rbs +106 -21
  58. data/sig/environment.rbs +2 -2
  59. data/sig/errors.rbs +15 -0
  60. data/sig/location.rbs +84 -3
  61. data/sig/locator.rbs +44 -0
  62. data/sig/members.rbs +76 -12
  63. data/sig/method_builder.rbs +1 -1
  64. data/sig/method_types.rbs +1 -1
  65. data/sig/namespace.rbs +1 -1
  66. data/sig/polyfill.rbs +4 -17
  67. data/sig/rbs.rbs +8 -4
  68. data/sig/typename.rbs +1 -1
  69. data/sig/types.rbs +60 -19
  70. data/sig/util.rbs +0 -4
  71. data/sig/writer.rbs +8 -2
  72. data/stdlib/dbm/0/dbm.rbs +43 -30
  73. data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
  74. data/stdlib/net-http/0/net-http.rbs +1846 -0
  75. data/stdlib/optparse/0/optparse.rbs +1214 -0
  76. data/stdlib/resolv/0/resolv.rbs +1504 -0
  77. data/stdlib/rubygems/0/requirement.rbs +84 -2
  78. data/stdlib/rubygems/0/version.rbs +2 -1
  79. data/stdlib/shellwords/0/shellwords.rbs +252 -0
  80. data/stdlib/socket/0/addrinfo.rbs +469 -0
  81. data/stdlib/socket/0/basic_socket.rbs +503 -0
  82. data/stdlib/socket/0/ip_socket.rbs +72 -0
  83. data/stdlib/socket/0/socket.rbs +2687 -0
  84. data/stdlib/socket/0/tcp_server.rbs +177 -0
  85. data/stdlib/socket/0/tcp_socket.rbs +35 -0
  86. data/stdlib/socket/0/udp_socket.rbs +111 -0
  87. data/stdlib/socket/0/unix_server.rbs +154 -0
  88. data/stdlib/socket/0/unix_socket.rbs +132 -0
  89. data/stdlib/timeout/0/timeout.rbs +5 -0
  90. data/steep/Gemfile.lock +19 -16
  91. metadata +18 -11
  92. data/bin/annotate-with-rdoc +0 -153
  93. data/bin/console +0 -14
  94. data/bin/query-rdoc +0 -103
  95. data/bin/rbs-prof +0 -9
  96. data/bin/run_in_md.rb +0 -49
  97. data/bin/setup +0 -8
  98. data/bin/sort +0 -89
  99. data/bin/steep +0 -4
  100. data/bin/test_runner.rb +0 -29
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/query-rdoc DELETED
@@ -1,103 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "rdoc"
4
-
5
- def store_for_class(name, stores:)
6
- stores.find do |store|
7
- store.find_class_named(name) || store.find_module_named(name)
8
- end
9
- end
10
-
11
- def format_comment(comment)
12
- out = RDoc::Markup::Document.new
13
- out << comment
14
- formatter = RDoc::Markup::ToMarkdown.new
15
- out.accept(formatter)
16
- end
17
-
18
- def comment_for_constant(name, stores:)
19
- *class_components, const_name = name.split(/::/)
20
- class_name = class_components.join("::")
21
-
22
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
23
- store.find_class_named(class_name) || store.find_module_named(class_name)
24
- }
25
-
26
- constant = klass.constants.find do |const|
27
- const.name == const_name
28
- end
29
-
30
- if constant&.documented?
31
- format_comment(constant.comment)
32
- end
33
- end
34
-
35
- def comment_for_class(class_name, stores:)
36
- klass = store_for_class(class_name, stores: stores)&.yield_self {|store|
37
- store.find_class_named(class_name) || store.find_module_named(class_name)
38
- }
39
-
40
- if klass&.documented?
41
- format_comment(klass.comment)
42
- end
43
- end
44
-
45
- def comment_for_method(klass, method, stores:)
46
- method = store_for_class(klass, stores: stores)&.load_method(klass, method)
47
-
48
- if method&.documented?
49
- out = RDoc::Markup::Document.new
50
-
51
- out << method.comment
52
-
53
- if method.arglists
54
- out << RDoc::Markup::Heading.new(1, "arglists 💪👽🚨 << Delete this section")
55
- arglists = method.arglists.chomp.split("\n").map {|line| line + "\n" }
56
- out << RDoc::Markup::Verbatim.new(*arglists)
57
- end
58
-
59
- out.accept(RDoc::Markup::ToMarkdown.new)
60
- end
61
- rescue RDoc::Store::MissingFileError
62
- nil
63
- end
64
-
65
- if ARGV.empty?
66
- puts 'query-rdoc [subject]'
67
- puts " subject ::= ClassName (class, module, or constant)"
68
- puts " | ClassName.method (singleton method)"
69
- puts " | ClassName#method (instance method)"
70
- exit
71
- end
72
-
73
- stores = []
74
- RDoc::RI::Paths.each true, true, false, false do |path, type|
75
- STDERR.puts "Loading store from #{path}..."
76
- store = RDoc::RI::Store.new(path, type)
77
- store.load_all
78
- stores << store
79
- end
80
-
81
- subject = ARGV[0]
82
-
83
- case
84
- when match = subject.match(/(?<constant_name>[^#]+)#(?<method_name>.+)/)
85
- STDERR.puts "Finding instance method #{match[:constant_name]} # #{match[:method_name]} ..."
86
- comment = comment_for_method(match[:constant_name], "##{match[:method_name]}", stores: stores)
87
- when match = subject.match(/(?<constant_name>[^.]+)\.(?<method_name>.+)/)
88
- STDERR.puts "Finding singleton method #{match[:constant_name]} . #{match[:method_name]} ..."
89
- comment = comment_for_method(match[:constant_name], "::#{match[:method_name]}", stores: stores)
90
- else
91
- STDERR.puts "Finding class/module/constant #{subject} ..."
92
- comment = comment_for_class(subject, stores: stores) || comment_for_constant(subject, stores: stores)
93
- end
94
-
95
- if comment
96
- STDERR.puts "Printing document..."
97
- comment.each_line do |line|
98
- puts "# #{line}"
99
- end
100
- else
101
- STDERR.puts "Nothing to print; failed to query the document..."
102
- exit 1
103
- end
data/bin/rbs-prof DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "stackprof"
4
-
5
- out = ENV["RBS_STACKPROF_OUT"] || 'tmp/stackprof-cpu-rbs.dump'
6
-
7
- StackProf.run(mode: :cpu, out: out, raw: true) do
8
- load File.join(__dir__, "../exe/rbs")
9
- end
data/bin/run_in_md.rb DELETED
@@ -1,49 +0,0 @@
1
- require "tmpdir"
2
- require "shellwords"
3
-
4
- ARGV.each do |path|
5
- puts "~~~~~~~ Checking #{path} ~~~~~~"
6
- content = File.read(path)
7
-
8
- snippets = []
9
- lines = []
10
- content.lines.each.with_index do |line, index|
11
- case line
12
- when /run-start:/
13
- lines = [[line, index+1]]
14
- when /run-end/
15
- lines << [line, index+1]
16
- snippets << lines
17
- lines = []
18
- else
19
- lines << [line, index+1]
20
- end
21
- end
22
-
23
- snippets.each do |lines|
24
- puts ">>> Code detected: "
25
- hd, _, *code_lines, _, _ = lines
26
-
27
- head = hd[0]
28
- head.gsub!(/^<!-- +/, "").gsub!(/ +-->$/, "")
29
- _,name,command = head.split(/:/)
30
-
31
- puts "# command=#{Shellwords.split(command).inspect}"
32
- puts "# name=#{name}"
33
- puts code_lines.map {|line, i| "#{"%4d" % i} #{line}" }.join
34
-
35
- code = code_lines.map(&:first).join
36
-
37
- puts ">>> Running..."
38
- Dir.mktmpdir do |dir|
39
- File.write(File.join(dir, name), code)
40
- pid = spawn({ "BUNDLE_GEMFILE" => File.join(__dir__, "../Gemfile") },
41
- *Shellwords.split(command),
42
- chdir: dir)
43
-
44
- _, status = Process.waitpid2(pid)
45
-
46
- status.success? or raise "Failed to execute code: #{code_lines.join}"
47
- end
48
- end
49
- end
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install --jobs 4 --retry 3
7
-
8
- # Do any other automated setup that you need to do here
data/bin/sort DELETED
@@ -1,89 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "rbs"
5
-
6
- Members = RBS::AST::Members
7
-
8
- def group(member)
9
- case member
10
- when Members::Include, Members::Extend, Members::Prepend
11
- 0
12
- when Members::ClassVariable
13
- -3
14
- when Members::ClassInstanceVariable
15
- -2
16
- when Members::InstanceVariable
17
- -1
18
- when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
19
- 2
20
- when Members::MethodDefinition
21
- if member.singleton?
22
- if member.name == :new
23
- 0.4
24
- else
25
- 1
26
- end
27
- else
28
- if member.name == :initialize
29
- 0.5
30
- else
31
- 3
32
- end
33
- end
34
- when Members::Alias
35
- if member.singleton?
36
- 1
37
- else
38
- 3
39
- end
40
- when Members::Private, Members::Public
41
- -4
42
- end
43
- end
44
-
45
- def key(member)
46
- case member
47
- when Members::Include, Members::Extend, Members::Prepend
48
- member.name.to_s
49
- when Members::ClassVariable, Members::ClassInstanceVariable, Members::InstanceVariable
50
- member.name.to_s
51
- when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
52
- member.name.to_s
53
- when Members::MethodDefinition
54
- member.name.to_s
55
- when Members::Alias
56
- member.new_name.to_s
57
- else
58
- 1
59
- end
60
- end
61
-
62
- ARGV.map {|f| Pathname(f) }.each do |path|
63
- puts "Opening #{path}..."
64
-
65
- buffer = RBS::Buffer.new(name: path, content: path.read)
66
- sigs = RBS::Parser.parse_signature(buffer)
67
-
68
- sigs.each do |sig|
69
- case sig
70
- when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module, RBS::AST::Declarations::Interface
71
- sig.members.sort! do |m1, m2|
72
- group1 = group(m1)
73
- group2 = group(m2)
74
-
75
- if group1 == group2
76
- key(m1) <=> key(m2)
77
- else
78
- group1 <=> group2
79
- end
80
- end
81
- end
82
- end
83
-
84
- puts "Writing #{path}..."
85
- path.open('w') do |out|
86
- writer = RBS::Writer.new(out: out)
87
- writer.write sigs
88
- end
89
- end
data/bin/steep DELETED
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
-
3
- GEMFILE=$(cd $(dirname $0); pwd)/../steep/Gemfile
4
- bundle exec --gemfile=${GEMFILE} steep $*
data/bin/test_runner.rb DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH << File.join(__dir__, "../lib")
4
-
5
- require "set"
6
-
7
- IS_LATEST_RUBY = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
8
- Gem::Version.new('3.0.0') <= ruby_version && ruby_version < Gem::Version.new('3.1.0')
9
- end
10
-
11
- unless IS_LATEST_RUBY
12
- STDERR.puts "⚠️⚠️⚠️⚠️ stdlib test assumes Ruby 3.0 but RUBY_VERSION==#{RUBY_VERSION} ⚠️⚠️⚠️⚠️"
13
- end
14
-
15
- KNOWN_FAILS = %w(dbm).map do |lib|
16
- /cannot load such file -- #{lib}/
17
- end
18
-
19
- ARGV.each do |arg|
20
- begin
21
- load arg
22
- rescue LoadError => exn
23
- if KNOWN_FAILS.any? {|pat| pat =~ exn.message }
24
- STDERR.puts "Loading #{arg} failed, ignoring it: #{exn.inspect}"
25
- else
26
- raise
27
- end
28
- end
29
- end