]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix b1232, rare formatting instability
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 25 Oct 2021 22:49:20 +0000 (15:49 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 25 Oct 2021 22:49:20 +0000 (15:49 -0700)
CHANGES.md
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/VerticalAligner.pm
local-docs/Release-Checklist.md

index a154df536ccb0e6edac5220ac3fb2c294f732124..5beb72fc7e78f61a4b0f97b46c83d4b04d41744e 100644 (file)
@@ -7,7 +7,7 @@
       lists of call args which are not contained within parens (next item).
 
     - Vertical alignment of function calls without parens has been improved with
-      the goal of making vertical alignment the essentially the same with or
+      the goal of making vertical alignment essentially the same with or
       without parens around the call args.  Some examples:
 
         # OLD
     - This version runs 10 to 15 percent faster on large files than the
       previous release due to optimizations made with the help of NYTProf.
 
+    - Robustness of perltidy is high. This version was subjected to many
+      cpu hours of testing with random input parameters. No instabilities,
+      internal fault checks, undefined variable references or other
+      irregularities were seen.
+
     - Numerous minor fixes have been made, mostly very rare formatting instabilities
       found in random testing. An effort has been made to minimize changes to
       existing formatting that these fixes produce, but occasional changes
index 4b9f724bfb55869e552a0b8071168c3e5a8e49e2..6bdff02fbd33c3e5097da535918d47e0d44111ae 100644 (file)
@@ -7831,6 +7831,28 @@ $obj= {foo => sub { "bar" ; }
 --indent-columns=1
 --maximum-line-length=47
 
+==> b1232.in <==
+# S1
+        $method.="AdminMode"
+          if(
+              (defined($context->{args}->{admin_mode}))
+              &&($context->{args}->{admin_mode}eq"yes")
+          );
+# S2
+        $method.="AdminMode"
+          if( (defined($context->{args}->{admin_mode}))
+              &&($context->{args}->{admin_mode}eq"yes")
+          );
+
+==> b1232.par <==
+--noadd-whitespace
+--delete-old-whitespace
+--indent-columns=8
+--line-up-parentheses
+--maximum-line-length=55
+--paren-vertical-tightness=1
+--weld-nested-containers
+
 ==> b131.in <==
         unless
           ( open( SCORE, "+>>$Score_File" ) )
index ff7c10e9529b8fd45d8ce72aa85c55c46672eab2..a81d3924fee4bee459995869791cb7566e678a39 100644 (file)
@@ -8494,14 +8494,69 @@ EOM
             # (2) the line does not exceed the allowable length
             if ( $iline_oo == $iline_oc ) {
 
-                # All the tokens are on one line, now check their length:
-                # - measure entire line if balanced
+                # All the tokens are on one line, now check their length.
+                # Start with the full line index range. We will reduce this
+                # in the coding below in some cases.
+                my $Kstart = $Kfirst;
+                my $Kstop  = $Klast;
+
+                # Note that the following minimal choice for measuring will
+                # work and will not cause any instabilities because it is
+                # invariant:
+
+                ##  my $Kstart = $Kouter_opening;
+                ##  my $Kstop  = $Kouter_closing;
+
+                # But that can lead to some undesirable welds.  So a little
+                # more complicated method has been developed.
+
+                # We are trying to avoid creating bad two-line welds when we are
+                # working on long, previously unwelded input text, such as
+
+                # INPUT (example of a long input line weld candidate):
+                ## $mutation->transpos( $self->RNA->position($mutation->label, $atg_label));
+
+                #  GOOD two-line break: (not welded; result marked too long):
+                ## $mutation->transpos(
+                ##                 $self->RNA->position($mutation->label, $atg_label));
+
+                #  BAD two-line break: (welded; result if we weld):
+                ## $mutation->transpos($self->RNA->position(
+                ##                                      $mutation->label, $atg_label));
+
+                # We can only get an approximate estimate of the final length,
+                # since the line breaks may change, and for -lp mode because
+                # even the indentation is not yet known.
+
+                my $level_first = $rLL->[$Kfirst]->[_LEVEL_];
+                my $level_last  = $rLL->[$Klast]->[_LEVEL_];
+                my $level_oo    = $rLL->[$Kouter_opening]->[_LEVEL_];
+                my $level_oc    = $rLL->[$Kouter_closing]->[_LEVEL_];
+
+                # - measure to the end of the original line if balanced
                 # - measure to the closing container if unbalanced (fixes b1230)
-                my $is_balanced =
-                  $rLL->[$Kfirst]->[_LEVEL_] == $rLL->[$Klast]->[_LEVEL_];
-                my $Kstop = $is_balanced ? $Klast : $Kouter_closing;
+                #if ( $level_first != $level_last ) { $Kstop = $Kouter_closing }
+                if ( $level_oc > $level_last ) { $Kstop = $Kouter_closing }
+
+                # - measure from the start of the original line if balanced
+                # - measure from the most previous token with same level
+                #   if unbalanced (b1232)
+                if ( $Kouter_opening > $Kfirst && $level_oo > $level_first ) {
+                    $Kstart = $Kouter_opening;
+                    for (
+                        my $KK = $Kouter_opening - 1 ;
+                        $KK > $Kfirst ;
+                        $KK -= 1
+                      )
+                    {
+                        next if ( $rLL->[$KK]->[_TYPE_] eq 'b' );
+                        last if ( $rLL->[$KK]->[_LEVEL_] < $level_oo );
+                        $Kstart = $KK;
+                    }
+                }
+
                 my $excess =
-                  $self->excess_line_length_for_Krange( $Kfirst, $Kstop );
+                  $self->excess_line_length_for_Krange( $Kstart, $Kstop );
 
                 # Note: coding simplified here for case b1219
                 $is_one_line_weld = $excess <= 0;
index ff1649131fc72e419278eb44c95582f3b947c7a7..b3179f69b0c41d853a00fdb1acffb6c5ca6b9b87 100644 (file)
@@ -2550,8 +2550,8 @@ EOM
                 $i++;
             }
             push @{$rline_hashes}, $rhash;
-            push @equals_info, [ $i_eq, $tok_eq, $pat_eq ];
-            push @line_info, [ $lev_min, $lev_max ];
+            push @equals_info,     [ $i_eq,    $tok_eq, $pat_eq ];
+            push @line_info,       [ $lev_min, $lev_max ];
             if ( defined($lev_min) ) {
                 my $lev_diff = $lev_max - $lev_min;
                 if ( $lev_diff > $max_lev_diff ) { $max_lev_diff = $lev_diff }
index 684ae4b7493d39a89b4c06e328a8404008160f2f..697ded141dfd17e4c54d3ce3ed4fe05d1573b3b7 100644 (file)
@@ -3,6 +3,7 @@
 - review tickets at [rt.cpan.org](https://rt.cpan.org/Public/Dist/Display.html?Name=Perl-Tidy) 
 - review the issues at [github](https://github.com/perltidy/perltidy/issues/)
 - compare formatting with the new version with previous version on all files in test area
+- compare formatting with the new version on selected projects and perltidy itself
 - profile with Devel::NYTProf with different parameters and compare with previous version: For example
   perl -d:NYTProf perltidy.pl -pbp -nst -nse -wn -xci perltidy.pl
   nytprofhtml --open