prism 2.0.0.rc2 → 2.0.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -2
  3. data/docs/serialization.md +19 -6
  4. data/ext/prism/api_node.c +80 -80
  5. data/ext/prism/extension.c +34 -67
  6. data/ext/prism/extension.h +1 -1
  7. data/include/prism/arena.h +8 -0
  8. data/include/prism/arena.hpp +42 -0
  9. data/include/prism/ast.h +11 -1
  10. data/include/prism/ast.hpp +641 -0
  11. data/include/prism/buffer.h +8 -0
  12. data/include/prism/buffer.hpp +55 -0
  13. data/include/prism/comments.h +17 -0
  14. data/include/prism/compiler/branch.h +26 -0
  15. data/include/prism/compiler/cplusplus.hpp +16 -0
  16. data/include/prism/compiler/exceptions.hpp +17 -0
  17. data/include/prism/compiler/format.h +2 -0
  18. data/include/prism/compiler/lifetimebound.hpp +25 -0
  19. data/include/prism/constant_pool.h +25 -0
  20. data/include/prism/diagnostic.h +18 -0
  21. data/include/prism/errors_format.h +8 -0
  22. data/include/prism/internal/node.h +8 -4
  23. data/include/prism/internal/stringy.h +1 -6
  24. data/include/prism/json.h +8 -0
  25. data/include/prism/line_offset_list.h +8 -0
  26. data/include/prism/magic_comments.h +18 -0
  27. data/include/prism/node.h +55 -10
  28. data/include/prism/node.hpp +272 -0
  29. data/include/prism/node_type.hpp +38 -0
  30. data/include/prism/options.h +10 -1
  31. data/include/prism/options.hpp +43 -0
  32. data/include/prism/parser.h +72 -64
  33. data/include/prism/parser.hpp +274 -0
  34. data/include/prism/prettyprint.h +8 -0
  35. data/include/prism/serialize.h +8 -0
  36. data/include/prism/source.h +8 -0
  37. data/include/prism/stream.h +8 -0
  38. data/include/prism/string_query.h +8 -0
  39. data/include/prism/stringy.h +16 -27
  40. data/include/prism/stringy.hpp +31 -0
  41. data/include/prism/version.h +9 -1
  42. data/include/prism.h +0 -8
  43. data/include/prism.hpp +24 -0
  44. data/lib/prism/serialize.rb +2549 -3281
  45. data/prism.gemspec +14 -1
  46. data/rbi/generated/prism/node.rbi +736 -0
  47. data/rbi/generated/prism/serialize.rbi +6 -5
  48. data/sig/generated/prism/node.rbs +736 -0
  49. data/sig/generated/prism/serialize.rbs +7 -5
  50. data/src/comments.c +2 -2
  51. data/src/diagnostic.c +8 -0
  52. data/src/node.c +216 -368
  53. data/src/options.c +7 -13
  54. data/src/parser.c +52 -48
  55. data/src/prism.c +175 -194
  56. data/src/regexp.c +0 -1
  57. data/src/serialize.c +2300 -1950
  58. data/src/source.c +8 -2
  59. data/src/stringy.c +3 -33
  60. metadata +14 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e07eb7cf91add89de3aa71e9707336a2a561c977b98f5a71ab31c9f0083623e4
4
- data.tar.gz: 684ec87f807ac1e17a3b251746745751707cf300b4d2f6429cdc852102261204
3
+ metadata.gz: 4d4d17cd8ed8987149af4087c871958987c7a842377950efa042958a05101e53
4
+ data.tar.gz: 96b76a2642bb6743ff23d060304901cf4ece8b68a1d5ed9c43d04694fec7106d
5
5
  SHA512:
6
- metadata.gz: 86a9128a3c56bffa1b9c6684f83e2e320fc58113f0a778ff1139d1393573ed5c42db80d7b9665b558aef9af9fbe72d84d929c997ce2ebdbfe07eafaa00864a86
7
- data.tar.gz: 02c7498a1119b1106aa3a75bd07ca4d2aca13ba133e8c716693bbb33cca1d3e6004ccc6811155a4adff65a6758088066e817d7084727b80f7b6437cc280b6040
6
+ metadata.gz: 3ed8f2568284d69d6ed643e4f861e0479858e818e2cbe7c4ba7e95dc879bf31033c764bd440988d9a08ec6212147c01290089e3fc11c9a30b633568c590203e9
7
+ data.tar.gz: 64ede09015b98f79710fb93664575e34e43965f0a36301fba58196e23ebd24897b7673ab62b9300d9aae6f9809e37ea13c7faa48ab69a1bb3aa0298ec92273b2
data/CHANGELOG.md CHANGED
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [2.0.0] - 2026-10-21
10
+
9
11
  ### Highlights
10
12
 
11
13
  - Significant performance and memory usage improvements.
@@ -13,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
13
15
  - Many documentation improvements, including a new playground.
14
16
  - Prism now ships accurate and complete RBS and RBI definitions.
15
17
  - The license is now owned by the Ruby developers.
18
+ - Prism now ships an official C++ interface.
16
19
 
17
20
  ### Added
18
21
 
@@ -67,6 +70,9 @@ Note that for this major version, almost every change listed below is breaking.
67
70
  - Most allocations are now performed through an arena.
68
71
  - You may now build side tables of comment attachments through the `attach_comments` option.
69
72
  - `newline_list` was renamed to `list_offset_list`.
73
+ - Visitor callbacks passed to `pm_visit_node` and `pm_visit_child_nodes` now return a `pm_visit_result_t` instead of a `bool`. Returning `PM_VISIT_DESCEND` or `PM_VISIT_SKIP` replaces returning `true` or `false`, and returning `PM_VISIT_STOP` ends the walk. Both functions now return `false` if the walk was stopped.
74
+ - `pm_string_t` is now a view of bytes owned by someone else. It no longer has a `type` field, `pm_string_owned_init` was removed, and `pm_string_constant_init` was renamed to `pm_string_init`, which takes the bytes as `const uint8_t *`.
75
+ - `pm_options_free` no longer frees the names of scope locals. The parser copies them when it is created, so they only need to remain valid until then.
70
76
 
71
77
  #### Rust
72
78
 
@@ -831,8 +837,9 @@ Note that for this major version, almost every change listed below is breaking.
831
837
 
832
838
  - 🎉 Initial release! 🎉
833
839
 
834
- [unreleased]: https://github.com/ruby/prism/compare/v1.9.0...HEAD
835
- [1.9.0]: https://github.com/ruby/prism/compare/v1.8.0...v1.9.0
840
+ [unreleased]: https://github.com/ruby/prism/compare/v2.0.0...HEAD
841
+ [2.0.0]: https://github.com/ruby/prism/compare/v1.9.0...v2.0.0
842
+ [1.9.0]: https://github.com/ruby/prism/compare/v1.8.1...v1.9.0
836
843
  [1.8.1]: https://github.com/ruby/prism/compare/v1.8.0...v1.8.1
837
844
  [1.8.0]: https://github.com/ruby/prism/compare/v1.7.0...v1.8.0
838
845
  [1.7.0]: https://github.com/ruby/prism/compare/v1.6.0...v1.7.0
@@ -125,8 +125,14 @@ The header is structured like the following table:
125
125
  | varuint | content pool size |
126
126
 
127
127
  After the header comes the body of the serialized string.
128
- The body consists of a sequence of nodes that is built using a prefix traversal order of the syntax tree.
129
- Each node is structured like the following table:
128
+ The body consists of a sequence of nodes that is built using a postfix traversal order of the syntax tree: the children of each node come before the node itself, so the root node comes last.
129
+ The body ends at the content pool offset specified in the header.
130
+
131
+ The children of a node are the values of its `node`, `node?`, and `node[]` fields, which are serialized in the order in which the fields are listed in `config.yml`.
132
+ A `node` field is serialized as its node, a `node?` field is serialized as its node or as a single `0` byte if the node is not present, and a `node[]` field is serialized as each of its nodes in order.
133
+ A loader can therefore keep a stack of loaded nodes: a `0` byte pushes an absent node, and each node pops its children off the top of the stack (they are in field order) and then pushes itself.
134
+
135
+ After its children, each node is structured like the following table:
130
136
 
131
137
  | # bytes | field |
132
138
  | --- | --- |
@@ -135,12 +141,11 @@ Each node is structured like the following table:
135
141
  | location | node location |
136
142
  | varuint | node flags |
137
143
 
138
- Every field on the node is then appended to the serialized string. The fields can be determined by referencing `config.yml`. Depending on the type of field, it could take a couple of different forms, described below:
144
+ Every other field on the node is then appended to the serialized string. The fields can be determined by referencing `config.yml`. Depending on the type of field, it could take a couple of different forms, described below:
139
145
 
140
146
  * `double` - A field that is a `double`. This is structured as a sequence of 8 bytes in native endian order.
141
- * `node` - A field that is a node. This is structured just as like parent node.
142
- * `node?` - A field that is a node that is optionally present. If the node is not present, then a single `0` byte will be written in its place. If it is present, then it will be structured just as like parent node.
143
- * `node[]` - A field that is an array of nodes. This is structured as a variable-length integer length, followed by the child nodes themselves.
147
+ * `node`, `node?` - Nothing is appended here, since the node has already been serialized as a child.
148
+ * `node[]` - A field that is an array of nodes. This is structured as a variable-length integer length, which is the number of children that belong to this field.
144
149
  * `string` - A field that is a string. For example, this is used as the name of the method in a call node, since it cannot directly reference the source string (as in `@-` or `foo=`). This is structured as a variable-length integer byte length, followed by the string bytes (_without_ a trailing null byte).
145
150
  * `constant` - A variable-length integer that represents an index in the constant pool.
146
151
  * `constant?` - An optional variable-length integer that represents an index in the constant pool. If it's not present, then a single `0` byte will be written in its place.
@@ -150,6 +155,14 @@ Every field on the node is then appended to the serialized string. The fields ca
150
155
  * `uint8` - A field that is an 8-bit unsigned integer. This is structured as a single byte.
151
156
  * `uint32` - A field that is a 32-bit unsigned integer. This is structured as a variable-length integer.
152
157
 
158
+ The `body` field of a `DefNode` is lazy, which means that loaders can skip it and load it later. The children of a `DefNode` are preceded by the following, which loaders that do not skip lazy fields can ignore:
159
+
160
+ | # bytes | field |
161
+ | --- | --- |
162
+ | `1` | `255` |
163
+ | `4` | the byte length of the children that come before the `body` child |
164
+ | `4` | the byte length of the `body` child |
165
+
153
166
  After the syntax tree, the content pool is serialized. This is a list of constants that were referenced from within the tree. The content pool begins at the offset specified in the header. Every constant is embedded in the serialization. Each constant is structured as follows:
154
167
 
155
168
  | # bytes | field |