Some thoughts on PDTs
Janne Blomqvist
blomqvist.janne@gmail.com
Mon Apr 24 08:01:00 GMT 2017
On Mon, Apr 24, 2017 at 12:50 AM, Thomas Koenig <tkoenig@netcologne.de> wrote:
> Hello world,
>
> after Jerry's implementation of DTIO, only PDTs are
> missing as a major F2003 feature from gfortran.
Great!
> I'd like to share some unordered thoughts on a way to
> implement these. Comments, corrections etc. are the whole
> point of this mail, so very highly welcome :-)
A few comments below. Probably I'm more showing my ignorance of PDT's
than contributing anything useful, but...
> To recap: A PDT could look like
>
> TYPE matrix (k, n)
> integer, kind :: k=4
> integer, len :: n
> real(k) :: a(n,n)
> END TYPE matrix
So thus we need to serialize some equivalent of the above in s-expr
form in the module file...
> with a later declaration of a type that is actually usable as
>
> TYPE (matrix(k=selected_real_kind(15),n=100) :: mymatrix
And at this point the instantiated type becomes more or less like a
normal non-PDT type, no? Probably we need to mangle the type
parameters into the name of the type for the vtable symbols etc.?
This could cause a bit of code bloat, or linker errors if there are
many places where the type is instantiated with the same parameters.
Particularly if the type has several methods etc. So maybe there could
be some clever trick to emit the type (and associated methods) only
once?
[snip]
> Things will get more interesting for an allocatable or pointer
> variable or dummy argument which is a PDT.
>
> Apparently, the kind number has to be a constant expression, which
> makes things a bit easier.
>
> Still, to pass a variable of a type like
>
> TYPE foo(k1, k2, n, m)
> integer, kind :: k1
> integer, kind :: k2
> integer, len :: n
> integer, len :: m
> real(kind=k1), dimension(n,m) :: a
> real(kind=k2), dimension(2*n,m) :: b
> END TYPE foo
>
> we would need some new type of descriptor. It is not totally clear to
> me at the moment what data this would need to contain, or how it would
> look like.
Do we actually need to pass a non-instantiated PDT? In that case,
well, guh. Greenspun's 10th rule springs to mind.. I'd be very
surprised if this in fact is needed.
--
Janne Blomqvist
More information about the Fortran
mailing list