Rename prior derived type to prior_spec to fix Fortran interface name collision - #140
Open
AdamOrmondroyd wants to merge 2 commits into
Open
Rename prior derived type to prior_spec to fix Fortran interface name collision#140AdamOrmondroyd wants to merge 2 commits into
AdamOrmondroyd wants to merge 2 commits into
Conversation
CI only exercised the python bindings, so the fortran interface failing to compile went unnoticed. Build the libraries, all three drivers and the examples, and smoke-test one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FtxjPgndTpcYEnnATa1oHr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
The Fortran interface didn't compile. Building the stock driver fails:
priors_moduledefined a derived type calledprior(the parsed ini-file priorspecification), and
interfaces_moduleimports it at module level for thepriorsmodule variable.gfortran drags that type name into any scope that does
use interfaces_module— even with an
only:clause naming justrun_polychord, and even if theimport is renamed inside
interfaces_module. The type lands in the user'snamespace as a hidden derived-type symbol called
prior.Using it as a function still works (
theta = prior(cube)compiles), but passingprioras an actual argument makes gfortran resolve the name to the type andreject it. Which is exactly what we ask users to do:
likelihoods/fortran/likelihood.f90tells you to write a function called
prior, and the driver passes it straightto
run_polychord. Renaming it at the use site (my_prior => prior) doesn'thelp either — the leaked symbol still wins.
The fix
Renamed the derived type
prior→prior_spec, and updated its five users.prior_specbecause the type isn't a prior — it describes one: which parametersit covers (
hypercube_indices/physical_indices), which kind it is(
prior_type), and that kind's numbers (parameters). It's whathypercube_to_physicalconsumes.Names considered and rejected:
prior_type— matchesparam_typeinparams_module, but_typealreadymeans "enum tag" throughout
priors.f90(uniform_type,gaussian_type, …),the type's own field is
prior_type, andprior_type_from_stringreturns oneof those integers, not the type.
priors— collides with the variable of that name at every single use site,which is the same shadowing bug, self-inflicted.
Verification
make polychord_fortrannow compiles and links; previously it did not build at all.make examples polychord_CC polychord_CC_iniall build clean../bin/gaussian ini/gaussian.iniruns to completion,log(Z) = -0.087 +/- 0.188for the 20-D unit Gaussian.
Notes
use priors_module, only: prior. It's an internal type for ini-file priorspecs, so this should affect nobody, but flagging it. Happy to add a
deprecated alias in
priors_moduleif wanted — the alias itself is harmless,it was only the
interfaces_modulere-export that leaked.write_paramnames_file(read_write.F90:965) andwrite_properties_file(read_write.F90:997) both importprior_specbutdeclare nothing of that type. Dead before this change too; left alone to keep
the diff focused, happy to drop them.
makejob to CI. It only exercised the python bindings before, whichis why a completely unbuildable fortran interface went unnoticed. The new job
builds the libraries, all three drivers and the examples, and smoke-tests one.
Verified against
master: every step passes there exceptBuild fortran driver, which fails with the error above — so the job catches this specificregression and nothing else.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FtxjPgndTpcYEnnATa1oHr