Skip to content

fix: make a second run a no-op - #16

Merged
sbryngelson merged 2 commits into
masterfrom
fix-idempotent-modernize-wrap
Oct 17, 2026
Merged

sbryngelson merged 2 commits into
masterfrom
fix-idempotent-modernize-wrap

Conversation

@sbryngelson

Copy link
Copy Markdown
Owner

Running ffmt twice changed 55 of 335 real Fortran files (magudi, paris, jcode, MFC-derived code, cell codes) and, with optional passes on, MFC's own source. This fixes every case I found; all 335 files and MFC src/ are now idempotent at line lengths 60/80/90/100/132, with indent-width 2, with every optional pass on, and with an alternate config.

One of these was worse than non-idempotent: a Fypp #:set x = a.strip() != '' or ... line over the limit had its Python != taken for a comment start, and the tail was moved above the statement (omp_macros.fpp, line length 80). Lines starting with # are no longer rewrapped.

Other causes:

  • trailing ; and legacy operators (.lt.) were removed after wrapping, so lines wrapped at the wrong length
  • a comment moved above end do/else was indented one level short
  • blank runs were collapsed after compaction/alignment, and only the first blank after a block opener was removed
  • comments hoisted out of continuations skipped the merging written comments get
  • split-statements ran after wrapping and scope tracking, mangling do ...; ...; enddo one-liners
  • bare commas (namelist, Fypp macro args) measured differently once a break added a space
  • a break between ) and a space-separated %member
  • a wrapped declaration was not recognized as a declaration
  • type = 0 was classified as a type definition
  • align-assignments padded continuation arguments such as & no_create=None

14 regression tests are added; 13 fail on current master (the Fypp-macro one guards against a change made during this work). Real failing inputs live in tests/fixtures/idempotence/.

On MFC src/ at the default config, output differs from master in one file: five blank lines master only adds on its second run.

cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo build --release and cargo test (429) pass locally. I could not run the MFC build jobs locally.

…s, blanks and split-statements

Running ffmt twice changed 55 of 335 real Fortran files before this. Causes fixed:
- strip trailing semicolons and modernize operators before wrapping, so lines wrap at their final length
- indent a comment moved above end do/else at the enclosing block depth
- collapse blank runs before compaction/alignment and drop the whole run after block openers
- lift comments hoisted out of continuations into ordinary comment lines so they merge like written ones
- split semicolon statements before scope tracking and wrapping
- treat bare commas as spaced when measuring breaks, and space top-level commas up front
- do not break between ) and a space-separated %member
- judge a wrapped declaration as a whole statement
- do not classify `type = 0` as a type definition
- keep continuation/directive lines out of align-assignments
- never run the Fortran wrapper on #-lines (a Fypp Python != was moved above its statement)
@sbryngelson
sbryngelson merged commit 9f121a2 into master Oct 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant