rbs 3.7.0.dev.1 → 3.7.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/.github/workflows/windows.yml +5 -3
  4. data/.gitignore +1 -0
  5. data/.rubocop.yml +6 -0
  6. data/CHANGELOG.md +47 -0
  7. data/Rakefile +23 -0
  8. data/config.yml +311 -0
  9. data/core/dir.rbs +1 -1
  10. data/core/kernel.rbs +2 -2
  11. data/core/process.rbs +1 -1
  12. data/core/set.rbs +1 -1
  13. data/docs/syntax.md +6 -4
  14. data/ext/rbs_extension/extconf.rb +10 -0
  15. data/ext/rbs_extension/parser.c +103 -110
  16. data/ext/rbs_extension/rbs_extension.h +1 -2
  17. data/{ext/rbs_extension → include/rbs}/constants.h +21 -19
  18. data/include/rbs/ruby_objs.h +72 -0
  19. data/include/rbs.h +7 -0
  20. data/lib/rbs/collection/config/lockfile_generator.rb +34 -5
  21. data/lib/rbs/collection/config.rb +2 -2
  22. data/lib/rbs/environment_loader.rb +5 -0
  23. data/lib/rbs/prototype/rb.rb +7 -3
  24. data/lib/rbs/types.rb +10 -3
  25. data/lib/rbs/version.rb +1 -1
  26. data/sig/ancestor_graph.rbs +1 -1
  27. data/sig/collection/config/lockfile_generator.rbs +9 -1
  28. data/sig/definition.rbs +1 -1
  29. data/sig/definition_builder.rbs +1 -1
  30. data/sig/environment.rbs +1 -1
  31. data/sig/prototype/rb.rbs +1 -1
  32. data/sig/type_alias_dependency.rbs +2 -2
  33. data/sig/type_alias_regularity.rbs +1 -1
  34. data/sig/type_param.rbs +3 -3
  35. data/sig/vendorer.rbs +1 -1
  36. data/{ext/rbs_extension → src}/constants.c +35 -36
  37. data/src/ruby_objs.c +793 -0
  38. data/stdlib/cgi/0/manifest.yaml +1 -0
  39. data/stdlib/csv/0/manifest.yaml +1 -0
  40. data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
  41. data/stdlib/json/0/json.rbs +1 -1
  42. data/stdlib/minitest/0/kernel.rbs +2 -2
  43. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
  44. data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
  45. data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
  46. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
  47. data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
  48. data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
  49. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  50. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  51. data/stdlib/minitest/0/minitest/mock.rbs +9 -5
  52. data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
  53. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
  54. data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
  55. data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
  56. data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
  57. data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
  58. data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
  59. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
  60. data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
  61. data/stdlib/minitest/0/minitest/spec.rbs +1 -1
  62. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
  63. data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
  64. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +1 -1
  65. data/stdlib/minitest/0/minitest/test.rbs +7 -14
  66. data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
  67. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  68. data/stdlib/minitest/0/minitest/unit.rbs +1 -2
  69. data/stdlib/minitest/0/minitest.rbs +41 -892
  70. data/stdlib/open-uri/0/manifest.yaml +1 -0
  71. data/stdlib/openssl/0/manifest.yaml +1 -0
  72. data/stdlib/openssl/0/openssl.rbs +26 -1
  73. data/stdlib/psych/0/core_ext.rbs +12 -0
  74. data/templates/include/rbs/constants.h.erb +20 -0
  75. data/templates/include/rbs/ruby_objs.h.erb +10 -0
  76. data/templates/src/constants.c.erb +36 -0
  77. data/templates/src/ruby_objs.c.erb +27 -0
  78. data/templates/template.rb +122 -0
  79. metadata +19 -9
  80. data/ext/rbs_extension/ruby_objs.c +0 -602
  81. data/ext/rbs_extension/ruby_objs.h +0 -51
  82. data/stdlib/minitest/0/manifest.yaml +0 -2
  83. /data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +0 -0
@@ -1,3 +1,4 @@
1
1
  dependencies:
2
2
  - name: tempfile
3
3
  - name: uri
4
+ - name: stringio
@@ -1,2 +1,3 @@
1
1
  dependencies:
2
2
  - name: socket
3
+ - name: digest
@@ -3164,7 +3164,7 @@ module OpenSSL
3164
3164
  # sha256.reset
3165
3165
  # digest2 = sha256.digest(data2)
3166
3166
  #
3167
- class Digest
3167
+ class Digest < ::Digest::Class
3168
3168
  # <!--
3169
3169
  # rdoc-file=ext/openssl/lib/openssl/digest.rb
3170
3170
  # - digest(name, data)
@@ -3665,6 +3665,23 @@ module OpenSSL
3665
3665
  #
3666
3666
  def self.hexdigest: (String | Digest algo, String key, String data) -> String
3667
3667
 
3668
+ # <!--
3669
+ # rdoc-file=ext/openssl/lib/openssl/hmac.rb
3670
+ # - HMAC.base64digest(digest, key, data) -> aString
3671
+ # -->
3672
+ # Returns the authentication code as a Base64-encoded string. The *digest*
3673
+ # parameter specifies the digest algorithm to use. This may be a String
3674
+ # representing the algorithm name or an instance of OpenSSL::Digest.
3675
+ #
3676
+ # ### Example
3677
+ # key = 'key'
3678
+ # data = 'The quick brown fox jumps over the lazy dog'
3679
+ #
3680
+ # hmac = OpenSSL::HMAC.base64digest('SHA1', key, data)
3681
+ # #=> "3nybhbi3iqa8ino29wqQcBydtNk="
3682
+ #
3683
+ def self.base64digest: (String | Digest algo, String key, String data) -> String
3684
+
3668
3685
  # <!-- rdoc-file=ext/openssl/ossl_hmac.c -->
3669
3686
  # Returns *hmac* updated with the message to be authenticated. Can be called
3670
3687
  # repeatedly with chunks of the message.
@@ -3712,6 +3729,14 @@ module OpenSSL
3712
3729
  #
3713
3730
  def hexdigest: () -> String
3714
3731
 
3732
+ # <!--
3733
+ # rdoc-file=ext/openssl/lib/openssl/hmac.rb
3734
+ # - hmac.base64digest -> string
3735
+ # -->
3736
+ # Returns the authentication code an a Base64-encoded string.
3737
+ #
3738
+ def base64digest: () -> String
3739
+
3715
3740
  # <!-- rdoc-file=ext/openssl/lib/openssl/hmac.rb -->
3716
3741
  # Returns the authentication code as a hex-encoded string. The *digest*
3717
3742
  # parameter specifies the digest algorithm to use. This may be a String
@@ -0,0 +1,12 @@
1
+ %a{annotate:rdoc:skip}
2
+ class Object
3
+ # <!--
4
+ # rdoc-file=ext/psych/lib/psych/core_ext.rb
5
+ # - to_yaml(options = {})
6
+ # -->
7
+ # Convert an object to YAML. See Psych.dump for more information on the
8
+ # available `options`.
9
+ #
10
+ def to_yaml: (?indentation: Integer, ?line_width: Integer, ?canonical: bool, ?header: bool) -> String
11
+ | [IO] (IO, ?indentation: Integer, ?line_width: Integer, ?canonical: bool, ?header: bool) -> IO
12
+ end
@@ -0,0 +1,20 @@
1
+ #ifndef RBS__CONSTANTS_H
2
+ #define RBS__CONSTANTS_H
3
+
4
+ extern VALUE RBS;
5
+
6
+ extern VALUE RBS_AST;
7
+ extern VALUE RBS_AST_Declarations;
8
+ extern VALUE RBS_AST_Directives;
9
+ extern VALUE RBS_AST_Members;
10
+ extern VALUE RBS_Types;
11
+ extern VALUE RBS_Types_Bases;
12
+ extern VALUE RBS_ParsingError;
13
+
14
+ <%- nodes.each do |node| -%>
15
+ extern VALUE <%= node.c_constant_name %>;
16
+ <%- end -%>
17
+
18
+ void rbs__init_constants();
19
+
20
+ #endif
@@ -0,0 +1,10 @@
1
+ #ifndef RBS__RUBY_OBJS_H
2
+ #define RBS__RUBY_OBJS_H
3
+
4
+ #include "ruby.h"
5
+
6
+ <%- nodes.each do |node| -%>
7
+ VALUE <%= node.c_function_name %>(<%= node.fields.map { |field| "#{field.c_type} #{field.name}" }.join(", ") %>);
8
+ <%- end -%>
9
+
10
+ #endif
@@ -0,0 +1,36 @@
1
+ #include "rbs_extension.h"
2
+
3
+ VALUE RBS_Parser;
4
+
5
+ VALUE RBS;
6
+ VALUE RBS_AST;
7
+ VALUE RBS_AST_Declarations;
8
+ VALUE RBS_AST_Directives;
9
+ VALUE RBS_AST_Members;
10
+ VALUE RBS_Parser;
11
+ VALUE RBS_Types;
12
+ VALUE RBS_Types_Bases;
13
+
14
+ <%- nodes.each do |node| -%>
15
+ VALUE <%= node.c_constant_name %>;
16
+ <%- end -%>
17
+
18
+ VALUE RBS_ParsingError;
19
+
20
+ #define IMPORT_CONSTANT(var, parent, name) { var = rb_const_get(parent, rb_intern(name)); rb_gc_register_mark_object(var); }
21
+
22
+ void rbs__init_constants(void) {
23
+ IMPORT_CONSTANT(RBS, rb_cObject, "RBS");
24
+ IMPORT_CONSTANT(RBS_ParsingError, RBS, "ParsingError");
25
+
26
+ IMPORT_CONSTANT(RBS_AST, RBS, "AST");
27
+ IMPORT_CONSTANT(RBS_AST_Declarations, RBS_AST, "Declarations");
28
+ IMPORT_CONSTANT(RBS_AST_Directives, RBS_AST, "Directives");
29
+ IMPORT_CONSTANT(RBS_AST_Members, RBS_AST, "Members");
30
+ IMPORT_CONSTANT(RBS_Types, RBS, "Types");
31
+ IMPORT_CONSTANT(RBS_Types_Bases, RBS_Types, "Bases");
32
+
33
+ <%- nodes.each do |node| -%>
34
+ IMPORT_CONSTANT(<%= node.c_constant_name %>, <%= node.c_parent_constant_name %>, "<%= node.ruby_class_name %>");
35
+ <%- end -%>
36
+ }
@@ -0,0 +1,27 @@
1
+ #include "rbs_extension.h"
2
+
3
+ #ifdef RB_PASS_KEYWORDS
4
+ // Ruby 2.7 or later
5
+ #define CLASS_NEW_INSTANCE(klass, argc, argv)\
6
+ rb_class_new_instance_kw(argc, argv, klass, RB_PASS_KEYWORDS)
7
+ #else
8
+ // Ruby 2.6
9
+ #define CLASS_NEW_INSTANCE(receiver, argc, argv)\
10
+ rb_class_new_instance(argc, argv, receiver)
11
+ #endif
12
+
13
+ <%- nodes.each do |node| -%>
14
+ VALUE <%= node.c_function_name %>(<%= node.fields.map { |field| "#{field.c_type} #{field.name}" }.join(", ") %>) {
15
+ VALUE _init_kwargs = rb_hash_new();
16
+ <%- node.fields.each do |field| -%>
17
+ rb_hash_aset(_init_kwargs, ID2SYM(rb_intern("<%= field.name %>")), <%= field.name %>);
18
+ <%- end -%>
19
+
20
+ return CLASS_NEW_INSTANCE(
21
+ <%= node.c_constant_name %>,
22
+ 1,
23
+ &_init_kwargs
24
+ );
25
+ }
26
+
27
+ <%- end -%>
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "fileutils"
5
+ require "yaml"
6
+
7
+ module RBS
8
+ class Template
9
+ class Field
10
+ attr_reader :name
11
+ attr_reader :c_type
12
+
13
+ def initialize(yaml)
14
+ @name = yaml["name"]
15
+ @c_type = "VALUE"
16
+ end
17
+ end
18
+
19
+ class Type
20
+ # The fully-qualified name of the auto-generated Ruby class for this type,
21
+ # e.g. `RBS::AST::Declarations::TypeAlias`
22
+ attr_reader :ruby_full_name #: String
23
+
24
+ # The name of the name of the auto-generated Ruby class for this type,
25
+ # e.g. `TypeAlias`
26
+ attr_reader :ruby_class_name #: String
27
+
28
+ # The name of the auto-generated C struct for this type,
29
+ # e.g. `rbs_ast_declarations_typealias_t`
30
+ attr_reader :c_type_name #: String
31
+
32
+ # The name of the pre-existing C function which constructs new Ruby objects of this type.
33
+ # e.g. `rbs_ast_declarations_typealias_new`
34
+ attr_reader :c_function_name #: String
35
+
36
+ # The name of the C constant which stores the Ruby VALUE pointing to the generated class.
37
+ # e.g. `RBS_AST_Declarations_TypeAlias`
38
+ attr_reader :c_constant_name #: String
39
+
40
+ # The name of the C constant in which the `c_constant_name` is nested.
41
+ # e.g. `RBS_AST_Declarations`
42
+ attr_reader :c_parent_constant_name #: String
43
+
44
+ attr_reader :fields #: Array[RBS::Template::Field]
45
+
46
+ def initialize(yaml)
47
+ @ruby_full_name = yaml["name"]
48
+ @ruby_class_name = @ruby_full_name[/[^:]+\z/] # demodulize-like
49
+ name = @ruby_full_name.gsub("::", "_")
50
+ @c_function_name = name.gsub(/(^)?(_)?([A-Z](?:[A-Z]*(?=[A-Z_])|[a-z0-9]*))/) { ($1 || $2 || "_") + $3.downcase } # underscore-like
51
+ @c_function_name.gsub!(/^rbs_types_/, 'rbs_')
52
+ @c_function_name.gsub!(/^rbs_ast_declarations_/, 'rbs_ast_decl_')
53
+ @c_constant_name = @ruby_full_name.gsub("::", "_")
54
+ @c_parent_constant_name = @ruby_full_name.split("::")[0..-2].join("::").gsub("::", "_")
55
+
56
+ @fields = yaml.fetch("fields", []).map { |field| Field.new(field) }.freeze
57
+ end
58
+ end
59
+
60
+ class << self
61
+ def render(out_file)
62
+ filepath = "templates/#{out_file}.erb"
63
+ template = File.expand_path("../#{filepath}", __dir__)
64
+
65
+ erb = read_template(template)
66
+ extension = File.extname(filepath.gsub(".erb", ""))
67
+
68
+ heading = <<~HEADING
69
+ /*----------------------------------------------------------------------------*/
70
+ /* This file is generated by the templates/template.rb script and should not */
71
+ /* be modified manually. */
72
+ /* To change the template see */
73
+ /* #{filepath + " " * (74 - filepath.size) } */
74
+ /*----------------------------------------------------------------------------*/
75
+ HEADING
76
+
77
+ write_to = File.expand_path("../#{out_file}", __dir__)
78
+ contents = heading + "\n" + erb.result_with_hash(locals)
79
+
80
+ if (extension == ".c" || extension == ".h") && !contents.ascii_only?
81
+ # Enforce that we only have ASCII characters here. This is necessary
82
+ # for non-UTF-8 locales that only allow ASCII characters in C source
83
+ # files.
84
+ contents.each_line.with_index(1) do |line, line_number|
85
+ raise "Non-ASCII character on line #{line_number} of #{write_to}" unless line.ascii_only?
86
+ end
87
+ end
88
+
89
+ FileUtils.mkdir_p(File.dirname(write_to))
90
+ File.write(write_to, contents)
91
+ end
92
+
93
+ private
94
+
95
+ def read_template(filepath)
96
+ template = File.read(filepath, encoding: Encoding::UTF_8)
97
+ erb = erb(template)
98
+ erb.filename = filepath
99
+ erb
100
+ end
101
+
102
+ def erb(template)
103
+ ERB.new(template, trim_mode: "-")
104
+ end
105
+
106
+ def locals
107
+ config = YAML.load_file(File.expand_path("../config.yml", __dir__))
108
+ {
109
+ nodes: config.fetch("nodes").map { |node| Type.new(node) }.sort_by(&:ruby_full_name),
110
+ }
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ unless ARGV.size == 1
117
+ $stderr.puts "Usage: ruby template.rb <out_file>"
118
+ exit 1
119
+ end
120
+
121
+ out_file = ARGV.first
122
+ RBS::Template.render(out_file)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.7.0.dev.1
4
+ version: 3.7.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-15 00:00:00.000000000 Z
11
+ date: 2024-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logger
@@ -48,6 +48,7 @@ files:
48
48
  - README.md
49
49
  - Rakefile
50
50
  - Steepfile
51
+ - config.yml
51
52
  - core/array.rbs
52
53
  - core/basic_object.rbs
53
54
  - core/binding.rbs
@@ -121,7 +122,6 @@ files:
121
122
  - core/set.rbs
122
123
  - core/signal.rbs
123
124
  - core/string.rbs
124
- - core/string_io.rbs
125
125
  - core/struct.rbs
126
126
  - core/symbol.rbs
127
127
  - core/thread.rbs
@@ -143,8 +143,6 @@ files:
143
143
  - docs/syntax.md
144
144
  - docs/tools.md
145
145
  - exe/rbs
146
- - ext/rbs_extension/constants.c
147
- - ext/rbs_extension/constants.h
148
146
  - ext/rbs_extension/extconf.rb
149
147
  - ext/rbs_extension/lexer.c
150
148
  - ext/rbs_extension/lexer.h
@@ -158,10 +156,11 @@ files:
158
156
  - ext/rbs_extension/parserstate.c
159
157
  - ext/rbs_extension/parserstate.h
160
158
  - ext/rbs_extension/rbs_extension.h
161
- - ext/rbs_extension/ruby_objs.c
162
- - ext/rbs_extension/ruby_objs.h
163
159
  - ext/rbs_extension/unescape.c
164
160
  - goodcheck.yml
161
+ - include/rbs.h
162
+ - include/rbs/constants.h
163
+ - include/rbs/ruby_objs.h
165
164
  - lib/rbs.rb
166
165
  - lib/rbs/ancestor_graph.rb
167
166
  - lib/rbs/annotate.rb
@@ -342,6 +341,8 @@ files:
342
341
  - sig/version.rbs
343
342
  - sig/visitor.rbs
344
343
  - sig/writer.rbs
344
+ - src/constants.c
345
+ - src/ruby_objs.c
345
346
  - stdlib/abbrev/0/abbrev.rbs
346
347
  - stdlib/abbrev/0/array.rbs
347
348
  - stdlib/base64/0/base64.rbs
@@ -379,7 +380,6 @@ files:
379
380
  - stdlib/logger/0/period.rbs
380
381
  - stdlib/logger/0/severity.rbs
381
382
  - stdlib/minitest/0/kernel.rbs
382
- - stdlib/minitest/0/manifest.yaml
383
383
  - stdlib/minitest/0/minitest.rbs
384
384
  - stdlib/minitest/0/minitest/abstract_reporter.rbs
385
385
  - stdlib/minitest/0/minitest/assertion.rbs
@@ -388,6 +388,8 @@ files:
388
388
  - stdlib/minitest/0/minitest/bench_spec.rbs
389
389
  - stdlib/minitest/0/minitest/benchmark.rbs
390
390
  - stdlib/minitest/0/minitest/composite_reporter.rbs
391
+ - stdlib/minitest/0/minitest/compress.rbs
392
+ - stdlib/minitest/0/minitest/error_on_warning.rbs
391
393
  - stdlib/minitest/0/minitest/expectation.rbs
392
394
  - stdlib/minitest/0/minitest/expectations.rbs
393
395
  - stdlib/minitest/0/minitest/guard.rbs
@@ -412,6 +414,7 @@ files:
412
414
  - stdlib/minitest/0/minitest/test.rbs
413
415
  - stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs
414
416
  - stdlib/minitest/0/minitest/unexpected_error.rbs
417
+ - stdlib/minitest/0/minitest/unexpected_warning.rbs
415
418
  - stdlib/minitest/0/minitest/unit.rbs
416
419
  - stdlib/minitest/0/minitest/unit/test_case.rbs
417
420
  - stdlib/monitor/0/monitor.rbs
@@ -436,6 +439,7 @@ files:
436
439
  - stdlib/pp/0/pp.rbs
437
440
  - stdlib/prettyprint/0/prettyprint.rbs
438
441
  - stdlib/pstore/0/pstore.rbs
442
+ - stdlib/psych/0/core_ext.rbs
439
443
  - stdlib/psych/0/dbm.rbs
440
444
  - stdlib/psych/0/manifest.yaml
441
445
  - stdlib/psych/0/psych.rbs
@@ -467,6 +471,7 @@ files:
467
471
  - stdlib/socket/0/udp_socket.rbs
468
472
  - stdlib/socket/0/unix_server.rbs
469
473
  - stdlib/socket/0/unix_socket.rbs
474
+ - stdlib/stringio/0/stringio.rbs
470
475
  - stdlib/strscan/0/string_scanner.rbs
471
476
  - stdlib/tempfile/0/tempfile.rbs
472
477
  - stdlib/time/0/time.rbs
@@ -509,6 +514,11 @@ files:
509
514
  - stdlib/zlib/0/version_error.rbs
510
515
  - stdlib/zlib/0/zlib.rbs
511
516
  - stdlib/zlib/0/zstream.rbs
517
+ - templates/include/rbs/constants.h.erb
518
+ - templates/include/rbs/ruby_objs.h.erb
519
+ - templates/src/constants.c.erb
520
+ - templates/src/ruby_objs.c.erb
521
+ - templates/template.rb
512
522
  homepage: https://github.com/ruby/rbs
513
523
  licenses:
514
524
  - BSD-2-Clause
@@ -532,7 +542,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
532
542
  - !ruby/object:Gem::Version
533
543
  version: '0'
534
544
  requirements: []
535
- rubygems_version: 3.5.23
545
+ rubygems_version: 3.5.11
536
546
  signing_key:
537
547
  specification_version: 4
538
548
  summary: Type signature for Ruby.