-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add assert statement to Fortran #70
Comments
Assert has been proposed before (https://j3-fortran.org/doc/year/04/04-376.txt) This was before my time on the committee, but I gather from what evidence I can find that there was not sufficient interest to move it forward. I have seen it implemented as a vendor extension. |
@sblionel thanks! I would like for each idea at this GitHub repository to eventually have a technical response from the committee why it was rejected. And if there is no technical reason, just a lack of sufficient interest at some point in the past, then I think we can revisit such an idea. For example in this particular case in light of #65 we can argue that rather than standardizing a preprocessor, let's improve Fortran so that the preprocessor is not needed (as much). |
|
Probably, |
@aradi the proposal here, as I understand it, is that |
DEC implemented ASSERT as follows: It is a declaration from the programmer to the optimizer that the given condition is met. The optimizer can then use that information. A separate option tells the compiler to generate run-time code to check that assertion, so you can choose to do that or not. Intel Fortran currently supports an ASSUME directive that provides information, but there is not currently any run-time code associated with that. |
@certik What happens, if in production mode (for whatever buggy reasons) the criteria is not met. The run-time code does not check for it, but it was taken into account during the optimization. Then the optimized code may produce results which are hard to understand/debug. But on the other hand, probably you can say, it is the programmers fault... |
Yes, it would give wrong results in Release mode, but not in Debug mode. In exactly the same way as you get wrong results if you go out of bounds (in Release mode). But in Debug mode, out of bounds, as well as the |
@certik OK, that's a good point. It makes sense, I agree, and would be consistent with current compiler behavior as well. |
If we can't have an ASSERT statement, I would be in favor of a standard assert subroutine. You can then use the pre-processor to create a macro ASSERT (or ERROR_ABORT) command. Here is my version that I "borrowed" from the FTL project ! Macros for assertions #ifdef GFORTRAN ERROR_ABORT just adds a logical to signal if you want to do a hard aborut (STOP, |
@rweed I think this would be a perfect addition to stdlib. Can you please open up an issue there? We already have a minimal So let's extend it, and then let's discuss the macros also, per your comment. |
C++ 2020 and Ada (2012?) defined three statements intended to make "Design by Contract" (DbC) an intrinsic part of the language. In C++ these three statements define the attributes: I have written a draft proposal for the incorporation of DbC in Fortran 202y. It, of course, includes an ASSERT statement as part of the proposal. If there is interest I can upload the proposal to my branch of the proposals directory. Once there, given the problems with my last PR, where it got added on to an existing PR, I don't know if I should do a PR or have someone else do the PR for me. |
@wclodius2 Yes, please upload it here. Try to create a new branch and put it there. Once you learn the process, it becomes simple. I can help. |
GitHub doesn’t let me do an additional fork on https://github.com/wclodius2/fortran_proposals <https://github.com/wclodius2/fortran_proposals>, but does let me do a fork on the original https://github.com/j3-fortran/fortran_proposals <https://github.com/j3-fortran/fortran_proposals>. Should I fork the original again?
… On Aug 1, 2020, at 3:11 PM, Ondřej Čertík ***@***.***> wrote:
@wclodius2 <https://github.com/wclodius2> Yes, please upload it here. Try to create a new branch and put it there. Once you learn the process, it becomes simple. I can help.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#70 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APTQDORJEOLRGNHAYVX7WHDR6SAI7ANCNFSM4JI3NFHQ>.
|
FWIW in not letting me fork on my repository it tells me "Cannot fork because you own this repository and are not a member of any organization." |
@wclodius2 here is how you do it. You already have a fork at GitHub (https://github.com/wclodius2/fortran_proposals) so that is all you need. Let's start from scratch on your computer, that way things will work exactly as I write them here. You will see that once you learn this workflow, you can apply it to any other project at GitHub. Go to some place on your computer where you want to have the
Then create a branch
This will push the Let me know if this works, and if something does not work, I'll help. |
Before I do anything irreversible what is the meaning of <name> in
git remote add <name> <url>
where you have put william for <name>, i.e., is it arbitrary or should it be my user name on my computer or something else?
… On Aug 4, 2020, at 8:53 AM, Ondřej Čertík ***@***.***> wrote:
@wclodius2 <https://github.com/wclodius2> here is how you do it. You already have a fork at GitHub (https://github.com/wclodius2/fortran_proposals <https://github.com/wclodius2/fortran_proposals>) so that is all you need. Let's start from scratch on your computer, that way things will work exactly as I write them here. You will see that once you learn this workflow, you can apply it to any other project at GitHub.
Go to some place on your computer where you want to have the fortran_proposals directory. Then initialize it as follows:
git clone https://github.com/j3-fortran/fortran_proposals
cd fortran_proposals
git remote add william ***@***.***:wclodius2/fortran_proposals.git
Then create a branch assert (you can name it any other way) and put your document in:
git checkout -b assert
# copy your document to proposals/assert, let's call it `assert.pdf` (I don't know what you call it)
git add proposals/assert/assert.pdf
git commit # an editor will open, write a commit message
git push william
This will push the assert branch into your fork, and it will also give you a link that will allow you to submit the Pull Request (PR).
Let me know if this works, and if something does not work, I'll help.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#70 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APTQDOTH72WGDCOILTM5PY3R7AOH3ANCNFSM4JI3NFHQ>.
|
The meaning of
Which is analogous to what I suggested for you. If I add william to mine, see what happens:
Now I can pull branches from you using |
On the
git push william
I get
The authenticity of host 'github.com (140.82.114.3)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,140.82.114.3' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
… On Aug 4, 2020, at 8:53 AM, Ondřej Čertík ***@***.***> wrote:
@wclodius2 <https://github.com/wclodius2> here is how you do it. You already have a fork at GitHub (https://github.com/wclodius2/fortran_proposals <https://github.com/wclodius2/fortran_proposals>) so that is all you need. Let's start from scratch on your computer, that way things will work exactly as I write them here. You will see that once you learn this workflow, you can apply it to any other project at GitHub.
Go to some place on your computer where you want to have the fortran_proposals directory. Then initialize it as follows:
git clone https://github.com/j3-fortran/fortran_proposals
cd fortran_proposals
git remote add william ***@***.***:wclodius2/fortran_proposals.git
Then create a branch assert (you can name it any other way) and put your document in:
git checkout -b assert
# copy your document to proposals/assert, let's call it `assert.pdf` (I don't know what you call it)
git add proposals/assert/assert.pdf
git commit # an editor will open, write a commit message
git push william
This will push the assert branch into your fork, and it will also give you a link that will allow you to submit the Pull Request (PR).
Let me know if this works, and if something does not work, I'll help.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#70 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/APTQDOTH72WGDCOILTM5PY3R7AOH3ANCNFSM4JI3NFHQ>.
|
That means your ssh key is not at GitHub (I assume it already was there). All you need to do is to create an ssh key:
and copy |
The new paper, design_by_contract.txt, contains a proposal to allow Fortran programmers to use "Design by Contract", proposing three new statements for the Fortran language: REQUIRES, ASSERT, and ENSURES. As such, among other things, it addresses issue j3-fortran#70 'Add assert statement to Fortran'. [ticket: j3-fortran#70]
In reviewing the paper prior to submitting a pull request I realized that I had misspelled .EQV. as .EQUIV. and that I had forgotten to mention ASSERT at one point where I discussed REQUIRES and ENSURES. [ticket: j3-fortran#70]
Changed ASSERTS, ENSURES, and REQUIRES to ASSERT, ENSURE, and REQUIRE, respectively [ticket: j3-fortran#70]
@wclodius2 I would like to see your proposal included in the Fortran 202Y work list if it's not too late. It look like the above comment thread trailed off without resolution of how to contribute the proposal. If I help, my preference would be to do so interactively via Zoom or something similar because I'm more likely to be able to help if there's dedicated synchronous time than if we bounce back and forth asynchronously. @certik would you like to join such a call if it happens? |
Feel free to use it. I assume that there is still a copu on the site. I have been into other things the past year and have not kept track of the progress on the project. I had assumed that there was not much interest in that work as the effort seemed to have gone in a rather different direction. Sent from my iPhoneOn Apr 7, 2023, at 3:15 PM, Damian Rouson ***@***.***> wrote:
@wclodius2 I would like to see your proposal included in the Fortran 202Y work list if it's not too late. It look like the above comment thread trailed off without resolution of how to contribute the proposal. If I help, my preference would be to do so interactively via Zoom or something similar because I'm more likely to be able to help if there's dedicated synchronous time than if we bounce back and forth asynchronously. @certik would you like to join such a call if it happens?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Our research library currently contains over 1300 FPP ASSERT macros that can be (de)activated under any compilation mode. This has proven vital to the health of the codebase and catching tens of intricate bugs that could have remained undetected. |
This was one of the reasons why I submitted issue #293 , this was motivated by people using macro preprocessors. Generics know the language, and can be much more expessive than (rather simple-minded) macros. Could you maybe list your use cases there, so we could try to formulate them there? |
@tkoenig1 #293 is close to what I dreamed of having in Fortran someday, hopefully very soon. I encounter many instances almost daily where macros appear as the only solution, to my knowledge (with the alternative being code duplication). I am not talking about generic types here, merely code patterns. For example, many logical branches of BLAS/LAPACK routines that I have inspected differ only in some array indices order, e.g., |
A compile-time static assert macro:
|
@klausler clever! Here is how to do with with gfortran: $ cat a.f90
#define STATIC_ASSERT(x) block; real(merge(kind(1.),-1,(x))), parameter :: fail = 1.; end block
!STATIC_ASSERT(1 > 2)
STATIC_ASSERT(sin(0.5) > 0.5)
end
$ gfortran -cpp a.f90
a.f90:3:48:
3 | STATIC_ASSERT(sin(0.5) > 0.5)
| 1
Error: Kind -1 not supported for type REAL at (1) |
You can even add a message: define STATIC_ASSERT(x,msg) block; character(kind=merge(kind('a'),-1,(x))), parameter :: fail = msg; end block $ gfortran -cpp -ffree-line-length-none assert.f90
assert.f90:2:69:
2 | STATIC_ASSERT(storage_size(1.d0) >= 80,"double precision must be at least 80-bit")
| 1
Error: Kind -1 is not supported for CHARACTER at (1)
$ gfortran -fdefault-real-16 -cpp -ffree-line-length-none assert.f90
$ |
One very common use case for a preprocessor is a custom
ASSERT
macro, that is empty in Release mode, but in Debug mode it checks the condition and prints out the filename and line number. As discussed in #65, Fortran is moving away from a preprocessor, and so by adding an assert statement into the language would eliminate one more use case for a preprocessor.From a user perspective, the syntax can be something like:
In Release mode, the
assert
would do nothing, in Debug mode theassert
would evaluate the condition (e.g.,i == 5
) and if it fails, it would print a nice stacktrace. This would be a much better behavior than the current practice, where typically theASSERT
macro only prints a filename+line, but not a full stacktrace, so it can be hard to figure out why it happened.The text was updated successfully, but these errors were encountered: