F2003 Finalization -- progress and problems

Daniel Kraft d@domob.eu
Mon Jun 9 15:17:00 GMT 2008


Hi,

find attached my current patch for finalization of derived types (part
2).  This already does a good deal of the work, including handling of
finalizing finalizable components (possibly scalarized if an array of
the original type is finalized) and makes finalization happen on already
some of the events mentioned by the standard.

BTW, except for my own test finalize_exec_5.f03 that is only partially
supported this patch runs through check-gfortran.

As you can easily see, there are a lot of points in the patch marked XXX
that I'm unsure about (to avoid confusion:  I will remove all XXX
comments before making the final patch that will eventually get
committed, those are the points I want to mark for discussion before the
patch is finished), and the patch is already growing a little big.  If
you want, we could split it once again for review, but that's up to you.
    After finishing the code, I want to write some little documentation
about how finalization works and is implemented if you want so in the
future everyone has it easier to work on it (now that I still know how
it works...), if you point me where to write this.  That could be part 3
or 4 of this patch, what do you think?

I'd claim that modulo surely a lot of bugs (:D) this patch implements
all of the type-finalization section but the "When finalization occurs"
part which is only partly implemented.

Still missing is handling finalization on some more tricky occasions:

a) when automatic deallocation happens, that should be no problem,

b) results of functions and structure-constructors after they have been
used:  I'm not sure how this could be done in resolution-phase (without
"rewriting" the code and introducing temporaries), but maybe in trans
this will be easier.  Any ideas and tipps?

c) what exactly does that "specification expression in scoping unit"
mean?  But otherwise, this sounds similar to b).

d) when a procedure is called that is not in a module (does not have an
interface?) its formal-argument list in the tree is NULL (as this
information is not known, I suppose).  How should we in this case
determine which arguments are INTENT(OUT) and need finalization before
the call?  Is this information there in trans?  I fear not.  So how
should we do this one?  Or am I simply missing something in the standard
that allows us to ignore such calls or similar?

And what's about:

FUNCTION foobar (a)
      INTEGER, INTENT(OUT) :: a
      a = 5
      foobar = 0
END FUNCTION

...

x = 1
WRITE (*,*) x + foobar (x)

Is this allowed?  If so, what it's supposed to output?  Or is there
something similar to sequence-points in C that makes this undefined
behaviour?

What's about calling an ELEMENTAL-procedure with a INTENT(OUT) argument
on an array?  Should the array be finalized as a whole or each element
seperatelly before the call?

e) intrinsic assignment: for ordinary assignments this is handled (but
I'm not yet checking in the test-suite if it really happens only for
intrinsic assignment; will be done in the future) easily.  OTOH, for
assignments inside WHERE/FORALL I still have to look into it; maybe this
will be easy, too, but there's at least something I'm thinking about:

WHERE (arr == 2)
      arr = 5
END WHERE

Should this finalize the whole masked arr at once or each element before
it is overwritten?  Can there be a similar unclarity for FORALL?

Ok, this got long enough...  Seems there are some tricky special-cases
for finalization or I've not yet understood it :D

Thanks for your comments!

Daniel

PS: I got a response from Damian Rouson regarding his "Fortran 2003 OOP
features test-codes" and got them from him, including that they will
probably be released with GPL/LGPL (he was not sure) when the article is
printed.  I hope this is good news ;)

-- 
Done:     Bar-Sam-Val-Wiz, Dwa-Elf-Hum-Orc, Cha-Law, Fem-Mal
Underway: Ran-Gno-Neu-Fem
To go:    Arc-Cav-Hea-Kni-Mon-Pri-Rog-Tou



-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch.diff
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080609/6c92a578/attachment.ksh>


More information about the Fortran mailing list