Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3903419
[Feature #21520] Rename Enumerator::Lazy#tee to #tap_each
Nuzair46 Mar 17, 2026
4bacd06
[ruby/prism] Use an arena for parser metadata
kddnewton Mar 7, 2026
ac38cff
[ruby/prism] Use the parser arena for the constant pool
kddnewton Mar 7, 2026
9fe3151
[ruby/prism] Speed up the constant hash function
kddnewton Mar 8, 2026
b0f68d7
[ruby/prism] Small optimization for parser_lex_magic_comment
kddnewton Mar 8, 2026
de448ea
[ruby/prism] Scan forward through inline whitespace to avoid writing …
kddnewton Mar 8, 2026
81f6ec4
[ruby/prism] Fast-paths for ASCII-only identifiers
kddnewton Mar 8, 2026
345b90b
[ruby/prism] Avoid unnecessary zero-ing of memory
kddnewton Mar 9, 2026
c6e7336
[ruby/prism] Pre-size arena to avoid unnecessary growth
kddnewton Mar 9, 2026
dfad9e8
[ruby/prism] Force the allocation to be inlined
kddnewton Mar 9, 2026
a91ae84
[ruby/prism] Inline pm_node_list_append, pm_char_is_whitespace, and p…
kddnewton Mar 9, 2026
648d46b
[ruby/prism] Avoid redundant whitespace scanning in magic comment lexing
kddnewton Mar 9, 2026
45f76d2
[ruby/prism] Potentially skip whitespace scanning for speed
kddnewton Mar 9, 2026
5ea721f
[ruby/prism] Inline three more functions, and lower the hash threshol…
kddnewton Mar 9, 2026
f042a3c
[ruby/prism] Lex simple integer values as we are lexing
kddnewton Mar 10, 2026
6551864
[ruby/prism] Only dispatch to lex_optional_float_suffix when it is po…
kddnewton Mar 10, 2026
c746def
[ruby/prism] Optimize constant pool hash for short strings
kddnewton Mar 10, 2026
120c9ed
[ruby/prism] Include string in constant pool entry to avoid chasing p…
kddnewton Mar 10, 2026
0666cea
[ruby/prism] SIMD/SWAR for strpbrk
kddnewton Mar 10, 2026
9a76883
[ruby/prism] Fix a bug where we removed the \r warning
kddnewton Mar 10, 2026
169ba06
[ruby/prism] Use a bloom filter to quickly reject local lookups
kddnewton Mar 11, 2026
bf33d7f
[ruby/prism] Cache strpbrk lookup tables
kddnewton Mar 11, 2026
9d82046
[ruby/prism] Fix up rebase errors
kddnewton Mar 17, 2026
c133e04
[ruby/prism] More correctly detect SIMD on MSVC
kddnewton Mar 17, 2026
677286e
[ruby/prism] Ensure allocations to the constant pool are through the …
kddnewton Mar 17, 2026
84611ce
Update constant pool API calls
kddnewton Mar 17, 2026
e09ca77
Update depend with new Prism structure
kddnewton Mar 17, 2026
ec3162c
Fix infinite loop in parser_lex_magic_comment
kddnewton Mar 17, 2026
5026acf
Do not use GCC-specific syntax for lookup tables
kddnewton Mar 17, 2026
968b999
[PRISM] Fix ASAN reading off end of strpbrk cache
kddnewton Mar 17, 2026
af85de8
Do not update the `dump_ast` specified in the `configure` options
nobu Mar 17, 2026
f7816b0
win32/configure.bat: Add `--with-dump-ast` option
nobu Mar 17, 2026
b7e4d57
ZJIT: linear scan register allocator (#16295)
tenderlove Mar 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ preludes: {$(VPATH)}miniprelude.c

{$(srcdir)}.rb.rbinc:
$(ECHO) making $@
-$(Q) $(MAKE) $(DUMP_AST)
-$(Q) $(MAKE) $(DUMP_AST_TARGET)
$(Q) $(BASERUBY) $(tooldir)/mk_builtin_loader.rb $(DUMP_AST) $(SRC_FILE)

$(BUILTIN_BINARY:yes=built)in_binary.rbbin: $(PREP) $(BUILTIN_RB_SRCS) $(srcdir)/template/builtin_binary.rbbin.tmpl
Expand Down
7 changes: 4 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ AC_SUBST(HAVE_BASERUBY)

AC_ARG_WITH(dump-ast,
AS_HELP_STRING([--with-dump-ast=DUMP_AST], [use DUMP_AST as dump_ast; for cross-compiling with a host-built dump_ast]),
[DUMP_AST=$withval],
[DUMP_AST='./dump_ast$(EXEEXT)'])
AC_SUBST(DUMP_AST)
[DUMP_AST=$withval DUMP_AST_TARGET=no],
[DUMP_AST='./dump_ast$(EXEEXT)' DUMP_AST_TARGET='$(DUMP_AST)'])
AC_SUBST(X_DUMP_AST, "${DUMP_AST}")
AC_SUBST(X_DUMP_AST_TARGET, "${DUMP_AST_TARGET}")

: ${GIT=git}
HAVE_GIT=yes
Expand Down
5 changes: 5 additions & 0 deletions depend
Original file line number Diff line number Diff line change
Expand Up @@ -11654,6 +11654,7 @@ prism/node.$(OBJEXT): {$(VPATH)}prism_xallocator.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/options.c
prism/options.$(OBJEXT): $(top_srcdir)/prism/options.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/util/pm_arena.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/util/pm_char.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/util/pm_line_offset_list.h
prism/options.$(OBJEXT): $(top_srcdir)/prism/util/pm_string.h
Expand Down Expand Up @@ -11965,6 +11966,7 @@ prism/util/pm_arena.$(OBJEXT): {$(VPATH)}internal/has/warning.h
prism/util/pm_arena.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
prism/util/pm_arena.$(OBJEXT): {$(VPATH)}prism_xallocator.h
prism/util/pm_buffer.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/util/pm_buffer.$(OBJEXT): $(top_srcdir)/prism/util/pm_arena.h
prism/util/pm_buffer.$(OBJEXT): $(top_srcdir)/prism/util/pm_buffer.c
prism/util/pm_buffer.$(OBJEXT): $(top_srcdir)/prism/util/pm_buffer.h
prism/util/pm_buffer.$(OBJEXT): $(top_srcdir)/prism/util/pm_char.h
Expand Down Expand Up @@ -11994,6 +11996,7 @@ prism/util/pm_buffer.$(OBJEXT): {$(VPATH)}internal/has/warning.h
prism/util/pm_buffer.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
prism/util/pm_buffer.$(OBJEXT): {$(VPATH)}prism_xallocator.h
prism/util/pm_char.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/util/pm_char.$(OBJEXT): $(top_srcdir)/prism/util/pm_arena.h
prism/util/pm_char.$(OBJEXT): $(top_srcdir)/prism/util/pm_char.c
prism/util/pm_char.$(OBJEXT): $(top_srcdir)/prism/util/pm_char.h
prism/util/pm_char.$(OBJEXT): $(top_srcdir)/prism/util/pm_line_offset_list.h
Expand Down Expand Up @@ -12050,6 +12053,7 @@ prism/util/pm_constant_pool.$(OBJEXT): {$(VPATH)}internal/has/warning.h
prism/util/pm_constant_pool.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
prism/util/pm_constant_pool.$(OBJEXT): {$(VPATH)}prism_xallocator.h
prism/util/pm_integer.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/util/pm_integer.$(OBJEXT): $(top_srcdir)/prism/util/pm_arena.h
prism/util/pm_integer.$(OBJEXT): $(top_srcdir)/prism/util/pm_buffer.h
prism/util/pm_integer.$(OBJEXT): $(top_srcdir)/prism/util/pm_char.h
prism/util/pm_integer.$(OBJEXT): $(top_srcdir)/prism/util/pm_integer.c
Expand Down Expand Up @@ -12080,6 +12084,7 @@ prism/util/pm_integer.$(OBJEXT): {$(VPATH)}internal/has/warning.h
prism/util/pm_integer.$(OBJEXT): {$(VPATH)}internal/xmalloc.h
prism/util/pm_integer.$(OBJEXT): {$(VPATH)}prism_xallocator.h
prism/util/pm_line_offset_list.$(OBJEXT): $(top_srcdir)/prism/defines.h
prism/util/pm_line_offset_list.$(OBJEXT): $(top_srcdir)/prism/util/pm_arena.h
prism/util/pm_line_offset_list.$(OBJEXT): $(top_srcdir)/prism/util/pm_line_offset_list.c
prism/util/pm_line_offset_list.$(OBJEXT): $(top_srcdir)/prism/util/pm_line_offset_list.h
prism/util/pm_line_offset_list.$(OBJEXT): {$(VPATH)}config.h
Expand Down
18 changes: 9 additions & 9 deletions enumerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ lazy_with_index(int argc, VALUE *argv, VALUE obj)
}

static struct MEMO *
lazy_tee_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_index)
lazy_tap_each_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_index)
{
struct proc_entry *entry = proc_entry_ptr(proc_entry);

Expand All @@ -2781,13 +2781,13 @@ lazy_tee_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_inde
return result;
}

static const lazyenum_funcs lazy_tee_funcs = {
lazy_tee_proc, 0,
static const lazyenum_funcs lazy_tap_each_funcs = {
lazy_tap_each_proc, 0,
};

/*
* call-seq:
* lazy.tee { |item| ... } -> lazy_enumerator
* lazy.tap_each { |item| ... } -> lazy_enumerator
*
* Passes each element through to the block for side effects only,
* without modifying the element or affecting the enumeration.
Expand All @@ -2797,7 +2797,7 @@ static const lazyenum_funcs lazy_tee_funcs = {
* without breaking laziness or misusing +map+.
*
* (1..).lazy
* .tee { |x| puts "got #{x}" }
* .tap_each { |x| puts "got #{x}" }
* .select(&:even?)
* .first(3)
* # prints: got 1, got 2, ..., got 6
Expand All @@ -2807,14 +2807,14 @@ static const lazyenum_funcs lazy_tee_funcs = {
*/

static VALUE
lazy_tee(VALUE obj)
lazy_tap_each(VALUE obj)
{
if (!rb_block_given_p())
{
rb_raise(rb_eArgError, "tried to call lazy tee without a block");
rb_raise(rb_eArgError, "tried to call lazy tap_each without a block");
}

return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_tee_funcs);
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_tap_each_funcs);
}

#if 0 /* for RDoc */
Expand Down Expand Up @@ -4692,7 +4692,7 @@ InitVM_Enumerator(void)
rb_define_method(rb_cLazy, "uniq", lazy_uniq, 0);
rb_define_method(rb_cLazy, "compact", lazy_compact, 0);
rb_define_method(rb_cLazy, "with_index", lazy_with_index, -1);
rb_define_method(rb_cLazy, "tee", lazy_tee, 0);
rb_define_method(rb_cLazy, "tap_each", lazy_tap_each, 0);

lazy_use_super_method = rb_hash_new_with_size(18);
rb_hash_aset(lazy_use_super_method, sym("map"), sym("_enumerable_map"));
Expand Down
55 changes: 55 additions & 0 deletions prism/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@
# define inline __inline
#endif

/**
* Force a function to be inlined at every call site. Use sparingly — only for
* small, hot functions where the compiler's heuristics fail to inline.
*/
#if defined(_MSC_VER)
# define PRISM_FORCE_INLINE __forceinline
#elif defined(__GNUC__) || defined(__clang__)
# define PRISM_FORCE_INLINE inline __attribute__((always_inline))
#else
# define PRISM_FORCE_INLINE inline
#endif

/**
* Old Visual Studio versions before 2015 do not implement sprintf, but instead
* implement _snprintf. We standard that here.
Expand Down Expand Up @@ -264,6 +276,49 @@
#define PRISM_UNLIKELY(x) (x)
#endif

/**
* Platform detection for SIMD / fast-path implementations. At most one of
* these macros is defined, selecting the best available vectorization strategy.
*/
#if (defined(__aarch64__) && defined(__ARM_NEON)) || (defined(_MSC_VER) && defined(_M_ARM64))
#define PRISM_HAS_NEON
#elif (defined(__x86_64__) && defined(__SSSE3__)) || (defined(_MSC_VER) && defined(_M_X64))
#define PRISM_HAS_SSSE3
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define PRISM_HAS_SWAR
#endif

/**
* Count trailing zero bits in a 64-bit value. Used by SWAR identifier scanning
* to find the first non-matching byte in a word.
*
* Precondition: v must be nonzero. The result is undefined when v == 0
* (matching the behavior of __builtin_ctzll and _BitScanForward64).
*/
#if defined(__GNUC__) || defined(__clang__)
#define pm_ctzll(v) ((unsigned) __builtin_ctzll(v))
#elif defined(_MSC_VER)
#include <intrin.h>
static inline unsigned pm_ctzll(uint64_t v) {
unsigned long index;
_BitScanForward64(&index, v);
return (unsigned) index;
}
#else
static inline unsigned
pm_ctzll(uint64_t v) {
unsigned c = 0;
v &= (uint64_t) (-(int64_t) v);
if (v & 0x00000000FFFFFFFFULL) c += 0; else c += 32;
if (v & 0x0000FFFF0000FFFFULL) c += 0; else c += 16;
if (v & 0x00FF00FF00FF00FFULL) c += 0; else c += 8;
if (v & 0x0F0F0F0F0F0F0F0FULL) c += 0; else c += 4;
if (v & 0x3333333333333333ULL) c += 0; else c += 2;
if (v & 0x5555555555555555ULL) c += 0; else c += 1;
return c;
}
#endif

/**
* We use -Wimplicit-fallthrough to guard potentially unintended fall-through between cases of a switch.
* Use PRISM_FALLTHROUGH to explicitly annotate cases where the fallthrough is intentional.
Expand Down
19 changes: 18 additions & 1 deletion prism/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,31 @@
#define PM_NODE_LIST_FOREACH(list, index, node) \
for (size_t index = 0; index < (list)->size && ((node) = (list)->nodes[index]); index++)

/**
* Slow path for pm_node_list_append: grow the list and append the node.
* Do not call directly — use pm_node_list_append instead.
*
* @param arena The arena to allocate from.
* @param list The list to append to.
* @param node The node to append.
*/
void pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);

/**
* Append a new node onto the end of the node list.
*
* @param arena The arena to allocate from.
* @param list The list to append to.
* @param node The node to append.
*/
void pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node);
static PRISM_FORCE_INLINE void
pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
if (list->size < list->capacity) {
list->nodes[list->size++] = node;
} else {
pm_node_list_append_slow(arena, list, node);
}
}

/**
* Prepend a new node onto the beginning of the node list.
Expand Down
Loading