1556 Commits
Author SHA1 Message Date
Kevin Newton e80cd771b3 [ruby/prism] Define PRISM_OOM
So we have a centralized place to handle out of memory errors.

https://github.com/ruby/prism/commit/14969912cc
2026-10-28 05:56:30 +00:00
Kevin Newton 65c8fc01ef [ruby/prism] Avoid strtoul for numbered references
https://github.com/ruby/prism/commit/432884bd14
2026-10-28 05:36:26 +00:00
Kevin Newton c7e123c750 [ruby/prism] Bump to v2.1.0
https://github.com/ruby/prism/commit/ca15cb3d8b
2026-10-28 05:16:22 +00:00
Kevin Newton caf4f279d1 [ruby/prism] Test embedded in CI
Make sure we do not accidentally break newlib/ARM embedded consumers.

https://github.com/ruby/prism/commit/19762c99ce
2026-10-27 14:17:54 +00:00
HASUMI Hitoshi f2f9b55680 [ruby/prism] Let an embedder set PM_CONSTANT_POOL_MIN_CAPACITY
The constant pool starts at source size / 120 entries, 4 at the least,
and doubles at a load of 3/4; each outgrown pair of arrays stays in the
metadata arena. An embedder that interns a fixed set of names into the
pool at every parse (mruby's compiler puts its 58 presyms there, as its
symbol table) grows a short program's pool from 4 to 128 and leaves
about 3 KB behind, as much as the pool itself. With the minimum under
#ifndef it can build with -DPM_CONSTANT_POOL_MIN_CAPACITY=128: measured
on a 32-bit build with 2 KB arena blocks, parsing one REPL line then
holds 6 KB instead of 10 KB. The default stays 4.

https://github.com/ruby/prism/commit/7ed8c71c59
2026-10-26 15:44:00 +00:00
HASUMI Hitoshi ab52c6ab86 [ruby/prism] Include sys/types.h before inttypes.h again, for newlib
61ebe5123 made defines.h include <sys/types.h> ahead of <inttypes.h>:
with an arm-none-eabi toolchain whose <stdint.h> is GCC's own, newlib's
<inttypes.h> never sees the marker it tests before defining the 64-bit
PRI macros, and PRIu64 goes undefined while PRIu32 does not. 400b21739
("Remove defines") took the header out and the workaround with it, so
a cross build of integer.c and errors_format.c, the two files that
include <inttypes.h> now, fails on such a toolchain (Debian's
gcc-arm-none-eabi 13.2.1 with newlib). Put the include back in those
two files, with the note.

https://github.com/ruby/prism/commit/ff42521e49
2026-10-26 15:43:58 +00:00
HASUMI Hitoshi 10c945beab [ruby/prism] Let an embedder set PM_ARENA_INITIAL_SIZE
The arena's first block is 8 KB, sized for a host. An embedder on a
small heap parses short programs (a REPL line uses about 6 KB in two
arenas) and pays two 8 KB blocks for each; with the constant under
#ifndef it can build with -DPM_ARENA_INITIAL_SIZE=2048 instead.

https://github.com/ruby/prism/commit/f7a062efd4
2026-10-26 15:43:57 +00:00
Kevin Newton 51f2767aa0 [ruby/prism] Avoid vsnprintf when possible
When formatting error messages, first try to format into a fixed
buffer instead of formatting once to get the length then a second
time to get the actual format.

https://github.com/ruby/prism/commit/557cffe23e
2026-10-26 15:38:14 +00:00
Kevin Newton 398c61b5eb [ruby/prism] Scratch arena
There are some constructs that only last for the duration of a
parse, and should no longer be held once the parse is through. For
those we should use a scratch arena, freed at the end of parsing.

https://github.com/ruby/prism/commit/30a255539e
2026-10-24 20:17:09 +00:00
Kevin Newton 41fc5017d6 [ruby/prism] Use xxh3 hashing for static literals
Instead of the half-baked murmur hash we were using. Also since
it now nicely spreads out the bits, keep all of the nodes in one
hash/allocation, and keep a 4-pointer buffer on the stack for the
majority case where there aren't that many keys.

https://github.com/ruby/prism/commit/cde8d1183c
2026-10-24 00:43:56 +00:00
Kevin Newton 8eff6a2b7d [ruby/prism] Bump to v2.0.0
https://github.com/ruby/prism/commit/e2727368fd
2026-10-21 14:45:46 +00:00
Kevin Newton 957a081892 [ruby/prism] Ship an official C++ interface
The C++ interface is intentionally minimal: it provides only a
couple of niceties in order to largely stay out of the way. It is
mostly used to provide:

* RAII for opaque resources
* Safe up and down casting for nodes
* string_view for various resources
* Iteration over resource lists

Note that if consumers want to use it, they must be on C++17 at
minimum.

https://github.com/ruby/prism/commit/57b8dbe0e9
2026-10-20 22:15:29 +00:00
Kevin Newton 85513912fa [ruby/prism] Use slice!(-n,n) instead of pop(n) to fix ractors
https://github.com/ruby/prism/commit/bda3cffb2a
2026-10-20 21:37:42 +00:00
Kevin Newton ac6ce58177 [ruby/prism] Fix cygwin
https://github.com/ruby/prism/commit/8adb1555ce
2026-10-20 21:33:59 +00:00
Kevin Newton 4f6a7e0fa9 [ruby/prism] Serialize using post-order traversal
This makes it so that you do not have to recurse when serializing
and deserializing, making this safe for deep trees.

https://github.com/ruby/prism/commit/ab92f0eb4b
2026-10-20 21:02:33 +00:00
Nobuyoshi Nakada b01ca2f752 [ruby/prism] Fix printf format attribute on ucrt64-mingw gcc 16.3
`__MINGW_PRINTF_FORMAT` is defined in stdio.h.

```
prism/buffer.c: In function 'pm_buffer_append_format':
prism/buffer.c:114:5: warning: function 'pm_buffer_append_format' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
  114 |     int result = vsnprintf(NULL, 0, format, arguments);
      |     ^~~
prism/buffer.c:123:9: warning: function 'pm_buffer_append_format' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
  123 |         vsnprintf(buffer->value + cursor, length, format, arguments);
      |         ^~~~~~~~~
```

https://github.com/ruby/prism/commit/72da47973e
2026-10-20 20:29:18 +00:00
Kevin Newton 2564ebb3c9 [ruby/prism] Expose pm_node_list_append and pm_parser_constant_insert
https://github.com/ruby/prism/commit/4896c9f025
2026-10-20 20:14:48 +00:00
Kevin Newton 8f4f3fdd8d [ruby/prism] Make strings just a view into memory
We do not want strings to have the ability or the contract of
having to be freed. This makes the API simpler and keeps us away
from dynamic allocation.

https://github.com/ruby/prism/commit/c9b06230ec
2026-10-20 16:00:01 -04:00
Kevin Newton 0fc3e6a8ae [ruby/prism] Avoid allocating when comparing magic comments
https://github.com/ruby/prism/commit/dd8b706c61
2026-10-20 19:07:47 +00:00
Kevin Newton 660b1f0bcf [ruby/prism] Default options start line to 1
https://github.com/ruby/prism/commit/770e381997
2026-10-20 17:25:17 +00:00
Kevin Newton 01ef241436 [ruby/prism] Add index and at APIs for constants
So that consumers don't unintentionally encode the fact that a
constant id is actually 1 + its index in the constants table.

Ideally this makes it so that we can change the underlying
implementation if we want to.

https://github.com/ruby/prism/commit/3a7f3cb6d5
2026-10-20 13:20:25 -04:00
Kevin Newton f25e997399 [ruby/prism] Add a first/next API for our iterables
This is as opposed to the *_each APIs we have been using, because
that adds the overhead of a passed around callback.

https://github.com/ruby/prism/commit/671ddb0022
2026-10-20 12:28:27 -04:00
Kevin Newton 3357fecc4b [ruby/prism] Expand visit function to return an enum
When visiting, sometimes you want to stop the whole walk, not just
stop at a certain level. For example when you find a particular node.

https://github.com/ruby/prism/commit/8dccefe1cc
2026-10-20 12:09:38 -04:00
Kevin Newton 6bb22453e7 [ruby/prism] Better C++ hygiene
Make all public prism headers check for C++ so that consumers do
not have to wrap includes in extern "C".

https://github.com/ruby/prism/commit/a7071e9939
2026-10-20 03:12:57 +00:00
Kevin Newton 21632a9b14 [ruby/prism] Bump to v2.0.0.rc2
https://github.com/ruby/prism/commit/5962f8f0d0
2026-10-20 01:44:20 +00:00
Kevin Newton ae6ef1bfb5 [ruby/prism] Add checksum
CRuby is now hashing the contents of a file and attaching that to
iseqs in order to properly determine if a file has changed since
it was compiled. This is used in a couple places, but namely it is
used for error_highlight to make sure it isn't highlighting stale
locations.

The hashing algorithm doesn't actually matter since it's just used
to compare across parses, so as long as it is consistent it's okay.
I wanted something fast and standard, so this commit implements the
XXH3_64 algorithm from the spec. Noteably it uses the default
secret and a seed of 0 to make things even simpler. With NEON and
SSE2 implementations, this thing flies quite a bit faster than the
upstream FNV-1a implementation.

I figured this could be useful for other consumers as well, in
particular for tools that generate some kind of metadata around
files (type checkers, linters, etc). Eventually a nice extension
may be to hash a minimal version of the contents (i.e., with
context-insensitive whitespace removed) so that changes to docs or
indentation do not change the hash value.

If you're using the C API, you are only charged for this function
if you actually call it since it is computed lazily. For everyone
else it is automatically called, but truthfully it is so fast that
the difference is completely negligible.

https://github.com/ruby/prism/commit/6b7c5773eb
2026-10-19 17:30:05 -04:00
Earlopain 2720e66e48 [ruby/prism] Add a link to the playground for code examples
Gives it a bit more visibility

https://github.com/ruby/prism/commit/8e0cd483af
2026-10-19 19:50:23 +00:00
Earlopain e4e11a7147 Fix some prism docs
The current version is too dynamic for rdoc
and so C methods like `Ruby::Prism.lex` are not doccumented.

Also tweak `Ruby::Prism` introduction. Ruby makes breaking changes
in minor versions all the time, no need to call it out.
2026-10-19 19:54:37 +02:00
Hiroshi SHIBATAandClaude Opus 5.5 dfe721da1e Clamp the parse_stream line length as size_t
long is narrower than the String length on mswin, so a gets result of 2GiB or more could turn negative, pass the clamp and reach memcpy as a huge size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 16:07:39 +09:00
Kevin Newton 5b1c373522 [ruby/prism] Attach block to correct argument inside jump value
https://github.com/ruby/prism/commit/7e8c702c33
2026-10-17 18:56:13 +00:00
Kevin Newton 58c56248c0 [ruby/prism] Keywords revisit
Introduce a perfect hash for keyword checking so we do not have to
do as many comparisons. This results in about a 1% speed up.

Also, introduce a function called by the C extension and the FFI
backend that can check if something is a keyword.

https://github.com/ruby/prism/commit/9d6a9e7d5f
2026-10-17 00:51:35 +00:00
Kevin Newton 7a5165e403 [ruby/prism] Use free lists for scopes and contexts
https://github.com/ruby/prism/commit/32fe8100c1
2026-10-16 16:59:23 +00:00
Kevin Newton ec4b2917f4 [ruby/prism] token_begins_argument_p cleanup
https://github.com/ruby/prism/commit/990ebbf60b
2026-10-15 21:11:53 +00:00
Kevin Newton 19c0ec232e [ruby/prism] Fix up handling Foo::Bar {} with a comma
https://github.com/ruby/prism/commit/4893d3b94e
2026-10-15 20:43:54 +00:00
Kevin Newton 12c4506f46 [ruby/prism] Fix up not command inside endless def
https://github.com/ruby/prism/commit/c3bdf7c769
2026-10-15 20:43:44 +00:00
Kevin Newton 8c7656f5ba [ruby/prism] Split up command write checks
Previously checking for a command write was the same concept as
checking for a command call, but in reality (and since 4.0) they
are different things.

https://github.com/ruby/prism/commit/e9cdac6b98
2026-10-15 20:24:39 +00:00
Kevin Newton 16e5778e07 [ruby/prism] Handle command assignment with endless def
A very subtle issue, but one that came up with fuzzers.

https://github.com/ruby/prism/commit/b57cd1f440
2026-10-15 19:37:22 +00:00
Kevin Newton 2d234f3cd0 [ruby/prism] Handle some insane syntax
Unparenthesized lambdas with do...end inside a while loop need to
change ever so slightly. No one is using this syntax, but a fuzzer
found it.

https://github.com/ruby/prism/commit/fe09f5ac08
2026-10-15 18:29:54 +00:00
Kevin Newton da2efcbf76 [ruby/prism] Bump to v2.0.0.rc1
https://github.com/ruby/prism/commit/e06e08af29
2026-10-15 14:31:55 +00:00
Kevin Newton 523d4fa59b [ruby/prism] Just abort on OOM for lex mode
https://github.com/ruby/prism/commit/7f276e542c
2026-10-13 22:24:40 +00:00
Kevin Newton 6d167eb483 [ruby/prism] Guard heredoc terminator checking by length
https://github.com/ruby/prism/commit/9c9474fdcd
2026-10-13 22:23:59 +00:00
Kevin Newton 2f4c707a8b [ruby/prism] Remove underscores from floats in one pass
https://github.com/ruby/prism/commit/6a44a3698d
2026-10-13 22:23:20 +00:00
Kevin Newton 56e8d2dd9a [ruby/prism] Invalid range check in EUC-JP
https://github.com/ruby/prism/commit/b81d200453
2026-10-13 22:17:47 +00:00
Earlopain a4ccceacf0 [ruby/prism] Make code examples explicitly ruby for rdoc
Because of the `^^^` hints, it's not valid ruby and so rdoc
gives it no syntax highlighting.
We can convince it otherwise and syntax-highlight syntax-invalid code.

Although it is syntax-invalid, the results look very good.

https://github.com/ruby/prism/commit/338b012386
2026-10-13 19:17:50 +00:00
Kevin Newton 1b19b75b9c [ruby/prism] Default to nearest instead of latest
https://github.com/ruby/prism/commit/b2cb61deb0
2026-10-13 18:13:55 +00:00
Kevin Newton 7dab22936b [ruby/prism] Put a depth check in parse_pattern
https://github.com/ruby/prism/commit/fb2fea4cb2
2026-10-13 17:48:06 +00:00
Kevin Newton 68e7541cfa [ruby/prism] Extract out parse_aref
https://github.com/ruby/prism/commit/aa0ebe032a
2026-10-13 17:48:06 +00:00
Kevin Newton 6227730b95 [ruby/prism] Extract parse_call
https://github.com/ruby/prism/commit/de9a651018
2026-10-13 17:48:06 +00:00
Kevin Newton 1c7dba3df4 [ruby/prism] Extract parse_equal
https://github.com/ruby/prism/commit/cad38e9ce5
2026-10-13 17:48:05 +00:00
Kevin Newton d3d04c19ca [ruby/prism] Extract parse_*_equal
https://github.com/ruby/prism/commit/3ea17ccfec
2026-10-13 17:48:05 +00:00