Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

PLUG IT IN!!!


devel / comp.lang.fortran / Re: Mixing functions and subroutines in a combined generic interface

SubjectAuthor
* Mixing functions and subroutines in a combined generic interfacePeter Klausler US
+* Re: Mixing functions and subroutines in a combined generic interfaceArjen Markus
|`* Re: Mixing functions and subroutines in a combined generic interfaceThomas Koenig
| `* Re: Mixing functions and subroutines in a combined generic interfacePeter Klausler US
|  `* Re: Mixing functions and subroutines in a combined generic interfaceThomas Koenig
|   `* Re: Mixing functions and subroutines in a combined generic interfacePeter Klausler US
|    +- Re: Mixing functions and subroutines in a combined generic interfacegah4
|    +* Re: Mixing functions and subroutines in a combined generic interfaceThomas Koenig
|    |`- Re: Mixing functions and subroutines in a combined generic interfacePeter Klausler US
|    `- Re: Mixing functions and subroutines in a combined generic interfaceFortranFan
+* Re: Mixing functions and subroutines in a combined generic interfaceFortranFan
|`- Re: Mixing functions and subroutines in a combined generic interfaceFortranFan
`- Re: Mixing functions and subroutines in a combined generic interfacegah4

1
Mixing functions and subroutines in a combined generic interface

<fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:62b:b0:4c5:5bb7:f0ad with SMTP id a11-20020a056214062b00b004c55bb7f0admr14600916qvx.36.1667927791898;
Tue, 08 Nov 2022 09:16:31 -0800 (PST)
X-Received: by 2002:ac8:4256:0:b0:3a4:fd1c:a5ca with SMTP id
r22-20020ac84256000000b003a4fd1ca5camr44893313qtm.77.1667927791692; Tue, 08
Nov 2022 09:16:31 -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: Tue, 8 Nov 2022 09:16:31 -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: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
Subject: Mixing functions and subroutines in a combined generic interface
From: pklausler@nvidia.com (Peter Klausler US)
Injection-Date: Tue, 08 Nov 2022 17:16:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2891
 by: Peter Klausler US - Tue, 8 Nov 2022 17:16 UTC

Generic interfaces are constrained in some specific circumstances to contain all functions or all subroutines, but in general they can contain both. (There's language in the standard that pertains to the visibility of intrinsic procedures of the same name that depends on whether a generic interface contains a mixture or not, so it must be possible.)

While it's probably not the best practice to explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together. For example:

> module m1
> interface generic
> module procedure func
> end interface
> contains
> integer function func(n)
> integer, intent(in) :: n
> func = n
> end function
> end module
>
> module m2
> interface generic
> module procedure subr
> end interface
> contains
> subroutine subr
> print *, 'ok'
> end subroutine
> end module
>
> program main
> use m1
> use m2
> call generic
> end

Some compilers can handle this example, some can't, and complain that a mixed generic interface is not allowed. I think that those compilers are incorrect. If you disagree, please let me know why.

Amusingly, if you delete the function's dummy argument from that example, *no* compiler can deal with it, since they apparently don't take the function/subroutine distinction into account when comparing specific procedures for distinguishability, only their dummy arguments. So I think I'm going to get to add another item to f18's documentation section on features that it supports that are standard but might as well not be.

Re: Mixing functions and subroutines in a combined generic interface

<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ad4:5c8c:0:b0:4b9:fe5:e7a8 with SMTP id o12-20020ad45c8c000000b004b90fe5e7a8mr51399506qvh.99.1667939454553;
Tue, 08 Nov 2022 12:30:54 -0800 (PST)
X-Received: by 2002:ac8:5f0b:0:b0:3a5:848e:d161 with SMTP id
x11-20020ac85f0b000000b003a5848ed161mr10820071qta.196.1667939454388; Tue, 08
Nov 2022 12:30:54 -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: Tue, 8 Nov 2022 12:30:54 -0800 (PST)
In-Reply-To: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=62.194.189.128; posting-account=A91wAAoAAADgBUxBX6QqsrSD26GLhVp8
NNTP-Posting-Host: 62.194.189.128
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: arjen.markus895@gmail.com (Arjen Markus)
Injection-Date: Tue, 08 Nov 2022 20:30:54 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3687
 by: Arjen Markus - Tue, 8 Nov 2022 20:30 UTC

On Tuesday, November 8, 2022 at 6:16:33 PM UTC+1, Peter Klausler US wrote:
> Generic interfaces are constrained in some specific circumstances to contain all functions or all subroutines, but in general they can contain both. (There's language in the standard that pertains to the visibility of intrinsic procedures of the same name that depends on whether a generic interface contains a mixture or not, so it must be possible.)
>
> While it's probably not the best practice to explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together. For example:
>
> > module m1
> > interface generic
> > module procedure func
> > end interface
> > contains
> > integer function func(n)
> > integer, intent(in) :: n
> > func = n
> > end function
> > end module
> >
> > module m2
> > interface generic
> > module procedure subr
> > end interface
> > contains
> > subroutine subr
> > print *, 'ok'
> > end subroutine
> > end module
> >
> > program main
> > use m1
> > use m2
> > call generic
> > end
>
> Some compilers can handle this example, some can't, and complain that a mixed generic interface is not allowed. I think that those compilers are incorrect. If you disagree, please let me know why.
>
> Amusingly, if you delete the function's dummy argument from that example, *no* compiler can deal with it, since they apparently don't take the function/subroutine distinction into account when comparing specific procedures for distinguishability, only their dummy arguments. So I think I'm going to get to add another item to f18's documentation section on features that it supports that are standard but might as well not be.

If you take away the argument from the function, then its interface is not distinguishable from the subroutine according to ifort. With the argument, it emits a warning, but builds the program.
gfortran does not accept it on the grounds of it being a mixture, with or without the argument n.

I do not know which one is right, but the mixups (pun not entirely intended) you sketch are unfortunate and possible. Renaming would solve it, but that is besides the point.

Regards,

Arjen

Re: Mixing functions and subroutines in a combined generic interface

<tkjr7g$344at$2@newsreader4.netcologne.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd6-161-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.lang.fortran
Subject: Re: Mixing functions and subroutines in a combined generic interface
Date: Thu, 10 Nov 2022 21:42:08 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <tkjr7g$344at$2@newsreader4.netcologne.de>
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com>
Injection-Date: Thu, 10 Nov 2022 21:42:08 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd6-161-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd6:161:0:7285:c2ff:fe6c:992d";
logging-data="3281245"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Thu, 10 Nov 2022 21:42 UTC

Arjen Markus <arjen.markus895@gmail.com> schrieb:
> On Tuesday, November 8, 2022 at 6:16:33 PM UTC+1, Peter Klausler US wrote:
>> Generic interfaces are constrained in some specific circumstances to contain all functions or all subroutines, but in general they can contain both. (There's language in the standard that pertains to the visibility of intrinsic procedures of the same name that depends on whether a generic interface contains a mixture or not, so it must be possible.)
>>
>> While it's probably not the best practice to explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together. For example:
>>
>> > module m1
>> > interface generic
>> > module procedure func
>> > end interface
>> > contains
>> > integer function func(n)
>> > integer, intent(in) :: n
>> > func = n
>> > end function
>> > end module
>> >
>> > module m2
>> > interface generic
>> > module procedure subr
>> > end interface
>> > contains
>> > subroutine subr
>> > print *, 'ok'
>> > end subroutine
>> > end module
>> >
>> > program main
>> > use m1
>> > use m2
>> > call generic
>> > end
>>
>> Some compilers can handle this example, some can't, and complain that a mixed generic interface is not allowed. I think that those compilers are incorrect. If you disagree, please let me know why.
>>
>> Amusingly, if you delete the function's dummy argument from that example, *no* compiler can deal with it, since they apparently don't take the function/subroutine distinction into account when comparing specific procedures for distinguishability, only their dummy arguments. So I think I'm going to get to add another item to f18's documentation section on features that it supports that are standard but might as well not be.
>
> If you take away the argument from the function, then its interface is not distinguishable from the subroutine according to ifort. With the argument, it emits a warning, but builds the program.
> gfortran does not accept it on the grounds of it being a mixture, with or without the argument n.
>
> I do not know which one is right, but the mixups (pun not entirely intended) you sketch are unfortunate and possible. Renaming would solve it, but that is besides the point.

I actually ran aross this some time ago.

The key is 15.4.3.4.5 Restrictions on generic declarations, where there
is a constraint:

C1514 Within the scope of a generic name, each pair of procedures
identified by that name shall both be subroutines or both be
functions, and [...]

I think this makes the code illegal, and not diagnosing it is a bug.

Please feel free to disagree :-)

Re: Mixing functions and subroutines in a combined generic interface

<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:454f:0:b0:3a5:41fd:2216 with SMTP id z15-20020ac8454f000000b003a541fd2216mr1954180qtn.338.1668117373563;
Thu, 10 Nov 2022 13:56:13 -0800 (PST)
X-Received: by 2002:a37:bc5:0:b0:6fa:1da0:2e7b with SMTP id
188-20020a370bc5000000b006fa1da02e7bmr1993826qkl.162.1668117373405; Thu, 10
Nov 2022 13:56:13 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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: Thu, 10 Nov 2022 13:56:13 -0800 (PST)
In-Reply-To: <tkjr7g$344at$2@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=12.154.207.45; posting-account=ZT-cAwoAAACx2tBPXm-WZoHIT8sjnGGy
NNTP-Posting-Host: 12.154.207.45
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com> <tkjr7g$344at$2@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: pklausler@nvidia.com (Peter Klausler US)
Injection-Date: Thu, 10 Nov 2022 21:56:13 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1961
 by: Peter Klausler US - Thu, 10 Nov 2022 21:56 UTC

On Thursday, November 10, 2022 at 1:42:11 PM UTC-8, Thomas Koenig wrote:
> The key is 15.4.3.4.5 Restrictions on generic declarations, where there
> is a constraint:
>
> C1514 Within the scope of a generic name, each pair of procedures
> identified by that name shall both be subroutines or both be
> functions, and [...]
>
> I think this makes the code illegal, and not diagnosing it is a bug.
>
> Please feel free to disagree :-)

I think that in my example above the "scope of the generic name" is one module or the other, but in the main program the generic name is being accessed via USE association and the main program is technically not in a (or the) scope of the generic name.

Re: Mixing functions and subroutines in a combined generic interface

<9f88b701-1e43-4f81-ae62-eeb8c4b1865en@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:2228:b0:6fa:2f16:88d1 with SMTP id n8-20020a05620a222800b006fa2f1688d1mr2430344qkh.462.1668125921565;
Thu, 10 Nov 2022 16:18:41 -0800 (PST)
X-Received: by 2002:a05:620a:1372:b0:6fa:182:f2d7 with SMTP id
d18-20020a05620a137200b006fa0182f2d7mr2351218qkl.360.1668125921366; Thu, 10
Nov 2022 16:18:41 -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, 10 Nov 2022 16:18:41 -0800 (PST)
In-Reply-To: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.53.0; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.53.0
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9f88b701-1e43-4f81-ae62-eeb8c4b1865en@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Fri, 11 Nov 2022 00:18:41 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5737
 by: FortranFan - Fri, 11 Nov 2022 00:18 UTC

On Tuesday, November 8, 2022 at 12:16:33 PM UTC-5, Peter Klausler US wrote:

> Generic interfaces are constrained in some specific circumstances to contain all functions or all subroutines, but in general they can contain both. (There's language in the standard that pertains to the visibility of intrinsic procedures of the same name that depends on whether a generic interface contains a mixture or not, so it must be possible.)
>

Re: "but in general they can contain both," from what I can understand from 18-007r1 document toward Fortran 2018, I do *not* think the semantics of the standard is such that "in general they can contain both" Sure the standard has following carve out but that does suggest any generality, in fact the section on "Restrictions on generic declarations" indicates the opposite:
"Within the scope of a generic name that is the same as the generic name of an intrinsic procedure, the intrinsic procedure is not accessible by its generic name if the procedures in the interface and the intrinsic procedure are *not all functions or not all subroutines*. If a generic invocation is consistent with both a specific procedure from an interface and an accessible intrinsic procedure, it is the specific procedure from the interface that is referenced."
(emphasis with asterisk is mine)


> While it's probably not the best practice to explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together. For example:
>

I think the intended message by the OP with example is misleading. The example is *not* "explicitly define an interface that has a mixture of functions and subroutines, it's possible for such an interface to be created -- perhaps inadvertently -- when an interface is defined in multiple locations and merged together"

Rather the example shows two different ultimate entities, both of which are generic interfaces named 'generic'. One ultimate entity is that for functions (func being one specific procedure in it) and the other for subroutines (subr being one specific procedure in this interface).

I think the standard only permits the second of these two entities to be referenced in the scope containing the USE statement, meaning the following:

A) consume the generic as a function, here note the order of USE statements
program main
use m2
use m1
print *, generic(42)
end

Or

B) consume the generic as a subroutine, note the order of USE statements is opposite to that A)
program main
use m1
use m2
call generic
end

It will take me effort to decode the standardese and try to explain in plain English but I think this is tied to semantics with "An ultimate entity is a module entity that is not accessed by use association. An accessed entity shall not be associated with two or more ultimate entities unless its identifier is not used, or the ultimate entities are generic interfaces. Generic interfaces are handled as described in 15.4.3.4."

I think this is also tied to how the standard permits extension of generic interfaces via USE statements, as in the following example:
module m1
interface generic
module procedure func
end interface
contains
integer function func(n)
integer, intent(in) :: n
func = n
end function
end module

module m2
interface generic
module procedure func
end interface
contains
real function func(n)
real, intent(in) :: n
func = n
end function
end module

program main
use m1
use m2
print *, generic(42)
print *, generic(99.0)
end

>.. So I think I'm going to get to add another item to f18's documentation section on features that it supports that are standard but might as well not be.

Honestly I think the "f18 documentation" on "features that it supports that are standard but might as well not be" needs a thorough review by a subgroup in the J3 committee, say JoR or /DATA or the Editor. I think there are inaccuracies in that "f18 documentation", the above comments by OP in the original post on generic interfaces will be one such if that were to get included. Until the f18 team (is it all at Nvidia?) can get it thoroughly reviewed and all corrections applied, ideally it will only be in the publicly available online with clearly stated disclaimers.

Re: Mixing functions and subroutines in a combined generic interface

<f83f389f-fc5f-4336-9fd0-0784ae572544n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:6c9:b0:6fa:9d10:1784 with SMTP id 9-20020a05620a06c900b006fa9d101784mr2233087qky.627.1668126021817;
Thu, 10 Nov 2022 16:20:21 -0800 (PST)
X-Received: by 2002:a37:a94f:0:b0:6fa:f77:f8ea with SMTP id
s76-20020a37a94f000000b006fa0f77f8eamr2376695qke.647.1668126021652; Thu, 10
Nov 2022 16:20:21 -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, 10 Nov 2022 16:20:21 -0800 (PST)
In-Reply-To: <9f88b701-1e43-4f81-ae62-eeb8c4b1865en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.53.0; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.53.0
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com> <9f88b701-1e43-4f81-ae62-eeb8c4b1865en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f83f389f-fc5f-4336-9fd0-0784ae572544n@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Fri, 11 Nov 2022 00:20:21 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2172
 by: FortranFan - Fri, 11 Nov 2022 00:20 UTC

On Thursday, November 10, 2022 at 7:18:43 PM UTC-5, FortranFan wrote:
> On Tuesday, November 8, 2022 at 12:16:33 PM UTC-5, Peter Klausler US wrote:
>
> > Generic interfaces are constrained in some specific circumstances to contain all functions or all subroutines, but in general they can contain both. (There's language in the standard that pertains to the visibility of intrinsic procedures of the same name that depends on whether a generic interface contains a mixture or not, so it must be possible.)
> >
> Re: "but in general they can contain both," from what I can understand from 18-007r1 document toward Fortran 2018, I do *not* think the semantics of the standard is such that "in general they can contain both" Sure the standard has following carve out but that does suggest any generality

Oops, omitted a key word: I meant "that does not suggest any generality"

Re: Mixing functions and subroutines in a combined generic interface

<tkmhte$35sbl$2@newsreader4.netcologne.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-144c-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.lang.fortran
Subject: Re: Mixing functions and subroutines in a combined generic interface
Date: Fri, 11 Nov 2022 22:21:34 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <tkmhte$35sbl$2@newsreader4.netcologne.de>
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com>
<tkjr7g$344at$2@newsreader4.netcologne.de>
<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com>
Injection-Date: Fri, 11 Nov 2022 22:21:34 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-144c-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:144c:0:7285:c2ff:fe6c:992d";
logging-data="3338613"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Fri, 11 Nov 2022 22:21 UTC

Peter Klausler US <pklausler@nvidia.com> schrieb:
> On Thursday, November 10, 2022 at 1:42:11 PM UTC-8, Thomas Koenig wrote:
>> The key is 15.4.3.4.5 Restrictions on generic declarations, where there
>> is a constraint:
>>
>> C1514 Within the scope of a generic name, each pair of procedures
>> identified by that name shall both be subroutines or both be
>> functions, and [...]
>>
>> I think this makes the code illegal, and not diagnosing it is a bug.
>>
>> Please feel free to disagree :-)
>
> I think that in my example above the "scope of the generic name"
> is one module or the other, but in the main program the generic
> name is being accessed via USE association and the main program
> is technically not in a (or the) scope of the generic name.

I disagree there. Both interfacs are accessed by use association
in the main program, and thus are in its scope.

At least this is how I interpret use association and 14.2.2.

Re: Mixing functions and subroutines in a combined generic interface

<3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:451f:b0:4bc:176f:a4fc with SMTP id oo31-20020a056214451f00b004bc176fa4fcmr4344476qvb.112.1668218557719;
Fri, 11 Nov 2022 18:02:37 -0800 (PST)
X-Received: by 2002:a05:620a:91b:b0:6fb:9b2:b946 with SMTP id
v27-20020a05620a091b00b006fb09b2b946mr3605794qkv.487.1668218557554; Fri, 11
Nov 2022 18:02:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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, 11 Nov 2022 18:02:37 -0800 (PST)
In-Reply-To: <tkmhte$35sbl$2@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=12.154.207.45; posting-account=ZT-cAwoAAACx2tBPXm-WZoHIT8sjnGGy
NNTP-Posting-Host: 12.154.207.45
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com> <tkjr7g$344at$2@newsreader4.netcologne.de>
<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com> <tkmhte$35sbl$2@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: pklausler@nvidia.com (Peter Klausler US)
Injection-Date: Sat, 12 Nov 2022 02:02:37 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1813
 by: Peter Klausler US - Sat, 12 Nov 2022 02:02 UTC

On Friday, November 11, 2022 at 2:21:37 PM UTC-8, Thomas Koenig wrote:
> I disagree there. Both interfacs are accessed by use association
> in the main program, and thus are in its scope.
>
> At least this is how I interpret use association and 14.2.2.

Thanks for the response. You're probably right. But since at least four compilers support this combination, so must I, and it's just a matter of determining how it should be documented.

Re: Mixing functions and subroutines in a combined generic interface

<3982361e-51e1-46d8-a780-48a54444efb5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:1988:b0:39c:bf89:65f0 with SMTP id u8-20020a05622a198800b0039cbf8965f0mr4032368qtc.35.1668219582231;
Fri, 11 Nov 2022 18:19:42 -0800 (PST)
X-Received: by 2002:a05:6214:247:b0:4bb:8572:99c5 with SMTP id
k7-20020a056214024700b004bb857299c5mr4396929qvt.77.1668219582063; Fri, 11 Nov
2022 18:19:42 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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, 11 Nov 2022 18:19:41 -0800 (PST)
In-Reply-To: <3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:1c0f:5abe:b5ed:dc7f;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:1c0f:5abe:b5ed:dc7f
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com> <tkjr7g$344at$2@newsreader4.netcologne.de>
<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com> <tkmhte$35sbl$2@newsreader4.netcologne.de>
<3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <3982361e-51e1-46d8-a780-48a54444efb5n@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: gah4@u.washington.edu (gah4)
Injection-Date: Sat, 12 Nov 2022 02:19:42 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1868
 by: gah4 - Sat, 12 Nov 2022 02:19 UTC

On Friday, November 11, 2022 at 6:02:39 PM UTC-8, Peter Klausler US wrote:

(snip)

> Thanks for the response. You're probably right. But since at least four
> compilers support this combination, so must I, and it's just a matter
> of determining how it should be documented.

Since compilers are allowed to support extensions, the fact that compilers
support it doesn't tell you much.

Re: Mixing functions and subroutines in a combined generic interface

<7cf07cff-3a79-4bef-bcb3-81f40b23b6e4n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ae9:c10c:0:b0:6fa:3cb1:da73 with SMTP id z12-20020ae9c10c000000b006fa3cb1da73mr3674671qki.175.1668222359289;
Fri, 11 Nov 2022 19:05:59 -0800 (PST)
X-Received: by 2002:a05:622a:1709:b0:3a5:7262:4844 with SMTP id
h9-20020a05622a170900b003a572624844mr4135975qtk.77.1668222359147; Fri, 11 Nov
2022 19:05:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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, 11 Nov 2022 19:05:58 -0800 (PST)
In-Reply-To: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:1c0f:5abe:b5ed:dc7f;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:1c0f:5abe:b5ed:dc7f
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7cf07cff-3a79-4bef-bcb3-81f40b23b6e4n@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: gah4@u.washington.edu (gah4)
Injection-Date: Sat, 12 Nov 2022 03:05:59 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2432
 by: gah4 - Sat, 12 Nov 2022 03:05 UTC

On Tuesday, November 8, 2022 at 9:16:33 AM UTC-8, Peter Klausler US wrote:
> Generic interfaces are constrained in some specific circumstances to contain
> all functions or all subroutines, but in general they can contain both.
> (There's language in the standard that pertains to the visibility of intrinsic
> procedures of the same name that depends on whether a generic
> interface contains a mixture or not, so it must be possible.)

I tried something like this some years ago, about Fortran 95 days:

real x
external sub, fun
x=3
call sf(sub,1,x)
call sf(fun, 2,x)
print *,x
end
subroutine sf(fs, i, x)
integer i
real x
external fs
if(i.eq.1) call fs(x)
if(i.eq.2) x=fs(3.0)
end
subroutine sub(y)
y=y+2
end
function fun(z)
fun = z*z
end

This shows some of the surprising ways Fortran considers functions and subroutines.

It won't compile this way, but will if you comment out either if statement.

Note also that it never calls a function as a subroutine or subroutine as a function.

It makes me suspect that Fortran also won't like mixing them as generics.

Re: Mixing functions and subroutines in a combined generic interface

<tknibo$36gkg$1@newsreader4.netcologne.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-144c-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.lang.fortran
Subject: Re: Mixing functions and subroutines in a combined generic interface
Date: Sat, 12 Nov 2022 07:35:20 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <tknibo$36gkg$1@newsreader4.netcologne.de>
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com>
<tkjr7g$344at$2@newsreader4.netcologne.de>
<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com>
<tkmhte$35sbl$2@newsreader4.netcologne.de>
<3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>
Injection-Date: Sat, 12 Nov 2022 07:35:20 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-144c-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:144c:0:7285:c2ff:fe6c:992d";
logging-data="3359376"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Sat, 12 Nov 2022 07:35 UTC

Peter Klausler US <pklausler@nvidia.com> schrieb:
> On Friday, November 11, 2022 at 2:21:37 PM UTC-8, Thomas Koenig wrote:
>> I disagree there. Both interfacs are accessed by use association
>> in the main program, and thus are in its scope.
>>
>> At least this is how I interpret use association and 14.2.2.
>
> Thanks for the response. You're probably right. But since at
> least four compilers support this combination, so must I, and it's
> just a matter of determining how it should be documented.

It's a violation of a numbered constraint, and not diagnosing it
is a bug in the compiler. See 4.2, conformance, clause 2:

# A processor conforms to this document if:
[...]

# (3) it contains the capability to detect and report the use within
# a submitted program unit of a form or relationship that is not
# permitted by the numbered syntax rules or constraints, including
# the deleted features described in Annex B;

So, you can support it, and you can even hide the check behind
some options, but unless you want a bug in the compiler, you need
to be able to issue a diagnostic.

As a matter of policy, I think all constraint violations should
be errors by default, and if needed, options should be used
to downgrade the error to a warning (which is still a diagnostic)
or to quieten it entirely.

Re: Mixing functions and subroutines in a combined generic interface

<bdb33a54-e4cb-469d-a267-4587e05b0decn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:a65:b0:4b1:7201:7673 with SMTP id ef5-20020a0562140a6500b004b172017673mr6887824qvb.62.1668279756504;
Sat, 12 Nov 2022 11:02:36 -0800 (PST)
X-Received: by 2002:ae9:df02:0:b0:6fa:349b:7ba9 with SMTP id
t2-20020ae9df02000000b006fa349b7ba9mr5789177qkf.339.1668279756342; Sat, 12
Nov 2022 11:02:36 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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: Sat, 12 Nov 2022 11:02:36 -0800 (PST)
In-Reply-To: <tknibo$36gkg$1@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=12.154.207.45; posting-account=ZT-cAwoAAACx2tBPXm-WZoHIT8sjnGGy
NNTP-Posting-Host: 12.154.207.45
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com> <tkjr7g$344at$2@newsreader4.netcologne.de>
<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com> <tkmhte$35sbl$2@newsreader4.netcologne.de>
<3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com> <tknibo$36gkg$1@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bdb33a54-e4cb-469d-a267-4587e05b0decn@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: pklausler@nvidia.com (Peter Klausler US)
Injection-Date: Sat, 12 Nov 2022 19:02:36 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2392
 by: Peter Klausler US - Sat, 12 Nov 2022 19:02 UTC

On Friday, November 11, 2022 at 11:35:23 PM UTC-8, Thomas Koenig wrote:
> So, you can support it, and you can even hide the check behind
> some options, but unless you want a bug in the compiler, you need
> to be able to issue a diagnostic.
>
> As a matter of policy, I think all constraint violations should
> be errors by default, and if needed, options should be used
> to downgrade the error to a warning (which is still a diagnostic)
> or to quieten it entirely.

Thanks for the advice. I think a portability warning (optionally fatal but not by default) is sufficient in this case and in the best interest of users trying to port code to a new compiler. The extension is benign, unambiguous, useful, and well supported elsewhere. Were it dangerous, ambiguous, easy to avoid, or peculiar to a single compiler, things would be otherwise.

Re: Mixing functions and subroutines in a combined generic interface

<14bcf326-2e9c-4ffe-a463-4ad4e61dff56n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:6214:881:b0:4bb:5f2c:fbb4 with SMTP id cz1-20020a056214088100b004bb5f2cfbb4mr6942794qvb.99.1668284251611;
Sat, 12 Nov 2022 12:17:31 -0800 (PST)
X-Received: by 2002:ae9:f810:0:b0:6fa:f77:f8ea with SMTP id
x16-20020ae9f810000000b006fa0f77f8eamr5781021qkh.647.1668284251395; Sat, 12
Nov 2022 12:17:31 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.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: Sat, 12 Nov 2022 12:17:31 -0800 (PST)
In-Reply-To: <3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=136.226.51.0; posting-account=ZZXq9AoAAAAQEcA7zKAGm0UFQh4gMBv7
NNTP-Posting-Host: 136.226.51.0
References: <fdcb8a2b-7845-470e-9664-465a958ae4d3n@googlegroups.com>
<d8e52a60-eea5-4d7e-a553-9e09dc96a2cen@googlegroups.com> <tkjr7g$344at$2@newsreader4.netcologne.de>
<b10b4cd4-49ea-43d6-be54-3bfee44e3ff9n@googlegroups.com> <tkmhte$35sbl$2@newsreader4.netcologne.de>
<3740ea12-e29e-4670-9359-dd17024fe17en@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <14bcf326-2e9c-4ffe-a463-4ad4e61dff56n@googlegroups.com>
Subject: Re: Mixing functions and subroutines in a combined generic interface
From: parekhvs@gmail.com (FortranFan)
Injection-Date: Sat, 12 Nov 2022 20:17:31 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3845
 by: FortranFan - Sat, 12 Nov 2022 20:17 UTC

On Friday, November 11, 2022 at 9:02:39 PM UTC-5, Peter Klausler US wrote:

> On Friday, November 11, 2022 at 2:21:37 PM UTC-8, Thomas Koenig wrote:
> > I disagree there. Both interfacs are accessed by use association
> > in the main program, and thus are in its scope.
> >
> > At least this is how I interpret use association and 14.2.2.
...
> Thanks for the response. You're probably right. But since at least four compilers support this combination, so must I, and it's just a matter of determining how it should be documented.

Re: ".. at least four compilers support this combination ..", I seriously doubt it.

The code in the original post is not generic enough to fully illustrate the issue. With the modification below, both Intel Fortran (IFORT, IFX) and gfortran appear to conform to the standard and detect and report the issue of a generic interface in a scope where the procedures are not all functions nor all subroutines:

module m1
interface generic
module procedure func
end interface
contains
integer function func(n)
integer, intent(in) :: n
func = n
end function
end module

module m2
interface generic
module procedure subr
end interface
contains
subroutine subr
print *, 'ok'
end subroutine
end module

program main
use m1
use m2
call generic
print *, generic(42)
end

C:\temp>ifort /c /standard-semantics p.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.7.0 Build 20220726_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

p.f90(24): warning #6706: There is a mixture of specific functions and specific subroutines for one generic-spec. [SUBR]
use m2
-------^

C:\temp>ifx /c /standard-semantics p.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2022.2.0 Build 20220730
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.

p.f90(24): warning #6706: There is a mixture of specific functions and specific subroutines for one generic-spec. [SUBR]
use m2
-------^

C:\temp>gfortran -c p.f90
p.f90:24:7:

24 | use m2
| 1
Error: In generic interface 'generic' at (1) procedures must be either all SUBROUTINEs or all FUNCTIONs

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor