Skip to content

Commit be7576d

Browse files
committed
feat: rm diagnostic_data arg & related types
This commit 1. Removes the diagnostic_data argument from the assert subroutine 2. Removes the types that existed solely to support that argument: a. characterizable_t b. intrinsic_array_t 3. Edits or deletes examples that referenced the removed entities 4. Edits or deletes documentation that referenced removed entities
1 parent 9dee1f5 commit be7576d

20 files changed

Lines changed: 49 additions & 989 deletions

.github/workflows/deploy-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
2525
- name: Build Developer Documentation
2626
run: |
27-
ford -I include doc-generator.md > ford_output.txt
27+
ford -I include ford.md > ford_output.txt
2828
# Turn warnings into errors
2929
cat ford_output.txt; if grep -q -i Warning ford_output.txt; then exit 1; fi
3030
cp ./README.md ./doc/html

README.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This assertion utility contains four public entities:
1919

2020
The `assert` subroutine
2121
* Error-terminates with a variable stop code when a caller-provided logical assertion fails,
22-
* Includes user-supplied diagnostic data in the output if provided by the calling procedure,
2322
* Is callable inside `pure` procedures, and
2423
* Can be eliminated at compile-time, as controlled by the `ASSERTIONS` preprocessor define.
2524

@@ -42,10 +41,6 @@ If instead `fpm install` is used, then either the user must copy `include/assert
4241
the user must invoke `assert` directly (via `call assert(...)`).
4342
In the latter approach when the assertions are disabled, the `assert` procedure will start and end with `if (.false.) then ... end if`, which might facilitate automatic removal of `assert` during the dead-code removal phase of optimizing compilers.
4443

45-
The `characterizable_t` type defines an `as_character()` deferred binding that produces `character` strings for use as diagnostic output from a user-defined derived type that extends `characterizable_t` and implements the deferred binding.
46-
47-
The `intrinsic_array_t` type that extends `characterizable_t` provides a convenient mechanism for producing diagnostic output from arrays of intrinsic type `complex`, `integer`, `logical`, or `real`.
48-
4944
Use Cases
5045
---------
5146
Two common use cases include
@@ -208,19 +203,19 @@ character for line-breaks in a macro invocation:
208203

209204
```fortran
210205
! OK for flang-new and gfortran
211-
call_assert_diagnose( computed_checksum == expected_checksum, \
212-
"Checksum mismatch failure!", \
213-
expected_checksum )
206+
call_assert_describe( computed_checksum == expected_checksum, \
207+
"Checksum mismatch failure!" \
208+
)
214209
```
215210

216211
Whereas Cray Fortran wants `&` line continuation characters, even inside
217212
a macro invocation:
218213

219214
```fortran
220215
! OK for Cray Fortran
221-
call_assert_diagnose( computed_checksum == expected_checksum, &
222-
"Checksum mismatch failure!", &
223-
expected_checksum )
216+
call_assert_describe( computed_checksum == expected_checksum, &
217+
"Checksum mismatch failure!" &
218+
)
224219
```
225220

226221
There appears to be no syntax acceptable to all compilers, so when writing
@@ -237,29 +232,29 @@ after macro expansion (on gfortran and flang-new):
237232

238233
```fortran
239234
! INCORRECT: cannot use Fortran comments inside macro invocation
240-
call_assert_diagnose( computed_checksum == expected_checksum, ! ensured since version 3.14
241-
"Checksum mismatch failure!", ! TODO: write a better message here
242-
computed_checksum )
235+
call_assert_describe( computed_checksum == expected_checksum, ! ensured since version 3.14
236+
"Checksum mismatch failure!" ! TODO: write a better message here
237+
)
243238
```
244239

245240
Depending on your compiler it *might* be possible to use a C-style block
246241
comment (because they are often removed by the preprocessor), for example with
247242
gfortran one can instead write the following:
248243

249244
```fortran
250-
call_assert_diagnose( computed_checksum == expected_checksum, /* ensured since version 3.14 */ \
251-
"Checksum mismatch failure!", /* TODO: write a better message here */ \
252-
computed_checksum )
245+
call_assert_describe( computed_checksum == expected_checksum, /* ensured since version 3.14 */ \
246+
"Checksum mismatch failure!" /* TODO: write a better message here */ \
247+
)
253248
```
254249

255250
However that capability might not be portable to other Fortran compilers.
256251
When in doubt, one can always move the comment outside the macro invocation:
257252

258253
```fortran
259254
! assert a property ensured since version 3.14
260-
call_assert_diagnose( computed_checksum == expected_checksum, \
261-
"Checksum mismatch failure!", \
262-
computed_checksum ) ! TODO: write a better message above
255+
call_assert_describe( computed_checksum == expected_checksum, \
256+
"Checksum mismatch failure!" \
257+
) ! TODO: write a better message above
263258
```
264259

265260
Legal Information

doc/assert_class_diagram.puml

Lines changed: 0 additions & 21 deletions
This file was deleted.

doc/example_class_diagram.puml

Lines changed: 0 additions & 29 deletions
This file was deleted.

example/README.md

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,82 +10,34 @@ The [simple_assertions.f90] example demonstrates a precondition and a
1010
postcondition, each with an assertion that checks the truth of a logical
1111
expression based on scalar, real values.
1212

13-
Derived type diagnostic data
14-
----------------------------
15-
16-
See [derived_type_diagnostic.f90]. For reasons related to runtime performance,
17-
it is desirable to ensure that any computation required to extract diagnostic
18-
data from an object only take place if the assertion fails. This is one of the
19-
main motivations for allowing objects to be passed to the `diagnostic_data`
20-
argument of `assert`. The generic programming facilities planned for
21-
"Fortran 202y" (two standards after Fortran 2018) will ultimately provide the
22-
best way to facilitate the extraction of diagnostic data from objects by
23-
empowering developers to express requirements on types such as that the types
24-
must support a specific procedure binding that can be used to extract output
25-
in character form, the form that `assert` uses for its error stop code. For
26-
now, we impose such a requirement through an `as_character` deferred binding
27-
on the provided `characterizable_t` abstract type.
28-
29-
Because it might prove problematic to require that a user type to extend the
30-
`characterizable_t` abstract type, the [derived_type_diagnostic.f90] example
31-
shows a workaround based on the class hierarchy described in the figure below.
32-
The figure shows a Unified Modeling Language ([UML]) class diagram with the
33-
`characterizable_t` abstract class, an example user's `stuff_t` class, and a
34-
`characterizable_stuff_t` class. The pattern expressed in the workaround
35-
aggregates the example user type, `stuff_t`, as a component inside the
36-
encapsulating `characterizable_stuff_t` type defined to extend `characterizable_t`
37-
for purposes of implementing `characterizable_t` parent type's deferred
38-
`as_character()` binding.
39-
40-
The figure below also shows two constraints written in UML's Object Constraint
41-
Language ([OCL]). The constraints describe the precondition and postcondition
42-
checked in [derived_type_diagnostic.f90] and the context for those constraints.
43-
44-
The UML diagram below was generated in the [Atom] editor [PlantUML] package
45-
from the PlantUML script in this repository's [doc] folder.
46-
47-
![Classes involved in Derived-Type Diagnostic Example](https://user-images.githubusercontent.com/13108868/130385757-6b79e5f1-5dec-440c-98f5-0f659c538754.png)
48-
4913
Running the examples
5014
--------------------
5115

5216
### Single-image execution
5317
```
5418
fpm run --example simple_assertions
55-
fpm run --example derived_type_diagnostic
5619
```
5720
where `fpm run` automatically invokes `fpm build` if necessary, .e.g., if the package's source code
58-
has changed since the most recent build. If `assert` is working correctly, the first `fpm run` above
59-
will error-terminate with the character stop code
60-
```
61-
Assertion "reciprocal: abs(error) < tolerance" failed on image 1 with diagnostic data "-1.00000000"
21+
has changed since the most recent build. If `assert` is working correctly, the `fpm run` above
22+
will error-terminate with the character stop code similar to the following
6223
```
63-
and the second `fpm run` above will error-terminate with the character stop code
64-
```
65-
Assertion "stuff_t%z(): self%defined()" failed on image 1 with diagnostic data "(none provided)"
24+
Assertion failure on image 1: reciprocal: abs(error) < tolerance
6625
```
6726

6827
### Multi-image execution with `gfortran` and OpenCoarrays
6928
```
7029
git clone git@github.com/sourceryinstitute/assert
7130
cd assert
7231
fpm run --compiler caf --runner "cafrun -n 2" --example simple_assertions
73-
fpm run --compiler caf --runner "cafrun -n 2" --example derived_type_diagnostic
7432
```
7533
Replace either instance of `2` above with the desired number of images to run for parallel execution.
7634
If `assert` is working correctly, both of the latter `fpm run` commands will error-terminate with one
7735
or more images providing stop codes analogous to those quoted in the [Single-image execution] section.
7836

79-
## Derived-type diagnostic data output
80-
To demonstrate the derived-type diagnostic data output capability, try replacing the
81-
`i%defined()` assertion in the [derived_type_diagnostic.f90](./derived_type_diagnostic.f90)
82-
with `.false.`.
83-
8437
[Hyperlinks]:#
8538
[OpenCoarrays]: https://github.com/sourceryinstitute/opencoarrays
8639
[Enforcing programming contracts]: #enforcing-programming-contracts
8740
[Single-image execution]: #single-image-execution
88-
[derived_type_diagnostic.f90]: ./derived_type_diagnostic.f90
8941
[simple_assertions.f90]: ./simple_assertions.f90
9042
[UML]: https://en.wikipedia.org/wiki/Unified_Modeling_Language
9143
[OCL]: https://en.wikipedia.org/wiki/Object_Constraint_Language

example/derived-type_diagnostic.F90

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)