Policy for exposing range structs

Anon via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 31 15:49:32 PDT 2016


On Thursday, 31 March 2016 at 20:40:03 UTC, Adam D. Ruppe wrote:
> meh, if it is allowed, it is going to happen. Why make it worse 
> when there's so little cost in making it better?

Define "little cost". Whatever compression algorithm chosen will 
need support added to any/all tools that want to demangle D. GDB 
and LLDB currently link to liblzma (on my system, at least. 
Configurations may vary). nm and objdump don't link to any 
compression lib. Good luck convincing binutils to add compression 
dependencies like that for D when they don't need them any other 
mangling schemes.

And no, ddemangle isn't a solution here, as then all those 
projects would need to be able to refer to it, and the best way 
for them to do that is to bundle it. Since ddemangle is written 
in D, that would mean binutils would suddenly depend on having a 
working D compiler. That won't happen in the next decade.

Also, any D code that uses core.demangle for any reason would 
suddenly depend on that compression library.

I'm not even fully convinced that my bootstring idea is low 
enough cost, and it's fairly simple, fast, and memory efficient 
compared to any compression algorithm.

> I often don't actually modify the string at all and by putting 
> the string as a template argument, it enables a kind of 
> compile-time memoization like I talked about here a short while 
> ago: http://stackoverflow.com/a/36251271/1457000
>
> The string may be exceedingly if imported from a file or 
> generated externally and cached:
>
> MyType!(import("definition.txt")) foo;
>
> enum foo = ctfeFunction();
>
> MyType!foo test;

Just assigning to an enum gets you memoization (tested on LDC w/ 
DFE 2.68.2).
I don't see how the template factors into this.

Now, yes, if you call the function directly multiple times 
assigning to different enums, it won't memoize those. And it 
doesn't work lazily how the SO question asked for, but this does:

enum lazily(string name: "foo") = ctfeFunction();

If you don't refer to lazily!"foo", ctfeFunction() never gets 
called. If you do, it gets called once, regardless of how many 
times you use lazily!"foo".

That gives you lazy memoization of any CTFEable function without 
ever needing the function parameters to become template 
parameters.

I'm not sure what MyType is, but that looks like a prime 
candidate for my previous post's mixin examples. If not, you 
could use "definition.txt" as its parameter, and have it import() 
as an implementation detail.

> $ is actually a valid identifier character in C

Nope. $ as an identifier character is a commonly supported 
extension, but code that uses it doesn't compile with `clang 
-std=c11 -Werror -pedantic`.


More information about the Digitalmars-d mailing list