Comments (12)
I think I would lean towards 2. A standard preprocessor is something Fortran probably should have settled on a long time ago. There are simply too many use cases for macros and preprocessor directives not too. I would be fine if fpm picked a preprocessor and just always used it, whether that file needed it or not.
from stdlib.
I think for testing, it's better to use or develop a more specific framework just for testing.
I think the main advantage of the assert macro is to test things like sizes of arrays when entering a subroutine, and other conditions that the code depends on. And in Release mode the macro is not executed, so there is no overhead.
from stdlib.
I think this is a good step forward. I planned to propose adding optional message
to assert
so that it can be used more universally for tests and validating user inputs, and this takes it even further with file
, line
, and optional abort on failure.
I suggest everything but the first argument to be optional
so it can be used in its minimal capacity.
Minor nit-pick: assertion .NEQV. .TRUE.
can be just .not. assertion
.
from stdlib.
My primary use for assert was in testing which is why I have the two global variables (num_failed_asserts, and num_asserts). Usually you have several tests you want to perform at one time and want some record of the number of failed tests versus the number of tests and additional information as to when/where the failed test occured. However, I tried to also allow for the case where you want to use assert for error_handling in a given subroutine etc and do a hard abort/stop when an appropriate stop condition was met. A couple of things with my code.
-
IK=>INT32 should be appended to the end of the USE ISO_FORTRAN_ENV. I normally have a module that defines IK but I removed it for simplicity.
-
There probably needs to be some kind of RESET_ASSERT subroutine to reset the num_failed_assert and num_assert values. Another option would be to make them PRIVATE and provide getter and setter functions but I considered that overkill for just two variables.
from stdlib.
Have we considered using fypp for assert macros? We already have it as a dependency.
from stdlib.
To clarify: this issue is for Debug time assert statements, that get skipped in Release mode. Testing framework is a different use case, to be discussed in #162. Note however, that a project like stdlib
will have a test suite, executed by the testing framework (#162), and this will call functions from stdlib such as save_txt()
to ensure they work, and those functions internally would have ASSERT
macros that would ensure that things are internally consistent (in Debug mode).
@milancurcic, @everythingfunctional I think stdlib should have such a macro.
However, the issue is that then by default the files ending with .f90
are not pre-processed by default, so the macro would not work. I can see two approaches:
- rename all files to
.F90
- pass the proper compiler flag to the Fortran compiler in CMake (later on, once we switch to
fpm
, it would do the same)
A third approach is to only do this for files that would use ASSERT
. I don't like this third option, as we should be free to use ASSERT
in any file, without having to fiddle with the build system or with a file extension.
Which approach do you prefer, 1) or 2)?
I think I prefer 2), simply because using upper case extension feels old fashioned, I am not aware of any modern language that would require that. See also j3-fortran/fortran_proposals#56.
from stdlib.
@everythingfunctional exactly. See also j3-fortran/fortran_proposals#65 for a related discussion about standardizing a pre-processor.
The only issue that I can see is that the typical CPP preprocessor is pretty limited in what it can do, and it does not understand Fortran's syntax. fypp
is an improvement. Even better would be to design intelligent macros for Fortran. That is all long term, a short term solution is to use CPP. However, I wouldn't like our choice to prevent us to implement intelligent macros in the future. However, for this we could use the edition
keyword (j3-fortran/fortran_proposals#83) that we can specify in fpm.toml
, just like Rust does it. So from some future moment, we could switch the pre-processor to something more intelligent and for legacy codes we would provide an option to explicitly keep using CPP for a particular file (one would have to specify that explicitly in fpm.toml
if a newer edition was required).
from stdlib.
Also note that the NAG compilers do not pre-process .F90
automatically, instead one has to use the -fpp
option, per open-mpi/ompi#7584. So that leaves us with option 2, as option 1 would not work anyway in all compilers.
from stdlib.
NAG does automatically preprocess .F90 files. Mostly. The issue is on macOS with case insensitive file names as I understand it. But surely that must be a problem for all compilers that decide solely on the basis of the file name?
from stdlib.
@certik Just to understand: According to your proposal some stdlibs files would then contain two different kind of macros: fypp-macros (when needed for generating "generic" interfaces) and cpp-style macros for the asserts? While technically possible (fypp's preprocessor instructions are orthogonal to the cpp instructions), wouldn't it be more to use only one preprocessor? Either cpp or fypp but not both? (And then, in case fypp is choosen, package it with stdlib (#133) to make sure, it does not become an extra dependency)?
from stdlib.
I am not sure. It seems we agree to just stick to .f90
and ensure we call the Fortran compilers with proper options. This also gives us the option to just use fypp, and not cpp.
I think the best way forward is to simply try a few approaches and see which one works the best.
Can fypp handle creating ASSERT like macros?
from stdlib.
Yes, of course, it is possible to write macros which depending on a flag/variable create different codes, see the according exampe.
from stdlib.
Related Issues (20)
- Support sorting arrays of bitsets HOT 2
- bitset count performance HOT 10
- A runtime error occurs when assigning a variable of `bitset_large` HOT 7
- Incorrect result for gamma functions of pure imaginary argument HOT 5
- Test: string_intrinsic (move) failed built with GCC 13.2 HOT 3
- Adding a procedure getting all keys in the hashmaps HOT 2
- Improve fpm build in README for faster getting started HOT 1
- test fault by string_intrisic HOT 1
- 'Sleep' not working when compiled in Win32 (x86) HOT 9
- Compilation error on Linux. Disabling hash/hashmap files compiles rest of the project successfully. HOT 6
- `string_intrinsic (Subprocess aborted)` failed HOT 7
- `bits()` in `bitset_type` returned a non-zero value even though no value is set. HOT 1
- Support for linear algebra HOT 6
- Hashtable write error on exit HOT 7
- use stdlib_math, only : gcd HOT 4
- The file src/stdlib_hashmap_chaining.f90 and two others are set as executable HOT 1
- Support for I/O of standard formats HOT 10
- Memory mapped features HOT 9
- Add `.gitignore` to `stdlib-fpm` deployment for generated test files HOT 1
- hash_functions test fails on i386: `Segmentation fault - invalid memory reference`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stdlib.