rbs 4.0.3 → 4.1.3
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/dependabot.yml +1 -1
- data/.github/workflows/bundle-update.yml +2 -2
- 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 +74 -0
- data/.github/workflows/release-gems.yml +235 -0
- 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 +113 -0
- data/Dockerfile.jruby +53 -0
- data/README.md +4 -4
- data/Rakefile +512 -82
- data/Steepfile +9 -0
- data/config.yml +26 -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 +247 -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 +18 -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 +14 -5
- 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 +6 -2
- 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 +61 -8
- 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 +93 -0
- data/wasm/rbs_wasm.c +423 -0
- metadata +29 -6
- data/.github/workflows/milestone.yml +0 -80
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -19
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# RBS AST binary serialization
|
|
2
|
+
|
|
3
|
+
This document describes the binary format used to move a parsed RBS AST out of
|
|
4
|
+
the parser and into Ruby objects without going through the Ruby C API. It exists
|
|
5
|
+
so that RBS can run on Ruby implementations that cannot load the C extension
|
|
6
|
+
(notably JRuby): the parser runs inside WebAssembly, serializes the result with
|
|
7
|
+
this format, and the host rebuilds `RBS::AST` objects in pure Ruby.
|
|
8
|
+
|
|
9
|
+
The encoder (`rbs_serialize_node`, `src/serialize.c`) and the schema that drives
|
|
10
|
+
the decoder (`RBS::WASM::SerializationSchema`, `lib/rbs/wasm/serialization_schema.rb`)
|
|
11
|
+
are both generated from `config.yml`, so they always agree. The decoder itself
|
|
12
|
+
is `RBS::WASM::Deserializer`.
|
|
13
|
+
|
|
14
|
+
## Conventions
|
|
15
|
+
|
|
16
|
+
- All multi-byte integers are **little-endian**.
|
|
17
|
+
- `u8`, `u32` are unsigned; `i32` is signed.
|
|
18
|
+
- `str` is a `u32` byte length followed by that many raw bytes (no terminator).
|
|
19
|
+
- A value is reconstructed to mirror exactly what `ast_translation.c` produces,
|
|
20
|
+
including string encodings: string/integer literal nodes are UTF-8, while
|
|
21
|
+
comments, annotations and symbols use the source buffer's encoding.
|
|
22
|
+
|
|
23
|
+
## Nodes
|
|
24
|
+
|
|
25
|
+
Every node begins with a `u8` **tag**:
|
|
26
|
+
|
|
27
|
+
- `0` — a NULL node (`nil` on the Ruby side).
|
|
28
|
+
- `1..N` — a node type, in the order they appear in `SerializationSchema::SCHEMA`.
|
|
29
|
+
- `SYMBOL_TAG` (`N + 1`) — an interned symbol, followed by `str` (the symbol's
|
|
30
|
+
bytes). Decoded with `String#to_sym`.
|
|
31
|
+
|
|
32
|
+
A few node types are encoded specially, matching their bespoke handling in
|
|
33
|
+
`ast_translation.c`:
|
|
34
|
+
|
|
35
|
+
| Node | Payload after tag | Decoded as |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| `RBS::AST::Bool` | `u8` | `true` / `false` |
|
|
38
|
+
| `RBS::AST::Integer` | `str` | `String#to_i` |
|
|
39
|
+
| `RBS::AST::String` | `str` | the string (UTF-8) |
|
|
40
|
+
| `RBS::Types::Record::FieldType` | node, then `u8` | `[type, required]` |
|
|
41
|
+
| `RBS::Signature` | node-list, then node-list | `[directives, declarations]` |
|
|
42
|
+
| `RBS::Namespace` | node-list, then `u8` | `RBS::Namespace[path, absolute]` |
|
|
43
|
+
| `RBS::TypeName` | node, then node | `RBS::TypeName[namespace, name]` |
|
|
44
|
+
|
|
45
|
+
Every other node is encoded generically:
|
|
46
|
+
|
|
47
|
+
1. If the node exposes a location, its **base location** is written (see below),
|
|
48
|
+
followed by one location range per declared child, in order.
|
|
49
|
+
2. Each field is written in declaration order, encoded by its type (see below).
|
|
50
|
+
|
|
51
|
+
The decoder constructs `Klass.new(location:, **fields)` (omitting `location:`
|
|
52
|
+
for nodes that do not expose one). For `Class`, `Module`, `Interface`,
|
|
53
|
+
`TypeAlias` and `MethodType`, `RBS::AST::TypeParam.resolve_variables` is applied
|
|
54
|
+
to `type_params` first, exactly as the C translation does.
|
|
55
|
+
|
|
56
|
+
## Fields
|
|
57
|
+
|
|
58
|
+
| Field type | Encoding |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| node (`rbs_node`, `rbs_type_name`, `rbs_ast_comment`, `rbs_ast_symbol`, ...) | a node (recursive; NULL allowed) |
|
|
61
|
+
| `rbs_node_list` | `u32` count, then that many nodes |
|
|
62
|
+
| `rbs_hash` | `u32` count, then count × (key node, value node) |
|
|
63
|
+
| `rbs_string` | `str` (source encoding) |
|
|
64
|
+
| `bool` | `u8` |
|
|
65
|
+
| enum | `u8` index into the enum's values (see `SCHEMA`) |
|
|
66
|
+
| `rbs_location_range` | a location range |
|
|
67
|
+
| `rbs_location_range_list` | `u32` count, then that many location ranges |
|
|
68
|
+
| `rbs_attr_ivar_name` | `u8` tag: `0` → `nil`, `1` → `false`, `2` → `str` → symbol |
|
|
69
|
+
|
|
70
|
+
## Location ranges
|
|
71
|
+
|
|
72
|
+
A location range is a `u8` presence flag:
|
|
73
|
+
|
|
74
|
+
- `0` — null range (`nil`, or a node with no location).
|
|
75
|
+
- `1` — followed by `i32` start and `i32` end **character** positions.
|
|
76
|
+
|
|
77
|
+
The base location and child ranges together let the decoder rebuild an
|
|
78
|
+
`RBS::Location` (with its required/optional children) through the public
|
|
79
|
+
`RBS::Location` API, so the same decoder works whether `RBS::Location` is backed
|
|
80
|
+
by the C extension or a pure-Ruby implementation.
|