-
Notifications
You must be signed in to change notification settings - Fork 99
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
Default Modern Fortran flags #359
Comments
As much as I'd love for fpm's defaults to encourage modern best practices, our desire for legacy codes to be ported to fpm packages and encourage "legacy" programmers to use it, means it's probably a no-go for a lot of our target users. That said, I would love for us to have a convenient option to turn lots of this kind of stuff on. As I mentioned in the discussion for my proposal for how we might deal with the compiler flags (#350), I think we should have an additional built in "profile", kind of like |
Another thought, perhaps we should have some sort of survey/poll for each supported compiler about what flags should be included in the default (
Thus, if a certain percentage of respondents (say 10-15%) say please don't turn this on, we won't, even if there is a large percentage of respondents who would like it. If a sufficient number of respondents indicate they would like it (25-30% ?), we turn it on by default. Thus a non-response to a particular flag indicates ambivalence about it for that particular respondent. The hard part will be setting up the survey with a reasonable set of flags to start with, and allowing participants to add additional suggestions. Does anyone know of a polling site that could accomplish such a thing? |
I was thinking about introducing a |
Fair enough. I note that I never met a single example of such "legacy" programmer that still actively writes code in fixed form and with implicit typing. The vast majority of them leverage libraries (making occasional modifications) of legacy code that could be packaged with |
I would also like to reclaim .f. As a new and radically innovative (for Fortran standrads, at least) tool, we have a unique opportunity to set the tone and recommended best practices, and even shift some long trends. Trends become trends because one or a few people decided something, and many just took it and accepted it without questions. Why do we have an idea of which source file suffixes correspond to fixed or free format? Because existing compilers told us. fpm should start with a clean slate and define its own conventions. Do we want fpm to always assume free format and explicit typing? I think so. But allow a flag (e.g. |
Given issues such as "implicit save", it'll be awesome if the Fortran enthusiasts with This can then help Fortranners try out options such as Outside of something like this that gets into the compiler side of things, I don't see what |
Thanks for the info. I was too optimist then. It is quite an ambitious task what you suggest but I know a lot of people that hate "implicit save" (I haven't been bitten by it, yet). Since you are talking about compiler development, it is worth CCing @certik |
One tweak that might make this option a bit safer would be that only the |
Yes, trying to "reclaim" That's why I had suggested, even as it was somewhat light-heartedly, to attempt a new convention of .mf, that can be an easier route, a separate lane, to march ahead. |
I see, but I am a bit hesitant: we all know that Jokes aside, I consider this community the avant-guard of Fortran and I believe that we should be a bit more brave. On the other hand, I see that many of the key contributors of |
@epagone can you join us at a Fortran call? We can discuss that there. There are pros and cons. In general, the |
@certik I can try. Do you mean the GSoC or the monthly call? I have seen that both have a quite packed agenda... |
@epagone I meant the monthly call. We all have a packed agenda, but a video call has been very efficient at arriving at an agreement, or at least make progress on an issues such as the one that you posted. Since the inception of I still believe we should be strict by default, and only provide options to override the strict behavior for legacy codes. Regarding reclaiming |
My view is to leave .f alone - changing this will break so much stuff it isn't funny, and it would rely on everyone updating compilers. Instead consider agreeing on a new extension - I like .ffr - for Fortran Free Form. The standard can't do anything about this - it would have to be multiple compiler developers agreeing to support the new file type. I wouldn't get my hopes up. |
🤔 ... what I meant is that the agenda of the call looks already packed with a few topics. Anyway, I have now shared my availability on Doodle and posted a short message on Discourse. I have a couple of questions:
Thank you. |
This proposal has zero ambition to convince any compiler vendors to change the way it behaves (at least in the short-medium term). It only suggests to set up by default some overridable, suitable flags to write Fortran in a modern way. However, I can see that this is a recurring misunderstanding: I have amended my first post with the hope to be more clear about it. PS: among all the many new, alternative extensions proposed for free form I like |
Given the Dr Fortran blogpost by Steve Lionel "Source Form Just Wants to be Free", maybe Fortranners should just "suck it up" and be willing to type a few more keystrokes for a 4-chaarcter extension instead of a new one with 1 or 2 or 3 alphanumeric characters!! And go with |
@epagone wrote:
Perfect, thanks!
Yes, we already have an issue for that: https://gitlab.com/lfortran/lfortran/-/issues/148
Yes, tons of ideas. I would like LFortran in this mode to print warnings (or error messages) for all things that we do not consider "modern". That way people can update their code to be following the latest recommendations. Things like "explicit imports" |
@epagone wrote:
I just found an example of one such programmer/project: PLTMG: A Software Package for Solving Elliptic Partial Differential Equations. The latest version 13.0 from 2018 continues to be developed in fixed-form and uses both implicit typing and common blocks. An example declaration block in the code: c-----------------------------------------------------------------------
c
c piecewise lagrange triangle multi grid package
c
c edition 13.0 - - - september, 2018
c
c-----------------------------------------------------------------------
subroutine mpiutl(isw)
cx
use mthdef
implicit real(kind=rknd) (a-h,o-z)
implicit integer(kind=iknd) (i-n)
include "mpif.h"
common /atest6/nproc,myid,mpisw,mpirgn,mpiint,mpiflt They also distribute the code via Netlib. 😄 |
@ivan-pi indeed, there are such cases, although they are a minority. They would be supported by |
Good find. Personally I'm not bothered about The above snip is from the current Fortran standard (as per its proxy, 18-007r1 document), section If the standard can be enhanced to state:
that will be a major, major step forward. Such a change will have NO backward compatibility issue with programs such as PLTMG because of the explicit IMPLICIT declarations. But now, it is due to an unknown but likely very tiny list of programs that supposedly have neither Where I work, a team had a situation in 2017 where a subtle bug got introduced due to a missing So the question I ask myself is this: what if compiler implementations become truly brave and they themselves stop supporting the The onus can then shift to those who want to continue with the old ways to do some "extra" work to avoid encountering errors with their unsafe coding practice. All other Fortranners will be freed from having to ensure |
On Discourse, @urbanjost adds an interesting suggestion for an additional feature: no line length limit. I agree. |
I agree too. Limiting to 80 columns should be done via formatting tools, but |
c.f.: https://wg5-fortran.org/N2151-N2200/N2184.pdf The next version of the standard referred to as Fortran 202X will allow for the following:
|
Discourse user gfortran: -cpp to further simplify extensions and avoid the uppercase/lowercase confusion that I have seen affecting many newcomers. I think that it's an excellent suggestion. As long as there are no side-effects, e.g. problems when there is no actual use of the preprocessor in the project (I do not have enough knowledge and experience to safely comment on this), I am in favour. Your comments please. |
Yes, we should not need a new file extension just to enable a pre-processor. However, we should decide whether to encourage using the C pre-processor or rather enable some other pre-processor by default. I can see pros and cons of this. |
Hi, I wanted to know if there are some thoughts on adding by default the /fpp flag within fpm? It seems to me this could avoid unnecessary build-time errors with many libraries requiring preprocessing. |
I believe it would likely be safe to "turn on" preprocessing even for projects that don't use it, but I'm not 100% sure. @gklimowicz has been doing some research into the area of preprocessing in Fortran, so perhaps he could provide some insight. |
Well, I don't have to look at sources to answer this, I don't think. If your code has no lines in it that begin with a And if your code does have lines in it that begins with
|
It is appealing. C of course always preprocesses files, but it has a standard preprocessor. The bigger issue is there is no standard set of macros defined, and some processors ( I entered bug reports for several of them) predefine relatively common words like linux and unix. Most prefix with an underscore so it is clear the word is unlikely regular code; but some preprocessors do not allow macros starting with an underscore. Scanning for a "#" in the beginning of a line is actually quite fast. vendor-supplied preprocessors vary significantly. There are likely to be issues until (if?) the next standard provides for a standard preprocessor, which may or may not even support macros for instance. We now allow the fpm file to specify a preprocessor and file suffixes to apply it to. Perhaps a compromise would be the "new" command would generate a fpm.toml file specifying the cpp processor and include .f, .f90 as suffixes to preprocess. No strong feelings but a little concern given the current state of Fortran preprocessing. Just mentioning that the fpm.toml file already has options that can give you the desired behavior, so there is no issue with dependencies if the package specifies what should be preprocessed and what should not as-is. Note that fpm itself needs "unix" undefined when built with ifort/ifx or errors occur as an example of little things that go wrong; and until/if everyone expects all files to be preprocessed it conflates using remote dependencies (do they or do they not expect preprocessing?). The user can specify it now via fpm.toml options. Until there is a standard preprocessor I lean towards leaving it the way it is; but discussing making it the pseudo-default via "fpm new". |
@epagone you might not know old enough coders then. :) I have met some and just met another last week. I'd like to help this person modernize their code and they're interested in doing so, but I'm stumbling into issues with the default settings in |
TL;DR
This proposal aims at collecting and setting up with
fpm
a modern Fortran environment by default (e.g. no implicit typing, no fixed form, etc...), without requiring any change to the current compilers behaviour or the standard. Packaging of important legacy code (of critical importance for much of the Fortran community but usually requiring special flags regardless) would be supported overriding the mentioned defaults.As of 2021 no one should reasonably write Fortran
implicit none
redundant as obvious)I believe that
fpm
should provide default, overridable compiler flags enforcing the above. In this way, a little bit more dust and rust will be hopefully removed from the perception of the language to potential newcomers. Furthermore, since these changes are difficult to implement into the standard,fpm
can be also presented as the only, long-awaited solution (by some practitioners, at least) to these issues.Packaging of legacy libraries would likely require regardless a tailored
fpm.toml
thus, it would be a matter of adding a few more specifications to override the above defaults.In more detail.
Fixed Form
This idea started from this conversation where I dream of reclaiming the
.f
extension for new code without resorting to the current, Jurassic.f90
to specify free from. The only potential issue that I foresee in this case is that legacy dependencies will be compiled with different flags but, if I understand correctly the logic offpm
, this should not be an issue.However, it would be really amazing if
fpm
would be able to autodetect the source code form, as @ivan-pi suggested here, but I guess that it would require quite a lot more work.Implcit typing
This sounds pretty simple to do, e.g.
-fimplicit-none
withgfortran
or-implicitnone
with Intel Fortran.Implcit save
Is this possible? Googling, I have seen that with
gfortran
-frecursive
might do the trick but I am not sure if it is really the case and if it will trigger some other side-effect undesired in a "default" setup (Intel seems to have-recursive
).What do you think?
The text was updated successfully, but these errors were encountered: