Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The existence of god implies a violation of causality.


devel / comp.lang.fortran / Re: Question on finalization standards

SubjectAuthor
* Question on finalization standardsAndrew Benson
`* Re: Question on finalization standardsFortranFan
 +* Re: Question on finalization standardsJohn
 |`* Re: Question on finalization standardsAndrew Benson
 | `* Re: Question on finalization standardsAndrew Benson
 |  `* Re: Question on finalization standardsPaul Richard Thomas
 |   `* Re: Question on finalization standardsAndrew Benson
 |    `- Re: Question on finalization standardsPaul Richard Thomas
 `- Re: Question on finalization standardsAndrew Benson

1
Question on finalization standards

<68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1270&group=comp.lang.fortran#1270

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:4111:: with SMTP id q17mr5363817qtl.264.1632502928636;
Fri, 24 Sep 2021 10:02:08 -0700 (PDT)
X-Received: by 2002:a25:ac8c:: with SMTP id x12mr14351600ybi.360.1632502928363;
Fri, 24 Sep 2021 10:02:08 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 24 Sep 2021 10:02:08 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=47.229.215.70; posting-account=rzkxqQoAAAAzbz4q6c7WiqzZGBqzOsB5
NNTP-Posting-Host: 47.229.215.70
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
Subject: Question on finalization standards
From: abenson@carnegiescience.edu (Andrew Benson)
Injection-Date: Fri, 24 Sep 2021 17:02:08 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 50
 by: Andrew Benson - Fri, 24 Sep 2021 17:02 UTC

I'm working (with much help from Paul Thomas) on adding finalization on intrinsic assignment to gfortran. There are a few instances where I'm unclear on precisely what is required by the standard, so would be very grateful for any insight any one here can offer.

The current issue is related to this example code:

module testmode
implicit none

type :: simple
character(4) :: scope="NONE"
integer :: ind
contains
final :: destructor1
end type simple

contains

subroutine destructor1(self)
type(simple), intent(inout) :: self
print *, "destructor1(", self%scope, ") ", self%ind
end subroutine destructor1

end module testmode

program test_final
use testmode
implicit none

type(simple), allocatable :: MyType
type(simple) :: ThyType = simple("MAIN", 21)

print *, "[1] ifort finalizes here, whereas gfortran does not."
MyType = ThyType

end program test_final

The new implementation of finalization on intrinsic assignment that I have in gfortran does not finalize MyType here, because it is not allocated prior to the assignment. This seems reasonable. But, Intel ifort does call the finalizer for MyType in this case.

Looking in the Fortran 2003 standards, section 4.5.5.2 "When finalization occurs" states:

"When an intrinsic assignment statement is executed, variable is finalized after evaluation of expr and before the definition of variable."

which doesn't really make it clear to me what should happen in this situation.

Re: Question on finalization standards

<f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1271&group=comp.lang.fortran#1271

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:a7d3:: with SMTP id q202mr12285538qke.418.1632513062942;
Fri, 24 Sep 2021 12:51:02 -0700 (PDT)
X-Received: by 2002:a25:104:: with SMTP id 4mr4436048ybb.485.1632513062606;
Fri, 24 Sep 2021 12:51:02 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 24 Sep 2021 12:51:02 -0700 (PDT)
In-Reply-To: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=165.225.39.122; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 165.225.39.122
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com>
Subject: Re: Question on finalization standards
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Fri, 24 Sep 2021 19:51:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 44
 by: FortranFan - Fri, 24 Sep 2021 19:51 UTC

On Friday, September 24, 2021 at 1:02:10 PM UTC-4, abe...@carnegiescience.edu wrote:

> I'm working (with much help from Paul Thomas) on adding finalization on intrinsic assignment to gfortran. There are a few instances where I'm unclear on precisely what is required by the standard, so would be very grateful for any insight any one here can offer.
>
> ..
> Looking in the Fortran 2003 standards, section 4.5.5.2 "When finalization occurs" states: ..

@abe...@carnegiescience.edu,

Thank you for taking the initiative to work on this in collaboration with Paul Thomas, that's great news for gfortran.

Here're some quick suggestions:

1) Discuss and decide with the gfortran team the plan for this, specifically which standard edition do you intent to target. I write this because you mention 2003 standard, but note there have been some revisions of significant consequence since, some of which were captured in Fortran 2008 Corrigenda that later went to official 2018 standard but which didn't catch everyone's attention. My suggestion will be to go with 18-007r1 document toward Fortran 2018 as your primary reference, but please do keep an eye an out during your planning and work for the *tweaks* that will indeed go into Fortran 202X when it gets published.

2) You may also want to consider other online resources such as the Fortran Discourse site (https://fortran-lang.discourse.group/) and GitHub Fortran Issues (https://github.com/j3-fortran/fortran_proposals) to engage with the Community on any and all topics that come up as you pursue this. This can be especially important toward the topic at hand - finalization - where you would do well to beware of *possible* "bugs" everywhere (!!) including in the standard and other compiler implementations. This is simply due to its history starting 2003 revision. So you can proceed to trust the standard, but please do try to *verify* everything and to crosscheck with the standards committee if anything doesn't make sense to you!

I'll provide my comments on your code example later.

Best,

Re: Question on finalization standards

<8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1272&group=comp.lang.fortran#1272

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:618c:: with SMTP id v134mr12586671qkb.231.1632515124996;
Fri, 24 Sep 2021 13:25:24 -0700 (PDT)
X-Received: by 2002:a25:9b46:: with SMTP id u6mr15025569ybo.39.1632515124841;
Fri, 24 Sep 2021 13:25:24 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 24 Sep 2021 13:25:24 -0700 (PDT)
In-Reply-To: <f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=73.40.218.30; posting-account=7tVJUQoAAACymEG6aShD5R0lhHCm_A0r
NNTP-Posting-Host: 73.40.218.30
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com> <f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
Subject: Re: Question on finalization standards
From: urbanjost@comcast.net (John)
Injection-Date: Fri, 24 Sep 2021 20:25:24 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
Lines: 14
 by: John - Fri, 24 Sep 2021 20:25 UTC

FYI: nvfortran does not, as well. I do find it unclear as to which it should do. Even though two for and one against from the compilers,
I lean towards towards the destructor being called as it is used in an assignment; but getting the committees to vote would be a nice way to resolve the question. It seems ideally there should be a formal way for compiler writers to petition for clarification.

+ : =====================================================
+ gfortran -O0 final1.f90
+ ./a.out
+ : =====================================================
+ ifort -O0 final1.f90
+ ./a.out
destructor1() 0
+ : =====================================================
+ ifx -O0 final1.f90
+ ./a.out
destructor1() 0
+ : =====================================================
+ nvfortran -O0 final1.f90
+ ./a.out

Re: Question on finalization standards

<32657644-a1e4-4188-ad99-8c904388052cn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1273&group=comp.lang.fortran#1273

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:9b16:: with SMTP id d22mr12746348qke.22.1632515455611;
Fri, 24 Sep 2021 13:30:55 -0700 (PDT)
X-Received: by 2002:a25:b09d:: with SMTP id f29mr14413068ybj.257.1632515455302;
Fri, 24 Sep 2021 13:30:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 24 Sep 2021 13:30:54 -0700 (PDT)
In-Reply-To: <f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=47.229.215.70; posting-account=rzkxqQoAAAAzbz4q6c7WiqzZGBqzOsB5
NNTP-Posting-Host: 47.229.215.70
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com> <f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <32657644-a1e4-4188-ad99-8c904388052cn@googlegroups.com>
Subject: Re: Question on finalization standards
From: abenson@carnegiescience.edu (Andrew Benson)
Injection-Date: Fri, 24 Sep 2021 20:30:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 63
 by: Andrew Benson - Fri, 24 Sep 2021 20:30 UTC

Thank you for your response. As you suggested, I took a look at the Fortran 2018 standard document, which I think clears up the ambiguity on this issue. Specifically, in section 7.5.6.3 "When finalization occurs", item 1 states:

"When an intrinsic assignment statement is executed (10.2.1.3), if the variable is not an unallocated allocatable variable, it is finalized after evaluation of expr and before the definition of the variable. If the variable is an allocated allocatable variable, or has an allocated allocatable subobject, that would be deallocated by intrinsic assignment, the finalization occurs before the deallocation."

I think the key part here is "if the variable is not an unallocated allocatable variable". So, if the variable is unallocated it should not be finalized.

So, based on my interpretation of that Intel has incorrect behavior here.

-Andrew

On Friday, September 24, 2021 at 12:51:04 PM UTC-7, FortranFan wrote:
> On Friday, September 24, 2021 at 1:02:10 PM UTC-4, abe...@carnegiescience..edu wrote:
>
> > I'm working (with much help from Paul Thomas) on adding finalization on intrinsic assignment to gfortran. There are a few instances where I'm unclear on precisely what is required by the standard, so would be very grateful for any insight any one here can offer.
> >
> > ..
> > Looking in the Fortran 2003 standards, section 4.5.5.2 "When finalization occurs" states: ..
>
> @abe...@carnegiescience.edu,
>
> Thank you for taking the initiative to work on this in collaboration with Paul Thomas, that's great news for gfortran.
>
> Here're some quick suggestions:
>
> 1) Discuss and decide with the gfortran team the plan for this, specifically which standard edition do you intent to target. I write this because you mention 2003 standard, but note there have been some revisions of significant consequence since, some of which were captured in Fortran 2008 Corrigenda that later went to official 2018 standard but which didn't catch everyone's attention. My suggestion will be to go with 18-007r1 document toward Fortran 2018 as your primary reference, but please do keep an eye an out during your planning and work for the *tweaks* that will indeed go into Fortran 202X when it gets published.
>
> 2) You may also want to consider other online resources such as the Fortran Discourse site (https://fortran-lang.discourse.group/) and GitHub Fortran Issues (https://github.com/j3-fortran/fortran_proposals) to engage with the Community on any and all topics that come up as you pursue this. This can be especially important toward the topic at hand - finalization - where you would do well to beware of *possible* "bugs" everywhere (!!) including in the standard and other compiler implementations. This is simply due to its history starting 2003 revision. So you can proceed to trust the standard, but please do try to *verify* everything and to crosscheck with the standards committee if anything doesn't make sense to you!
>
> I'll provide my comments on your code example later.
>
> Best,

Re: Question on finalization standards

<c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1274&group=comp.lang.fortran#1274

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:a886:: with SMTP id r128mr12580836qke.453.1632515513780;
Fri, 24 Sep 2021 13:31:53 -0700 (PDT)
X-Received: by 2002:a5b:385:: with SMTP id k5mr14213764ybp.65.1632515513566;
Fri, 24 Sep 2021 13:31:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.snarked.org!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 24 Sep 2021 13:31:53 -0700 (PDT)
In-Reply-To: <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=47.229.215.70; posting-account=rzkxqQoAAAAzbz4q6c7WiqzZGBqzOsB5
NNTP-Posting-Host: 47.229.215.70
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
<f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com> <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com>
Subject: Re: Question on finalization standards
From: abenson@carnegiescience.edu (Andrew Benson)
Injection-Date: Fri, 24 Sep 2021 20:31:53 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
Lines: 17
 by: Andrew Benson - Fri, 24 Sep 2021 20:31 UTC

Thanks for testing this with nvfortran - it's good to have a third "opinion" here!

On Friday, September 24, 2021 at 1:25:26 PM UTC-7, John wrote:
> FYI: nvfortran does not, as well. I do find it unclear as to which it should do. Even though two for and one against from the compilers,
> I lean towards towards the destructor being called as it is used in an assignment; but getting the committees to vote would be a nice way to resolve the question. It seems ideally there should be a formal way for compiler writers to petition for clarification.
> + : =====================================================
> + gfortran -O0 final1.f90
> + ./a.out
> + : =====================================================
> + ifort -O0 final1.f90
> + ./a.out
> destructor1() 0
> + : =====================================================
> + ifx -O0 final1.f90
> + ./a.out
> destructor1() 0
> + : =====================================================
> + nvfortran -O0 final1.f90
> + ./a.out

Re: Question on finalization standards

<ba37128b-6096-45dc-82dc-21812392d704n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1282&group=comp.lang.fortran#1282

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ad4:4567:: with SMTP id o7mr2016403qvu.57.1632774760461;
Mon, 27 Sep 2021 13:32:40 -0700 (PDT)
X-Received: by 2002:a25:ac8c:: with SMTP id x12mr2236877ybi.360.1632774760104;
Mon, 27 Sep 2021 13:32:40 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 27 Sep 2021 13:32:39 -0700 (PDT)
In-Reply-To: <c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=47.229.215.70; posting-account=rzkxqQoAAAAzbz4q6c7WiqzZGBqzOsB5
NNTP-Posting-Host: 47.229.215.70
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
<f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com> <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
<c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ba37128b-6096-45dc-82dc-21812392d704n@googlegroups.com>
Subject: Re: Question on finalization standards
From: abenson@carnegiescience.edu (Andrew Benson)
Injection-Date: Mon, 27 Sep 2021 20:32:40 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 173
 by: Andrew Benson - Mon, 27 Sep 2021 20:32 UTC

Another finalization question (I'll also post this on the Fortran Discourse site and at the GitHub Fortran Issues site).

This example considers finalization of a class array:

module testmode
implicit none

character(4) :: scope = "MAIN"

logical, parameter :: instrument = .false.

type :: simple
character(4) :: scope
integer :: ind
contains
final :: destructor1, destructor2
end type simple

type, extends(simple) :: complicated
real :: rind
contains
final :: destructor3, destructor4
end type complicated

integer :: check_scalar
integer :: check_array(4)
real :: check_real
real :: check_rarray(4)
integer :: final_count = 0

contains

subroutine destructor1(self)
type(simple), intent(inout) :: self
print *, "destructor1(", self%scope, ") ", self%ind
end subroutine destructor1

subroutine destructor2(self)
type(simple), intent(inout) :: self(:)
print *, "destructor2(", self(1)%scope, ") ", self%ind
end subroutine destructor2

subroutine destructor3(self)
type(complicated), intent(inout) :: self
print *, "destructor3(", self%scope, ") ", self%rind
end subroutine destructor3

subroutine destructor4(self)
type(complicated), intent(inout) :: self(:)
if (size(self, 1) .gt. 0) then
print *, "destructor4(", self(1)%scope, ") ", size(self%rind), self%rind
else
print *, "destructor4"
end if
end subroutine destructor4

function constructor1(ind) result(res)
type(simple), allocatable :: res
integer, intent(in) :: ind
scope = "CTR1"
allocate (res, source = simple ("SOUR", ind))
res%scope = scope
end function constructor1

function constructor2(ind, rind) result(res)
class(simple), allocatable :: res(:)
integer, intent(in) :: ind(:)
real, intent(in), optional :: rind(:)
type(complicated), allocatable :: src(:)
integer :: sz
integer :: i
scope = "CTR2"
if (present (rind)) then
sz = min (size (ind, 1), size (rind, 1))
src = [(complicated ("SOUR", ind(i), rind(i)), i = 1, sz)]
allocate (res, source = src)
src%scope = "SRC "
res%scope=scope
else
sz = size (ind, 1)
allocate (res, source = [(simple (scope, ind(i)), i = 1, sz)])
end if
end function constructor2
end module testmode

program test_final
use testmode
implicit none

class(simple), allocatable :: MyClassArray(:)

! *****************
! Class assignments
! *****************

allocate (MyClassArray, source = [complicated(scope, 1, 2.0),complicated(scope, 3, 4.0)])
print *, "[3] ...until here. Both call the rank-1 finalizer for the extended &
type but ifort calls the rank-0 finalizer for the parent type, while &
gfortran uses the rank-1 finalizer."
deallocate (MyClassArray)
end program test_final

With gfortran (including the patches for finalization on intrinsic assignment that I'm working on), this results in:

[3] ...until here. Both call the rank-1 finalizer for the extended type but ifort calls the rank-0 finalizer for the parent type, while gfortran uses the rank-1 finalizer.
destructor4(MAIN) 2 2.00000000 4.00000000
destructor2(MAIN) 1 3

which shows that, when deallocating 'MyClassArray', the rank-1 finalizer for the extended type 'complicated' is called, and then the rank-1 finalizer for the parent type 'simple' is called.

But, under ifort I get:

[3] ...until here. Both call the rank-1 finalizer for the extended type but ifo
rt calls the rank-0 finalizer for the parent type, while gfortran uses the rank
-1 finalizer.
destructor4(MAIN) 2 2.000000 4.000000
destructor1(MAIN) 1
destructor1(MAIN) 3

showing that the rank-1 finalizer is called for the extended type, but then the scalar finalizer of the parent type is called twice, once for each element in the array.

ifort's behavior seems incorrect here, but I'd be interested to hear anyone's opinion on this.

Thanks,
Andrew

On Friday, September 24, 2021 at 1:31:55 PM UTC-7, Andrew Benson wrote:
> Thanks for testing this with nvfortran - it's good to have a third "opinion" here!
> On Friday, September 24, 2021 at 1:25:26 PM UTC-7, John wrote:
> > FYI: nvfortran does not, as well. I do find it unclear as to which it should do. Even though two for and one against from the compilers,
> > I lean towards towards the destructor being called as it is used in an assignment; but getting the committees to vote would be a nice way to resolve the question. It seems ideally there should be a formal way for compiler writers to petition for clarification.
> > + : ====================================================> > + gfortran -O0 final1.f90
> > + ./a.out
> > + : ====================================================> > + ifort -O0 final1.f90
> > + ./a.out
> > destructor1() 0
> > + : ====================================================> > + ifx -O0 final1.f90
> > + ./a.out
> > destructor1() 0
> > + : ====================================================> > + nvfortran -O0 final1.f90
> > + ./a.out

Re: Question on finalization standards

<01af4522-a33b-4bfb-af63-489756d936f3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1589&group=comp.lang.fortran#1589

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:54c:: with SMTP id m12mr27825588qtx.300.1643911290903;
Thu, 03 Feb 2022 10:01:30 -0800 (PST)
X-Received: by 2002:a81:3491:: with SMTP id b139mr2796527ywa.450.1643911290712;
Thu, 03 Feb 2022 10:01:30 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 3 Feb 2022 10:01:30 -0800 (PST)
In-Reply-To: <ba37128b-6096-45dc-82dc-21812392d704n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23c4:ac9c:a301:a1a2:716a:a3aa:8505;
posting-account=HvUZPgoAAAAcrlczjQmxlT215Ot2vYZd
NNTP-Posting-Host: 2a00:23c4:ac9c:a301:a1a2:716a:a3aa:8505
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
<f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com> <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
<c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com> <ba37128b-6096-45dc-82dc-21812392d704n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <01af4522-a33b-4bfb-af63-489756d936f3n@googlegroups.com>
Subject: Re: Question on finalization standards
From: paul.richard.thomas@gmail.com (Paul Richard Thomas)
Injection-Date: Thu, 03 Feb 2022 18:01:30 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 34
 by: Paul Richard Thomas - Thu, 3 Feb 2022 18:01 UTC

Hi Andrew,

> With gfortran (including the patches for finalization on intrinsic assignment that I'm working on), this results in:
>
> [3] ...until here. Both call the rank-1 finalizer for the extended type but ifort calls the rank-0 finalizer for the parent type, while gfortran uses the rank-1 finalizer.
> destructor4(MAIN) 2 2.00000000 4.00000000
> destructor2(MAIN) 1 3
>
> which shows that, when deallocating 'MyClassArray', the rank-1 finalizer for the extended type 'complicated' is called, and then the rank-1 finalizer for the parent type 'simple' is called.
>
> But, under ifort I get:
>
> [3] ...until here. Both call the rank-1 finalizer for the extended type but ifo
> rt calls the rank-0 finalizer for the parent type, while gfortran uses the rank
> -1 finalizer.
> destructor4(MAIN) 2 2.000000 4.000000
> destructor1(MAIN) 1
> destructor1(MAIN) 3
>
> showing that the rank-1 finalizer is called for the extended type, but then the scalar finalizer of the parent type is called twice, once for each element in the array.
>
> ifort's behavior seems incorrect here, but I'd be interested to hear anyone's opinion on this.

I have just posted a large patch on finalization. In the accomanying message, I conclude that ifort is correct. From F2018 7.5.6.3:
(2) All finalizable components that appear in the type definition are finalized in a processor-dependent
order. If the entity being finalized is an array, each finalizable component of each element of that
entity is finalized separately.
(3) If the entity is of extended type and the parent type is finalizable, the parent component is finalized.

The parent type is indeed a component and should apparently be treated as such. I have not yet ahad the intestinal fortitude to correct it in gfortran!

Regards

Paul

Re: Question on finalization standards

<5b046710-3b8d-4aa5-a1de-6ee5433f55dan@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1590&group=comp.lang.fortran#1590

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a37:a107:: with SMTP id k7mr24297062qke.333.1643911529743;
Thu, 03 Feb 2022 10:05:29 -0800 (PST)
X-Received: by 2002:a25:6e8b:: with SMTP id j133mr6771934ybc.148.1643911529460;
Thu, 03 Feb 2022 10:05:29 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 3 Feb 2022 10:05:29 -0800 (PST)
In-Reply-To: <01af4522-a33b-4bfb-af63-489756d936f3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=75.140.15.40; posting-account=rzkxqQoAAAAzbz4q6c7WiqzZGBqzOsB5
NNTP-Posting-Host: 75.140.15.40
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
<f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com> <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
<c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com> <ba37128b-6096-45dc-82dc-21812392d704n@googlegroups.com>
<01af4522-a33b-4bfb-af63-489756d936f3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5b046710-3b8d-4aa5-a1de-6ee5433f55dan@googlegroups.com>
Subject: Re: Question on finalization standards
From: abenson@carnegiescience.edu (Andrew Benson)
Injection-Date: Thu, 03 Feb 2022 18:05:29 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 39
 by: Andrew Benson - Thu, 3 Feb 2022 18:05 UTC

Hi Paul,

Thanks - after reading those lines from the standard carefully (a few times over!) that does make sense.

Thanks,
Andrew

On Thursday, February 3, 2022 at 10:01:33 AM UTC-8, Paul Richard Thomas wrote:
> Hi Andrew,
> > With gfortran (including the patches for finalization on intrinsic assignment that I'm working on), this results in:
> >
> > [3] ...until here. Both call the rank-1 finalizer for the extended type but ifort calls the rank-0 finalizer for the parent type, while gfortran uses the rank-1 finalizer.
> > destructor4(MAIN) 2 2.00000000 4.00000000
> > destructor2(MAIN) 1 3
> >
> > which shows that, when deallocating 'MyClassArray', the rank-1 finalizer for the extended type 'complicated' is called, and then the rank-1 finalizer for the parent type 'simple' is called.
> >
> > But, under ifort I get:
> >
> > [3] ...until here. Both call the rank-1 finalizer for the extended type but ifo
> > rt calls the rank-0 finalizer for the parent type, while gfortran uses the rank
> > -1 finalizer.
> > destructor4(MAIN) 2 2.000000 4.000000
> > destructor1(MAIN) 1
> > destructor1(MAIN) 3
> >
> > showing that the rank-1 finalizer is called for the extended type, but then the scalar finalizer of the parent type is called twice, once for each element in the array.
> >
> > ifort's behavior seems incorrect here, but I'd be interested to hear anyone's opinion on this.
> I have just posted a large patch on finalization. In the accomanying message, I conclude that ifort is correct. From F2018 7.5.6.3:
> (2) All finalizable components that appear in the type definition are finalized in a processor-dependent
> order. If the entity being finalized is an array, each finalizable component of each element of that
> entity is finalized separately.
> (3) If the entity is of extended type and the parent type is finalizable, the parent component is finalized.
>
> The parent type is indeed a component and should apparently be treated as such. I have not yet ahad the intestinal fortitude to correct it in gfortran!
>
> Regards
>
> Paul

Re: Question on finalization standards

<3076714b-1612-487c-b00b-65956cb6581fn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1595&group=comp.lang.fortran#1595

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ae9:df85:: with SMTP id t127mr3681251qkf.744.1644142623870;
Sun, 06 Feb 2022 02:17:03 -0800 (PST)
X-Received: by 2002:a25:4807:: with SMTP id v7mr5721478yba.380.1644142623686;
Sun, 06 Feb 2022 02:17:03 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Sun, 6 Feb 2022 02:17:03 -0800 (PST)
In-Reply-To: <5b046710-3b8d-4aa5-a1de-6ee5433f55dan@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23c4:ac9c:a301:a1a2:716a:a3aa:8505;
posting-account=HvUZPgoAAAAcrlczjQmxlT215Ot2vYZd
NNTP-Posting-Host: 2a00:23c4:ac9c:a301:a1a2:716a:a3aa:8505
References: <68fc4369-ab33-4060-a85c-c65b8f13e304n@googlegroups.com>
<f213b777-8dcb-476e-a8ee-ceda629eaf15n@googlegroups.com> <8de205c3-6ba9-40d5-ad93-3ce1a899b02dn@googlegroups.com>
<c0aedbee-372c-4e2f-98b1-f88d96196c96n@googlegroups.com> <ba37128b-6096-45dc-82dc-21812392d704n@googlegroups.com>
<01af4522-a33b-4bfb-af63-489756d936f3n@googlegroups.com> <5b046710-3b8d-4aa5-a1de-6ee5433f55dan@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3076714b-1612-487c-b00b-65956cb6581fn@googlegroups.com>
Subject: Re: Question on finalization standards
From: paul.richard.thomas@gmail.com (Paul Richard Thomas)
Injection-Date: Sun, 06 Feb 2022 10:17:03 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 27
 by: Paul Richard Thomas - Sun, 6 Feb 2022 10:17 UTC

On Thursday, 3 February 2022 at 18:05:32 UTC, abe...@carnegiescience.edu wrote:
> Hi Paul,
>
> Thanks - after reading those lines from the standard carefully (a few times over!) that does make sense.
>
> Thanks,
> Andrew
> On Thursday, February 3, 2022 at 10:01:33 AM UTC-8, Paul Richard Thomas wrote:
> > Hi Andrew,
....snip...
> > I have just posted a large patch on finalization. In the accomanying message, I conclude that ifort is correct. From F2018 7.5.6.3:
> > (2) All finalizable components that appear in the type definition are finalized in a processor-dependent
> > order. If the entity being finalized is an array, each finalizable component of each element of that
> > entity is finalized separately.
> > (3) If the entity is of extended type and the parent type is finalizable, the parent component is finalized.
> >
> > The parent type is indeed a component and should apparently be treated as such. I have not yet ahad the intestinal fortitude to correct it in gfortran!
> >
> > Regards
> >
> > Paul

A dissenting voice: NAG Fortran compiler version 7.1 (thanks Damian) does the same as gfortran. Paragraph 3 seems to be somewhat prone to ambiguous interpretation.

It turned out that making gfortran comply with ifort is much easier than I thought it would be.

Paul


devel / comp.lang.fortran / Re: Question on finalization standards

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor