Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Loose bits sink chips.


devel / comp.lang.fortran / Re: Does any compiler implement finalization correctly for function results?

SubjectAuthor
* Does any compiler implement finalization correctly for function results?Peter Klausler US
+- Re: Does any compiler implement finalization correctly for functionSteven G. Kargl
+* Re: Does any compiler implement finalization correctly for functionSteve Lionel
|`* Re: Does any compiler implement finalization correctly for function results?FortranFan
| `* Re: Does any compiler implement finalization correctly for functionSteve Lionel
|  +- Re: Does any compiler implement finalization correctly for function results?FortranFan
|  `* Re: Does any compiler implement finalization correctly for function results?gah4
|   `* Re: Does any compiler implement finalization correctly for functionSteve Lionel
|    `- Re: Does any compiler implement finalization correctly for function results?jfh
`* Re: Does any compiler implement finalization correctly for function results?FortranFan
 `* Re: Does any compiler implement finalization correctly for function results?FortranFan
  `* Re: Does any compiler implement finalization correctly for function results?bara...@gmail.com
   `- Re: Does any compiler implement finalization correctly for function results?FortranFan

1
Does any compiler implement finalization correctly for function results?

<9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a0c:9d41:0:b0:54c:a7ff:d102 with SMTP id n1-20020a0c9d41000000b0054ca7ffd102mr476131qvf.73.1675365378642;
Thu, 02 Feb 2023 11:16:18 -0800 (PST)
X-Received: by 2002:a05:6870:4292:b0:163:6f84:4659 with SMTP id
y18-20020a056870429200b001636f844659mr383008oah.231.1675365378306; Thu, 02
Feb 2023 11:16:18 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 2 Feb 2023 11:16:18 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=12.154.207.45; posting-account=ZT-cAwoAAACx2tBPXm-WZoHIT8sjnGGy
NNTP-Posting-Host: 12.154.207.45
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
Subject: Does any compiler implement finalization correctly for function results?
From: pklausler@nvidia.com (Peter Klausler US)
Injection-Date: Thu, 02 Feb 2023 19:16:18 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2791
 by: Peter Klausler US - Thu, 2 Feb 2023 19:16 UTC

Consider this simple test:

module m
type t
integer n
contains
final :: final
end type
contains
type(t) function func(n)
integer, intent(in) :: n
func = t(n)
end function
impure elemental subroutine final(x)
type(t), intent(in out) :: x
print *, 'final: ', x%n
end subroutine
end module

program test
use m
character(20) buffer
1 format(5I2)
write(buffer,1) (func(j),j=1,5)
print *, 'wrote: ', buffer
end

Fortran 2018 is fairly clear on the expected behavior: 7.5.6.3p5 "If an executable construct references a nonpointer function, the result is finalized after execution of the innermost executable construct containing the reference." So one would expect five lines "final: 1", "final: 2", &c. to "final: 5", followed by "wrote: 1 2 3 4 5".

Tried it on recent releases of six currently maintained Fortran compilers, and none of them produced these expected results. Instead, I observed:

Compiler A:
wrote: 1 2 3 4 5

Compilers B & C:
final: 0
final: 1
final: 2
final: 3
final: 4
final: 5
wrote: 1 2 3 4 5

Compiler D:
final: 0
final: 0
final: 0
final: 0
final: 0
wrote: 1 2 3 4 5

Compiler E:
final: 0
final: 1
final: -1955471140
final: 2
final: -1955471140
final: 3
final: -1955471140
final: 4
final: -1955471140
final: 5
wrote: 1 2 3 4 5

Compiler F:
I/O recursion detected.

If you know of a compiler that produces something other than these, please let me know about it.

Re: Does any compiler implement finalization correctly for function results?

<trh2nn$10ukm$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: sgk@REMOVEtroutmask.apl.washington.edu (Steven G. Kargl)
Newsgroups: comp.lang.fortran
Subject: Re: Does any compiler implement finalization correctly for function
results?
Date: Thu, 2 Feb 2023 19:25:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <trh2nn$10ukm$1@dont-email.me>
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 2 Feb 2023 19:25:43 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2cd25107f72bc370b3a409e06eccfec6";
logging-data="1079958"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/lCbayuWlcinm6rzm1vLLE"
User-Agent: Pan/0.145 (Duplicitous mercenary valetism; d7e168a
git.gnome.org/pan2)
Cancel-Lock: sha1:C/ba8QJamkbbFdWrFqKemdzFBRc=
 by: Steven G. Kargl - Thu, 2 Feb 2023 19:25 UTC

On Thu, 02 Feb 2023 11:16:18 -0800, Peter Klausler US wrote:

>
> If you know of a compiler that produces something other
> than these, please let me know about it.

gfortran has a number of known issues with finalization.
There is a patch that supposes addresses most/all open bug
reports, which might make it into gcc 13.1 when released.

https://gcc.gnu.org/pipermail/fortran/2023-January/058723.html

--
steve

Re: Does any compiler implement finalization correctly for function results?

<k42ibdFa6q8U1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: steve@seesignature.invalid (Steve Lionel)
Newsgroups: comp.lang.fortran
Subject: Re: Does any compiler implement finalization correctly for function
results?
Date: Thu, 2 Feb 2023 14:47:57 -0500
Lines: 37
Message-ID: <k42ibdFa6q8U1@mid.individual.net>
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Zdui3plTPeVizg5eTn2kgA+rcJDw9bBFQ86IDnbgMoMklq1EPd
Cancel-Lock: sha1:Bu8IgnGUmahicDvDKCHJR0B8Gzs=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:110.0) Gecko/20100101
Thunderbird/110.0
Content-Language: en-US
In-Reply-To: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
 by: Steve Lionel - Thu, 2 Feb 2023 19:47 UTC

On 2/2/2023 2:16 PM, Peter Klausler US wrote:
> If you know of a compiler that produces something other than these, please let me know about it.

Compiler G
final: 0
final: 1
final: 0
final: 2
final: 0
final: 3
final: 0
final: 4
final: 0
final: 5
wrote: 1 2 3 4 5

(This is similar to your compiler E, however, so these may be the same.)

I don't understand what is happening here. From my stepping through with
a debugger, using a compiler that gives the B/C result, there is an
uninitialized instantiation of the type that is finalized before the
function returns. In the B/C case, this happens only once - clearly in
compiler G (E) it happens on each call to func.

I hope that someone can explain this, because I can't.

(The recursive I/O error is just incorrect.)
--
Steve Lionel
ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
Retired Intel Fortran developer/support
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
LinkedIn: https://www.linkedin.com/in/stevelionel
Blog: https://stevelionel.com/drfortran
WG5: https://wg5-fortran.org

Re: Does any compiler implement finalization correctly for function results?

<e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:28d6:b0:72c:3855:7b1b with SMTP id l22-20020a05620a28d600b0072c38557b1bmr228147qkp.235.1675369170393;
Thu, 02 Feb 2023 12:19:30 -0800 (PST)
X-Received: by 2002:a05:6870:c082:b0:15f:db26:fd99 with SMTP id
c2-20020a056870c08200b0015fdb26fd99mr535242oad.71.1675369170084; Thu, 02 Feb
2023 12:19:30 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 2 Feb 2023 12:19:29 -0800 (PST)
In-Reply-To: <k42ibdFa6q8U1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.53.5; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.53.5
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com> <k42ibdFa6q8U1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Thu, 02 Feb 2023 20:19:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2159
 by: FortranFan - Thu, 2 Feb 2023 20:19 UTC

On Thursday, February 2, 2023 at 2:48:01 PM UTC-5, Steve Lionel wrote:

> ..
> (The recursive I/O error is just incorrect.) ..

@Steve Lionel,

Not sure what you mean by, "The recursive I/O error is just incorrect."

Arguably one can view the code in the original post to attempt I/O data transfer in a similar manner as the following silly snippet:

print *, f(1)
contains
integer function f(a)
integer, intent(in) :: a
f = a + 1
print *, f
end function
end

But this silly code does NOT conform, if I recall correctly the last I checked the standard. However the processors are not required to detect and report this and at run-time, some tend to *freeze up* during the data transfer to the same IO unit. Thus the processor in question might be trying to help prevent such a problematic scenario and report out the nonconforming behavior to the programmer?

Re: Does any compiler implement finalization correctly for function results?

<k42ksdFaj8dU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: steve@seesignature.invalid (Steve Lionel)
Newsgroups: comp.lang.fortran
Subject: Re: Does any compiler implement finalization correctly for function
results?
Date: Thu, 2 Feb 2023 15:31:09 -0500
Lines: 16
Message-ID: <k42ksdFaj8dU1@mid.individual.net>
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<k42ibdFa6q8U1@mid.individual.net>
<e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net A2Lg6usqvdLvKjapPwvzwQO/LRyaPAhtW8rz2eQEXOIeaPw77u
Cancel-Lock: sha1:bE6H2cwecrgE0t3HdF7lffsECeU=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:110.0) Gecko/20100101
Thunderbird/110.0
Content-Language: en-US
In-Reply-To: <e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
 by: Steve Lionel - Thu, 2 Feb 2023 20:31 UTC

On 2/2/2023 3:19 PM, FortranFan wrote:
> Not sure what you mean by, "The recursive I/O error is just incorrect."

There is no recursive I/O here. The function writes to unit *, the main
program does an internal write. These are allowed to coexist (12.12p2)

--
Steve Lionel
ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
Retired Intel Fortran developer/support
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
LinkedIn: https://www.linkedin.com/in/stevelionel
Blog: https://stevelionel.com/drfortran
WG5: https://wg5-fortran.org

Re: Does any compiler implement finalization correctly for function results?

<1e951bca-15d0-415e-a44a-439ae8e9aa4en@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ae9:c018:0:b0:705:b29d:c666 with SMTP id u24-20020ae9c018000000b00705b29dc666mr666839qkk.462.1675371491276;
Thu, 02 Feb 2023 12:58:11 -0800 (PST)
X-Received: by 2002:a05:6871:1c7:b0:163:8cc6:870 with SMTP id
q7-20020a05687101c700b001638cc60870mr543165oad.143.1675371490969; Thu, 02 Feb
2023 12:58:10 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 2 Feb 2023 12:58:10 -0800 (PST)
In-Reply-To: <k42ksdFaj8dU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.61.29; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.61.29
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<k42ibdFa6q8U1@mid.individual.net> <e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
<k42ksdFaj8dU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1e951bca-15d0-415e-a44a-439ae8e9aa4en@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Thu, 02 Feb 2023 20:58:11 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1649
 by: FortranFan - Thu, 2 Feb 2023 20:58 UTC

On Thursday, February 2, 2023 at 3:31:16 PM UTC-5, Steve Lionel wrote:

>..
> There is no recursive I/O here. The function writes to unit *, the main
> program does an internal write. These are allowed to coexist (12.12p2) ..

My bad, you're right - I misread the code in the original post and *overlooked* the fact the main program first has write to an internal file.

Re: Does any compiler implement finalization correctly for function results?

<79d8e16b-1153-4017-9403-8bf137d26cf3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:2687:b0:71a:23b2:e2 with SMTP id c7-20020a05620a268700b0071a23b200e2mr512610qkp.139.1675372284490;
Thu, 02 Feb 2023 13:11:24 -0800 (PST)
X-Received: by 2002:a05:6870:138f:b0:163:4123:b832 with SMTP id
15-20020a056870138f00b001634123b832mr413280oas.216.1675372284200; Thu, 02 Feb
2023 13:11:24 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 2 Feb 2023 13:11:23 -0800 (PST)
In-Reply-To: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.61.29; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.61.29
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <79d8e16b-1153-4017-9403-8bf137d26cf3n@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Thu, 02 Feb 2023 21:11:24 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2227
 by: FortranFan - Thu, 2 Feb 2023 21:11 UTC

On Thursday, February 2, 2023 at 2:16:20 PM UTC-5, pkla...@nvidia.com wrote:

> .. So one would expect five lines "final: 1", "final: 2", &c. to "final: 5", followed by "wrote: 1 2 3 4 5". ..

For whatever it's worth, my take is the code in the original post does not conform in that component 'n' of the derived type 't' gets referenced before it's defined.

This has to do with first line in paragraph 1 of section 7.5.6.3 When finalization occurs should also apply, "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."

So the local object 'func` corresponding to the function result is "not an unallocated allocatable variable" should be "finalized after evaluation of expr and before the definition of the variable." And when that happens, the impure finalizer ends referencing component 'n' before it's defined.

Re: Does any compiler implement finalization correctly for function results?

<32797cbf-2418-427e-8252-4a27db7bc1cfn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:7f83:0:b0:3b8:6db0:7562 with SMTP id z3-20020ac87f83000000b003b86db07562mr726141qtj.76.1675372765686;
Thu, 02 Feb 2023 13:19:25 -0800 (PST)
X-Received: by 2002:a05:6870:14cf:b0:163:bd7f:bc7a with SMTP id
l15-20020a05687014cf00b00163bd7fbc7amr465201oab.175.1675372765356; Thu, 02
Feb 2023 13:19:25 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 2 Feb 2023 13:19:25 -0800 (PST)
In-Reply-To: <79d8e16b-1153-4017-9403-8bf137d26cf3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.61.0; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.61.0
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com> <79d8e16b-1153-4017-9403-8bf137d26cf3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <32797cbf-2418-427e-8252-4a27db7bc1cfn@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Thu, 02 Feb 2023 21:19:25 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2952
 by: FortranFan - Thu, 2 Feb 2023 21:19 UTC

On Thursday, February 2, 2023 at 4:11:26 PM UTC-5, FortranFan wrote:

> ..
> For whatever it's worth, my take is the code in the original post does not conform in that component 'n' of the derived type 't' gets referenced before it's defined. ..

Perhaps the following code can be considered for the analysis in order to focus on finalization and move past the nonconforming aspects and any IO bugs/misunderstanding:

module m
type t
integer :: n = -1
character(len=8) :: s = "default"
contains
final :: final
end type
contains
type(t) function func(n)
integer, intent(in) :: n
func%s = "lvar-fun"
func = t(n,s="rhs-tmp")
end function
impure elemental subroutine final(x)
type(t), intent(in out) :: x
print *, 'final: ', trim(x%s), "; n = ", x%n
end subroutine
end module

program test
use m
type(t), allocatable :: a(:)
a = [( func(j), j=1,5 )]
print *, 'wrote: ', (a(j)%n, j=1,size(a))
end

For whatever it's worth, I believe the conforming response by the processor shall be as follows:
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: rhs-tmp; n = 1
final: rhs-tmp; n = 2
final: rhs-tmp; n = 3
final: rhs-tmp; n = 4
final: rhs-tmp; n = 5
wrote: 1 2 3 4 5

However, I find the following:

Compiler A:
wrote: 1 2 3 4 5

Compiler B or C (I'm guessing, one of these)
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: lvar-fun; n = -1
final: rhs-tmp; n = 5
wrote: 1 2 3 4 5

Re: Does any compiler implement finalization correctly for function results?

<48cbaf54-1a49-4745-b7c2-cf5e37a2e1ccn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:e83:b0:537:c03e:fdaa with SMTP id hf3-20020a0562140e8300b00537c03efdaamr625426qvb.24.1675383166311;
Thu, 02 Feb 2023 16:12:46 -0800 (PST)
X-Received: by 2002:a05:6870:4292:b0:163:6f84:4659 with SMTP id
y18-20020a056870429200b001636f844659mr462567oah.231.1675383165921; Thu, 02
Feb 2023 16:12:45 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Thu, 2 Feb 2023 16:12:45 -0800 (PST)
In-Reply-To: <k42ksdFaj8dU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:60ef:fb43:decd:eec6;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:60ef:fb43:decd:eec6
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<k42ibdFa6q8U1@mid.individual.net> <e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
<k42ksdFaj8dU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <48cbaf54-1a49-4745-b7c2-cf5e37a2e1ccn@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: gah4@u.washington.edu (gah4)
Injection-Date: Fri, 03 Feb 2023 00:12:46 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1820
 by: gah4 - Fri, 3 Feb 2023 00:12 UTC

On Thursday, February 2, 2023 at 12:31:16 PM UTC-8, Steve Lionel wrote:
> On 2/2/2023 3:19 PM, FortranFan wrote:
> > Not sure what you mean by, "The recursive I/O error is just incorrect."
> There is no recursive I/O here. The function writes to unit *, the main
> program does an internal write. These are allowed to coexist (12.12p2)
They weren't always allowed to coexist.

It would be strange to implement finalization in a compiler that old, though.

Now, when did it change?

Re: Does any compiler implement finalization correctly for function results?

<9cbacf62-2f0b-429a-9c25-0e7d105218c6n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:6226:b0:72b:74d3:6497 with SMTP id ou38-20020a05620a622600b0072b74d36497mr444506qkn.436.1675439583278;
Fri, 03 Feb 2023 07:53:03 -0800 (PST)
X-Received: by 2002:a05:6870:f58f:b0:163:b85e:f1ca with SMTP id
eh15-20020a056870f58f00b00163b85ef1camr786667oab.262.1675439582953; Fri, 03
Feb 2023 07:53:02 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 3 Feb 2023 07:53:02 -0800 (PST)
In-Reply-To: <32797cbf-2418-427e-8252-4a27db7bc1cfn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:9e8:79cb:6a00:52e0:8df1:c24f:3ae4;
posting-account=Uz-_NAoAAAAY9kqilxIoZYvEBeHOB4QA
NNTP-Posting-Host: 2001:9e8:79cb:6a00:52e0:8df1:c24f:3ae4
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<79d8e16b-1153-4017-9403-8bf137d26cf3n@googlegroups.com> <32797cbf-2418-427e-8252-4a27db7bc1cfn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9cbacf62-2f0b-429a-9c25-0e7d105218c6n@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: baradi09@gmail.com (bara...@gmail.com)
Injection-Date: Fri, 03 Feb 2023 15:53:03 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2476
 by: bara...@gmail.com - Fri, 3 Feb 2023 15:53 UTC

> For whatever it's worth, I believe the conforming response by the processor shall be as follows:
> final: lvar-fun; n = -1
> final: lvar-fun; n = -1
> final: lvar-fun; n = -1
> final: lvar-fun; n = -1
> final: lvar-fun; n = -1
> final: rhs-tmp; n = 1
> final: rhs-tmp; n = 2
> final: rhs-tmp; n = 3
> final: rhs-tmp; n = 4
> final: rhs-tmp; n = 5
> wrote: 1 2 3 4 5

If it is of interest, the NAG compiler (7.1, build 7118) produces exactly this result.

However, I do not understand, why this result is the standard conforming one. Looking at the line

func = t(n,s="rhs-tmp")

I would have naively thought, it

1: creates t()
2: finalizes func and creates a new instance (as it were a case for an intent(out) dummy argument)
3: assigns t to func (by copying its content)
4: finalizes t

I understand, that it makes much more sense to use "move semantics" instead of the "copy semantics" I've described above, but I could not find the spot, where this is explicitely allowed/treated by the standard.

Re: Does any compiler implement finalization correctly for function results?

<k44qsbFkrelU1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: steve@seesignature.invalid (Steve Lionel)
Newsgroups: comp.lang.fortran
Subject: Re: Does any compiler implement finalization correctly for function
results?
Date: Fri, 3 Feb 2023 11:25:48 -0500
Lines: 55
Message-ID: <k44qsbFkrelU1@mid.individual.net>
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<k42ibdFa6q8U1@mid.individual.net>
<e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
<k42ksdFaj8dU1@mid.individual.net>
<48cbaf54-1a49-4745-b7c2-cf5e37a2e1ccn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net NGozYpdu0rB0FkP4/guV4gqVSesK6L3bP6ZViRz46VLjjQAWWr
Cancel-Lock: sha1:AlwyQX8o7Y5QdXPttUXEBvo9EwY=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:110.0) Gecko/20100101
Thunderbird/110.0
Content-Language: en-US
In-Reply-To: <48cbaf54-1a49-4745-b7c2-cf5e37a2e1ccn@googlegroups.com>
 by: Steve Lionel - Fri, 3 Feb 2023 16:25 UTC

On 2/2/2023 7:12 PM, gah4 wrote:
> On Thursday, February 2, 2023 at 12:31:16 PM UTC-8, Steve Lionel wrote:
>> On 2/2/2023 3:19 PM, FortranFan wrote:
>>> Not sure what you mean by, "The recursive I/O error is just incorrect."
>> There is no recursive I/O here. The function writes to unit *, the main
>> program does an internal write. These are allowed to coexist (12.12p2)
>
> They weren't always allowed to coexist.
>
> It would be strange to implement finalization in a compiler that old, though.
>
> Now, when did it change?

You made me look!

F2003 was the first to have any wording on this - I can't find relevant
wording in prior standards:

"An input/output statement that is executed while another input/output
statement is being executed is called a recursive input/output statement.

A recursive input/output statement shall not identify an external unit
except that a child data transfer statement may identify its parent data
transfer statement external unit." 9.11 p2-3

A simplistic reading of this is that co-executing I/O statements, where
one identifies an external unit and one an internal unit, are allowed. A
more careful reading suggests order is important, and that if the
internal unit statement is started first, you're not allowed to start a
recursive operation on an external unit (which is what the test program
does.) I don't think this is what was intended.

F2008 revised this text, eliminating the ordering implication:

"An input/output statement that is executed while another input/output
statement is being executed is a recursive input/output statement. A
recursive input/output statement shall not identify an external unit
that is identified by another input/output statement being executed
except that a child data transfer statement may identify its parent data
transfer statement external unit." 9.12p2

So as of F2008, recursive data transfer statements were allowed as long
as they didn't both identify the same external unit.

F2018 did not change the wording here.
--
Steve Lionel
ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
Retired Intel Fortran developer/support
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
LinkedIn: https://www.linkedin.com/in/stevelionel
Blog: https://stevelionel.com/drfortran
WG5: https://wg5-fortran.org

Re: Does any compiler implement finalization correctly for function results?

<244bd274-ec5a-4934-a7b9-f577e5ea41aen@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:5e0b:0:b0:3ba:11a1:e88c with SMTP id h11-20020ac85e0b000000b003ba11a1e88cmr67580qtx.147.1675442040361;
Fri, 03 Feb 2023 08:34:00 -0800 (PST)
X-Received: by 2002:a05:6870:f58f:b0:163:b85e:f1ca with SMTP id
eh15-20020a056870f58f00b00163b85ef1camr801369oab.262.1675442039971; Fri, 03
Feb 2023 08:33:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 3 Feb 2023 08:33:59 -0800 (PST)
In-Reply-To: <9cbacf62-2f0b-429a-9c25-0e7d105218c6n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=165.225.39.98; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 165.225.39.98
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<79d8e16b-1153-4017-9403-8bf137d26cf3n@googlegroups.com> <32797cbf-2418-427e-8252-4a27db7bc1cfn@googlegroups.com>
<9cbacf62-2f0b-429a-9c25-0e7d105218c6n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <244bd274-ec5a-4934-a7b9-f577e5ea41aen@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Fri, 03 Feb 2023 16:34:00 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2095
 by: FortranFan - Fri, 3 Feb 2023 16:33 UTC

On Friday, February 3, 2023 at 10:53:04 AM UTC-5, bara...@gmail.com wrote:

> ..
> 4: finalizes t
>
> I understand, that it makes much more sense to use "move semantics" instead of the "copy semantics" I've described above, but I could not find the spot, where this is explicitely allowed/treated by the standard.

Under section 7.5.6.3 When finalization occurs in the standard, I don't recall anything being stipulated for finalization of "whatever" is done by a structure constructor which is what is 't' in your blurb above.

Thus I don't believe a conforming processor shall "finalize t". Hence my comment on what the conforming response shall be.

Re: Does any compiler implement finalization correctly for function results?

<ffadc915-09ef-481a-9cc7-3b47ab81e009n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:29e8:b0:556:57ff:64d1 with SMTP id jv8-20020a05621429e800b0055657ff64d1mr682246qvb.8.1675463247637;
Fri, 03 Feb 2023 14:27:27 -0800 (PST)
X-Received: by 2002:a05:6808:c6:b0:378:4bd3:b102 with SMTP id
t6-20020a05680800c600b003784bd3b102mr459296oic.299.1675463247261; Fri, 03 Feb
2023 14:27:27 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Fri, 3 Feb 2023 14:27:26 -0800 (PST)
In-Reply-To: <k44qsbFkrelU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=115.189.83.97; posting-account=KnYfEgoAAAD1tUJTvdAUZ3XojNa5tezZ
NNTP-Posting-Host: 115.189.83.97
References: <9b92f033-409c-44ce-ae73-828c3b872f15n@googlegroups.com>
<k42ibdFa6q8U1@mid.individual.net> <e6f090f2-2faa-4951-afff-673f93d77c5cn@googlegroups.com>
<k42ksdFaj8dU1@mid.individual.net> <48cbaf54-1a49-4745-b7c2-cf5e37a2e1ccn@googlegroups.com>
<k44qsbFkrelU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ffadc915-09ef-481a-9cc7-3b47ab81e009n@googlegroups.com>
Subject: Re: Does any compiler implement finalization correctly for function results?
From: harperjf2@gmail.com (jfh)
Injection-Date: Fri, 03 Feb 2023 22:27:27 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 4228
 by: jfh - Fri, 3 Feb 2023 22:27 UTC

On Saturday, February 4, 2023 at 5:25:51 AM UTC+13, Steve Lionel wrote:
> On 2/2/2023 7:12 PM, gah4 wrote:
> > On Thursday, February 2, 2023 at 12:31:16 PM UTC-8, Steve Lionel wrote:
> >> On 2/2/2023 3:19 PM, FortranFan wrote:
> >>> Not sure what you mean by, "The recursive I/O error is just incorrect."
> >> There is no recursive I/O here. The function writes to unit *, the main
> >> program does an internal write. These are allowed to coexist (12.12p2)
> >
> > They weren't always allowed to coexist.
> >
> > It would be strange to implement finalization in a compiler that old, though.
> >
> > Now, when did it change?
> You made me look!
>
> F2003 was the first to have any wording on this - I can't find relevant
> wording in prior standards:
>
> "An input/output statement that is executed while another input/output
> statement is being executed is called a recursive input/output statement.
>
> A recursive input/output statement shall not identify an external unit
> except that a child data transfer statement may identify its parent data
> transfer statement external unit." 9.11 p2-3
>
> A simplistic reading of this is that co-executing I/O statements, where
> one identifies an external unit and one an internal unit, are allowed. A
> more careful reading suggests order is important, and that if the
> internal unit statement is started first, you're not allowed to start a
> recursive operation on an external unit (which is what the test program
> does.) I don't think this is what was intended.
>
> F2008 revised this text, eliminating the ordering implication:
>
> "An input/output statement that is executed while another input/output
> statement is being executed is a recursive input/output statement. A
> recursive input/output statement shall not identify an external unit
> that is identified by another input/output statement being executed
> except that a child data transfer statement may identify its parent data
> transfer statement external unit." 9.12p2
>
> So as of F2008, recursive data transfer statements were allowed as long
> as they didn't both identify the same external unit.
>
> F2018 did not change the wording here.
> --
> Steve Lionel
> ISO/IEC JTC1/SC22/WG5 (Fortran) Convenor
> Retired Intel Fortran developer/support
> Email: firstname at firstnamelastname dot com
> Twitter: @DoctorFortran
> LinkedIn: https://www.linkedin.com/in/stevelionel
> Blog: https://stevelionel.com/drfortran
> WG5: https://wg5-fortran.org

That implies that Steve's earlier posting saying "There is no recursive I/O here. The function writes to unit *, the main
program does an internal write. These are allowed to coexist (12.12p2)" was not quite right. The I/O was recursive according to F2008 but it was allowed by that standard.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor