Tobias Burnus
2012-11-27 18:29:15 UTC
Dear all,
effectively, this patch doesn't do anything. Except, it updates the â
deactivated â finalization wrapper.
Note: This patch does not include any code to actually call the
finalization wrapper. Nor is the modified code ever called in gfortran.
However, that patch paves the road to a proper finalization (and
polymorphic deallocation) support. When I mention below that I tested
the patch: That was with the larger but incomplete
final-2012-11-27-v2.diff patch, available at
https://userpage.physik.fu-berlin.de/~tburnus/final/ Note that the patch
there has known issues and does not incorporate all of Janus changes.
Changes relative to the trunk:
* Properly handles coarray components: Those may not be finalized for
intrinsic assignment; with this patch there is now a generated "IF"
condition to ensure this in the wrapper.
* While arrays arguments to the wrapper have to be contiguous, the new
version takes a "stride" argument which allows noncontiguity in the
lowest dimension. That is: One can pass a contiguous array directly to
the parent's finalizer even if it then isn't anymore contiguous (for the
parent type). If the finalizers are all elemental (or scalar), no
copy-in/copy-out is needed. However, if it is passed to an array final
subroutine, the array is packed using the following code:
if (stride == STORAGE_SIZE (array)/NUMERIC_STORAGE_SIZE
|| 0 == STORAGE_SIZE (array)) then
call final_rank3 (array)
else
block
type(t) :: tmp(shape (array))
do i = 0, size (array)-1
addr = transfer (c_loc (array), addr) + i * stride
call c_f_pointer (transfer (addr, cptr), ptr)
addr = transfer (c_loc (tmp), addr)
+ i * STORAGE_SIZE (array)/NUMERIC_STORAGE_SIZE
call c_f_pointer (transfer (addr, cptr), ptr2)
ptr2 = ptr
end do
call final_rank3 (tmp)
end block
end if
Build and regtested on x86-64-gnu-linux.
OK for the trunk?
Tobias
PS: I don't know when I will have time to continue working on the patch.
The next steps from my side are: First, submit some smaller bits from
the final-2012-11-27-v2.diff patch, even if they will be unused.
Secondly, do some cleanup and fix a few issues and merge Janus' patch.
(My patch is based on the 2012-10-26 version of the patch, Janus' latest
patch was 2012-11-04.) At that point, one might consider enabling the
FINAL feature partially (e.g. only polymorphic deallocation by not
allowing FINAL) or fully.
PPS: The patch was successfully tested with the following test case (and
some small variations of it):
module m
type t
integer :: i
contains
final :: fini
end type t
type, extends(t) :: t2
integer :: j
contains
final :: fini2
end type t2
contains
subroutine fini(x)
! type(t), intent(in) :: x(:,:)
type(t), intent(inout) :: x(:,:)
print *, 'SHAPE:', shape(x)
print *, x
end subroutine fini
impure elemental subroutine fini2(x)
type(t2), intent(inout) :: x
print *, 'FINI2 - elemental: ', x%i
x%i = x%i+10*x%i
end subroutine fini2
end module m
use m
class(t2), allocatable :: x(:,:)
allocate(t2 :: x(2,3))
x(:,:)%i = reshape([1,2,3,4,5,6],[2,3])
print *, 'HELLO: ', x%i
deallocate(x)
end
effectively, this patch doesn't do anything. Except, it updates the â
deactivated â finalization wrapper.
Note: This patch does not include any code to actually call the
finalization wrapper. Nor is the modified code ever called in gfortran.
However, that patch paves the road to a proper finalization (and
polymorphic deallocation) support. When I mention below that I tested
the patch: That was with the larger but incomplete
final-2012-11-27-v2.diff patch, available at
https://userpage.physik.fu-berlin.de/~tburnus/final/ Note that the patch
there has known issues and does not incorporate all of Janus changes.
Changes relative to the trunk:
* Properly handles coarray components: Those may not be finalized for
intrinsic assignment; with this patch there is now a generated "IF"
condition to ensure this in the wrapper.
* While arrays arguments to the wrapper have to be contiguous, the new
version takes a "stride" argument which allows noncontiguity in the
lowest dimension. That is: One can pass a contiguous array directly to
the parent's finalizer even if it then isn't anymore contiguous (for the
parent type). If the finalizers are all elemental (or scalar), no
copy-in/copy-out is needed. However, if it is passed to an array final
subroutine, the array is packed using the following code:
if (stride == STORAGE_SIZE (array)/NUMERIC_STORAGE_SIZE
|| 0 == STORAGE_SIZE (array)) then
call final_rank3 (array)
else
block
type(t) :: tmp(shape (array))
do i = 0, size (array)-1
addr = transfer (c_loc (array), addr) + i * stride
call c_f_pointer (transfer (addr, cptr), ptr)
addr = transfer (c_loc (tmp), addr)
+ i * STORAGE_SIZE (array)/NUMERIC_STORAGE_SIZE
call c_f_pointer (transfer (addr, cptr), ptr2)
ptr2 = ptr
end do
call final_rank3 (tmp)
end block
end if
Build and regtested on x86-64-gnu-linux.
OK for the trunk?
Tobias
PS: I don't know when I will have time to continue working on the patch.
The next steps from my side are: First, submit some smaller bits from
the final-2012-11-27-v2.diff patch, even if they will be unused.
Secondly, do some cleanup and fix a few issues and merge Janus' patch.
(My patch is based on the 2012-10-26 version of the patch, Janus' latest
patch was 2012-11-04.) At that point, one might consider enabling the
FINAL feature partially (e.g. only polymorphic deallocation by not
allowing FINAL) or fully.
PPS: The patch was successfully tested with the following test case (and
some small variations of it):
module m
type t
integer :: i
contains
final :: fini
end type t
type, extends(t) :: t2
integer :: j
contains
final :: fini2
end type t2
contains
subroutine fini(x)
! type(t), intent(in) :: x(:,:)
type(t), intent(inout) :: x(:,:)
print *, 'SHAPE:', shape(x)
print *, x
end subroutine fini
impure elemental subroutine fini2(x)
type(t2), intent(inout) :: x
print *, 'FINI2 - elemental: ', x%i
x%i = x%i+10*x%i
end subroutine fini2
end module m
use m
class(t2), allocatable :: x(:,:)
allocate(t2 :: x(2,3))
x(:,:)%i = reshape([1,2,3,4,5,6],[2,3])
print *, 'HELLO: ', x%i
deallocate(x)
end