digitalmars.D - typeinfo comparison - 'is' or '=='?
- Gregor Richards (18/18) May 06 2006 Partially to learn the DMD frontend and partially because it's cool and
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (8/17) May 07 2006 This is a problem for GDC too, when running on old compilers (GCC 3.3)
- Bruno Medeiros (6/15) May 07 2006 Yet, that would make the comparison slower, just because of a compiler
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/8) May 07 2006 Sure, depends on whether you want it working on other platforms or not.
- Burton Radons (12/21) May 07 2006 The opCmp method in almost all of the TypeInfo are completely inadequate...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/22) May 07 2006 Yes, if the typeid for pointer types could be fixed, that would be good.
- John Reimer (4/4) May 08 2006 What's this? Burton Radons appearing out of the blue again?
- Bruno Medeiros (9/33) May 07 2006 Whoa there, I just realized: This is a global language issue, it is not
- Bruno Medeiros (19/52) May 08 2006 Hum, actually, after some tests, and a very brief look in Phobos, it
- Sean Kelly (5/23) May 07 2006 Why not create a source file with all the declarations and a header
- Gregor Richards (4/7) May 07 2006 There are infinite possibilities.
Partially to learn the DMD frontend and partially because it's cool and useful, I've been writing a D compiler targetting C ( http://www.dsource.org/projects/tdc/ ) I've ran into an issue with typeinfo objects. It seems that for any type, there should be a static object containing the type info, and furthermore there should only be one in the output program. My reasoning behind this is that several .d files in phobos/ use 'is' to compare typeinfo's, which implies to me that the 'typeid' operator will return a reference to a statically declared type (since otherwise it could return a different value and you'd get false negatives) Unfortunately, this poses a bit of a problem when using .c as the output. Anything I try to declare statically would end up declared into every .o file. That's a (slightly) solvable problem with some linkers, but probably unsolvable with .so-linkage or .dll-linkage, unless I'm misunderstanding the situation. So my question is: Am I wrong, or is the code in phobos/std/boxer.d and phobos/std/stream.d wrong? - Gregor Richards
May 06 2006
Gregor Richards wrote:I've ran into an issue with typeinfo objects. It seems that for any type, there should be a static object containing the type info, and furthermore there should only be one in the output program. My reasoning behind this is that several .d files in phobos/ use 'is' to compare typeinfo's, which implies to me that the 'typeid' operator will return a reference to a statically declared type (since otherwise it could return a different value and you'd get false negatives)This is a problem for GDC too, when running on old compilers (GCC 3.3) that doesn't support once-only linkage and therefore duplicates objects. http://www.digitalmars.com/d/archives/D/gnu/1594.htmlSo my question is: Am I wrong, or is the code in phobos/std/boxer.d and phobos/std/stream.d wrong?Well, not "wrong" - it is just not portable ? But changing it from 'is' over to use '==' instead would make it work in more places than it does. So I think that Phobos should be changed. --anders
May 07 2006
Anders F Björklund wrote:Yet, that would make the comparison slower, just because of a compiler technology limitation, no? That doesn't sound good to me. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DSo my question is: Am I wrong, or is the code in phobos/std/boxer.d and phobos/std/stream.d wrong?Well, not "wrong" - it is just not portable ? But changing it from 'is' over to use '==' instead would make it work in more places than it does. So I think that Phobos should be changed. --anders
May 07 2006
Bruno Medeiros wrote:Yet, that would make the comparison slower, just because of a compiler technology limitation, no? That doesn't sound good to me.Sure, depends on whether you want it working on other platforms or not. Since DMD and Phobos only supports Windows and linux, I guess it is OK for them to do it in a way that is the fastest on those two platforms. But it still has to be patched, in the GDC / GPhobos versions of them ? --anders
May 07 2006
Anders F Björklund wrote:Gregor Richards wrote:The opCmp method in almost all of the TypeInfo are completely inadequate for their task; for example, according to DMD "typeid (void *) == typeid (char *)"; any chained type (pointers, arrays, delegates, functions) has this problem, which would allow for data corruption in unboxing. That's why I used "is" instead: it's better to reject an unboxing than to do it wrong.So my question is: Am I wrong, or is the code in phobos/std/boxer.d and phobos/std/stream.d wrong?Well, not "wrong" - it is just not portable ? But changing it from 'is' over to use '==' instead would make it work in more places than it does.So I think that Phobos should be changed.std.boxer should be changed but only after TypeInfo has been fixed. I sent Walter a partial fix* for it (which was faster too) shortly after writing std.boxer; I don't know why he didn't incorporate it. Walter? * Delegates and functions cannot be truly fixed until the TypeInfo includes parameter information.
May 07 2006
Burton Radons wrote:That is a much more valid reason to use "is" than the performance one...Well, not "wrong" - it is just not portable ? But changing it from 'is' over to use '==' instead would make it work in more places than it does.The opCmp method in almost all of the TypeInfo are completely inadequate for their task; for example, according to DMD "typeid (void *) == typeid (char *)"; any chained type (pointers, arrays, delegates, functions) has this problem, which would allow for data corruption in unboxing. That's why I used "is" instead: it's better to reject an unboxing than to do it wrong.Yes, if the typeid for pointer types could be fixed, that would be good. (as I know that was one of the major problems for the "readf" methods) --andersSo I think that Phobos should be changed.std.boxer should be changed but only after TypeInfo has been fixed. I sent Walter a partial fix* for it (which was faster too) shortly after writing std.boxer; I don't know why he didn't incorporate it. Walter? * Delegates and functions cannot be truly fixed until the TypeInfo includes parameter information.
May 07 2006
What's this? Burton Radons appearing out of the blue again? Good to see you around, Burton! :D -JJR
May 08 2006
Anders F Björklund wrote:Gregor Richards wrote:Whoa there, I just realized: This is a global language issue, it is not just a matter of Phobos. It has to be defined globally (by the language itself) what is the correct way to compare two types. I mean, what if in a D program one uses == / is with a TypeInfo? Wouldn't GDC support == ? -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DI've ran into an issue with typeinfo objects. It seems that for any type, there should be a static object containing the type info, and furthermore there should only be one in the output program. My reasoning behind this is that several .d files in phobos/ use 'is' to compare typeinfo's, which implies to me that the 'typeid' operator will return a reference to a statically declared type (since otherwise it could return a different value and you'd get false negatives)This is a problem for GDC too, when running on old compilers (GCC 3.3) that doesn't support once-only linkage and therefore duplicates objects. http://www.digitalmars.com/d/archives/D/gnu/1594.htmlSo my question is: Am I wrong, or is the code in phobos/std/boxer.d and phobos/std/stream.d wrong?Well, not "wrong" - it is just not portable ? But changing it from 'is' over to use '==' instead would make it work in more places than it does. So I think that Phobos should be changed. --anders
May 07 2006
Bruno Medeiros wrote:Anders F Björklund wrote:Hum, actually, after some tests, and a very brief look in Phobos, it seems there are two kinds of comparisons available, each one corresponding to each operator. "is" tests for exact type equality, and "==" tests for meta-type equality (aka archetype, type type, super type?) Example: writefln(typeid(FooBar) is typeid(Foo)); //false writefln(typeid(FooBar) == typeid(int*)); //false writefln(typeid(FooBar) == typeid(Foo)); //true,same metatype(class) writefln(typeid(char*) == typeid(int*)); //true,same metatype(pointer) Then there's also the equals method of TypeInfo, and that I didn't quite understand what it does (or when). It seems to me redundant versus opEquals. In any case, it seems both operands must support their respective usage. We could use some official documentation on this too, as there's quite no mention of it anywhere, I think. -- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DGregor Richards wrote:Whoa there, I just realized: This is a global language issue, it is not just a matter of Phobos. It has to be defined globally (by the language itself) what is the correct way to compare two types. I mean, what if in a D program one uses == / is with a TypeInfo? Wouldn't GDC support == ?I've ran into an issue with typeinfo objects. It seems that for any type, there should be a static object containing the type info, and furthermore there should only be one in the output program. My reasoning behind this is that several .d files in phobos/ use 'is' to compare typeinfo's, which implies to me that the 'typeid' operator will return a reference to a statically declared type (since otherwise it could return a different value and you'd get false negatives)This is a problem for GDC too, when running on old compilers (GCC 3.3) that doesn't support once-only linkage and therefore duplicates objects. http://www.digitalmars.com/d/archives/D/gnu/1594.htmlSo my question is: Am I wrong, or is the code in phobos/std/boxer.d and phobos/std/stream.d wrong?Well, not "wrong" - it is just not portable ? But changing it from 'is' over to use '==' instead would make it work in more places than it does. So I think that Phobos should be changed. --anders
May 08 2006
Gregor Richards wrote:Partially to learn the DMD frontend and partially because it's cool and useful, I've been writing a D compiler targetting C ( http://www.dsource.org/projects/tdc/ ) I've ran into an issue with typeinfo objects. It seems that for any type, there should be a static object containing the type info, and furthermore there should only be one in the output program.That's right.My reasoning behind this is that several .d files in phobos/ use 'is' to compare typeinfo's, which implies to me that the 'typeid' operator will return a reference to a statically declared type (since otherwise it could return a different value and you'd get false negatives) Unfortunately, this poses a bit of a problem when using .c as the output. Anything I try to declare statically would end up declared into every .o file. That's a (slightly) solvable problem with some linkers, but probably unsolvable with .so-linkage or .dll-linkage, unless I'm misunderstanding the situation.Why not create a source file with all the declarations and a header file, included by everything, that has an "extern" declaration for each one? Sean
May 07 2006
Sean Kelly wrote:Why not create a source file with all the declarations and a header file, included by everything, that has an "extern" declaration for each one?There are infinite possibilities. void *, void **, void ***, void ****, void *[]*[], char (*)()[], etc, etc. - Gregor Richards
May 07 2006