rbs 3.8.0 → 3.9.0.dev.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.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +7 -7
- data/.github/workflows/typecheck.yml +2 -0
- data/.github/workflows/windows.yml +15 -0
- data/.rubocop.yml +20 -1
- data/CHANGELOG.md +14 -0
- data/Rakefile +5 -2
- data/config.yml +6 -0
- data/core/data.rbs +1 -1
- data/core/enumerator.rbs +14 -2
- data/core/exception.rbs +148 -39
- data/core/gc.rbs +2 -2
- data/core/io.rbs +7 -3
- data/core/kernel.rbs +58 -16
- data/core/method.rbs +2 -2
- data/core/module.rbs +3 -3
- data/core/proc.rbs +2 -2
- data/core/ractor.rbs +4 -1
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/regexp.rbs +4 -2
- data/core/ruby_vm.rbs +8 -8
- data/core/rubygems/version.rbs +2 -2
- data/core/string.rbs +1 -1
- data/core/time.rbs +1 -1
- data/core/unbound_method.rbs +1 -1
- data/docs/syntax.md +10 -5
- data/ext/rbs_extension/extconf.rb +2 -1
- data/ext/rbs_extension/location.c +32 -10
- data/ext/rbs_extension/location.h +4 -3
- data/ext/rbs_extension/main.c +22 -1
- data/ext/rbs_extension/parser.c +144 -136
- data/ext/rbs_extension/parserstate.c +40 -9
- data/ext/rbs_extension/parserstate.h +6 -4
- data/include/rbs/ruby_objs.h +6 -6
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/lib/rbs/ast/declarations.rb +9 -4
- data/lib/rbs/ast/directives.rb +10 -0
- data/lib/rbs/ast/members.rb +2 -0
- data/lib/rbs/ast/type_param.rb +2 -2
- data/lib/rbs/cli/validate.rb +1 -0
- data/lib/rbs/cli.rb +3 -3
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -7
- data/lib/rbs/collection/sources/rubygems.rb +1 -1
- data/lib/rbs/definition.rb +46 -31
- data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
- data/lib/rbs/definition_builder.rb +86 -30
- data/lib/rbs/environment.rb +33 -18
- data/lib/rbs/errors.rb +23 -0
- data/lib/rbs/locator.rb +2 -0
- data/lib/rbs/method_type.rb +2 -0
- data/lib/rbs/parser_aux.rb +38 -1
- data/lib/rbs/subtractor.rb +3 -3
- data/lib/rbs/test/hook.rb +2 -2
- data/lib/rbs/test/type_check.rb +7 -5
- data/lib/rbs/types.rb +44 -5
- data/lib/rbs/unit_test/spy.rb +4 -2
- data/lib/rbs/unit_test/type_assertions.rb +17 -11
- data/lib/rbs/validator.rb +4 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +10 -5
- data/lib/rbs.rb +1 -0
- data/rbs.gemspec +1 -1
- data/sig/collection/config/lockfile_generator.rbs +1 -1
- data/sig/declarations.rbs +10 -3
- data/sig/definition.rbs +67 -14
- data/sig/definition_builder.rbs +17 -3
- data/sig/directives.rbs +17 -1
- data/sig/environment.rbs +2 -0
- data/sig/errors.rbs +16 -0
- data/sig/parser.rbs +5 -1
- data/sig/subtractor.rbs +1 -1
- data/sig/test/type_check.rbs +2 -2
- data/sig/type_param.rbs +1 -1
- data/sig/types.rbs +3 -0
- data/sig/unit_test/spy.rbs +2 -0
- data/sig/unit_test/type_assertions.rbs +2 -0
- data/sig/validator.rbs +4 -0
- data/sig/writer.rbs +1 -1
- data/src/ruby_objs.c +12 -6
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/cgi/0/core.rbs +10 -0
- data/stdlib/json/0/json.rbs +52 -50
- data/stdlib/monitor/0/monitor.rbs +13 -4
- data/stdlib/net-http/0/net-http.rbs +2 -2
- data/stdlib/openssl/0/openssl.rbs +73 -73
- data/stdlib/resolv/0/resolv.rbs +8 -8
- data/stdlib/socket/0/addrinfo.rbs +1 -1
- data/stdlib/socket/0/unix_socket.rbs +4 -2
- data/stdlib/stringio/0/stringio.rbs +1 -1
- data/stdlib/uri/0/common.rbs +17 -0
- metadata +4 -7
- data/templates/include/rbs/constants.h.erb +0 -20
- data/templates/include/rbs/ruby_objs.h.erb +0 -10
- data/templates/src/constants.c.erb +0 -36
- data/templates/src/ruby_objs.c.erb +0 -27
- data/templates/template.rb +0 -122
@@ -104,7 +104,9 @@ class UNIXSocket < BasicSocket
|
|
104
104
|
#
|
105
105
|
# *mode* is the same as the argument passed to IO.for_fd
|
106
106
|
#
|
107
|
-
def recv_io: (
|
107
|
+
def recv_io: () -> IO
|
108
|
+
| (singleton(Integer)?) -> Integer
|
109
|
+
| [T] (IO::_ForFd[T], ?untyped mode) -> T
|
108
110
|
|
109
111
|
# <!--
|
110
112
|
# rdoc-file=ext/socket/unixsocket.c
|
@@ -151,7 +153,7 @@ class UNIXSocket < BasicSocket
|
|
151
153
|
#
|
152
154
|
# *io* may be any kind of IO object or integer file descriptor.
|
153
155
|
#
|
154
|
-
def send_io: (
|
156
|
+
def send_io: (IO | Integer) -> void
|
155
157
|
|
156
158
|
private
|
157
159
|
|
data/stdlib/uri/0/common.rbs
CHANGED
@@ -115,6 +115,14 @@ end
|
|
115
115
|
module URI
|
116
116
|
include URI::RFC2396_REGEXP
|
117
117
|
|
118
|
+
# <!--
|
119
|
+
# rdoc-file=lib/uri/common.rb
|
120
|
+
# - decode_uri_component(str, enc=Encoding::UTF_8)
|
121
|
+
# -->
|
122
|
+
# Like URI.decode_www_form_component, except that `'+'` is preserved.
|
123
|
+
#
|
124
|
+
def self.decode_uri_component: (String str, ?encoding enc) -> String
|
125
|
+
|
118
126
|
# <!--
|
119
127
|
# rdoc-file=lib/uri/common.rb
|
120
128
|
# - decode_www_form(str, enc=Encoding::UTF_8, separator: '&', use__charset_: false, isindex: false)
|
@@ -189,6 +197,15 @@ module URI
|
|
189
197
|
#
|
190
198
|
def self.decode_www_form_component: (String str, ?encoding enc) -> String
|
191
199
|
|
200
|
+
# <!--
|
201
|
+
# rdoc-file=lib/uri/common.rb
|
202
|
+
# - encode_uri_component(str, enc=nil)
|
203
|
+
# -->
|
204
|
+
# Like URI.encode_www_form_component, except that `' '` (space) is encoded as
|
205
|
+
# `'%20'` (instead of `'+'`).
|
206
|
+
#
|
207
|
+
def self.encode_uri_component: (String str, ?encoding enc) -> String
|
208
|
+
|
192
209
|
# <!--
|
193
210
|
# rdoc-file=lib/uri/common.rb
|
194
211
|
# - encode_www_form(enum, enc=nil)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.9.0.dev.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Soutaro Matsumoto
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-03-06 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: logger
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- include/rbs.h
|
161
161
|
- include/rbs/constants.h
|
162
162
|
- include/rbs/ruby_objs.h
|
163
|
+
- include/rbs/util/rbs_constant_pool.h
|
163
164
|
- lib/rbs.rb
|
164
165
|
- lib/rbs/ancestor_graph.rb
|
165
166
|
- lib/rbs/annotate.rb
|
@@ -342,6 +343,7 @@ files:
|
|
342
343
|
- sig/writer.rbs
|
343
344
|
- src/constants.c
|
344
345
|
- src/ruby_objs.c
|
346
|
+
- src/util/rbs_constant_pool.c
|
345
347
|
- stdlib/abbrev/0/abbrev.rbs
|
346
348
|
- stdlib/abbrev/0/array.rbs
|
347
349
|
- stdlib/base64/0/base64.rbs
|
@@ -513,11 +515,6 @@ files:
|
|
513
515
|
- stdlib/zlib/0/version_error.rbs
|
514
516
|
- stdlib/zlib/0/zlib.rbs
|
515
517
|
- stdlib/zlib/0/zstream.rbs
|
516
|
-
- templates/include/rbs/constants.h.erb
|
517
|
-
- templates/include/rbs/ruby_objs.h.erb
|
518
|
-
- templates/src/constants.c.erb
|
519
|
-
- templates/src/ruby_objs.c.erb
|
520
|
-
- templates/template.rb
|
521
518
|
homepage: https://github.com/ruby/rbs
|
522
519
|
licenses:
|
523
520
|
- BSD-2-Clause
|
@@ -1,20 +0,0 @@
|
|
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
|
@@ -1,36 +0,0 @@
|
|
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
|
-
}
|
@@ -1,27 +0,0 @@
|
|
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 -%>
|
data/templates/template.rb
DELETED
@@ -1,122 +0,0 @@
|
|
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)
|