From 02dbdb2b85706fb3ff50fa7b27de8278279e8773 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 10 Jan 2022 16:26:57 -0800 Subject: [PATCH] fix b1285, b1286; rare -lp instability --- dev-bin/run_convergence_tests.pl.data | 23 +++++++++ lib/Perl/Tidy/Formatter.pm | 71 +++++++++++++++++---------- 2 files changed, 69 insertions(+), 25 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index c0af63ef..3d4c01ca 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -8824,6 +8824,29 @@ use overload --paren-vertical-tightness=2 --weld-nested-containers +==> b1285.in <== +foreach $func ( + @{$Win32API::Registry::EXPORT_TAGS{FuncA} + }, + @{$Win32API::Registry::EXPORT_TAGS{FuncW} + } + ); + +foreach $func ( + @{$Win32API::Registry::EXPORT_TAGS{FuncA} + }, + @{ $Win32API::Registry::EXPORT_TAGS{FuncW} + } + ); + + +==> b1285.par <== +--brace-vertical-tightness=2 +--continuation-indentation=10 +--extended-line-up-parentheses +--indent-columns=2 +--maximum-line-length=49 + ==> b1287.in <== $" < 2 ? $_[ $/ ][ $. ] |= 1 << $" : diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index e93362cb..8c638ec1 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -20454,6 +20454,8 @@ sub get_available_spaces_to_go { { ## begin closure set_lp_indentation + use constant DEBUG_LP => 0; + # Stack of -lp index objects which survives between batches. my $rLP; my $max_lp_stack; @@ -20903,42 +20905,52 @@ EOM : undef; } - # initialization on empty stack.. $in_lp_mode = $rLP->[$max_lp_stack]->[_lp_object_]; + + #----------------------------------------------- + # Initialize indentation spaces on empty stack.. + #----------------------------------------------- if ( $max_lp_stack == 0 ) { $space_count = $level * $rOpts_indent_columns; } - # if this is a BLOCK, add the standard increment - elsif ($last_nonblank_block_type) { - $space_count += $standard_increment; - } + #---------------------------------------- + # Add the standard space increment if ... + #---------------------------------------- + elsif ( - # if this is not a sequenced item, add the standard increment - elsif ( !$last_nonblank_seqno ) { - $space_count += $standard_increment; - } + # if this is a BLOCK, add the standard increment + $last_nonblank_block_type - # add the standard increment for containers excluded by user - # rules or which contain here-docs or multiline qw text - elsif ( defined($last_nonblank_seqno) - && $ris_excluded_lp_container->{$last_nonblank_seqno} ) - { - $space_count += $standard_increment; - } + # or if this is not a sequenced item + || !$last_nonblank_seqno - # if last nonblank token was not structural indentation, - # just use standard increment - elsif ( $last_nonblank_type ne '{' ) { - $space_count += $standard_increment; - } + # or this continer is excluded by user rules + # or contains here-docs or multiline qw text + || defined($last_nonblank_seqno) + && $ris_excluded_lp_container->{$last_nonblank_seqno} + + # or if last nonblank token was not structural indentation + || $last_nonblank_type ne '{' + + # and do not start -lp under stress .. fixes b1244, b1255 + || !$in_lp_mode && $level >= $lp_cutoff_level + + ) + { - # do not start -lp under stress .. fixes b1244, b1255 - elsif ( !$in_lp_mode && $level >= $lp_cutoff_level ) { + # If we have entered lp mode, use the top lp object to get + # the current indentation spaces because it may have + # changed. Fixes b1285, b1286. + if ($in_lp_mode) { + $space_count = $in_lp_mode->get_spaces(); + } $space_count += $standard_increment; } - # otherwise use the space to the first non-blank level change + #--------------------------------------------------------------- + # -lp mode: try to use space to the first non-blank level change + #--------------------------------------------------------------- else { # see how much space we have available @@ -21013,7 +21025,9 @@ EOM } } - # update state, but not on a blank token + #------------------------------------------- + # update the state, but not on a blank token + #------------------------------------------- if ( $type ne 'b' ) { if ( $rLP->[$max_lp_stack]->[_lp_object_] ) { @@ -21064,6 +21078,13 @@ EOM K_begin_line => $K_begin_line, ); + DEBUG_LP && do { + my $tok_beg = $rLL->[$K_begin_line]->[_TOKEN_]; + print STDERR <= 0 ) { $rlp_object_list->[$max_lp_object_list] = $lp_object; -- 2.39.5