From d85d62be38a373d176a2c269fb2e53829aee43d0 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Thu, 3 Feb 2022 13:04:45 -0800 Subject: [PATCH] fix rare -xlp instability b1314 involving one-line blocks --- dev-bin/run_convergence_tests.pl.data | 44 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 18 +++++++++++ 2 files changed, 62 insertions(+) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 542e0449..d2fd516e 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -9309,6 +9309,50 @@ WriteMakefile( --indent-columns=8 --maximum-line-length=63 +==> b1314.in <== +# S1 +WriteMakefile( + 'NAME' => 'Gimp::Net', + 'VERSION_FROM' => '../Gimp.pm', + +#'INC' => "$INC1 $CPPFLAGS $pdl_inc $cfg{GLIB_CFLAGS} $CFLAGS", + 'INC' => "$INC1 $CPPFLAGS $pdl_inc $CFLAGS", + 'DEFINE' => "$DEFINE1 $DEFS", + 'TYPEMAPS' => + [ "$topdir/typemap", @pdl_typemaps ], + +#dynamic_lib => { OTHERLDFLAGS => "$LDFLAGS $LIBS $cfg{GLIB_LIBS}" }, + dynamic_lib => + { OTHERLDFLAGS => "$LDFLAGS $LIBS" }, + 'PM' => { + 'Net.pm' => '$(INST_LIBDIR)/Net.pm', + }, +); + +# S2 +WriteMakefile( + 'NAME' => 'Gimp::Net', + 'VERSION_FROM' => '../Gimp.pm', + +#'INC' => "$INC1 $CPPFLAGS $pdl_inc $cfg{GLIB_CFLAGS} $CFLAGS", + 'INC' => "$INC1 $CPPFLAGS $pdl_inc $CFLAGS", + 'DEFINE' => "$DEFINE1 $DEFS", + 'TYPEMAPS' => + [ "$topdir/typemap", @pdl_typemaps ], + +#dynamic_lib => { OTHERLDFLAGS => "$LDFLAGS $LIBS $cfg{GLIB_LIBS}" }, + dynamic_lib => + { OTHERLDFLAGS => "$LDFLAGS $LIBS" }, + 'PM' => { 'Net.pm' => '$(INST_LIBDIR)/Net.pm', }, +); + +==> b1314.par <== +--comma-arrow-breakpoints=2 +--continuation-indentation=6 +--extended-line-up-parentheses +--indent-columns=8 +--maximum-line-length=54 + ==> b140.in <== $cmd[ $i ]=[ $s, $e, $cmd, \@hunk, $i ] ; diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7d920fd1..13ffdabb 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -334,6 +334,7 @@ my ( @levels_to_go, @leading_spaces_to_go, @reduced_spaces_to_go, + @standard_spaces_to_go, @mate_index_to_go, @ci_levels_to_go, @nesting_depth_to_go, @@ -12382,6 +12383,8 @@ EOM $leading_spaces_to_go[$max_index_to_go] = $reduced_spaces + $rOpts_continuation_indentation * $ci_level; } + $standard_spaces_to_go[$max_index_to_go] = + $leading_spaces_to_go[$max_index_to_go]; DEBUG_STORE && do { my ( $a, $b, $c ) = caller(); @@ -18946,6 +18949,21 @@ EOM my $excess = $self->excess_line_length( $i_opening_minus, $i ); + # Use standard spaces for indentation of lists in -lp mode + # if it gives a longer line length. This helps to avoid an + # instability due to forming and breaking one-line blocks. + # This fixes case b1314. + my $indentation = $leading_spaces_to_go[$i_opening_minus]; + if ( ref($indentation) + && $ris_broken_container->{$type_sequence} ) + { + my $lp_spaces = $indentation->get_spaces(); + my $std_spaces = + $standard_spaces_to_go[$i_opening_minus]; + my $diff = $std_spaces - $lp_spaces; + if ( $diff > 0 ) { $excess += $diff } + } + my $tol = $length_tol; # boost tol for an -lp container -- 2.39.5