From 1cee1a72a1570c6415e34adb6f8a0aab374c08d0 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 12 Nov 2021 15:34:27 -0800 Subject: [PATCH] merge two weld cutoff limits, fixes b1252 --- dev-bin/run_convergence_tests.pl.data | 38 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 23 +++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 4407e908..9141fa4c 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -8154,6 +8154,44 @@ WriteMakefile( --line-up-parentheses --maximum-line-length=35 +==> b1252.in <== +# S1 +@pack= + ([ +"ufunc.pd", + Ufunc, + PDL::Ufunc + ]); +# S2 +@pack=([ +"ufunc.pd", + Ufunc, + PDL::Ufunc + ]); + +==> b1252.par <== +--noadd-whitespace +--break-before-all-operators +--break-before-paren=3 +--continuation-indentation=8 +--delete-old-whitespace +--maximum-line-length=10 +--opening-paren-right +--stack-closing-block-brace +--stack-closing-hash-brace +--stack-closing-paren +--stack-closing-square-bracket +--stack-opening-hash-brace +--stack-opening-paren +--stack-opening-square-bracket +--tight-secret-operators +--trim-pod +--novalign-code +--variable-maximum-line-length +--vertical-tightness-closing=1 +--vertical-tightness=0 +--weld-nested-containers + ==> b131.in <== unless ( open( SCORE, "+>>$Score_File" ) ) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 8514480e..793e2b99 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -8346,6 +8346,27 @@ sub weld_nested_containers { my $multiline_tol = $single_line_tol + 1 + max( $rOpts_indent_columns, $rOpts_continuation_indentation ); + # Define a welding cutoff level: do not start a weld if the inside + # container level equals or exceeds this level. We use the minimum of two + # criteria, either of which may be more restrictive. + # Start with a value based on the global stress (cases b1206, b1243): + # Note that this has a minimum cutoff level of 3. + my $weld_cutoff_level = $stress_level + 3; + + # But use an alternative criterion if more restrictive (cases b1206, b1252) + # This allows the cutoff level to go down to 0 in extreme cases. + foreach my $level_test ( 0 .. $weld_cutoff_level ) { + my $max_len = $maximum_text_length_at_level[ $level_test + 1 ]; + my $excess_inside_space = + $max_len - + $rOpts_continuation_indentation - + $rOpts_indent_columns - 8; + if ( $excess_inside_space <= 0 ) { + $weld_cutoff_level = $level_test; + last; + } + } + my $length_to_opening_seqno = sub { my ($seqno) = @_; my $KK = $K_opening_container->{$seqno}; @@ -8428,7 +8449,7 @@ sub weld_nested_containers { # welds can still be made. This rule will seldom be a limiting factor # in actual working code. Fixes b1206, b1243. my $inner_level = $inner_opening->[_LEVEL_]; - if ( $inner_level > $stress_level + 2 ) { next } + if ( $inner_level >= $weld_cutoff_level ) { next } # Set flag saying if this pair starts a new weld my $starting_new_weld = !( @welds && $outer_seqno == $welds[-1]->[0] ); -- 2.39.5