public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Steve Kargl <sgk@troutmask.apl.washington.edu>
To: Harald Anlauf via Fortran <fortran@gcc.gnu.org>
Subject: Re: typespec in forall and implied-do
Date: Sun, 20 Nov 2022 15:31:04 -0800	[thread overview]
Message-ID: <Y3q4uPLdtfYOKAoN@troutmask.apl.washington.edu> (raw)
In-Reply-To: <trinity-592b5772-1d2d-4e13-8f57-8259676682c4-1668979720632@3c-app-gmx-bs70>

On Sun, Nov 20, 2022 at 10:28:40PM +0100, Harald Anlauf via Fortran wrote:
> Steve,
> 
> for unknown reasons I cannot reply to your mail on gmane,
> so trying directly via mailing list.
> 
> I tried your patch, and it works on the supplied testcases.
> 
> However, there is a scoping issue for the declaration of the
> index variable, as can be seen by the following variation:
> 
> program foo
>   use iso_fortran_env, only : k => real_kinds
>   implicit none
>   integer, parameter :: n = size(k)
>   integer(8) :: i
> !!$  integer, parameter :: &
> !!$       &  p(n) = [(precision(real(1.,k(i))), integer :: i = 1, n)]
>   integer, parameter :: &
>        &  q(n) = [(kind(i), integer(2) :: i = 1, n)]
>   integer, parameter :: &
>        &  r(n) = [(storage_size(i), integer(1) :: i = 1, n)]
> !!$  print *, p
>   print *, q
>   print *, r
> end program foo
> 
> After your patch, gfortran prints:
> 
>            8           8           8           8
>           64          64          64          64
> 
> This suggests that the integer kind is taken from the host decl,
> which is kind=8, and not the local one (2 or 1).
> 
> Crayftn (which chokes on your original testcase):
> 
>  3*2
>  3*8
> 
> This is what I expect.
> 
> Intel doesn't accept storage_size() here, which is a bug.
> Commenting the uses of array r, I then get:
> 
>            2           2           2
> 
> At least this agrees with Cray.
> 
> Can you have another look at this?
> 

Unfortunately, gfortran does not define a namespace for an implied-do
index and uses a kludge by adding the attr.implied_index attribute to
the symbol.  Unfortunately**2, gfortran uses gfc_match_iterator for 
all places that 'i = start, stop [,step]' and there is no way to know
if what is being parsed.  With the introduction of an optional typespec,
there is no easy way to deal with it in a clean way.  Things get messy
quickly when trying to deal with implicit typing and explicitly typed
symbols.  So, if the implied-do index has previously been typed such as

    integer(8) i
    print *, (i, integer(2) i=1, 3)

the integer(2) is ignored.  That's this part of the gfc_match_iterator
diff

+  if (seen_ts && var->ts.type == BT_UNKNOWN)
+    {
+      var->ts.type = ts.type;
+      var->ts.kind = ts.kind;
+      var->symtree->n.sym->ts.type = ts.type;
+      var->symtree->n.sym->ts.kind = ts.kind;
+    }

Perhaps, a better way would be to simply create a shadow symbol
if a typespec appears in an iterator 

    print *, (i, integer i=1,3)

would become 

    print *, (_i, integer _i=1,3)

The issue is then that implied-do object list needs to be walked
and all occurrence of i must be replaced with _i.

-- 
Steve

  reply	other threads:[~2022-11-20 23:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-20 21:28 Harald Anlauf
2022-11-20 23:31 ` Steve Kargl [this message]
     [not found]   ` <d2efcc09-f5be-904e-fb70-f75fdabbee1f@orange.fr>
     [not found]     ` <Y3vHlojilLVU8qC2@troutmask.apl.washington.edu>
2022-11-27 19:17       ` Mikael Morin
2022-11-27 19:33         ` Mikael Morin
2022-11-20 23:33 ` Steve Kargl
2022-11-22 21:15 ` Harald Anlauf
2022-11-22 21:59   ` Steve Kargl
  -- strict thread matches above, loose matches on Subject: below --
2022-11-16  1:13 Steve Kargl
2022-11-16  2:31 ` Steve Kargl
2022-11-16 20:24   ` Steve Kargl
2022-11-16 18:08 ` Steve Kargl
2022-11-16 18:20 ` Steve Kargl
2022-11-16 21:30 ` Steve Kargl
2022-11-17  0:32   ` Steve Kargl
2022-11-17  0:47     ` Steve Kargl
2022-11-17  4:15       ` Steve Kargl
2022-11-17 18:48 ` Steve Kargl

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=Y3q4uPLdtfYOKAoN@troutmask.apl.washington.edu \
    --to=sgk@troutmask.apl.washington.edu \
    --cc=fortran@gcc.gnu.org \
    /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).