Jump to page: 1 2
Thread overview
[Issue 12100] __GENTYPE to generate ever different types
Apr 21, 2014
Andrej Mitrovic
Apr 21, 2014
Andrej Mitrovic
Apr 23, 2014
Andrej Mitrovic
Apr 23, 2014
Andrej Mitrovic
Apr 06, 2016
Simen Kjaeraas
Apr 10, 2016
Simen Kjaeraas
Dec 17, 2022
Iain Buclaw
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com

--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
How about __uniqueID, which would create a unique string ID? I'd imagine this would be more useful since it's more generic, and you could easily create a wrapper for it via:

-----
template GENTYPE()
{
    mixin("struct %1$s { }; alias GENTYPE = %1$s".format(__uniqueID));
}
-----

--
April 21, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to Andrej Mitrovic from comment #1)
> How about __uniqueID, which would create a unique string ID? I'd imagine this would be more useful since it's more generic, and you could easily create a wrapper for it via:
> 
> -----
> template GENTYPE()
> {
>     mixin("struct %1$s { }; alias GENTYPE = %1$s".format(__uniqueID));
> }
> -----

Also __uniqueID would be useful for generating parameter names, and pretty much anywhere where you're using string mixins and need to use some unique names.

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #3 from bearophile_hugs@eml.cc ---
(In reply to Andrej Mitrovic from comment #1)
> How about __uniqueID, which would create a unique string ID?

Yes, a progressive integer is enough.

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

monarchdodra@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com

--- Comment #4 from monarchdodra@gmail.com ---
(In reply to bearophile_hugs from comment #3)
> (In reply to Andrej Mitrovic from comment #1)
> > How about __uniqueID, which would create a unique string ID?
> 
> Yes, a progressive integer is enough.

Well, it still has to be unique cross-compilation run: If you compile several different objects differently, then the integer won't be unique.

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #5 from monarchdodra@gmail.com ---
(In reply to Andrej Mitrovic from comment #1)
> How about __uniqueID, which would create a unique string ID? I'd imagine this would be more useful since it's more generic, and you could easily create a wrapper for it via:
> 
> -----
> template GENTYPE()
> {
>     mixin("struct %1$s { }; alias GENTYPE = %1$s".format(__uniqueID));
> }
> -----

Basically, we're asking for a static PRNG? In this particular case, the final result is a string or type, but at the core, what we need is a compile time PRNG?

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #6 from bearophile_hugs@eml.cc ---
(In reply to monarchdodra from comment #5)

> Basically, we're asking for a static PRNG?

No, I am asking for a integer that is incremented every time by 1, and that is exported as a range by every pre-compiled module to avoid duplicatio7ns. (a random number can't be unique, unless you use something like 512 random bits).

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to monarchdodra from comment #4)
> (In reply to bearophile_hugs from comment #3)
> > (In reply to Andrej Mitrovic from comment #1)
> > > How about __uniqueID, which would create a unique string ID?
> > 
> > Yes, a progressive integer is enough.
> 
> Well, it still has to be unique cross-compilation run: If you compile several different objects differently, then the integer won't be unique.

Hmm.. I don't know about that. Really all I wanted was:

auto a = __uniqueID;  // "asdf01"
auto b = __uniqueID;  // "asdf02"

It's just something that's incremented internally, but this can only be done during that compilation run. I'm not sure whether this would cause any problems.

DMD already has something like this that it uses internally, but at runtime (of the DMD executable), Lexer::uniqueId.

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #8 from monarchdodra@gmail.com ---
(In reply to bearophile_hugs from comment #6)
> (In reply to monarchdodra from comment #5)
> 
> > Basically, we're asking for a static PRNG?
> 
> No, I am asking for a integer that is incremented every time by 1, and that is exported as a range by every pre-compiled module to avoid duplicatio7ns. (a random number can't be unique, unless you use something like 512 random bits).

Right, I was thinking kind of thinking "UUID unique".

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #9 from monarchdodra@gmail.com ---
(In reply to Andrej Mitrovic from comment #7)
> Hmm.. I don't know about that. Really all I wanted was:
> 
> auto a = __uniqueID;  // "asdf01"
> auto b = __uniqueID;  // "asdf02"
> 
> It's just something that's incremented internally, but this can only be done during that compilation run. I'm not sure whether this would cause any problems.
> 
> DMD already has something like this that it uses internally, but at runtime (of the DMD executable), Lexer::uniqueId.

Yeah, but I'm saying that:

//----
module mod_a;

immutable a = __uniqueID;  // "asdf01"
//----
module mod_b;

immutable b = __uniqueID;  // "asdf??"
//----
module main;

import mod_a, mod_d;
static assert(a != b);
//----

dmd -c mod_a.d
dmd -c mod_b.d
dmd mod_d.o mod_b.o main.d

Then a "simple" increment scheme won't work, since you'd have reset between two runs, and have created a duplicate.

But I guess at this point, we agree on the final functionality. The rest is implementation detail.

--
April 23, 2014
https://issues.dlang.org/show_bug.cgi?id=12100

--- Comment #10 from Andrej Mitrovic <andrej.mitrovich@gmail.com> ---
(In reply to monarchdodra from comment #9)
> Yeah, but I'm saying that:
> import mod_a, mod_d;
> static assert(a != b);

One workaround for this is to encode the module name in the identifier (hence why a string-based approach might be more useful than just a trait that returns a number).

--
« First   ‹ Prev
1 2