From: Steve Hancock Date: Wed, 5 May 2021 13:05:59 +0000 (-0700) Subject: Update welding rule to avoid blinking states X-Git-Tag: 20210402.01~52 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=07efa9de15461342e85f19d83b1a803a4bac7c1e;p=perltidy.git Update welding rule to avoid blinking states --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index b9f92345..f1ed0ceb 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -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: diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 50809f35..53bcab1d 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,37 @@ =over 4 +=item B + +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 Several random test cases produced an instability involving -otr and -lp. diff --git a/t/snippets/expect/wn8.wn b/t/snippets/expect/wn8.wn index 39e2970b..cba25789 100644 --- a/t/snippets/expect/wn8.wn +++ b/t/snippets/expect/wn8.wn @@ -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 diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 2ff9249d..8b38f8b9 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -320,6 +320,8 @@ ../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 @@ -460,5 +462,3 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets24.t rt136417.def -../snippets24.t rt136417.rt136417 diff --git a/t/snippets18.t b/t/snippets18.t index 5cd0e2ed..51249bbb 100644 --- a/t/snippets18.t +++ b/t/snippets18.t @@ -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