Fortran FINALization
This directory contains some draft patches to implement support for FINAL subroutines
Status as of 2013-05-31 on the 4.9 trunk
Finalization wrapper is now generated (but not yet used), FINAL parsing is enabled.
PATCH: http://gcc.gnu.org/ml/fortran/2013-05/msg00129.html – adds support for finalization of ALLOCATABLEs at end-of-scope, intent(out),allocatable and explicit DEALLOCATE.
Upcoming: Finalization for intent(out) and end of scope for nonallocatables.
See below for some additional TODO items (partially now obsolete). Besides those, additional work is required.
Note: The patches in this directory have now largely obsoleted by the committed and submitted patched.
Supported by the patches in this directory
- The finalization is invoked for DEALLOCATE, end of scope, for INTENT(OUT) and MOVE_ALLOC [some issues remain, cf. below]
- Basic implementation works.
UPDATE 2013-05-28
PATCHES: Enable FINAL infrastructure, but no finalization is done yet
Work in progress:
- finalize-allocatables-2013-05-27.diff adds finalization for allocatables. See patch for remaining tasks.
- Additional tasks: Ensure that the other callers of gfc_trans_dealloc_allocated finalize when possible (requires expr); ditto for gfc_deallocate_scalar_with_status. Main work item is the deallocation of components.
Pending issues:
- See old 2013-03-31 patch for some additional features (needs to be rediffed).
- TODO: End of scope handling for polymorphic allocatables. Refactor deallocate functions.
- TODO: Cleanup of the current patch
- See below for additional to-do items.
UPDATE 2013-05-27
UPDATE 2013-03-31
- Bugfixes merged to the trunk.
- See latest patch, which includes a first test case and no test suite failures.
- TODO: Fix finalization for arrays with INTENT(OUT), array CLASS: Fix end-of-scope dealloc+finalize
- Major cleanup of the code, more test cases, also to show polymorphic deallocate.
- Add end of scope finalization for nonallocatables (also for components) and add test cases for it.
- Fix OPTIONAL/ELEMENTAL handling
- See other possible TODO items below
UPDATE 2013-03-25
- Rediff, some bug fixes, first test case (see bugs in the test case)
- TODO: Call FINAL for allocatable intent(out) in the caller (no longer calling in the callee).
- See 2013-02-17 for additional TODO items
UPDATE 2013-02-17
- Rediff and fix a couple of bugs
- No test-suite failures
- WARNING: FINAL subroutines are mishandled for ALLOCATABLE dummys
with INTENT(OUT) as they are already deallocated in trans-expr.c
before the call while the current patch handles them via
trans-decl.c in the callee.
- TODO: Testing and add test cases en mass; checking for issues with OPTIONAL, ELEMENTAL etc. (cf. PR54618), allocatable components (esp. coarray ones), handling deallocation failures with coarrays ?, plugging memory leaks in the compiler itself; invoking code for the finalizer (for nonallocatables, compontents, assignments [also with sections/vector subscripts]); check that calling assumed-size/explicit-size finalization subroutines works for packed and nonpacked arrays, …
UPDATE 2013-01-05
- The wrapper patch has been committed. Now only calls to the wrapper have to be inserted.
- See today's patch for a start.
- See 2012-12-29 for a to-do list.
UPDATE 2012-12-31
- Submitted patches, fixing the remaing issues for the wrapper; another auxiliary function.
- Missing: Actual calls to the wrapper. (The patch on this page contains some.)
- See 2012-12-29 for a to-do list.
UPDATE 2012-12-30
- See 2012-12-29.
- Preparations for stride support (noncontiguous arrays).
UPDATE 2012-12-29
- Support for CLASS(*), no test-suite failures.
- Internal _.F_stride function, fixes in invoking the final wrapper.
- Main remaining issue: Supporting arrays with stride (e.g. assumed-shape intent-out arrays). Requires an update of the scalarizer and package code in the final wrapper, using the _F.stride function.
- Other to-do items: Testing, test-case writting, checking for issues with OPTIONAL, ELEMENTAL etc. (cf. PR54618), allocatable components (esp. coarray ones), handling deallocation failures with coarrays ?, plugging memory leaks in the compiler itself; invoking code for the finalizer (for nonallocatables, compontents, assignments [also with sections/vector subscripts]); check that calling assumed-size/explicit-size finalization subroutines works for packed and nonpacked arrays, …
UPDATE 2012-12-03
- The FINAL wrapper should be now complete.
- TODO 1: Continue merging Janus's 2012-11-04 patch, including test-case fixes; clean up of the current patch
- TODO 2: Fix issues mentioned in the old patch thread and on this page.
UPDATE 2012-11-27
- Current patch based on the 2012-10-26 patch
- It does not contain the changes of the 2012-11-04 patch
- Changes compared to 2012-10-26:
- Pass stride to the wrapper - avoid unnecessary repacking (which is also not implemented)
- INCOMPLETE: Packing of the arrays when calling array finalization subroutines
- Coarray fixes: Scalar corrays don't ICE, coarrays are only finalized if fini_coarray is true
- Short-term TODO: Finish incomplete part, fix some of the smaller issues mentioned below and incorporate the changes of the 2012-11-04 patch
Still to be done
- Handle CLASS(*)
- Check that scope-leaving variables which aren't allocatable are properly finalized.
- For intent(out), adapt OPTIONAL (ALLOCATABLE) NULL check after PR54618 has been fixed.
- Don't add the vtab->_final == NULL check if the declared type is known to have a non-null finalizer.
- Assumed-rank arrays: Packing support when passing a noncontiguous array to CONTIGUOUS dummy (to be used for calling the parent's wrapper procedure)
- Allocatable components – especially intrinsic assignment with coarray components (Unrelated to FINAL but also needed: deregister calls for coarray components)
- For allocatable coarray components: Handle STAT_STOPPED_IMAGE for DEALLOCATE
- Too much finalization: Variables in the main program are finalized, but shouldn't. (Are other implicitly/explicitly SAVEd vars also affected?)
- Clean up and refactoring of the patch
- The current version leaks quite a lot of memory, e.g. in generate_finalization_wrapper in the call to gfc_lval_expr_from_sym at
finalize_component (gfc_lval_expr_from_sym (ptr), derived, comp,
gfc_lval_expr_from_sym (stat), &block);
- New test cases, fix tree-scan-counts.
Fixed in 2012-09-18
- All regression-suite failures (except of the tree-scan-times ones)
- For CLASS(...),INTENT(OUT), no vtab->_final == NULL check is generated if it is known to be non-NULL. (Still to be done at other parts of the code)
Fixed in 2012-09-11
- Fix class.c's ts.interface for EXPR_NULL - otherwise one gets in trouble for CLASS
- Some test suite and FINAL test case fixes