]> git.donarmstrong.com Git - perltidy.git/commitdiff
Update welding rule to avoid blinking states
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 5 May 2021 13:05:59 +0000 (06:05 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 5 May 2021 13:05:59 +0000 (06:05 -0700)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod
t/snippets/expect/wn8.wn
t/snippets/packing_list.txt
t/snippets18.t

index b9f92345c03ce682bc1af47fb1cebfe9f713a314..f1ed0ceb932e3bd3b1499354a34d198b43d4add4 100644 (file)
@@ -7621,11 +7621,29 @@ EOM
         #    $_[0]->();
         # } );
 
+        # Updated to fix cases b1082 b1102 b1106 b1115:
+        # Also, do not weld to an intact inner block if the outer opening token
+        # is on a different line. For example, this prevents oscillation
+        # between these two states in case b1106:
+
+        #    return map{
+        #        ($_,[$self->$_(@_[1..$#_])])
+        #    }@every;
+
+        #    return map { (
+        #        $_, [ $self->$_( @_[ 1 .. $#_ ] ) ]
+        #    ) } @every;
+
+        # The effect of this change on typical code is very minimal.  Sometimes
+        # it may take a second iteration to converge, but this gives protection
+        # against blinking.
+
         if (   !$do_not_weld_rule
             && !$is_one_line_weld
             && $iline_ic == $iline_io )
         {
-            $do_not_weld_rule = 2 if ( $token_oo eq '(' );
+            $do_not_weld_rule = 2
+              if ( $token_oo eq '(' || $iline_oo != $iline_io );
         }
 
         # DO-NOT-WELD RULE 3:
index 50809f35b3f8784ca92115fb1879746990ef10d8..53bcab1d8c140c55a9a95295e9e191c68b07f873 100644 (file)
@@ -2,6 +2,37 @@
 
 =over 4
 
+=item B<Update welding rule to avoid blinking states>
+
+Random testing with unusual parameter combinations produced some unstable welds.
+For example case b1106 has these parameters
+
+    --noadd-whitespace
+    --continuation-indentation=6
+    --delete-old-whitespace
+    --line-up-parentheses
+    --maximum-line-length=36
+    --variable-maximum-line-length
+    --weld-nested-containers
+
+and was switching between these two states:
+
+            return map{
+                ($_,[$self->$_(@_[1..$#_])])
+            }@every;
+
+            return map { (
+                $_, [ $self->$_( @_[ 1 .. $#_ ] ) ]
+            ) } @every;
+
+An existing rule, WELD RULE 2, was updated to prevent welding to an intact
+one-line weld, as in the first snippet, if it is on a separate line from the
+first opening token.  With this change, both of these states are stable.
+
+This update fixes cases b1082 b1102 b1106 b1115.
+
+4 May 2021.
+
 =item B<Fix problem of conflict of -otr and -lp>
 
 Several random test cases produced an instability involving -otr and -lp.
index 39e2970b622aacc9de0090d46d00047c6e3cef74..cba257896b6b8f88aa38fcefed05751c811815fe 100644 (file)
@@ -3,7 +3,9 @@
             # fixed RULE 1 only applies to '('
             my $res = eval { { $die_on_fetch, 0 } };
 
-            my $res = eval { { $die_on_fetch, 0 } };
+            my $res = eval {
+                { $die_on_fetch, 0 }
+            };
 
             # fixed RULE 2 applies to any inner opening token; this is a stable
             # state with -wn
index 2ff9249d6899e232a3c569cbd8d9fadf53f44c98..8b38f8b9e2f2cfba2700b33ec7db5556dfc65462 100644 (file)
 ../snippets24.t        lpxl.lpxl5
 ../snippets24.t        git63.def
 ../snippets24.t        align35.def
+../snippets24.t        rt136417.def
+../snippets24.t        rt136417.rt136417
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets24.t        rt136417.def
-../snippets24.t        rt136417.rt136417
index 5cd0e2eda38224e3e06df7196749ab79844f9af1..51249bbbff46e99fcf5254e71455ec5ed58ccb1f 100644 (file)
@@ -339,7 +339,9 @@ my ( $a, $b, $c ) = @_;    # test -nsak="my for"
             # fixed RULE 1 only applies to '('
             my $res = eval { { $die_on_fetch, 0 } };
 
-            my $res = eval { { $die_on_fetch, 0 } };
+            my $res = eval {
+                { $die_on_fetch, 0 }
+            };
 
             # fixed RULE 2 applies to any inner opening token; this is a stable
             # state with -wn