Skip to content

Commit 98ce67c

Browse files
committed
regcomp_study.c - disable CURLYX optimizations when EVAL has been seen anywhere
Historically we disabled CURLYX optimizations when they *contained* an EVAL, on the assumption that the optimization might affect how many times, etc, the eval was called. However, this is also true for CURLYX with evals *afterwards*. If the CURLYN or CURLYM optimization can prune off the search space, then an eval afterwards will be affected. An when you take into account GOSUB, it means that an eval in front might be affected by an optimization after it. So for now we disable CURLYN and CURLYM in any pattern with an EVAL.
1 parent 0678333 commit 98ce67c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

regcomp_debug.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ Perl_debug_studydata(pTHX_ const char *where, scan_data_t *data,
8383
DECLARE_AND_GET_RE_DEBUG_FLAGS;
8484

8585
DEBUG_OPTIMISE_MORE_r({
86-
if (!data)
86+
if (!data) {
87+
Perl_re_indentf(aTHX_ "%s: NO DATA",
88+
depth,
89+
where);
8790
return;
91+
}
8892
Perl_re_indentf(aTHX_ "%s: M/S/D: %" IVdf "/%" IVdf "/%" IVdf " Pos:%" IVdf "/%" IVdf " Flags: 0x%" UVXf,
8993
depth,
9094
where,

regcomp_study.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,23 +2688,26 @@ Perl_study_chunk(pTHX_
26882688
stopmin = min;
26892689
DEBUG_STUDYDATA("after-whilem accept", data, depth, is_inf, min, stopmin, delta);
26902690
}
2691+
DEBUG_STUDYDATA("PRE CURLYX_TO_CURLYN", data, depth, is_inf, min, stopmin, delta);
26912692
/* Try powerful optimization CURLYX => CURLYN. */
26922693
if ( RE_OPTIMIZE_CURLYX_TO_CURLYN
26932694
&& OP(oscan) == CURLYX
26942695
&& data
2695-
&& data->flags & SF_IN_PAR
2696-
&& !(data->flags & SF_HAS_EVAL)
2696+
&& !pRExC_state->code_blocks /* XXX: for now disable whenever eval
2697+
is seen anywhere. We need a better
2698+
way. */
2699+
&& ( ( data->flags & (SF_IN_PAR|SF_HAS_EVAL) ) == SF_IN_PAR )
26972700
&& !deltanext
26982701
&& minnext == 1
26992702
&& mutate_ok
27002703
) {
2704+
DEBUG_STUDYDATA("CURLYX_TO_CURLYN", data, depth, is_inf, min, stopmin, delta);
27012705
/* Try to optimize to CURLYN. */
27022706
regnode *nxt = REGNODE_AFTER_type(oscan, tregnode_CURLYX);
27032707
regnode * const nxt1 = nxt;
27042708
#ifdef DEBUGGING
27052709
regnode *nxt2;
27062710
#endif
2707-
27082711
/* Skip open. */
27092712
nxt = regnext(nxt);
27102713
if (!REGNODE_SIMPLE(OP(nxt))
@@ -2741,10 +2744,15 @@ Perl_study_chunk(pTHX_
27412744
}
27422745
nogo:
27432746

2747+
DEBUG_STUDYDATA("PRE CURLYX_TO_CURLYM", data, depth, is_inf, min, stopmin, delta);
2748+
27442749
/* Try optimization CURLYX => CURLYM. */
27452750
if ( RE_OPTIMIZE_CURLYX_TO_CURLYM
27462751
&& OP(oscan) == CURLYX
27472752
&& data
2753+
&& !pRExC_state->code_blocks /* XXX: for now disable whenever eval
2754+
is seen anywhere. We need a better
2755+
way. */
27482756
&& !(data->flags & (SF_HAS_PAR|SF_HAS_EVAL))
27492757
&& !deltanext /* atom is fixed width */
27502758
&& minnext != 0 /* CURLYM can't handle zero width */
@@ -2753,6 +2761,7 @@ Perl_study_chunk(pTHX_
27532761
&& !(RExC_seen & REG_UNFOLDED_MULTI_SEEN)
27542762
&& mutate_ok
27552763
) {
2764+
DEBUG_STUDYDATA("CURLYX_TO_CURLYM", data, depth, is_inf, min, stopmin, delta);
27562765
/* XXXX How to optimize if data == 0? */
27572766
/* Optimize to a simpler form. */
27582767
regnode *nxt = REGNODE_AFTER_type(oscan, tregnode_CURLYX); /* OPEN */

t/re/pat_re_eval.t

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ sub run_tests {
168168
[ 1, qr#^((??{"(?:bla|)"}))((??{$nested_tags}))$#, "bla blubb <bla><blubb></blubb></bla>", "a b <bla><blubb></blubb></bla>" ],
169169
[ 1, qr#^((??{"(?!)?"}))((??{$nested_tags}))$#, "bla blubb <bla><blubb></blubb></bla>", "a b <bla><blubb></blubb></bla>" ],
170170
[ 1, qr#^((??{"(?:|<(/?bla)>)"}))((??{$nested_tags}))\1$#, "bla blubb <bla><blubb></blubb></bla>", "a b <bla><blubb></blubb></bla>" ],
171-
[ 0, qr#^((??{"(?!)"}))?((??{$nested_tags}))(?!)$#, "bla blubb undef", "a b undef" ],
171+
[ 0, qr#^((??{"(?!)"}))?((??{$nested_tags}))(?!)$#, # changed in perl 5.37.7
172+
"bla blubb blub blu bl b bl b undef",
173+
"a b b u l b l b undef" ],
172174

173175
) { #"#silence vim highlighting
174176
$c++;

0 commit comments

Comments
 (0)