From 61b28e66d04fee911bc320bb27aaef7c75d0bfeb Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 23 Oct 2021 18:03:52 -0700 Subject: [PATCH] fix b1231, rare instability involving -bbp=3 -bbpi=2 -iob -xci --- CHANGES.md | 18 +++++++-------- dev-bin/run_convergence_tests.pl.data | 32 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 13 ++++++++++- 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7621f46e..5ae134bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ## 2021 07 17.04 - - Added two new parameters to control the block types to which the + - Two new parameters were added to control the block types to which the -bl (--opening-brace-on-new-line) flag applies. The new parameters are -block-left-list=s, or -bll=s, and --block-left-exclusion-list=s, or -blxl=s. Previously the -bl flag was 'hardwired' to apply to @@ -17,10 +17,10 @@ the controls. If you want to recover the exact previous default behavior of the -bli then add the -bl flag. - - Partial fix issue for git #74, the -lp formatting style was + - A partial fix was made for issue for git #74. The -lp formatting style was being lost when a one-line anonymous sub was followed by a closing brace. - - Fix issue git #73, the -nfpva flag was not working correctly. + - Fixed issue git #73, in which the -nfpva flag was not working correctly. Some unwanted vertical alignments of spaced function perens were being made. @@ -33,8 +33,8 @@ comment, '#>>V', can be lost. A workaround for the previous version is to include the parameter '-mbl=2'. - - Vertical alignment of function calls without parens has been improved - and is now closer to alignment results with parens. For example + - Vertical alignment of function calls without parens has been improved and + in many cases is closer to what alignment would be if parens had been used. # OLD mkTextConfig $c, $x, $y, -anchor => 'se', $color; @@ -51,12 +51,10 @@ - This version runs 10 to 15 percent faster on large files than the previous release due to optimizations made with the help of NYTProf. - - This version was subjected to over 200 cpu hours of testing with random input - parameters with no instabilities (metastable states) or other irregularities - seen. - - Numerous minor fixes have been made, mostly very rare formatting instabilities - found in random testing. A complete list is at: + found in random testing. An effort has been made to minimize changes to + existing formatting, but some changes will invariably occur. Many of these + updates are listed at: https://github.com/perltidy/perltidy/blob/master/local-docs/BugLog.pod diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 4fb95222..4b9f724b 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -7799,6 +7799,38 @@ $obj= {foo => sub { "bar" ; } --vertical-tightness=2 --weld-nested-containers +==> b1231.in <== +# S1 +@data = + ( + [ + "1st", "2nd", "3rd", "4th", + "5th", "6th", "7th", "8th", + "9th" + ], + [ + 1, 2, 5, 6, 3, 1.5, 1, 3, 4 + ], + ); +# S2 +@data = + ( + [ + "1st", "2nd", "3rd", "4th", "5th", "6th", + "7th", "8th", "9th" + ], + [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4 ], + ); + +==> b1231.par <== +--break-before-paren-and-indent=2 +--break-before-paren=3 +--continuation-indentation=9 +--extended-continuation-indentation +--ignore-old-breakpoints +--indent-columns=1 +--maximum-line-length=47 + ==> b131.in <== unless ( open( SCORE, "+>>$Score_File" ) ) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 41459647..794d5e29 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -9451,7 +9451,10 @@ sub break_before_list_opening_containers { my $length_tol = max( 1, $rOpts_continuation_indentation, $rOpts_indent_columns ); if ($rOpts_ignore_old_breakpoints) { - $length_tol += $rOpts_maximum_line_length; + + # Patch suggested by b1231; the old tol was excessive. + ## $length_tol += $rOpts_maximum_line_length; + $length_tol *= 2; } my $rbreak_before_container_by_seqno = {}; @@ -9507,6 +9510,14 @@ sub break_before_list_opening_containers { my $ci = $rLL->[$KK]->[_CI_LEVEL_]; + # Fix for b1231: the has_list_with_lec does not cover all cases. + # A broken container containing a list and with line-ending commas + # will stay broken, so can be treated as if it had a list with lec. + $has_list_with_lec ||= + $has_list + && $ris_broken_container->{$seqno} + && $rlec_count_by_seqno->{$seqno}; + DEBUG_BBX && print STDOUT "BBX: Looking at seqno=$seqno, token = $token with option=$break_option\n"; -- 2.39.5