Skip to content

Commit 9d82046

Browse files
committed
[ruby/prism] Fix up rebase errors
ruby/prism@b2658d2262
1 parent bf33d7f commit 9d82046

5 files changed

Lines changed: 19 additions & 17 deletions

File tree

prism/prism.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8851,7 +8851,7 @@ escape_write_escape_encoded(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_
88518851
}
88528852

88538853
if (width == 1) {
8854-
if (*parser->current.end == '\n') pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
8854+
if (*parser->current.end == '\n') pm_line_offset_list_append(&parser->metadata_arena, &parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
88558855
escape_write_byte(parser, buffer, regular_expression_buffer, flags, escape_byte(*parser->current.end++, flags));
88568856
} else if (width > 1) {
88578857
// Valid multibyte character. Just ignore escape.
@@ -9168,7 +9168,7 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
91689168
return;
91699169
}
91709170

9171-
if (peeked == '\n') pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
9171+
if (peeked == '\n') pm_line_offset_list_append(&parser->metadata_arena, &parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
91729172
parser->current.end++;
91739173
escape_write_byte(parser, buffer, regular_expression_buffer, flags, escape_byte(peeked, flags | PM_ESCAPE_FLAG_CONTROL));
91749174
return;
@@ -9227,7 +9227,7 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
92279227
return;
92289228
}
92299229

9230-
if (peeked == '\n') pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
9230+
if (peeked == '\n') pm_line_offset_list_append(&parser->metadata_arena, &parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
92319231
parser->current.end++;
92329232
escape_write_byte(parser, buffer, regular_expression_buffer, flags, escape_byte(peeked, flags | PM_ESCAPE_FLAG_CONTROL));
92339233
return;
@@ -9281,15 +9281,15 @@ escape_read(pm_parser_t *parser, pm_buffer_t *buffer, pm_buffer_t *regular_expre
92819281
return;
92829282
}
92839283

9284-
if (peeked == '\n') pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
9284+
if (peeked == '\n') pm_line_offset_list_append(&parser->metadata_arena, &parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 1);
92859285
parser->current.end++;
92869286
escape_write_byte(parser, buffer, regular_expression_buffer, flags, escape_byte(peeked, flags | PM_ESCAPE_FLAG_META));
92879287
return;
92889288
}
92899289
}
92909290
case '\r': {
92919291
if (peek_offset(parser, 1) == '\n') {
9292-
pm_line_offset_list_append(&parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 2);
9292+
pm_line_offset_list_append(&parser->metadata_arena, &parser->line_offsets, PM_TOKEN_END(parser, &parser->current) + 2);
92939293
parser->current.end += 2;
92949294
escape_write_byte_encoded(parser, buffer, flags, escape_byte('\n', flags));
92959295
return;

prism/regexp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pm_regexp_parse_error(pm_regexp_parser_t *parser, const uint8_t *start, const ui
128128
loc_length = (uint32_t) (parser->node_end - parser->node_start);
129129
}
130130

131-
pm_diagnostic_list_append_format(&pm->error_list, loc_start, loc_length, PM_ERR_REGEXP_PARSE_ERROR, message);
131+
pm_diagnostic_list_append_format(&pm->metadata_arena, &pm->error_list, loc_start, loc_length, PM_ERR_REGEXP_PARSE_ERROR, message);
132132
}
133133

134134
/**
@@ -146,7 +146,7 @@ pm_regexp_parse_error(pm_regexp_parser_t *parser, const uint8_t *start, const ui
146146
loc_start__ = (uint32_t) ((parser_)->node_start - pm__->start); \
147147
loc_length__ = (uint32_t) ((parser_)->node_end - (parser_)->node_start); \
148148
} \
149-
pm_diagnostic_list_append_format(&pm__->error_list, loc_start__, loc_length__, diag_id, __VA_ARGS__); \
149+
pm_diagnostic_list_append_format(&pm__->metadata_arena, &pm__->error_list, loc_start__, loc_length__, diag_id, __VA_ARGS__); \
150150
} while (0)
151151

152152
/**
@@ -1397,6 +1397,7 @@ pm_regexp_format_for_error(pm_buffer_t *buffer, const pm_encoding_t *encoding, c
13971397
*/
13981398
#define PM_REGEXP_ENCODING_ERROR(parser, diag_id, ...) \
13991399
pm_diagnostic_list_append_format( \
1400+
&(parser)->parser->metadata_arena, \
14001401
&(parser)->parser->error_list, \
14011402
(uint32_t) ((parser)->node_start - (parser)->parser->start), \
14021403
(uint32_t) ((parser)->node_end - (parser)->node_start), \

prism/templates/src/node.c.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ pm_node_list_grow(pm_arena_t *arena, pm_node_list_t *list, size_t size) {
3939
}
4040

4141
/**
42-
* Append a new node onto the end of the node list.
42+
* Slow path for pm_node_list_append: grow the list and append the node.
43+
* Do not call directly - use pm_node_list_append instead.
4344
*/
4445
void
45-
pm_node_list_append(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
46+
pm_node_list_append_slow(pm_arena_t *arena, pm_node_list_t *list, pm_node_t *node) {
4647
pm_node_list_grow(arena, list, 1);
4748
list->nodes[list->size++] = node;
4849
}

prism/util/pm_char.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ pm_strspn_regexp_option(const uint8_t *string, ptrdiff_t length) {
107107
return pm_strspn_char_kind(string, length, PRISM_CHAR_BIT_REGEXP_OPTION);
108108
}
109109

110-
/**
111-
* Returns true if the given character matches the given kind.
112-
*/
113-
static inline bool
114-
pm_char_is_char_kind(const uint8_t b, uint8_t kind) {
115-
return (pm_byte_table[b] & kind) != 0;
116-
}
117-
118110

119111
/**
120112
* Scan through the string and return the number of characters at the start of

prism/util/pm_strpbrk.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ pm_strpbrk_cache_update(pm_parser_t *parser, const uint8_t *charset) {
6767
memset(parser->strpbrk_cache.high_lut, 0, sizeof(parser->strpbrk_cache.high_lut));
6868
memset(parser->strpbrk_cache.table, 0, sizeof(parser->strpbrk_cache.table));
6969

70+
// Always include NUL in the tables. The slow path uses strchr, which
71+
// always matches NUL (it finds the C string terminator), so NUL is
72+
// effectively always a breakpoint. Replicating that here lets the fast
73+
// scanner handle NUL at full speed instead of bailing to the slow path.
74+
parser->strpbrk_cache.low_lut[0x00] |= (uint8_t) (1 << 0);
75+
parser->strpbrk_cache.high_lut[0x00] = (uint8_t) (1 << 0);
76+
parser->strpbrk_cache.table[0] |= (uint64_t) 1;
77+
7078
size_t charset_len = 0;
7179
for (const uint8_t *c = charset; *c != '\0'; c++) {
7280
parser->strpbrk_cache.low_lut[*c & 0x0F] |= (uint8_t) (1 << (*c >> 4));

0 commit comments

Comments
 (0)