]> git.donarmstrong.com Git - perltidy.git/commitdiff
Use stress_level to fix cases b1197-b1204
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 13 Sep 2021 14:23:17 +0000 (07:23 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 13 Sep 2021 14:23:17 +0000 (07:23 -0700)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index 237239a4b55d1b42987092644ca0d9d2b973f8f9..9b97c452236f1df50d3c5896f39cf632caa66bde 100644 (file)
@@ -7204,6 +7204,57 @@ ok(
 --maximum-line-length=42
 --weld-nested-containers
 
+==> b1197.in <==
+# S1
+if (
+         compare ( "$file.new",
+                  $file ) )
+
+# S2
+if (
+         compare ("$file.new", $file ) )
+
+==> b1197.par <==
+--continuation-indentation=10
+--extended-continuation-indentation
+--indent-columns=9
+--maximum-line-length=48
+--paren-vertical-tightness-closing=1
+--paren-vertical-tightness=1
+--space-function-paren
+
+==> b1198.in <==
+if (
+         open( SH, '<', "${outdir}config_h.SH" ) )
+
+if (
+         open( SH, '<',
+                  "${outdir}config_h.SH" ) )
+
+==> b1198.par <==
+--continuation-indentation=10
+--extended-continuation-indentation
+--indent-columns=9
+--maximum-line-length=48
+--paren-vertical-tightness-closing=1
+--variable-maximum-line-length
+
+==> b1199.in <==
+                  if (
+                           open( CONFIG_H_SH, '<',
+                                    'config_h.SH' ) )
+
+                  if (
+                           open( CONFIG_H_SH, '<', 'config_h.SH' ) )
+
+==> b1199.par <==
+--continuation-indentation=10
+--extended-continuation-indentation
+--indent-columns=9
+--maximum-line-length=48
+--paren-vertical-tightness-closing=1
+--variable-maximum-line-length
+
 ==> b120.in <==
 # Same as bug96
 # State 1
@@ -7225,6 +7276,59 @@ ok(
 --line-up-parentheses
 --space-terminal-semicolon
 
+==> b1202.in <==
+      $_res = (
+                  $severity_host_count{
+                        $b}
+                  <=> $severity_host_count{
+                        $a}
+      );
+
+      $_res =
+               ( $severity_host_count{$b}
+                 <=> $severity_host_count{$a}
+               );
+
+==> b1202.par <==
+--continuation-indentation=9
+--extended-continuation-indentation
+--indent-columns=6
+--line-up-parentheses
+--maximum-line-length=47
+
+==> b1203.in <==
+                              if(
+                                     !$found
+                                    &&$word
+                                    &&(($ref_info=
+                                          $references{$word})) )
+
+                              if(
+                                     !$found
+                                    &&$word
+                                    &&((
+                                          $ref_info=$references{
+                                                $word} )) )
+
+==> b1203.par <==
+--noadd-whitespace
+--delete-old-whitespace
+--indent-columns=6
+--maximum-line-length=69
+--paren-vertical-tightness-closing=1
+--weld-nested-containers
+
+==> b1205.in <==
+# S1 (x was being misparsed as a function call)
+        print $" x( 27 - @| ) . $. . $" x 5;
+
+# S2
+        print $" x ( 27 - @| ) . $. . $" x 5;
+
+==> b1205.par <==
+--nowant-right-space='x'
+--space-function-paren
+
 ==> b131.in <==
         unless
           ( open( SCORE, "+>>$Score_File" ) )
index a3ca1d4865aa80fd9ed232f9ecfbbd78736cedd5..c86fd18ae72b95eebe642782c86c97f7e8ff86c2 100644 (file)
@@ -291,6 +291,7 @@ my (
     # from level.
     @maximum_line_length_at_level,
     @maximum_text_length_at_level,
+    $stress_level,
 
     # Total number of sequence items in a weld, for quick checks
     $total_weld_count,
@@ -1772,6 +1773,26 @@ EOM
         }
     }
 
+    # Find a '$stress_level' = an estimated indentation level at which
+    # indentation starts to be under stress.
+    my $denom = max( 1, $rOpts_indent_columns );
+
+    # Define a fixed number of spaces for a typical variable.
+    # Cases b1197-b1204 work ok with const=12 but not with const=8
+    my $const = 16;
+    $stress_level = 0;
+    foreach my $level ( 0 .. $level_max ) {
+        my $remaining_cycles = max(
+            0,
+            (
+                $maximum_text_length_at_level[$level] -
+                  $rOpts_continuation_indentation - $const
+            ) / $denom
+        );
+        last if ( $remaining_cycles <= 3 );    # 2 does not work
+        $stress_level = $level;
+    }
+
     initialize_weld_nested_exclusion_rules($rOpts);
     initialize_line_up_parentheses_exclusion_rules($rOpts);
     return;
@@ -9700,6 +9721,15 @@ sub extended_ci {
           $maximum_text_length_at_level[$level] -
           $ci_level * $rOpts_continuation_indentation;
 
+        # Fix for b1197 b1198 b1199 b1200 b1201 b1202
+        # Do not apply -xci if we are running out of space
+        if ( $level >= $stress_level ) {
+            DEBUG_XCI
+              && print
+"XCI: Skipping seqno=$seqno, level=$level exceeds stress level=$stress_level\n";
+            next;
+        }
+
         # remember how much space is available for patch b1031 above
         my $space =
           $maximum_text_length - $len_tol - $rOpts_continuation_indentation;
@@ -17093,6 +17123,12 @@ sub set_continuation_breaks {
                     $cab_flag = 5;
                 }
 
+                # Ignore old breakpoints when under stress.
+                # Fixes b1203 b1204 as well as b1197-b1200.
+                if ( $levels_to_go[$i_opening] >= $stress_level ) {
+                    $cab_flag = 2;
+                }
+
                 if (  !$is_long_term
                     && $saw_opening_structure
                     && $is_opening_token{ $tokens_to_go[$i_opening] }
index 470a1616e2c23e67ae136943c755be8a6f4ccc6e..7e1a5845612ddb74296e2cd293fad517d4bf97ad 100644 (file)
@@ -2,6 +2,28 @@
 
 =over 4
 
+=item B<Use stress_level to fix cases b1197-b1204>
+
+Testing with random input parameters produced a number of cases of unstable
+formatting. All of these involved some combination of a short maximum line
+length, a large -ci and -i, and often one or more of -xci -lp and -wn.  These
+parameters can force lines to break at poor locations.  All of these cases were
+fixed by introducing a quantity called the 'stress_level', which is the
+approximate indentation level at which the line break logic comes under high
+stress and become unstable.  For default parameters the stress level is about
+12, but unusual parameter combinations can make it much less, even as low as
+zero.  For code which is at an indentation level greater than this depth, some
+defensive actions are taken to avoid instability, such as temporarily turning
+off the -xci flag when the indentation depth exceeds the stress level.  Most
+actual working code will not be influenced by this logic.  Actual code which
+has a very deep indentation level can avoid problems by using a long line
+length, a short number of indentation spaces, or even the whitespace-cycle
+parameter.
+
+This update fixes issues b1197 b1198 b1199 b1200 b1201 b1202 b1203 b1204
+
+12 Sep 2021.
+
 =item B<Fix unusual hanging side comment issue, c070>
 
 This issues can be illustrated with the following input script:
@@ -38,7 +60,7 @@ a closing side comment.  This update fixes this:
 
 This fixes issue c070.
 
-10 Sep 2021.
+10 Sep 2021, ec6ccf9.
 
 =item B<Fix parsing issue c068>
 
@@ -59,7 +81,7 @@ removed a new special variable would be created.
 
 This fixes issue c068.
 
-7 Sep 2021.
+7 Sep 2021, 9bc23d1.
 
 
 =item B<Fix parsing problem issue c066>
@@ -71,7 +93,7 @@ This issue is illustrated with the following line (rt80058):
 Running perltidy generated a warning message which is caused by the lack of
 space before the 'eq'. This update fixes the problem.
 
-4 Sep 2021.
+4 Sep 2021, df79a20.
 
 =item B<Fix unusual parsing problem issue c065>
 
@@ -100,7 +122,7 @@ which is equivalent to the original script.
 
 This fixes issue c065.
 
-4 Sep 2021.
+4 Sep 2021, f242f78.
 
 
 =item B<Fix formatting instability issues b1195, b1196>
@@ -108,7 +130,7 @@ This fixes issue c065.
 Testing with random parameters produced two similar cases of unstable
 formatting which are fixed with this update.
 
-28 Aug 2021.
+28 Aug 2021, ab9ad39.
 
 =item B<Fix formatting instability issue b1194>