79 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 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 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 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
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 976b89be4a [ruby/prism] Do not report regexp errors twice with captures
When named captures were present we would reprocess the regexp and
accidentally report errors twice.

https://github.com/ruby/prism/commit/e2e11ad07f
2026-10-13 17:12:17 +00:00
Kevin Newton 98fd04f76c [ruby/prism] attach_comments
Revisit how we attach comments, allowing consumers to do it in C.

https://github.com/ruby/prism/commit/eb3528e580
2026-10-12 13:01:34 -04:00
Kevin Newton 31ace4fd6a [ruby/prism] Use SSE2, not SSSE3
Pre-compilation could potentially enable SSSE3, when the target
the code is being installed on might not actually have it. In
order to use more modern instruction sets, we need runtime
detection. It's simpler just to rely on the baseline for now.

https://github.com/ruby/prism/commit/1bab98e441
2026-10-12 15:11:45 +00:00
Kevin Newton 32154539ad [ruby/prism] Add a bitmask on context for context_p
https://github.com/ruby/prism/commit/ba8a8a7642
2026-09-29 20:18:02 +00:00
Kevin Newton b74b3b45e8 [ruby/prism] Add a constant id set
There are times when we don't need explicit order in a list of
constants, namely when looking at names of captures in a pattern
match and names of captures in a regular expression. In these cases
it's better to be linear with respect to the number of names, so
using a hash makes a little more sense.

https://github.com/ruby/prism/commit/d1c23d4956
2026-09-29 19:02:58 +00:00
Kevin Newton da36b454dc [ruby/prism] Add an implicit words sep token
The parse.y grammar has the concept of a words separator that must
delimit words in a word list literal. Prism previously didn't emit
these in the token stream because they don't actually correspond
to any source code.

However, in order to better compare against the vendored grammars,
it's much easier if we do emit them. This commit adds them into
the token stream without actually touching the parser, so it
barely effects anything except conformance.

Since we have split up all those other tokens now and we have this
in place, we now don't need any special handling: our tokens stream
is pretty much exactly a superset of parse.y's token stream,
meaning it's very easy to drive a parse.y grammar using prism's
token stream provided you have a mapping of token names.

https://github.com/ruby/prism/commit/f941f7beb2
2026-09-29 18:55:35 +00:00
Hiroshi SHIBATAandClaude Opus 5.5 2a96d32a95 prism: Use _BitScanForward64 only on 64-bit MSVC
_BitScanForward64 is not available for 32-bit x86, so the i386-mswin32 build failed at prism.c. Use the portable fallback there, as ntz_int64 in internal/bits.h does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 15:59:45 +09:00
Earlopain 8cdc7b5957 [ruby/prism] [Fix https://github.com/ruby/prism/pull/22254] Put real
storage behind `PM_STRING_EMPTY`
(https://github.com/ruby/prism/pull/4228)

Some places memcpy the source, and NULL there is undefined behaviour.

Fixes https://bugs.ruby-lang.org/issues/22254

https://github.com/ruby/prism/commit/d0b36ceb34
2026-09-23 07:42:54 +00:00
Kevin Newton 12e5584ddc [ruby/prism] Warn on duplicated key with **hash only
Previously we were just checking the token, which meant something
like `{ a: 1, **{a: 2}.select { false } }` would warn. As esoteric
as this is, it was possible. This also happily gets rid of the
current_hash_keys field on parser, making it just a tad bit slimmer.

https://github.com/ruby/prism/commit/3783ab0d31
2026-08-27 16:56:51 +00:00
Kevin Newton aa63c4329b [ruby/prism] Fix up duplicate key warning
When there are strings that resolve to the same bytes but resolve
to different encodings, we need to not warn.

https://github.com/ruby/prism/commit/b776e364cd
2026-07-31 13:03:26 +00:00
Kevin Newton 2526cb6154 [ruby/prism] Port diagnostics format to Prism from CRuby
https://github.com/ruby/prism/commit/46a5f19f77
2026-07-24 17:08:34 -04:00
Earlopain 0888fa8cb5 [ruby/prism] Fix Prism.parse_comments locations for FFI backend
Offsets are not serialized but the locations require them to work correctly.

https://github.com/ruby/prism/commit/aa27d61d65
2026-06-17 10:52:40 +00:00
Benoit Daloze d3ef85a100 [ruby/prism] Fix array-bounds error with GCC 9
* In file included from /usr/include/string.h:535,
                 from include/prism/internal/arena.h:12,
                 from src/prism.c:6:
  In function 'memset',
    inlined from 'lex_mode_push_regexp' at src/prism.c:290:5:
  .../string_fortified.h:59:10: error: '__builtin_memset' offset [26, 34] from the object at 'lex_mode' is out of the bounds of referenced subobject 'breakpoints' with type 'uint8_t[7]' {aka 'unsigned char[7]'} at offset 18 [-Werror=array-bounds]

https://github.com/ruby/prism/commit/2908c1c6c5
2026-04-29 08:02:33 +00:00
Earlopain ce398d7545 [ruby/prism] Remove a warning from discarded-qualifiers
I've been seeing this for a while now:
```
../../../../ext/prism/../../src/memchr.c: In function ‘pm_memchr’:
../../../../ext/prism/../../src/memchr.c:35:16: warning: return discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
   35 |         return memchr(memory, character, number);
      |                ^~~~~~
```

https://github.com/ruby/prism/commit/a3b1f10dbc
2026-04-01 11:14:42 +00:00
Kevin Newton a47827c854 [ruby/prism] Provide a single-entry cache on parser for avoiding constant hashes
https://github.com/ruby/prism/commit/56cdcbbb8c
2026-03-20 16:43:58 +00:00
Kevin Newton e72b7a232c [ruby/prism] Rename strings to stringy because of linux conflicts
https://github.com/ruby/prism/commit/eb1d518736
2026-03-20 09:37:43 -04:00
Kevin Newton 6ddd7c65de [ruby/prism] Introduce pm_source_t
https://github.com/ruby/prism/commit/f50c25b5c1
2026-03-20 09:37:43 -04:00
Kevin Newton 8c6d7956f8 [ruby/prism] Also expose pm_constant_id_list_init, pm_constant_id_list_append, and pm_string_owned_init
https://github.com/ruby/prism/commit/a52c48186e
2026-03-20 09:37:43 -04:00
Kevin Newton ce20d6bf01 [ruby/prism] pm_parser_constant_find
https://github.com/ruby/prism/commit/d4a3ef9e43
2026-03-20 09:37:43 -04:00
Kevin Newton 6397c09f72 [ruby/prism] Add necessary functions for CRuby integration
https://github.com/ruby/prism/commit/6ba2c6424e
2026-03-20 09:37:43 -04:00
Kevin Newton 7e0c76d619 [ruby/prism] Clean up documentation
https://github.com/ruby/prism/commit/94d16c61cf
2026-03-20 09:37:43 -04:00
Kevin Newton 0fd41dee8e [ruby/prism] Fix up bindings
https://github.com/ruby/prism/commit/1c1e94849e
2026-03-20 09:37:43 -04:00
Kevin Newton 8261a4f8d9 [ruby/prism] Rebase
https://github.com/ruby/prism/commit/665bcf3056
2026-03-20 09:37:43 -04:00
Kevin Newton 162c22d9b1 [ruby/prism] Make some token logic internal
https://github.com/ruby/prism/commit/06a944a08f
2026-03-20 09:37:43 -04:00
Kevin Newton 84094a5c6e [ruby/prism] Move JSON to its own TU
https://github.com/ruby/prism/commit/3b09886633
2026-03-20 09:37:43 -04:00
Kevin Newton 16f663be85 [ruby/prism] pm_parser_init and pm_parser_cleanup -> internal
https://github.com/ruby/prism/commit/879139efc9
2026-03-20 09:37:43 -04:00
Kevin Newton 367547c113 [ruby/prism] Make the constant pool fully opaque
https://github.com/ruby/prism/commit/250b2c9ac5
2026-03-20 09:37:43 -04:00
Kevin Newton 056554b83d [ruby/prism] Make arena fully opaque
https://github.com/ruby/prism/commit/93085a52d9
2026-03-20 09:37:43 -04:00
Kevin Newton 3308fb6274 [ruby/prism] Move some of arena internal
https://github.com/ruby/prism/commit/639da14de5
2026-03-20 09:37:43 -04:00
Kevin Newton 28e5edb00d [ruby/prism] Move node list append internal
https://github.com/ruby/prism/commit/2867c529a3
2026-03-20 09:37:43 -04:00
Kevin Newton 5aa2d50532 [ruby/prism] Remove iterators, just use callbacks
https://github.com/ruby/prism/commit/e0d17eb9e7
2026-03-20 09:37:43 -04:00
Kevin Newton 6da0749712 [ruby/prism] Fix up build
https://github.com/ruby/prism/commit/bbc2023d0b
2026-03-20 09:37:43 -04:00
Kevin Newton 77612f35f9 [ruby/prism] Move magic comments entirely internal
https://github.com/ruby/prism/commit/f2e8648522
2026-03-20 09:37:43 -04:00
Kevin Newton 90dd3fc604 [ruby/prism] Move diagnostics entirely internal
https://github.com/ruby/prism/commit/6f40516041
2026-03-20 09:37:43 -04:00
Kevin Newton 80c51a80cd [ruby/prism] Move more constants internal
https://github.com/ruby/prism/commit/84b08e23d6
2026-03-20 09:37:43 -04:00
Kevin Newton e94f3013f4 [ruby/prism] Move comment into its own section
https://github.com/ruby/prism/commit/1ddff36b54
2026-03-20 09:37:43 -04:00
Kevin Newton 8b1a08e358 [ruby/prism] Make pm_comment_t opaque
https://github.com/ruby/prism/commit/0b17e49b8b
2026-03-20 09:37:43 -04:00
Kevin Newton e1929edf61 [ruby/prism] Move some options internal metadata internal
https://github.com/ruby/prism/commit/da00377f7d
2026-03-20 09:37:43 -04:00
Kevin Newton 30536aa86d [ruby/prism] Move encoding entirely internal
https://github.com/ruby/prism/commit/10ebcaf908
2026-03-20 09:37:43 -04:00
Kevin Newton 92e3614189 [ruby/prism] Move some serialize functions internal
https://github.com/ruby/prism/commit/2b84d22051
2026-03-20 09:37:43 -04:00
Kevin Newton ffe114ceea [ruby/prism] Move static literals entirely internal
https://github.com/ruby/prism/commit/7cb8b59590
2026-03-20 09:37:43 -04:00
Kevin Newton 0b503f256d [ruby/prism] Make parser an opaque pointer
https://github.com/ruby/prism/commit/3da08fd638
2026-03-20 09:37:43 -04:00