[J3] [EXTERNAL] [BULK] Clarification needed on finalization
Jean Perier
jperier at nvidia.com
Fri Jan 19 17:22:40 UTC 2024
Hi Malcom, thanks for the reply, I originally asked the question to Mark, so I will reply directly.
To be clearer, if I am asking about the finalization behavior expectation, it is because the standard requirements about deallocation (and maybe what it means to take the value of something with allocatable components) are not clear here IMHO.
Hence, it is precisely not clear why your citation from the standard about deallocation implying finalization applies here.
I do not see what in the standards says that the allocatable components of structure and array constructors must be automatically deallocated (I could not find applicable paragraph in 9.7.3.2).
Currently, I will make the outrageous claim that the standard conformant implementation would be to have the memory leaks.
If we can all agree that the memory should obviously be cleaned-up, then:
Q1: Should it happen with Fortran deallocation semantics (implying finalization), or is it just a matter of freeing the memory of all the allocatable sub-objects like IFORT is doing (skipping finalization) ?
Q2: If it is a Fortran deallocation that is required, when should it happen (after it is used, after the end of the statement/construct...)?
The answers "2" for the finalization example is also assuming that the allocatable components have been "moved" from the structure constructor value to the array constructor value. Otherwise, "4" would be the expected answer as XLF is doing.
In `[t:: x, y]`, the compiler would obviously not "move" the variable allocatable components. Yet, as far as I known, the same standard section applies to how the array constructor value of `[t:: x, y]`, and `[t:: t(x=finalizable(1)), t(x=finalizable(2))]`, are made.
This moving/not moving aspects in struct/array ctors is usually transparent for the user, so up for the compiler as an optimization. But when coupled with finalization, it is not transparent anymore, hence needs clarification.
Q3: Does a compiler have to "move" the allocatable components from the structure constructor values into the array constructor values instead of copying them?
Answering Q1/Q2/Q3 would allow applying Malcom's standard reference and agreeing on an expected behavior for the finalization example.
So, my question for the J3 is: can someone point me to standard references answering Q1/Q2/Q3?
Jean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20240119/888f4b79/attachment.htm>
More information about the J3
mailing list