Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support disabling of implicit typing in package manifest #577

Closed
awvwgk opened this issue Sep 23, 2021 · 8 comments · Fixed by #864
Closed

Support disabling of implicit typing in package manifest #577

awvwgk opened this issue Sep 23, 2021 · 8 comments · Fixed by #864
Labels
specification Issue regarding fpm manifest and model

Comments

@awvwgk
Copy link
Member

awvwgk commented Sep 23, 2021

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 #359
Draft PR: #506

@awvwgk awvwgk added the specification Issue regarding fpm manifest and model label Sep 23, 2021
@epagone
Copy link
Contributor

epagone commented Sep 23, 2021

As mentioned in the linked PR, I'd like to give this a try, if you agree. If you do, any pointers are welcome.

@awvwgk
Copy link
Member Author

awvwgk commented Sep 23, 2021

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.

!> Configuration data for build
type :: build_config_t

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:

fpm/src/fpm_model.f90

Lines 96 to 105 in beaf9a8

!> Type for describing a single package
type package_t
!> Name of package
character(:), allocatable :: name
!> Array of sources
type(srcfile_t), allocatable :: sources(:)
end type package_t

The package_t in the fpm model is build from the package manifest in src/fpm.f90:

fpm/src/fpm.f90

Lines 159 to 160 in beaf9a8

model%packages(i)%name = dependency%name
if (.not.allocated(model%packages(i)%sources)) allocate(model%packages(i)%sources(0))

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:

do j=1,size(model%packages)

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:

fpm/src/fpm_compiler.f90

Lines 72 to 81 in beaf9a8

!> Definition of compiler object
type :: compiler_t
!> Identifier of the compiler
integer(compiler_enum) :: id = id_unknown
!> Path to the Fortran compiler
character(len=:), allocatable :: fc
!> Path to the C compiler
character(len=:), allocatable :: cc
!> Print all commands
logical :: echo = .true.

@epagone
Copy link
Contributor

epagone commented Sep 23, 2021

Wow, thank you so much Sebastian @awvwgk !

@awvwgk
Copy link
Member Author

awvwgk commented Sep 23, 2021

You're welcome.

@ivan-pi
Copy link
Member

ivan-pi commented Sep 29, 2021

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?

@certik
Copy link
Member

certik commented Sep 29, 2021

It's the default in lfortran. I am in a process of adding a flag to enable implicit typing.

@awvwgk
Copy link
Member Author

awvwgk commented Jul 15, 2022

I guess this issue has gone stale for some time now.

@epagone I cleared your assignment to encourage others to pick it up.

@awvwgk
Copy link
Member Author

awvwgk commented Jul 15, 2022

I made a quick and hacky proof-of-concept implementation in 25f6553, which works with GFortran. Needs some more thoughts and polishing before this can become a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
specification Issue regarding fpm manifest and model
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants