Skip to content

fix: inline Fortran constant defaults in _fc() to prevent Homebrew sync failures#1419

Merged
sbryngelson merged 2 commits into
MFlowCode:masterfrom
sbryngelson:fix/homebrew-fallback-constants
May 11, 2026
Merged

fix: inline Fortran constant defaults in _fc() to prevent Homebrew sync failures#1419
sbryngelson merged 2 commits into
MFlowCode:masterfrom
sbryngelson:fix/homebrew-fallback-constants

Conversation

@sbryngelson
Copy link
Copy Markdown
Member

@sbryngelson sbryngelson commented May 10, 2026

Fixes #1420.

Summary

  • Fixes the v5.3.1 Homebrew regression where every install crashed on startup with RuntimeError: Fortran constant 'num_ib_patches_max' not found in m_constants.fpp
  • Root cause: NIB = _fc("num_ib_patches_max") was added to definitions.py (Ib collisions #1348) but _FALLBACK_CONSTANTS in namelist_parser.py was never updated — two places that must stay in sync with no enforcement
  • On Homebrew, src/ is not installed so get_fortran_constants() returns {}, making _fc() fall through to the stale fallback

Fix

_fc(name, default) now requires an inline default value co-located with the call site. There is no longer a separate dict to forget. Adding a new _fc() call without a default is a type error.

# Before — default lived in a separate dict, easy to miss:
NIB = _fc("num_ib_patches_max")   # raises on Homebrew if dict not updated

# After — default is right here, impossible to forget:
NIB = _fc("num_ib_patches_max", 50000)

_FALLBACK_CONSTANTS and the fallback logic in get_fortran_constants() are removed. The function now simply returns {} when src/common/m_constants.fpp is unavailable.

Test plan

  • Verify ./mfc.sh precheck passes (CI lint gate)
  • Trigger homebrew-mfc bottle workflow and confirm Sod shock tube test passes

…nc failures

Previously, _fc() raised if a constant was absent from _FALLBACK_CONSTANTS,
a separate dict that could silently drift from definitions.py. This caused
the v5.3.1 Homebrew build to fail: NIB = _fc('num_ib_patches_max') was added
to definitions.py but _FALLBACK_CONSTANTS was never updated, so every Homebrew
install hit a RuntimeError on startup.

Fix: _fc(name, default) now requires an inline default — the default lives
alongside the call, so they can't get out of sync. Remove _FALLBACK_CONSTANTS
and simplify get_fortran_constants() to return {} when src/ is unavailable.
@qodo-code-review
Copy link
Copy Markdown
Contributor

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@github-actions
Copy link
Copy Markdown

Claude Code Review

Head SHA: f9316a4

Files changed:

  • 2
  • toolchain/mfc/params/definitions.py
  • toolchain/mfc/params/namelist_parser.py

Findings

num_patches_max fallback silently reduced from 1000 → 10

File: toolchain/mfc/params/definitions.py (changed hunk)

The removed _FALLBACK_CONSTANTS dict (in namelist_parser.py) used "num_patches_max": 1000. The replacement inline default in definitions.py is:

NUM_PATCHES_MAX = _fc("num_patches_max", 10)   # patch_icpp (Fortran array bound)

The new fallback of 10 is 100× smaller than the 1000 that was there before. In Homebrew installs where m_constants.fpp is unavailable and _FC is an empty dict, NUM_PATCHES_MAX now silently becomes 10.

This has two concrete consequences in the Homebrew fallback path:

  1. Constraint validationCONSTRAINTS["num_patches"] = {"min": 0, "max": NUM_PATCHES_MAX} now rejects any case file with more than 10 patches, even though the Fortran binary allows up to 1000. Users with > 10 patches would get a spurious validation error.
  2. Registry loop — any registration code that loops up to NUM_PATCHES_MAX would only register parameters for 10 patches instead of 1000.

The other four constants (NF, NPR, NB, NIB) either matched the old fallback values or were not in the old fallback at all, so they are unaffected. Only num_patches_max had an explicit old fallback of 1000 that is now lost.

Fix: change the inline default to match the old fallback: _fc("num_patches_max", 1000).

@sbryngelson sbryngelson merged commit 2ecf477 into MFlowCode:master May 11, 2026
82 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 64.95%. Comparing base (462cac7) to head (83f4818).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1419   +/-   ##
=======================================
  Coverage   64.95%   64.95%           
=======================================
  Files          72       72           
  Lines       18880    18880           
  Branches     1573     1573           
=======================================
  Hits        12263    12263           
  Misses       5641     5641           
  Partials      976      976           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

bug: Homebrew v5.3.1 install crashes on startup — num_ib_patches_max missing from Fortran constants fallback

1 participant