public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jerry D <jvdelisle2@gmail.com>
To: Harald Anlauf <anlauf@gmx.de>,
	Paul Richard Thomas <paul.richard.thomas@gmail.com>
Cc: Alessandro Fanfarillo <alessandro.fanfarillo@gmail.com>,
	gcc-patches <gcc-patches@gcc.gnu.org>,
	Andrew Benson <abenson@carnegiescience.edu>,
	"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR37336 (Finalization) - [F03] Finish derived-type finalization
Date: Thu, 10 Feb 2022 18:15:49 -0800	[thread overview]
Message-ID: <2f8d72bc-01b0-f8f7-cbd2-d931c5985d8d@gmail.com> (raw)
In-Reply-To: <3cbaf568-84ac-8498-558f-9560fe395d66@gmx.de>

For what it is worth.

On 2/10/22 11:49 AM, Harald Anlauf via Fortran wrote:
> Hi Paul,
>
> Am 10.02.22 um 13:25 schrieb Paul Richard Thomas via Fortran:
>> Conclusions on ifort:
>> (i) The agreement between gfortran, with the patch applied, and ifort is
>> strongest of all the other brands;
>> (ii) The disagreements are all down to the treatment of the parent
>> component of arrays of extended types: gfortran finalizes the parent
>> component as an array, whereas ifort does a scalarization. I have a 
>> patch
>> ready to do likewise.
>>
>> Overall conclusions:
>> (i) Sort out whether or not derived type constructors are considered 
>> to be
>> functions;
>> (ii) Come to a conclusion about scalarization of parent components of
>> extended type arrays;
>> (iii) Check and, if necessary, correct the ordering of finalization in
>> intrinsic assignment of class arrays.
>> (iv) Finalization is difficult to graft on to existing pre-F2003 
>> compilers,
>> as witnessed by the range of implementations.
>>
>> I would be really grateful for thoughts on (i) and (ii). My gut 
>> feeling, as
>> remarked in the submission, is that we should aim to be as close as
>> possible, if not identical to, ifort. Happily, that is already the case.
>
> I am really sorry to be such a bother, but before we think we should
> do the same as Intel, we need to understand what Intel does and whether
> that is actually correct.  Or not inconsistent with the standard.
> And I would really like to understand even the most simple, stupid case.
>
> I did reduce testcase finalize_38.f90 to an almost bare minimum,
> see attached, and changed the main to
>
>   type(simple), parameter   :: ThyType   = simple(21)
>   type(simple)              :: ThyType2  = simple(22)
>   type(simple), allocatable :: MyType, MyType2
>
>   print *, "At start of program: ", final_count
>
>   MyType = ThyType
>   print *, "After 1st allocation:", final_count
>
>   MyType2 = ThyType2
>   print *, "After 2nd allocation:", final_count
>
> Note that "ThyType" is now a parameter.
>
----- snip ----
Ignore whether Thytype is  a Parameter.  Regardless Mytype and Mytype2 
are allocated upon the assignment.  Now if these are never used 
anywhere, it seems to me the deallocation can be done by the compiler 
anywhere after the last time it is used.  So it can be either after the 
PRINT statement before the end if the program or right after the 
assignment before your PRINT statements that examine the value of 
final_count.  I think the result is arbitrary/undefined in your reduced 
test case

I do not have the Intel compiler yet, so I was going to suggest see what 
it does if your test program prints something from within MyType and 
MyType2 after all your current print statements at the end.  Try this 
variation of the main program.

program test_final
   use testmode
   implicit none
   type(simple), parameter   :: ThyType   = simple(21)
   type(simple)              :: ThyType2  = simple(22)
   type(simple), allocatable :: MyType, MyType2

   print *, "At start of program: ", final_count

   MyType = ThyType
   print *, "After 1st allocation:", final_count

   MyType2 = ThyType2
   print *, "After 2nd allocation:", final_count

   print  *, MyType%ind, MyType2%ind, final_count
   deallocate(Mytype)
   print  *, MyType%ind, MyType2%ind, final_count
   deallocate(Mytype2)
   print  *, MyType%ind, MyType2%ind, final_count

end program test_final

I get with trunk:

$ ./a.out
  At start of program:            0
  After 1st allocation:            0
  After 2nd allocation:           0
           21         22           0
            0          22           1
            0          0             2

Which makes sense to me.

Regards,

Jerry

  parent reply	other threads:[~2022-02-11  2:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 17:14 Paul Richard Thomas
2022-02-07 21:09 ` Harald Anlauf
2022-02-07 21:09   ` Harald Anlauf
2022-02-08 11:22   ` Paul Richard Thomas
2022-02-08 18:29     ` Harald Anlauf
2022-02-08 18:29       ` Harald Anlauf
2022-02-09  2:35       ` Jerry D
2022-02-10 12:25       ` Paul Richard Thomas
2022-02-10 19:49         ` Harald Anlauf
2022-02-10 19:49           ` Harald Anlauf
2022-02-11  2:15           ` Jerry D [this message]
2022-02-11  9:08           ` Paul Richard Thomas
2022-02-11 21:08             ` Harald Anlauf
2022-02-11 21:08               ` Harald Anlauf
2022-02-11 21:59               ` Paul Richard Thomas
2022-02-16 18:49                 ` Paul Richard Thomas
2022-02-17 20:55                   ` Harald Anlauf
2022-02-17 20:55                     ` Harald Anlauf
2022-02-17 21:23                   ` Thomas Koenig
2022-02-18 18:06                     ` Paul Richard Thomas
2023-01-02 13:15                       ` Paul Richard Thomas
     [not found]                         ` <trinity-a4069639-4079-4f60-b928-1fec82384b1e-1672953005015@3c-app-gmx-bap48>
2023-01-05 21:14                           ` Fw: " Harald Anlauf
2023-01-06  3:08                             ` Jerry D
2023-01-06  8:33                               ` Harald Anlauf
2023-01-07 10:57                                 ` Paul Richard Thomas
2023-01-07 15:28                                   ` Thomas Koenig
2023-01-07 18:35                                     ` Paul Richard Thomas
2023-01-08 12:03                                       ` Thomas Koenig
2023-01-08 13:42                                         ` Paul Richard Thomas
2023-01-09 20:42                                   ` Aw: " Harald Anlauf
2023-01-11 20:56                                     ` Harald Anlauf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2f8d72bc-01b0-f8f7-cbd2-d931c5985d8d@gmail.com \
    --to=jvdelisle2@gmail.com \
    --cc=abenson@carnegiescience.edu \
    --cc=alessandro.fanfarillo@gmail.com \
    --cc=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=paul.richard.thomas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).