(j3.2006) ELEMENTAL finalizers vs. finalizing elementally
Michael Ingrassia
michaeli
Mon Apr 14 12:14:28 EDT 2008
Here's a confusing case.
I remember discussions impinging on this but not the details.
MODULE FOO
TYPE POINT
REAL :: X, Y
CONTAINS
FINAL :: S
END TYPE POINT
CONTAINS
SUBROUTINE S(P) ! not ELEMENTAL
TYPE(POINT) P
PRINT *, 'Finalizer was called'
END SUBROUTINE S
END MODULE FOO
USE FOO
TYPE(POINT), ALLOCATABLE :: A(:)
ALLOCATE(A(12))
DEALLOCATE(A) ! Finalization would occur here
END
A is of a finalizable type and ought to be finalized when deallocated
[59:19-20].
A is an array.
You can't finalize all of A at once by calling a finalizer, because there
aren't any rank-1 finalizers in sight nor any elemental finalizers in
sight.
Conceivably you could finalize each element of array A separately by
calling S once per element of A.
That is, it is a logical thing that would be possible to do manually.
But I argue that you shouldn't, that the standard doesn't say to do that.
FInalizing each element of an array separately is reserved for
finaliable components (that happen to be arrays) (rule (2) [59:9-11] ).
And A here isn't a component.
So no finalizers should get called.
On this reading, you do rather different things when you
finalize an array "at the top of the finalization tree" -- an entity
finalized because of one of the rules in 4.5.5.2 directly applies -- vs.
finalizing an array "lower down on the finalization tree" -- an entity
finalized as part of the recursion in rule (2) of 4.5.5.1.
For the former you call ELEMENTAL finalizers if you have them handy,
for the latter you don't call ELEMENTAL finalizers but you finalize
each element of the array separately using any scalar finalizers you
have handy.
--Michael I.
More information about the J3
mailing list