Support disabling of implicit typing in package manifest
Motivation
Allow packages to opt-out from default implicit typing in Fortran. This allows to get the full befits of implicit none in every scope without having to remember typing it.
More difficult is whether we can find options in every compiler to actually guarantee that this is working.
Specification
The build table seems most appropriate for this option:
[build]
implicit-typing = false
Prior Art
Compiler flags:
| compiler | option |
|---|---|
| GFortran | -fimplicit-none |
| NVHPC | -Mdclchk |
| nagfor | -u |
| Cray/HPE | -eI |
| SilverFrost FTN95 | /IMPLICIT_NONE |
| ifort (Windows) | /warn:declarations,errors |
| ifort (Linux, macOS) | -warn declarations,errors |
| flang | -fimplicit-none-type-always |
| IBM XL Fortran | -qundef or -u |
Additional Information
Related issue https://github.com/fortran-lang/fpm/issues/359 Draft PR: https://github.com/fortran-lang/fpm/pull/506
As mentioned in the linked PR, I'd like to give this a try, if you agree. If you do, any pointers are welcome.
Alright, here is a brief outline of a strategy to implement this feature. All references are based on the patch from #575.
To implement this feature we need to represent it in the package manifest, this happens in the derived types defined in src/fpm/manifest, every table has a corresponding source file there. For the implicit-typing I'd recommend to add another logical in the build table, you can follow one of the existing logical data types defined there.
https://github.com/fortran-lang/fpm/blob/beaf9a86f83c2de0ebc593f5d8bb924cbdb42ed0/src/fpm/manifest/build.f90#L22-L23
The next step is to get the information into the fpm model, since this is a package resolved option, it shouldn't go into the top-level, but should be included in the package_t:
https://github.com/fortran-lang/fpm/blob/beaf9a86f83c2de0ebc593f5d8bb924cbdb42ed0/src/fpm_model.f90#L96-L105
The package_t in the fpm model is build from the package manifest in src/fpm.f90:
https://github.com/fortran-lang/fpm/blob/beaf9a86f83c2de0ebc593f5d8bb924cbdb42ed0/src/fpm.f90#L159-L160
Once you have the information about the implicit typing in the model, it must be made accessible in the target generation (src/fpm_targets.f90). The loop over the packages in the model is the right place to extract this information:
https://github.com/fortran-lang/fpm/blob/beaf9a86f83c2de0ebc593f5d8bb924cbdb42ed0/src/fpm_targets.f90#L195
Eventually, the correct flag should be added to the compile_flags of the array of build_target_ptr. Adding it to the compile_flags for the Fortran targets automatically takes care everything (including the build hash), there is no need to adjust the build backend.
The remaining issue is to get the correct command line argument for enabling this option, the model has a compiler object which can be adjusted to provide the correct argument:
https://github.com/fortran-lang/fpm/blob/beaf9a86f83c2de0ebc593f5d8bb924cbdb42ed0/src/fpm_compiler.f90#L72-L81
Wow, thank you so much Sebastian @awvwgk !
You're welcome.
I've updated the table of options with more compilers (see original issue post). Here are the sources for each of them:
@certik, do you have a flag for LFortran already?
It's the default in lfortran. I am in a process of adding a flag to enable implicit typing.
I guess this issue has gone stale for some time now.
@epagone I cleared your assignment to encourage others to pick it up.
I made a quick and hacky proof-of-concept implementation in 25f65534f25a95354c5f494e0a5eb31025006150, which works with GFortran. Needs some more thoughts and polishing before this can become a pull request.