5 ms·
I'm hoping that the Rust compiler is good enough to compile this back to a bit-shift instruction?
by chrisseaton 5y ago
I'm hoping that the Rust compiler is good enough to compile this back to a bit-shift instruction?
- jjgreen 5y agoThat would be impressive, could someone check?
- SekstiNi 5y agoUnfortunately, but expectedly, it cannot reason about it [1]. Even if it could I'm not sure it would be allowed to elide the allocation(s). [1] https://godbolt.org/z/63xEcfaEE https://godbolt.org/z/63xEcfaEE
- jjgreen 5y agoPity, if it ever does then I'll put aside my distaste for the whole "curl <url> | sh" thing and learn the language.
- h2odragon 5y agoThe metaphysics of that are going to be interesting. "Do what I mean" programming meets all the stories about why one shouldn't accept bargains with fairies or djinn. "I can't let you use `strcpy()` there, Dave" is the least of it.
- coldtea 5y agoNo need to check, that would be almost impossible, unless they could read the programmer's mind for the intent...
- AnIdiotOnTheNet 5y agoWhich I think is the argument behind declarative languages. If we can encode the intent precisely, then at least in theory the compiler can find the optimal solution for the given architecture and other constraints. Of course in practice that probably requires strong AI to accomplish.
- yholio 5y agoYou are surely joking. It would have to make a static inference that a numeric variable is converted to a string variable, then processed as a string to base 2 representation, then truncated as a string that can only contain the '1' and '0' characters, then converted back into binary.
- chrisseaton 5y ago> It would have to make a static inference Not necessarily a static inference... could be speculative. Code folding golf is a bit of a hobby of mine. For example you can optimise through the string-integer conversion by storing a special string that remembers it was originally an integer and returning that value again instead of re-parsing. I work on a compiler that does that one for real, for example. I don't seriously think Rust does this right now, but would be a challenge to try.
- reitzensteinm 5y agoCould Graal? That would be pretty impressive.
- spaetzleesser 5y agoThat would go way further than existing optimizers can go.
- dev_tty01 5y agoAnd a lot further than we should want them to attempt to go.