rbs 4.0.3 → 4.1.0
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/.dockerignore +37 -0
- data/.github/workflows/bundle-update.yml +1 -1
- data/.github/workflows/c-check.yml +14 -6
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/jruby.yml +79 -0
- data/.github/workflows/milestone.yml +13 -2
- data/.github/workflows/ruby.yml +43 -3
- data/.github/workflows/rust.yml +13 -10
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +5 -2
- data/.github/workflows/wasm.yml +55 -0
- data/.github/workflows/windows.yml +5 -2
- data/.gitignore +8 -0
- data/CHANGELOG.md +84 -4
- data/Dockerfile.jruby +53 -0
- data/README.md +3 -3
- data/Rakefile +105 -3
- data/Steepfile +9 -0
- data/config.yml +24 -0
- data/core/array.rbs +243 -180
- data/core/builtin.rbs +7 -6
- data/core/class.rbs +5 -3
- data/core/enumerable.rbs +109 -109
- data/core/enumerator/product.rbs +5 -5
- data/core/enumerator.rbs +28 -28
- data/core/file.rbs +24 -1018
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/float.rbs +0 -24
- data/core/hash.rbs +117 -101
- data/core/integer.rbs +21 -58
- data/core/io.rbs +25 -7
- data/core/kernel.rbs +26 -11
- data/core/match_data.rbs +1 -1
- data/core/module.rbs +88 -74
- data/core/numeric.rbs +3 -0
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/pathname.rbs +0 -10
- data/core/ractor.rbs +0 -10
- data/core/range.rbs +23 -23
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/ruby_vm.rbs +40 -0
- data/core/rubygems/errors.rbs +4 -1
- data/core/rubygems/requirement.rbs +0 -10
- data/core/rubygems/rubygems.rbs +4 -1
- data/core/rubygems/specification.rbs +8 -0
- data/core/rubygems/version.rbs +0 -160
- data/core/set.rbs +3 -3
- data/core/struct.rbs +16 -16
- data/core/thread.rbs +9 -14
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/inline.md +65 -7
- data/docs/rbs_by_example.md +20 -20
- data/docs/release.md +69 -0
- data/docs/syntax.md +2 -2
- data/docs/wasm_serialization.md +80 -0
- data/ext/rbs_extension/ast_translation.c +1298 -956
- data/ext/rbs_extension/ast_translation.h +4 -0
- data/ext/rbs_extension/class_constants.c +2 -0
- data/ext/rbs_extension/class_constants.h +1 -0
- data/ext/rbs_extension/extconf.rb +1 -0
- data/ext/rbs_extension/legacy_location.c +11 -6
- data/ext/rbs_extension/main.c +139 -4
- data/include/rbs/ast.h +323 -298
- data/include/rbs/defines.h +13 -0
- data/include/rbs/lexer.h +1 -0
- data/include/rbs/serialize.h +39 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
- data/lib/rbs/ast/ruby/annotations.rb +42 -0
- data/lib/rbs/ast/ruby/comment_block.rb +6 -4
- data/lib/rbs/ast/ruby/declarations.rb +11 -1
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
- data/lib/rbs/ast/ruby/members.rb +40 -1
- data/lib/rbs/buffer.rb +48 -11
- data/lib/rbs/cli.rb +3 -5
- data/lib/rbs/collection/config/lockfile_generator.rb +14 -1
- data/lib/rbs/collection/sources/git.rb +6 -0
- data/lib/rbs/definition_builder/method_builder.rb +12 -6
- data/lib/rbs/environment.rb +10 -3
- data/lib/rbs/inline_parser.rb +54 -28
- data/lib/rbs/namespace.rb +47 -11
- data/lib/rbs/parser_aux.rb +4 -2
- data/lib/rbs/prototype/rbi.rb +193 -25
- data/lib/rbs/prototype/runtime.rb +2 -0
- data/lib/rbs/resolver/type_name_resolver.rb +12 -14
- data/lib/rbs/rewriter.rb +70 -0
- data/lib/rbs/test/type_check.rb +6 -1
- data/lib/rbs/type_name.rb +33 -13
- data/lib/rbs/unit_test/type_assertions.rb +9 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/runtime.rb +196 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +14 -2
- data/lib/rbs_jars.rb +39 -0
- data/lib/rdoc_plugin/parser.rb +5 -0
- data/rbs.gemspec +32 -2
- data/sig/annotate/rdoc_annotater.rbs +12 -9
- data/sig/ast/ruby/annotations.rbs +49 -0
- data/sig/ast/ruby/members.rbs +21 -1
- data/sig/buffer.rbs +19 -1
- data/sig/collection/config/lockfile_generator.rbs +2 -0
- data/sig/inline_parser.rbs +2 -0
- data/sig/manifest.yaml +0 -1
- data/sig/namespace.rbs +20 -0
- data/sig/parser.rbs +10 -0
- data/sig/prototype/rbi.rbs +33 -4
- data/sig/resolver/type_name_resolver.rbs +2 -4
- data/sig/rewriter.rbs +45 -0
- data/sig/typename.rbs +15 -0
- data/sig/unit_test/type_assertions.rbs +4 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/src/ast.c +186 -162
- data/src/lexer.c +220 -193
- data/src/lexer.re +2 -1
- data/src/lexstate.c +10 -1
- data/src/parser.c +55 -5
- data/src/serialize.c +958 -0
- data/src/util/rbs_allocator.c +14 -8
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/delegate/0/delegator.rbs +2 -1
- data/stdlib/digest/0/digest.rbs +11 -5
- data/stdlib/erb/0/erb.rbs +1 -1
- data/stdlib/etc/0/etc.rbs +18 -4
- data/stdlib/fileutils/0/fileutils.rbs +21 -21
- data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
- data/stdlib/json/0/json.rbs +6 -6
- data/stdlib/monitor/0/monitor.rbs +2 -2
- data/stdlib/openssl/0/openssl.rbs +46 -40
- data/stdlib/resolv/0/resolv.rbs +1 -1
- data/stdlib/shellwords/0/shellwords.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +32 -10
- data/stdlib/strscan/0/string_scanner.rbs +74 -55
- data/stdlib/tempfile/0/manifest.yaml +3 -0
- data/stdlib/timeout/0/timeout.rbs +0 -5
- data/stdlib/tsort/0/cyclic.rbs +1 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +9 -9
- data/stdlib/uri/0/generic.rbs +0 -5
- data/stdlib/zlib/0/gzip_reader.rbs +2 -2
- data/stdlib/zlib/0/zstream.rbs +0 -1
- data/wasm/README.md +60 -0
- data/wasm/rbs_wasm.c +423 -0
- metadata +28 -5
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -19
|
@@ -7,6 +7,7 @@ module RBS
|
|
|
7
7
|
| SkipAnnotation
|
|
8
8
|
| ReturnTypeAnnotation
|
|
9
9
|
| InstanceVariableAnnotation
|
|
10
|
+
| ModuleSelfAnnotation
|
|
10
11
|
| ParamTypeAnnotation
|
|
11
12
|
| SplatParamTypeAnnotation
|
|
12
13
|
| DoubleSplatParamTypeAnnotation
|
|
@@ -237,6 +238,54 @@ module RBS
|
|
|
237
238
|
def type_fingerprint: () -> untyped
|
|
238
239
|
end
|
|
239
240
|
|
|
241
|
+
# `@rbs module-self: NAME[ARGS] -- comment` annotation in leading comments
|
|
242
|
+
#
|
|
243
|
+
# ```
|
|
244
|
+
# @rbs module-self: _Each[String, Integer] -- comment
|
|
245
|
+
# ^^^^ -- prefix_location
|
|
246
|
+
# ^^^^^^^^^^^ -- keyword_location
|
|
247
|
+
# ^ -- colon_location
|
|
248
|
+
# ^ -- open_bracket_location
|
|
249
|
+
# ^ -- args_comma_locations[0]
|
|
250
|
+
# ^ -- close_bracket_location
|
|
251
|
+
# ^^^^^^^^^^ -- comment_location
|
|
252
|
+
# ```
|
|
253
|
+
#
|
|
254
|
+
class ModuleSelfAnnotation < Base
|
|
255
|
+
attr_reader keyword_location: Location
|
|
256
|
+
|
|
257
|
+
attr_reader colon_location: Location
|
|
258
|
+
|
|
259
|
+
attr_reader name: TypeName
|
|
260
|
+
|
|
261
|
+
attr_reader args: Array[Types::t]
|
|
262
|
+
|
|
263
|
+
attr_reader open_bracket_location: Location?
|
|
264
|
+
|
|
265
|
+
attr_reader close_bracket_location: Location?
|
|
266
|
+
|
|
267
|
+
attr_reader args_comma_locations: Array[Location]
|
|
268
|
+
|
|
269
|
+
attr_reader comment_location: Location?
|
|
270
|
+
|
|
271
|
+
def initialize: (
|
|
272
|
+
location: Location,
|
|
273
|
+
prefix_location: Location,
|
|
274
|
+
keyword_location: Location,
|
|
275
|
+
colon_location: Location,
|
|
276
|
+
name: TypeName,
|
|
277
|
+
args: Array[Types::t],
|
|
278
|
+
open_bracket_location: Location?,
|
|
279
|
+
close_bracket_location: Location?,
|
|
280
|
+
args_comma_locations: Array[Location],
|
|
281
|
+
comment_location: Location?,
|
|
282
|
+
) -> void
|
|
283
|
+
|
|
284
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
|
285
|
+
|
|
286
|
+
def type_fingerprint: () -> untyped
|
|
287
|
+
end
|
|
288
|
+
|
|
240
289
|
class ParamTypeAnnotation < Base
|
|
241
290
|
attr_reader name_location: Location
|
|
242
291
|
|
data/sig/ast/ruby/members.rbs
CHANGED
|
@@ -16,6 +16,7 @@ module RBS
|
|
|
16
16
|
| IncludeMember | ExtendMember | PrependMember
|
|
17
17
|
| AttrReaderMember | AttrWriterMember | AttrAccessorMember
|
|
18
18
|
| InstanceVariableMember
|
|
19
|
+
| ModuleSelfMember
|
|
19
20
|
|
|
20
21
|
class MethodTypeAnnotation
|
|
21
22
|
class DocStyle
|
|
@@ -83,10 +84,15 @@ module RBS
|
|
|
83
84
|
|
|
84
85
|
attr_reader name: Symbol
|
|
85
86
|
attr_reader node: Prism::DefNode
|
|
87
|
+
attr_reader kind: :instance | :singleton
|
|
86
88
|
attr_reader method_type: MethodTypeAnnotation
|
|
87
89
|
attr_reader leading_comment: CommentBlock?
|
|
88
90
|
|
|
89
|
-
def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation, CommentBlock? leading_comment) -> void
|
|
91
|
+
def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation, CommentBlock? leading_comment, ?kind: :instance | :singleton) -> void
|
|
92
|
+
|
|
93
|
+
def singleton?: () -> bool
|
|
94
|
+
|
|
95
|
+
def instance?: () -> bool
|
|
90
96
|
|
|
91
97
|
def location: () -> Location
|
|
92
98
|
|
|
@@ -172,6 +178,20 @@ module RBS
|
|
|
172
178
|
|
|
173
179
|
def type_fingerprint: () -> untyped
|
|
174
180
|
end
|
|
181
|
+
|
|
182
|
+
class ModuleSelfMember < Base
|
|
183
|
+
attr_reader annotation: Annotations::ModuleSelfAnnotation
|
|
184
|
+
|
|
185
|
+
def initialize: (Buffer, Annotations::ModuleSelfAnnotation) -> void
|
|
186
|
+
|
|
187
|
+
def name: () -> TypeName
|
|
188
|
+
|
|
189
|
+
def args: () -> Array[Types::t]
|
|
190
|
+
|
|
191
|
+
def location: () -> Location
|
|
192
|
+
|
|
193
|
+
def type_fingerprint: () -> untyped
|
|
194
|
+
end
|
|
175
195
|
end
|
|
176
196
|
end
|
|
177
197
|
end
|
data/sig/buffer.rbs
CHANGED
|
@@ -60,6 +60,19 @@ module RBS
|
|
|
60
60
|
def rbs_location: (Prism::Location) -> Location
|
|
61
61
|
| (Prism::Location, Prism::Location) -> Location
|
|
62
62
|
|
|
63
|
+
# Translate a byte offset (into the top buffer's source) to a character offset.
|
|
64
|
+
#
|
|
65
|
+
# Resolution is delegated to the top buffer, which keeps a sparse cache of
|
|
66
|
+
# resolved (byte, char) pairs so successive calls scan only the delta from the
|
|
67
|
+
# nearest cached pair. Amortizes to O(content_size) across all calls; a single
|
|
68
|
+
# call is one byteslice + length.
|
|
69
|
+
#
|
|
70
|
+
def character_offset: (Integer byte_offset) -> Integer
|
|
71
|
+
|
|
72
|
+
# Sparse cache backing `#character_offset`: a pair `[byte_keys, char_values]`
|
|
73
|
+
# kept in ascending byte order to support binary search.
|
|
74
|
+
@character_offset_cache: [Array[Integer], Array[Integer]]?
|
|
75
|
+
|
|
63
76
|
# Construct a buffer from substrings of this buffer.
|
|
64
77
|
#
|
|
65
78
|
# The returned buffer contains lines from given ranges.
|
|
@@ -75,7 +88,12 @@ module RBS
|
|
|
75
88
|
# buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline
|
|
76
89
|
# ```
|
|
77
90
|
#
|
|
78
|
-
|
|
91
|
+
# `byte_lines_hint:` is an optional performance hint: byte ranges corresponding
|
|
92
|
+
# to `lines:`. When provided, slicing uses `byteslice` (O(slice_size) per line)
|
|
93
|
+
# instead of `content[char_range]`, which on a multi-byte string is O(content_size)
|
|
94
|
+
# per call. Result is identical either way.
|
|
95
|
+
#
|
|
96
|
+
%a{pure} def sub_buffer: (lines: Array[Range[Integer]], ?byte_lines_hint: Array[Range[Integer]]?) -> Buffer
|
|
79
97
|
|
|
80
98
|
%a{pure} def parent_buffer: () -> Buffer?
|
|
81
99
|
|
data/sig/inline_parser.rbs
CHANGED
|
@@ -110,6 +110,8 @@ module RBS
|
|
|
110
110
|
|
|
111
111
|
def report_unused_block: (AST::Ruby::CommentBlock) -> void
|
|
112
112
|
|
|
113
|
+
def visit_class_or_module_body: (module_context, Prism::ClassNode | Prism::ModuleNode) -> void
|
|
114
|
+
|
|
113
115
|
private
|
|
114
116
|
|
|
115
117
|
def parse_mixin_call: (Prism::CallNode) -> void
|
data/sig/manifest.yaml
CHANGED
data/sig/namespace.rbs
CHANGED
|
@@ -40,10 +40,30 @@ module RBS
|
|
|
40
40
|
|
|
41
41
|
@parent: Namespace?
|
|
42
42
|
|
|
43
|
+
@hash: Integer?
|
|
44
|
+
|
|
43
45
|
self.@root: Namespace?
|
|
44
46
|
|
|
45
47
|
self.@empty: Namespace?
|
|
46
48
|
|
|
49
|
+
self.@intern_mutex: Mutex
|
|
50
|
+
|
|
51
|
+
# Per-`absolute` flag tries of nested Hashes keyed on path Symbols,
|
|
52
|
+
# with the cached Namespace stored under the `INTERN_LEAF` sentinel
|
|
53
|
+
# at each path's terminal node.
|
|
54
|
+
self.@intern_trie_absolute: Hash[Symbol | Module, untyped]
|
|
55
|
+
|
|
56
|
+
self.@intern_trie_relative: Hash[Symbol | Module, untyped]
|
|
57
|
+
|
|
58
|
+
INTERN_LEAF: Module
|
|
59
|
+
|
|
60
|
+
# Returns an interned `Namespace` instance.
|
|
61
|
+
#
|
|
62
|
+
# Subsequent calls with structurally equal `path` and `absolute` arguments
|
|
63
|
+
# return the same object. The internal `path` array is duplicated and
|
|
64
|
+
# frozen before being cached.
|
|
65
|
+
def self.[]: (Array[Symbol] path, boolish absolute) -> Namespace
|
|
66
|
+
|
|
47
67
|
# Returns new _empty_ namespace.
|
|
48
68
|
def self.empty: () -> Namespace
|
|
49
69
|
|
data/sig/parser.rbs
CHANGED
|
@@ -140,6 +140,16 @@ module RBS
|
|
|
140
140
|
|
|
141
141
|
def self._parse_signature: (Buffer, Integer start_pos, Integer end_pos) -> [Array[AST::Directives::t], Array[AST::Declarations::t]]
|
|
142
142
|
|
|
143
|
+
# Parse and serialize the result to the binary format consumed by
|
|
144
|
+
# RBS::WASM::Deserializer (see ext/rbs_extension/main.c and
|
|
145
|
+
# docs/wasm_serialization.md). The `_to_bytes` variants exist so the
|
|
146
|
+
# round-trip can be exercised on CRuby.
|
|
147
|
+
def self._parse_type_to_bytes: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof, bool void_allowed, bool self_allowed, bool classish_allowed) -> String?
|
|
148
|
+
|
|
149
|
+
def self._parse_method_type_to_bytes: (Buffer, Integer start_pos, Integer end_pos, Array[Symbol] variables, bool require_eof) -> String?
|
|
150
|
+
|
|
151
|
+
def self._parse_signature_to_bytes: (Buffer, Integer start_pos, Integer end_pos) -> String
|
|
152
|
+
|
|
143
153
|
def self._parse_type_params: (Buffer, Integer start_pos, Integer end_pos, bool module_type_params) -> Array[AST::TypeParam]
|
|
144
154
|
|
|
145
155
|
def self._lex: (Buffer, Integer end_pos) -> Array[[Symbol, Location[untyped, untyped]]]
|
data/sig/prototype/rbi.rbs
CHANGED
|
@@ -2,7 +2,17 @@ module RBS
|
|
|
2
2
|
module Prototype
|
|
3
3
|
class RBI
|
|
4
4
|
include Helpers
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
type visibility = :private | :protected | :public
|
|
7
|
+
|
|
8
|
+
class Context
|
|
9
|
+
attr_accessor singleton: bool
|
|
10
|
+
|
|
11
|
+
attr_accessor visibility: visibility
|
|
12
|
+
|
|
13
|
+
def initialize: (singleton: bool, visibility: visibility) -> void
|
|
14
|
+
end
|
|
15
|
+
|
|
6
16
|
attr_reader decls: Array[AST::Declarations::t]
|
|
7
17
|
|
|
8
18
|
type module_decl = AST::Declarations::Class | AST::Declarations::Module
|
|
@@ -13,13 +23,15 @@ module RBS
|
|
|
13
23
|
# Last subsequent `sig` calls
|
|
14
24
|
attr_reader last_sig: Array[RubyVM::AbstractSyntaxTree::Node]?
|
|
15
25
|
|
|
26
|
+
@contexts: Array[Context]
|
|
27
|
+
|
|
28
|
+
@emitted_visibility: Hash[Integer, visibility]
|
|
29
|
+
|
|
16
30
|
def initialize: () -> void
|
|
17
31
|
|
|
18
32
|
def parse: (String) -> void
|
|
19
33
|
|
|
20
|
-
def
|
|
21
|
-
|
|
22
|
-
def current_namespace: () -> Namespace
|
|
34
|
+
def append_decl: (AST::Declarations::t decl) -> void
|
|
23
35
|
|
|
24
36
|
def push_class: (
|
|
25
37
|
RubyVM::AbstractSyntaxTree::Node name,
|
|
@@ -35,6 +47,17 @@ module RBS
|
|
|
35
47
|
# The inner most module/class definition, raises on toplevel
|
|
36
48
|
def current_module!: () -> module_decl
|
|
37
49
|
|
|
50
|
+
def current_context: () -> Context?
|
|
51
|
+
|
|
52
|
+
def current_context!: () -> Context
|
|
53
|
+
|
|
54
|
+
# Visibility of a member, given as `private def ...` in RBS
|
|
55
|
+
#
|
|
56
|
+
# Returns `nil` for members in a visibility _section_, which `sync_visibility` emits instead.
|
|
57
|
+
def member_visibility: (Context) -> AST::Members::visibility?
|
|
58
|
+
|
|
59
|
+
def sync_visibility: (visibility) -> void
|
|
60
|
+
|
|
38
61
|
# Put a `sig` call to current list.
|
|
39
62
|
def push_sig: (RubyVM::AbstractSyntaxTree::Node node) -> void
|
|
40
63
|
|
|
@@ -45,6 +68,12 @@ module RBS
|
|
|
45
68
|
|
|
46
69
|
def process: (RubyVM::AbstractSyntaxTree::Node node, comments: Hash[Integer, AST::Comment], ?outer: Array[RubyVM::AbstractSyntaxTree::Node]) -> void
|
|
47
70
|
|
|
71
|
+
def process_visibility: (RubyVM::AbstractSyntaxTree::Node node, outer: Array[RubyVM::AbstractSyntaxTree::Node], comments: Hash[Integer, AST::Comment]) -> void
|
|
72
|
+
|
|
73
|
+
def process_attribute: (RubyVM::AbstractSyntaxTree::Node node, comments: Hash[Integer, AST::Comment]) -> void
|
|
74
|
+
|
|
75
|
+
def attribute_type: (:attr_reader | :attr_writer | :attr_accessor kind, Array[RubyVM::AbstractSyntaxTree::Node]? sigs) -> Types::t
|
|
76
|
+
|
|
48
77
|
def method_type: (RubyVM::AbstractSyntaxTree::Node? args_node, RubyVM::AbstractSyntaxTree::Node? type_node, variables: Array[AST::TypeParam], overloads: Integer) -> MethodType?
|
|
49
78
|
|
|
50
79
|
def parse_params: (RubyVM::AbstractSyntaxTree::Node args_node, RubyVM::AbstractSyntaxTree::Node args, MethodType method_type, variables: Array[AST::TypeParam], overloads: Integer) -> MethodType
|
|
@@ -6,8 +6,6 @@ module RBS
|
|
|
6
6
|
# It just ignores included modules and super classes.
|
|
7
7
|
#
|
|
8
8
|
class TypeNameResolver
|
|
9
|
-
type query = [TypeName, context]
|
|
10
|
-
|
|
11
9
|
def initialize: (Set[TypeName] all_names, Hash[TypeName, [TypeName, context]] aliases) -> void
|
|
12
10
|
|
|
13
11
|
def self.build: (Environment) -> instance
|
|
@@ -32,7 +30,7 @@ module RBS
|
|
|
32
30
|
|
|
33
31
|
attr_reader aliases: Hash[TypeName, [TypeName, context]]
|
|
34
32
|
|
|
35
|
-
attr_reader cache: Hash[
|
|
33
|
+
attr_reader cache: Hash[context, Hash[TypeName, TypeName?]]
|
|
36
34
|
|
|
37
35
|
# Returns the type name if it exists in `all_names` (normalized)
|
|
38
36
|
#
|
|
@@ -42,7 +40,7 @@ module RBS
|
|
|
42
40
|
#
|
|
43
41
|
def aliased_name?: (TypeName) -> TypeName?
|
|
44
42
|
|
|
45
|
-
def try_cache: (
|
|
43
|
+
def try_cache: (TypeName, context) { () -> TypeName? } -> TypeName?
|
|
46
44
|
|
|
47
45
|
# Translates the head module name in the context and returns an absolute type name
|
|
48
46
|
#
|
data/sig/rewriter.rbs
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
# Rewriter performs targeted character-range replacements on Buffer content.
|
|
3
|
+
#
|
|
4
|
+
# Unlike Writer which regenerates entire source from AST, Rewriter preserves
|
|
5
|
+
# everything outside the rewritten ranges, including non-documentation comments.
|
|
6
|
+
#
|
|
7
|
+
# Rewrite requests are buffered and applied all at once when `#string` is called.
|
|
8
|
+
#
|
|
9
|
+
class Rewriter
|
|
10
|
+
attr_reader buffer: Buffer
|
|
11
|
+
|
|
12
|
+
# Initialize with a toplevel buffer.
|
|
13
|
+
# Raises if the buffer has a parent (non-toplevel).
|
|
14
|
+
#
|
|
15
|
+
def initialize: (Buffer buffer) -> void
|
|
16
|
+
|
|
17
|
+
# Register a rewrite request for the given location.
|
|
18
|
+
#
|
|
19
|
+
def rewrite: (Location[untyped, untyped] location, String string) -> self
|
|
20
|
+
|
|
21
|
+
# Add a new comment before the earliest of the given locations.
|
|
22
|
+
#
|
|
23
|
+
def add_comment: (*Location[untyped, untyped] locations, content: String) -> self
|
|
24
|
+
|
|
25
|
+
# Replace an existing comment's content.
|
|
26
|
+
#
|
|
27
|
+
def replace_comment: (AST::Comment comment, content: String) -> self
|
|
28
|
+
|
|
29
|
+
# Delete an existing comment.
|
|
30
|
+
#
|
|
31
|
+
def delete_comment: (AST::Comment comment) -> self
|
|
32
|
+
|
|
33
|
+
# Apply all buffered rewrites and return the resulting string.
|
|
34
|
+
#
|
|
35
|
+
# Raises if any rewrite ranges overlap.
|
|
36
|
+
#
|
|
37
|
+
def string: () -> String
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def format_comment: (String content, String indent) -> String
|
|
42
|
+
|
|
43
|
+
@rewrites: Array[[Location[untyped, untyped], String]]
|
|
44
|
+
end
|
|
45
|
+
end
|
data/sig/typename.rbs
CHANGED
|
@@ -28,6 +28,21 @@ module RBS
|
|
|
28
28
|
#
|
|
29
29
|
def initialize: (namespace: Namespace, name: Symbol) -> void
|
|
30
30
|
|
|
31
|
+
@hash: Integer?
|
|
32
|
+
|
|
33
|
+
self.@intern_mutex: Mutex
|
|
34
|
+
|
|
35
|
+
# Two-level Hash keyed by canonical Namespace identity (outer uses
|
|
36
|
+
# `compare_by_identity`) and name Symbol.
|
|
37
|
+
self.@intern_cache: Hash[Namespace, Hash[Symbol, TypeName]]
|
|
38
|
+
|
|
39
|
+
# Returns an interned `TypeName` instance.
|
|
40
|
+
#
|
|
41
|
+
# The given `namespace` is canonicalized so cached instances always hold an
|
|
42
|
+
# interned namespace. Subsequent calls with structurally equal arguments
|
|
43
|
+
# return the same object.
|
|
44
|
+
def self.[]: (Namespace namespace, Symbol name) -> TypeName
|
|
45
|
+
|
|
31
46
|
def ==: (untyped other) -> bool
|
|
32
47
|
|
|
33
48
|
def hash: () -> Integer
|
|
@@ -179,6 +179,10 @@ module RBS
|
|
|
179
179
|
#
|
|
180
180
|
def assert_type: (String | Types::t value_type, untyped value) -> void
|
|
181
181
|
|
|
182
|
+
# Asserts if RBS definition declares given `method_name` with `visibility`
|
|
183
|
+
#
|
|
184
|
+
def assert_visibility: (:private | :public visibility, Symbol method_name) -> void
|
|
185
|
+
|
|
182
186
|
# Allow non _simple-type_ method types given to `assert_send_type` and `refute_send_type`
|
|
183
187
|
#
|
|
184
188
|
# ```ruby
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
module WASM
|
|
3
|
+
# Rebuilds RBS::AST objects from the binary buffer produced by
|
|
4
|
+
# `rbs_serialize_node` (src/serialize.c), driven by SerializationSchema.
|
|
5
|
+
class Deserializer
|
|
6
|
+
@bytes: String
|
|
7
|
+
|
|
8
|
+
@buffer: Buffer
|
|
9
|
+
|
|
10
|
+
@encoding: Encoding
|
|
11
|
+
|
|
12
|
+
@pos: Integer
|
|
13
|
+
|
|
14
|
+
@class_cache: Hash[String, untyped]
|
|
15
|
+
|
|
16
|
+
# Deserialize a buffer produced for a whole signature, returning
|
|
17
|
+
# `[directives, declarations]` to match RBS::Parser._parse_signature.
|
|
18
|
+
def self.deserialize: (String bytes, Buffer buffer) -> untyped
|
|
19
|
+
|
|
20
|
+
# Deserialize a bare node list (RBS::Parser._parse_type_params).
|
|
21
|
+
def self.deserialize_node_list: (String bytes, Buffer buffer) -> Array[untyped]
|
|
22
|
+
|
|
23
|
+
# Deserialize the token stream from rbs_wasm_lex (RBS::Parser._lex).
|
|
24
|
+
def self.deserialize_tokens: (String bytes, Buffer buffer) -> Array[[ Symbol, Location ]]
|
|
25
|
+
|
|
26
|
+
def initialize: (String bytes, Buffer buffer) -> void
|
|
27
|
+
|
|
28
|
+
# Reads the next node and returns the reconstructed Ruby value.
|
|
29
|
+
def read_node: () -> untyped
|
|
30
|
+
|
|
31
|
+
def read_node_list: () -> Array[untyped]
|
|
32
|
+
|
|
33
|
+
def read_tokens: () -> Array[[ Symbol, Location ]]
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def read_struct: (Array[untyped] entry) -> untyped
|
|
38
|
+
|
|
39
|
+
def read_field: (untyped reader) -> untyped
|
|
40
|
+
|
|
41
|
+
def read_hash: () -> Hash[untyped, untyped]
|
|
42
|
+
|
|
43
|
+
def read_count: () -> Integer
|
|
44
|
+
|
|
45
|
+
def read_location: (Array[untyped]? loc_children) -> Location?
|
|
46
|
+
|
|
47
|
+
def read_location_value: () -> Location?
|
|
48
|
+
|
|
49
|
+
def read_location_value_list: () -> Array[Location?]
|
|
50
|
+
|
|
51
|
+
def read_attr_ivar_name: () -> (Symbol | false | nil)
|
|
52
|
+
|
|
53
|
+
def read_range: () -> [ Integer, Integer ]?
|
|
54
|
+
|
|
55
|
+
def read_u8: () -> Integer
|
|
56
|
+
|
|
57
|
+
def read_u32: () -> Integer
|
|
58
|
+
|
|
59
|
+
def read_i32: () -> Integer
|
|
60
|
+
|
|
61
|
+
def read_string: (Encoding encoding) -> String
|
|
62
|
+
|
|
63
|
+
def class_for: (String name) -> untyped
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
module WASM
|
|
3
|
+
# Generated from config.yml. See `templates/lib/rbs/wasm/serialization_schema.rb.erb`.
|
|
4
|
+
module SerializationSchema
|
|
5
|
+
# The node tag used for interned symbols (`rbs_ast_symbol`).
|
|
6
|
+
SYMBOL_TAG: Integer
|
|
7
|
+
|
|
8
|
+
# Indexed by node tag. Each entry describes how to decode one node; see the
|
|
9
|
+
# generated file for the exact shape.
|
|
10
|
+
SCHEMA: Array[Array[untyped]?]
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|