diff options
author | Kevin Newton <[email protected]> | 2024-08-28 16:35:03 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-09-12 13:43:04 -0400 |
commit | ea2af5782df63266577ba08a4ef4c30b6d63e564 (patch) | |
tree | 1ef6184d389a1f95fa911f519c7d8c0091502f00 /prism_compile.c | |
parent | f2919bd11c570fc5f5440d1f101be38f61e3d16b (diff) |
Switch the default parser from parse.y to Prism
This commit switches the default parser to Prism. There are a
couple of additional changes related to this that are a part of
this as well to make this happen.
* Switch the default parser in parse.h
* Remove the Prism-specific workflow and add a parse.y-specific
workflow to CI so that it continues to be tested
* Update a few test exclusions since Prism has the correct
behavior but parse.y doesn't per
https://bugs.ruby-lang.org/issues/20504.
* Skips a couple of tests on RBS which are failing because they
are using RubyVM::AbstractSyntaxTree.of.
Fixes [Feature #20564]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11497
Diffstat (limited to 'prism_compile.c')
-rw-r--r-- | prism_compile.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/prism_compile.c b/prism_compile.c index 0be5c92078..29511e7d39 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1399,10 +1399,12 @@ pm_compile_hash_elements(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l switch (PM_NODE_TYPE(element)) { case PM_ASSOC_NODE: { // Pre-allocation check (this branch can be omitted). - if (PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && ( - (!static_literal && ((index + min_tmp_hash_length) < elements->size)) || - (first_chunk && stack_length == 0) - )) { + if ( + PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && ( + (!static_literal && ((index + min_tmp_hash_length) < elements->size)) || + (first_chunk && stack_length == 0) + ) + ) { // Count the elements that are statically-known. size_t count = 1; while (index + count < elements->size && PM_NODE_FLAG_P(elements->nodes[index + count], PM_NODE_FLAG_STATIC_LITERAL)) count++; @@ -5641,6 +5643,14 @@ pm_compile_constant_path_operator_write_node(rb_iseq_t *iseq, const pm_constant_ } /** + * Many nodes in Prism can be marked as a static literal, which means slightly + * different things depending on which node it is. Occasionally we need to omit + * container nodes from static literal checks, which is where this macro comes + * in. + */ +#define PM_CONTAINER_P(node) (PM_NODE_TYPE_P(node, PM_ARRAY_NODE) || PM_NODE_TYPE_P(node, PM_HASH_NODE) || PM_NODE_TYPE_P(node, PM_RANGE_NODE)) + +/** * Compiles a prism node into instruction sequences. * * iseq - The current instruction sequence object (used for locals) @@ -5867,12 +5877,21 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, new_array_size++; } } - else if (PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && !static_literal && ((index + min_tmp_array_size) < elements->size)) { + else if ( + PM_NODE_FLAG_P(element, PM_NODE_FLAG_STATIC_LITERAL) && + !PM_CONTAINER_P(element) && + !static_literal && + ((index + min_tmp_array_size) < elements->size) + ) { // If we have a static literal, then there's the potential // to group a bunch of them together with a literal array // and then concat them together. size_t right_index = index + 1; - while (right_index < elements->size && PM_NODE_FLAG_P(elements->nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL)) right_index++; + while ( + right_index < elements->size && + PM_NODE_FLAG_P(elements->nodes[right_index], PM_NODE_FLAG_STATIC_LITERAL) && + !PM_CONTAINER_P(elements->nodes[right_index]) + ) right_index++; size_t tmp_array_size = right_index - index; if (tmp_array_size >= min_tmp_array_size) { @@ -8975,7 +8994,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, pm_node_t *value = cast->value; name = cast->name; - if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !(PM_NODE_TYPE_P(value, PM_ARRAY_NODE) || PM_NODE_TYPE_P(value, PM_HASH_NODE) || PM_NODE_TYPE_P(value, PM_RANGE_NODE))) { + if (PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) && !PM_CONTAINER_P(value)) { rb_ary_push(default_values, pm_static_literal_value(iseq, value, scope_node)); } else { @@ -9285,7 +9304,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, pm_node_t *value = cast->value; name = cast->name; - if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_NODE_TYPE_P(value, PM_ARRAY_NODE) || PM_NODE_TYPE_P(value, PM_HASH_NODE) || PM_NODE_TYPE_P(value, PM_RANGE_NODE)) { + if (!PM_NODE_FLAG_P(value, PM_NODE_FLAG_STATIC_LITERAL) || PM_CONTAINER_P(value)) { LABEL *end_label = NEW_LABEL(location.line); pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, name, 0); @@ -9815,6 +9834,8 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret, } } +#undef PM_CONTAINER_P + /** True if the given iseq can have pre execution blocks. */ static inline bool pm_iseq_pre_execution_p(rb_iseq_t *iseq) |