rbs 2.8.4 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +17 -17
  5. data/README.md +1 -0
  6. data/Rakefile +66 -0
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +18 -2
  12. data/ext/rbs_extension/constants.h +9 -1
  13. data/ext/rbs_extension/lexer.c +834 -777
  14. data/ext/rbs_extension/lexer.h +3 -1
  15. data/ext/rbs_extension/lexer.re +3 -1
  16. data/ext/rbs_extension/lexstate.c +4 -2
  17. data/ext/rbs_extension/parser.c +287 -57
  18. data/ext/rbs_extension/ruby_objs.c +71 -5
  19. data/ext/rbs_extension/ruby_objs.h +9 -2
  20. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  21. data/lib/rbs/ast/declarations.rb +49 -2
  22. data/lib/rbs/ast/directives.rb +39 -0
  23. data/lib/rbs/ast/members.rb +49 -15
  24. data/lib/rbs/cli.rb +38 -19
  25. data/lib/rbs/collection/config/lockfile.rb +115 -0
  26. data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
  27. data/lib/rbs/collection/config.rb +12 -40
  28. data/lib/rbs/collection/installer.rb +9 -13
  29. data/lib/rbs/collection/sources/base.rb +2 -2
  30. data/lib/rbs/collection/sources/git.rb +135 -62
  31. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  32. data/lib/rbs/collection/sources/stdlib.rb +10 -13
  33. data/lib/rbs/collection/sources.rb +7 -1
  34. data/lib/rbs/collection.rb +1 -0
  35. data/lib/rbs/definition.rb +1 -1
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  37. data/lib/rbs/definition_builder/method_builder.rb +3 -3
  38. data/lib/rbs/definition_builder.rb +456 -579
  39. data/lib/rbs/environment/use_map.rb +77 -0
  40. data/lib/rbs/environment.rb +356 -85
  41. data/lib/rbs/environment_loader.rb +20 -17
  42. data/lib/rbs/environment_walker.rb +1 -1
  43. data/lib/rbs/errors.rb +34 -37
  44. data/lib/rbs/locator.rb +3 -3
  45. data/lib/rbs/parser_aux.rb +8 -6
  46. data/lib/rbs/prototype/helpers.rb +29 -13
  47. data/lib/rbs/prototype/node_usage.rb +99 -0
  48. data/lib/rbs/prototype/rb.rb +3 -2
  49. data/lib/rbs/prototype/rbi.rb +6 -4
  50. data/lib/rbs/prototype/runtime.rb +25 -12
  51. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  52. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  53. data/lib/rbs/sorter.rb +3 -3
  54. data/lib/rbs/substitution.rb +19 -0
  55. data/lib/rbs/test/setup.rb +1 -1
  56. data/lib/rbs/type_alias_dependency.rb +1 -1
  57. data/lib/rbs/type_alias_regularity.rb +3 -3
  58. data/lib/rbs/types.rb +1 -5
  59. data/lib/rbs/validator.rb +25 -3
  60. data/lib/rbs/variance_calculator.rb +2 -2
  61. data/lib/rbs/version.rb +1 -1
  62. data/lib/rbs/writer.rb +54 -19
  63. data/lib/rbs.rb +3 -2
  64. data/lib/rdoc_plugin/parser.rb +3 -3
  65. data/schema/members.json +15 -10
  66. data/sig/ancestor_graph.rbs +22 -2
  67. data/sig/collection/config/lockfile.rbs +80 -0
  68. data/sig/collection/config/lockfile_generator.rbs +53 -0
  69. data/sig/collection/config.rbs +5 -48
  70. data/sig/collection/installer.rbs +1 -1
  71. data/sig/collection/sources.rbs +76 -33
  72. data/sig/constant.rbs +1 -1
  73. data/sig/declarations.rbs +36 -3
  74. data/sig/definition.rbs +1 -1
  75. data/sig/definition_builder.rbs +94 -82
  76. data/sig/directives.rbs +61 -0
  77. data/sig/environment.rbs +150 -28
  78. data/sig/environment_loader.rbs +2 -2
  79. data/sig/errors.rbs +42 -0
  80. data/sig/members.rbs +31 -7
  81. data/sig/parser.rbs +8 -15
  82. data/sig/prototype/node_usage.rbs +20 -0
  83. data/sig/resolver/constant_resolver.rbs +1 -2
  84. data/sig/shims/bundler.rbs +31 -0
  85. data/sig/shims/rubygems.rbs +15 -0
  86. data/sig/shims.rbs +0 -22
  87. data/sig/substitution.rbs +6 -0
  88. data/sig/use_map.rbs +35 -0
  89. data/sig/validator.rbs +12 -5
  90. data/sig/writer.rbs +6 -2
  91. metadata +16 -9
  92. data/lib/rbs/constant_table.rb +0 -167
  93. data/lib/rbs/type_name_resolver.rb +0 -67
  94. data/sig/constant_table.rbs +0 -30
  95. data/sig/type_name_resolver.rbs +0 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '038fda245a80a2e3eb408a3e8aa872f50e36b24a994ff4a6c4d8576cab7d6634'
4
- data.tar.gz: ccc5db43cae3907aa594ac0ce53df343bb6b942b484fb507d9248fc33305be81
3
+ metadata.gz: 37f0e00e909c3e55bf8f8a80187fe4825d325e8b5ffc392d749058dba6d37561
4
+ data.tar.gz: 541db099d371d39611212952a07f545be143dd26845532665ee3f7c48fe5e3f7
5
5
  SHA512:
6
- metadata.gz: 1b8fe38a58cca575ac24d8cfb3745c39ac19a3638c45e665cd7cda7923ccc46f7304c6e9cc86126ca5f159118d0bf5e9d055aff1134ebdedf79fec17998f1558
7
- data.tar.gz: 1cefb1986f35af43f6a903452545a61622df14358acb06b70a3b94f4ceb3ba697cfaf2c364d5d77b2c4e77a962f03326fc30194e1e81c3ba51e2931a63954597
6
+ metadata.gz: 68e344e08d8aa8333dc8a4c4292e8b45ba7eab22027c570dc7c18f5e9f86289914ee742261e423bb5ea2924ccb3cbf9516de67150f86a8dd6aabdf573404c1ed
7
+ data.tar.gz: 680e1b9be1495dae9c1842c7e5b49984c819fe2c54fea9002d3508727b60847bc0fbee737ef2625f603e00406f612008f9b515be37cb662ed5dd4ee1b4af736f
@@ -6,9 +6,6 @@ on:
6
6
  - master
7
7
  pull_request: {}
8
8
 
9
- env:
10
- LANG: 'C.UTF-8'
11
-
12
9
  jobs:
13
10
  test:
14
11
  runs-on: "ubuntu-latest"
data/Gemfile CHANGED
@@ -18,7 +18,7 @@ gem "dbm"
18
18
  gem 'digest'
19
19
  gem 'tempfile'
20
20
  gem "prime"
21
- gem "rdoc"
21
+ gem "rdoc", "< 6.5.0"
22
22
 
23
23
  # Test gems
24
24
  gem "rbs-amber", path: "test/assets/test-gem"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs (2.8.4)
4
+ rbs (3.0.0.dev.2)
5
5
 
6
6
  PATH
7
7
  remote: test/assets/test-gem
@@ -19,35 +19,35 @@ GEM
19
19
  debase-ruby_core_source (>= 0.10.12)
20
20
  debase-ruby_core_source (0.10.16)
21
21
  diff-lcs (1.5.0)
22
- digest (3.1.0)
22
+ digest (3.1.1)
23
23
  forwardable (1.3.2)
24
24
  goodcheck (3.1.0)
25
25
  marcel (>= 1.0, < 2.0)
26
26
  psych (>= 3.1, < 5.0)
27
27
  rainbow (>= 3.0, < 4.0)
28
28
  strong_json (>= 1.1, < 2.2)
29
- json (2.6.2)
29
+ json (2.6.3)
30
30
  json-schema (3.0.0)
31
31
  addressable (>= 2.8)
32
32
  marcel (1.0.2)
33
- minitest (5.16.3)
33
+ minitest (5.17.0)
34
34
  parallel (1.22.1)
35
- parser (3.1.2.1)
35
+ parser (3.1.3.0)
36
36
  ast (~> 2.4.1)
37
- power_assert (2.0.1)
37
+ power_assert (2.0.2)
38
38
  prime (0.1.2)
39
39
  forwardable
40
40
  singleton
41
- psych (4.0.4)
41
+ psych (4.0.6)
42
42
  stringio
43
43
  public_suffix (4.0.7)
44
44
  rainbow (3.1.1)
45
45
  rake (13.0.6)
46
- rake-compiler (1.2.0)
46
+ rake-compiler (1.2.1)
47
47
  rake
48
48
  rdoc (6.4.0)
49
49
  psych (>= 4.0.0)
50
- regexp_parser (2.6.0)
50
+ regexp_parser (2.6.1)
51
51
  rexml (3.2.5)
52
52
  rspec (3.12.0)
53
53
  rspec-core (~> 3.12.0)
@@ -62,7 +62,7 @@ GEM
62
62
  diff-lcs (>= 1.2.0, < 2.0)
63
63
  rspec-support (~> 3.12.0)
64
64
  rspec-support (3.12.0)
65
- rubocop (1.39.0)
65
+ rubocop (1.40.0)
66
66
  json (~> 2.3)
67
67
  parallel (~> 1.10)
68
68
  parser (>= 3.1.2.1)
@@ -72,7 +72,7 @@ GEM
72
72
  rubocop-ast (>= 1.23.0, < 2.0)
73
73
  ruby-progressbar (~> 1.7)
74
74
  unicode-display_width (>= 1.4.0, < 3.0)
75
- rubocop-ast (1.23.0)
75
+ rubocop-ast (1.24.0)
76
76
  parser (>= 3.1.1.0)
77
77
  rubocop-rubycw (0.1.6)
78
78
  rubocop (~> 1.0)
@@ -80,11 +80,11 @@ GEM
80
80
  rake (>= 0.8.1)
81
81
  ruby-progressbar (1.11.0)
82
82
  singleton (0.1.1)
83
- stackprof (0.2.22)
84
- stringio (3.0.2)
83
+ stackprof (0.2.23)
84
+ stringio (3.0.4)
85
85
  strong_json (2.1.2)
86
- tempfile (0.1.2)
87
- test-unit (3.5.5)
86
+ tempfile (0.1.3)
87
+ test-unit (3.5.7)
88
88
  power_assert
89
89
  unicode-display_width (2.3.0)
90
90
 
@@ -105,7 +105,7 @@ DEPENDENCIES
105
105
  rake-compiler
106
106
  rbs!
107
107
  rbs-amber!
108
- rdoc
108
+ rdoc (< 6.5.0)
109
109
  rspec
110
110
  rubocop
111
111
  rubocop-rubycw
@@ -115,4 +115,4 @@ DEPENDENCIES
115
115
  test-unit
116
116
 
117
117
  BUNDLED WITH
118
- 2.3.14
118
+ 2.4.6
data/README.md CHANGED
@@ -131,6 +131,7 @@ puts singleton.methods[:gsub]
131
131
  - [Writing signatures guide](docs/sigs.md)
132
132
  - [Stdlib signatures guide](docs/stdlib.md)
133
133
  - [Syntax](docs/syntax.md)
134
+ - [RBS by Example](docs/rbs_by_example.md)
134
135
 
135
136
  ## Development
136
137
 
data/Rakefile CHANGED
@@ -233,3 +233,69 @@ task :test_generate_stdlib do
233
233
  sh "RBS_GENERATE_TEST_PATH=/tmp/Thread_Mutex_test.rb rake 'generate:stdlib_test[Thread::Mutex]'"
234
234
  sh "ruby -c /tmp/Thread_Mutex_test.rb"
235
235
  end
236
+
237
+ Rake::Task[:release].enhance do
238
+ Rake::Task[:"release:note"].invoke
239
+ end
240
+
241
+ namespace :release do
242
+ desc "Explain the post-release steps automatically"
243
+ task :note do
244
+ version = Gem::Version.new(RBS::VERSION)
245
+ major, minor, patch, *_ = RBS::VERSION.split(".")
246
+ major = major.to_i
247
+ minor = minor.to_i
248
+ patch = patch.to_i
249
+
250
+ puts "🎉🎉🎉🎉 Congratulations for **#{version}** release! 🎉🎉🎉🎉"
251
+ puts
252
+ puts "There are a few things left to complete the release. 💪"
253
+ puts
254
+
255
+ if patch == 0 || version.prerelease?
256
+ puts "* [ ] Update release note: https://github.com/ruby/rbs/wiki/Release-Note-#{major}.#{minor}"
257
+ end
258
+
259
+ if patch == 0 && !version.prerelease?
260
+ puts "* [ ] Delete `RBS XYZ is the latest version of...` from release note: https://github.com/ruby/rbs/wiki/Release-Note-#{major}.#{minor}"
261
+ end
262
+
263
+ puts "* [ ] Publish a release at GitHub"
264
+ puts "* [ ] Make some announcements on Twitter/Mustdon/Slack/???"
265
+
266
+ puts
267
+ puts
268
+
269
+ puts "✏️ Making a draft release on GitHub..."
270
+
271
+ content = File.read(File.join(__dir__, "CHANGELOG.md"))
272
+ changelog = content.scan(/^## \d.*?(?=^## \d)/m)[0]
273
+ changelog = changelog.sub(/^.*\n^.*\n/, "").rstrip
274
+
275
+ notes = <<NOTES
276
+ [Release note](https://github.com/ruby/rbs/wiki/Release-Note-#{major}.#{minor})
277
+
278
+ #{changelog}
279
+ NOTES
280
+
281
+ command = [
282
+ "gh",
283
+ "release",
284
+ "create",
285
+ "--draft",
286
+ "v#{RBS::VERSION}",
287
+ "--title=#{RBS::VERSION}",
288
+ "--notes=#{notes}"
289
+ ]
290
+
291
+ if version.prerelease?
292
+ command << "--prerelease"
293
+ end
294
+
295
+ require "open3"
296
+ output, status = Open3.capture2(*command)
297
+ if status.success?
298
+ puts " >> Done! Open #{output.chomp} and publish the release!"
299
+ end
300
+ end
301
+ end
data/core/array.rbs CHANGED
@@ -850,7 +850,7 @@ class Array[unchecked out Elem] < Object
850
850
  #
851
851
  # Array#slice is an alias for Array#[].
852
852
  #
853
- def []: (int index) -> Elem
853
+ def []: %a{implicitly-returns-nil} (int index) -> Elem
854
854
  | (int start, int length) -> ::Array[Elem]?
855
855
  | (::Range[::Integer?] range) -> ::Array[Elem]?
856
856
 
data/core/builtin.rbs CHANGED
@@ -23,7 +23,7 @@ interface _ToHash[K, V]
23
23
  end
24
24
 
25
25
  interface _ToProc
26
- def to_proc: () -> untyped
26
+ def to_proc: () -> Proc
27
27
  end
28
28
 
29
29
  interface _ToPath
data/core/hash.rbs CHANGED
@@ -698,7 +698,7 @@ class Hash[unchecked out K, unchecked out V] < Object
698
698
  # h = {foo: 0, bar: 1, baz: 2}
699
699
  # h[:nosuch] # => nil
700
700
  #
701
- def []: (K arg0) -> V
701
+ def []: %a{implicitly-returns-nil} (K arg0) -> V
702
702
 
703
703
  # <!--
704
704
  # rdoc-file=hash.c
data/core/module.rbs CHANGED
@@ -1536,5 +1536,5 @@ class Module < Object
1536
1536
  # `attr_reader(name)` but deprecated. Returns an array of defined method names
1537
1537
  # as symbols.
1538
1538
  #
1539
- def attr: (*Symbol | String arg0) -> NilClass
1539
+ def attr: (*Symbol | String arg0) -> Array[Symbol]
1540
1540
  end
@@ -10,7 +10,7 @@ VALUE RBS_AST_TypeParam;
10
10
 
11
11
  VALUE RBS_AST_Declarations;
12
12
 
13
- VALUE RBS_AST_Declarations_Alias;
13
+ VALUE RBS_AST_Declarations_TypeAlias;
14
14
  VALUE RBS_AST_Declarations_Constant;
15
15
  VALUE RBS_AST_Declarations_Global;
16
16
  VALUE RBS_AST_Declarations_Interface;
@@ -18,6 +18,13 @@ VALUE RBS_AST_Declarations_Module;
18
18
  VALUE RBS_AST_Declarations_Module_Self;
19
19
  VALUE RBS_AST_Declarations_Class;
20
20
  VALUE RBS_AST_Declarations_Class_Super;
21
+ VALUE RBS_AST_Declarations_ModuleAlias;
22
+ VALUE RBS_AST_Declarations_ClassAlias;
23
+
24
+ VALUE RBS_AST_Directives;
25
+ VALUE RBS_AST_Directives_Use;
26
+ VALUE RBS_AST_Directives_Use_SingleClause;
27
+ VALUE RBS_AST_Directives_Use_WildcardClause;
21
28
 
22
29
  VALUE RBS_AST_Members;
23
30
  VALUE RBS_AST_Members_Alias;
@@ -30,6 +37,7 @@ VALUE RBS_AST_Members_Extend;
30
37
  VALUE RBS_AST_Members_Include;
31
38
  VALUE RBS_AST_Members_InstanceVariable;
32
39
  VALUE RBS_AST_Members_MethodDefinition;
40
+ VALUE RBS_AST_Members_MethodDefinition_Overload;
33
41
  VALUE RBS_AST_Members_Prepend;
34
42
  VALUE RBS_AST_Members_Private;
35
43
  VALUE RBS_AST_Members_Public;
@@ -79,7 +87,7 @@ void rbs__init_constants(void) {
79
87
 
80
88
  RBS_AST_Declarations = rb_const_get(RBS_AST, rb_intern("Declarations"));
81
89
 
82
- RBS_AST_Declarations_Alias = rb_const_get(RBS_AST_Declarations, rb_intern("Alias"));
90
+ RBS_AST_Declarations_TypeAlias = rb_const_get(RBS_AST_Declarations, rb_intern("TypeAlias"));
83
91
  RBS_AST_Declarations_Constant = rb_const_get(RBS_AST_Declarations, rb_intern("Constant"));
84
92
  RBS_AST_Declarations_Global = rb_const_get(RBS_AST_Declarations, rb_intern("Global"));
85
93
  RBS_AST_Declarations_Interface = rb_const_get(RBS_AST_Declarations, rb_intern("Interface"));
@@ -87,6 +95,13 @@ void rbs__init_constants(void) {
87
95
  RBS_AST_Declarations_Module_Self = rb_const_get(RBS_AST_Declarations_Module, rb_intern("Self"));
88
96
  RBS_AST_Declarations_Class = rb_const_get(RBS_AST_Declarations, rb_intern("Class"));
89
97
  RBS_AST_Declarations_Class_Super = rb_const_get(RBS_AST_Declarations_Class, rb_intern("Super"));
98
+ RBS_AST_Declarations_ClassAlias = rb_const_get(RBS_AST_Declarations, rb_intern("ClassAlias"));
99
+ RBS_AST_Declarations_ModuleAlias = rb_const_get(RBS_AST_Declarations, rb_intern("ModuleAlias"));
100
+
101
+ RBS_AST_Directives = rb_const_get(RBS_AST, rb_intern("Directives"));
102
+ RBS_AST_Directives_Use = rb_const_get(RBS_AST_Directives, rb_intern("Use"));
103
+ RBS_AST_Directives_Use_SingleClause = rb_const_get(RBS_AST_Directives_Use, rb_intern("SingleClause"));
104
+ RBS_AST_Directives_Use_WildcardClause = rb_const_get(RBS_AST_Directives_Use, rb_intern("WildcardClause"));
90
105
 
91
106
  RBS_AST_Members = rb_const_get(RBS_AST, rb_intern("Members"));
92
107
  RBS_AST_Members_Alias = rb_const_get(RBS_AST_Members, rb_intern("Alias"));
@@ -99,6 +114,7 @@ void rbs__init_constants(void) {
99
114
  RBS_AST_Members_Include = rb_const_get(RBS_AST_Members, rb_intern("Include"));
100
115
  RBS_AST_Members_InstanceVariable = rb_const_get(RBS_AST_Members, rb_intern("InstanceVariable"));
101
116
  RBS_AST_Members_MethodDefinition = rb_const_get(RBS_AST_Members, rb_intern("MethodDefinition"));
117
+ RBS_AST_Members_MethodDefinition_Overload = rb_const_get(RBS_AST_Members_MethodDefinition, rb_intern("Overload"));
102
118
  RBS_AST_Members_Prepend = rb_const_get(RBS_AST_Members, rb_intern("Prepend"));
103
119
  RBS_AST_Members_Private = rb_const_get(RBS_AST_Members, rb_intern("Private"));
104
120
  RBS_AST_Members_Public = rb_const_get(RBS_AST_Members, rb_intern("Public"));
@@ -9,7 +9,7 @@ extern VALUE RBS_AST_Comment;
9
9
  extern VALUE RBS_AST_TypeParam;
10
10
 
11
11
  extern VALUE RBS_AST_Declarations;
12
- extern VALUE RBS_AST_Declarations_Alias;
12
+ extern VALUE RBS_AST_Declarations_TypeAlias;
13
13
  extern VALUE RBS_AST_Declarations_Class_Super;
14
14
  extern VALUE RBS_AST_Declarations_Class;
15
15
  extern VALUE RBS_AST_Declarations_Constant;
@@ -17,6 +17,13 @@ extern VALUE RBS_AST_Declarations_Global;
17
17
  extern VALUE RBS_AST_Declarations_Interface;
18
18
  extern VALUE RBS_AST_Declarations_Module_Self;
19
19
  extern VALUE RBS_AST_Declarations_Module;
20
+ extern VALUE RBS_AST_Declarations_ModuleAlias;
21
+ extern VALUE RBS_AST_Declarations_ClassAlias;
22
+
23
+ extern VALUE RBS_AST_Directives;
24
+ extern VALUE RBS_AST_Directives_Use;
25
+ extern VALUE RBS_AST_Directives_Use_SingleClause;
26
+ extern VALUE RBS_AST_Directives_Use_WildcardClause;
20
27
 
21
28
  extern VALUE RBS_AST_Members;
22
29
  extern VALUE RBS_AST_Members_Alias;
@@ -29,6 +36,7 @@ extern VALUE RBS_AST_Members_Extend;
29
36
  extern VALUE RBS_AST_Members_Include;
30
37
  extern VALUE RBS_AST_Members_InstanceVariable;
31
38
  extern VALUE RBS_AST_Members_MethodDefinition;
39
+ extern VALUE RBS_AST_Members_MethodDefinition_Overload;
32
40
  extern VALUE RBS_AST_Members_Prepend;
33
41
  extern VALUE RBS_AST_Members_Private;
34
42
  extern VALUE RBS_AST_Members_Public;