Question about finalization of abstract types
Damian Rouson
damian@rouson.net
Sat Jan 4 19:39:00 GMT 2014
Hi Tobias,
I don’t think the following code falls into one of the three categories of cases you listed for which finalization is not yet implemented, but gfortran doesn’t call the final subroutine:
module foo_module
implicit none
type foo
contains
final :: hello
end type
contains
subroutine hello(this)
type(foo) :: this
print *,"Hello from finalizer."
end subroutine
end module
program main
use foo_module
implicit none
block
type(foo) :: bar
end block
end program
I tested this with the current trunk. FYI, the NAG compiler does call the final subroutine in this case.
Damian
On Dec 15, 2013, at 11:19 AM, Tobias Burnus <burnus@net-b.de> wrote:
> Hi Damian and Andrew,
>
> Andrew Benson wrote:
>> Hi Damian,
>>
>>> An abstract type can, however, have a finalizable component. Instead of
>>> having a pointer in the abstract, why not have finalizable component that
>>> itself has a pointer component? Here’s what I recommend:
>>> [...]
>>>
>>> I have corresponded with at least six compiler teams on this subject and all
>>> concluded that an abstract type with a finalizable component is acceptable.
>>> Of the six, I think gfortran is the only one that won’t yet finalize the
>>> component (although it does accept the syntax).
>
> Well, it *does* finalize the component. It doesn't yet cover all cases, but in some it works. For instance:
>
> module m2
> use test
> type, extends(testType) :: t
> end type t
> end module m2
>
> use m2
> block
> type(t) :: x
> allocate(x%something%d)
> end block
> end
>
> (Without BLOCK "x" doesn't get finalized because variables in the main program implicitly have the SAVE attribute.)
>
>>> I think Tobias has worked on supporting finalization in the above case so hopefully he can give us an
>>> update on the status. It would be great for you to add your voice in support of the need for this work. :)
>
> Currently missing are:
>
> a) Finalization of the LHS during intrinsic assignment:
> finalizable = ...
> (There are a very few cases which already are finalized.)
>
> b) Finalization of functions results after their use, e.g.
> call foo(f())
> or
> ... = f()
> [Vaguely related: Scalar allocatable function results are currently not deallocated.]
>
> c) Finalization of structure/array constructors after their use.
>
> Already working:
> * INTENT(OUT) deallocation (including defined assignment)
> * End of scope deallocation
> * Manual DEALLCATE
> * Some additional cases involving finalizable components
>
>
> Completing the finalization support is still on my to-do list. Still the following is higher on my list: Working on the regressions - in particular on one regression for the namelist debugging/DWARFpatch; for the prediction (performance regression) - see today's email. I also have a bunch of other items I'd like to write patches for (some have already half-working draft patches, including finalization).
>
> Tobias
More information about the Fortran
mailing list