Settings

Theme

Show HN: Rust compiler in PHP emitting x86-64 executables

github.com

60 points by mrconter11 4 days ago · 55 comments

Reader

qalmakka 21 hours ago

I think people don't really realise that compilers are "difficult" projects in the same way as an appendicectomy is for a skilled surgeon, i.e. the surgery is "routine" only because the surgeons spent decades honing their skills to do these routinely. The hard part was training someone to be able to do that.

Writing a compiler/interpreter is _extremely_ straightforward; a lexer -> parser -> ast -> semantic analysis -> {codegen -> linker | evaluator} pipeline is a very widely understood and tested way to write a compiler in any language, regardless of what language you are trying to compile. The hard part is _learning_ how it works, but after that implementing a compiler is a kind of mechanical activity. That's why LLMs are so great at writing parsers: they can just read the source of any compiler (and they probably read all of them) and apply the same stuff mechanically, with almost a 100% accuracy. We even have formal languages to define parsers and RTL and stuff, that's how "mechanical" the whole process can be.

I'm pretty sure that any skilled compiler dev with the ISO C standard and a few packs of Red Bulls can apecode a working C compiler in a few days, give or take. The hard part isn't doing that, the hard part is the decades of iterative improvements to make it generate extremely performant yet correct code as fast as possible.

swalsh 21 hours ago

I bet claude was hyping this guy up as he was building it. "Absolutely, a rust compiler written in PHP is a great idea!"

  • embedding-shape 20 hours ago

    Does it matter who the sycophant was or just that there was a sycophant?

    My partner does that as well as LLMs at this point; "Sure honey, I remember you've talked a lot about Rust and about Clojure in the past, and you seem excited about this Clojure-To-Rust transpiler you're building, it sounds like a great idea!", is that bad too?

  • jlg23 20 hours ago

    Every compiler in any language for any language has at the very least educational value.

    On the other hand, demeaning comments without any traces of constructive criticism don't have any value.

  • nz 20 hours ago

    There is no comment on whether LLMs/agents have been used. I feel like projects should explicitly say if they were _or_ were not used. There is no license file, and no copyright header either. This feels like "fauxpen-source": imagine getting LEX+YACC to generate a parser, and presenting the generated C code as "open-source".

    This is just another way to throw binaries over the wire, but much worse. This has the _worst_ qualities of the GPL _and_ pseudo-free-software-licenses (i.e. the EULAs used by mongo and others). It has all the deceptive qualities of the latter (e.g. we are open but not really -- similar to Sun Microsystems [love this company btw, in spite of its blunders], trying to convince people that NeWS is "free" but that the cost of media [the CD-ROM] is $900), with the viral qualities of the former (e.g. the fruit of the poison tree problem -- if you use this in your code, then not only can you not copyright the code, but you might actually be liable for infringement of copyright and/or patents).

    I would appreciate it if the contributor, mrconter11, would treat HN as an internet space filled with intelligent thinking people, and not a bunch of shallow and mindless rubes. (Please (1) explicitly disclose both the use and absence of use of LLMs -- people are more likely to use your software this way, and preserves the integrity of the open source ecosystem, and (2) share you prompts and session).

    So passes the glory of open source.

    • stephenlind 20 hours ago

      According to his Readme he seems to have built a 3D engine completely from scratch 8 years ago without using any library:

      https://github.com/mrconter1/IntuitiveEngine

      > A simple 3D engine made only with 2D drawLine functions.

      • nz 20 hours ago

        That is (slightly) reassuring (but the rest of his portfolio does not inspire confidence). Nevertheless, we should be required to disclose whether the code has been (legally) tainted or not. This will help people make informed decisions, and will also help people replace the code if legal consequences appear on the horizon, or if they are ready to move from prototype to production.

abricq 20 hours ago

> Useful if you need to compile Rust on a shared hosting server from 2008 where the only installed runtime is PHP.

Not sure if it was meant as a joke or not, but this cracked me up

  • timw4mail 16 hours ago

    The code style seems to be targeting some old version of PHP...but I'm absolutely sure typed properties require a newer version of PHP than existed in 2008. (If I recall correctly, that's around the days of PHP 5.4 or so)

medi8r 20 hours ago

Next: A wordpress plugin to compile Firefox to WASM.

gregman1 a day ago

You never know what’s going on in someone else’s Claude Max plan =D

  • orthogonal_cube a day ago

    Interesting that both you and nxtfari made essentially the same comment within an hour of each other, though yours is slightly modified

    • dashzebra 21 hours ago

      Yeah, right? Are we just... talking with bots?

      • nirui 21 hours ago

        That's a collision of 64 letters of entropy within 20 mins.

        Searching the term on DDG return this very page as the only result, I can confirm it's not a common term/meme.

        We're living on a dead Internet are we?

      • didacusc 20 hours ago

        well there is a context to this of people doing ridiculous projects just because they can through LLMs, of which Claude excels at for code-writing, so it makes sense that two users would have a similar reaction to this. also copying jokes from other people is as old as time (just check youtube comments from 2008)

      • bakugo 20 hours ago

        It's pretty obvious that Anthropic has a bot army that advertises Claude in basically every post, I thought most people would've noticed by now.

        • IshKebab 20 hours ago

          I don't think it's obvious. A likelier explanation is just that a lot of people are using Claude (especially HN types). Do you have any actual evidence?

          • bakugo 18 hours ago

            You can explain away any obvious astroturfing campaign with "wow, so many people love this product and feel the need to bring it up all the time in unrelated contexts!" if you want to.

            If you think two people making the exact same comment about "Claude Max" (not even just Claude, specifically bringing up the $200 subscription) on an unrelated post is organic, I don't know what to tell you.

    • tgv 20 hours ago

      nxtfari is a less than half a year old account...

    • etyhhgfff 12 hours ago

      Just another glitch in the matrix. Guess whst chances were that this happend by pure coincidence. Dead Internet Theory is real.

nxtfari a day ago

you never know what’s going on in someone else’s claude max plan

wiseowise a day ago

Are all PHP developers named Rasmus?

  • doctor_phil a day ago

    I also for a second thought this was Rasmus Lerdorf, the creator of PHP. In my head I just have him as Rasmus L-something, so this guy was just a hash collision. :)

mohsen1 21 hours ago

Here I thought my experiment with pushing xz to compress Alpine binaries harder was a waste of time / tokens

https://github.com/mohsen1/fesh

mike_d a day ago

Sometimes when doing offensive security work you end up in the strangest environments with limited tools, odd quirks, broken shells, and god knows what else. But you know what is almost always available and just works? PHP.

  • psychoslave a day ago

    Nop. awk, bash or some POSIX shell certainly. Perl most likely, despite it’s plunge in popularity. On a modern Mac, awk, bash and Perl are preinstalled with the system. PHP is not even necessarily present at system level on a PHP dev box as it might be only installed in some container.

nasretdinov a day ago

I wonder if the compiler runs on https://github.com/VKCOM/kphp (a PHP->C++ transpiler)

holg 4 days ago

interesting proof of concept, in php, who would have thought :D

  • devmor a day ago

    I think that proof of concepts are PHP’s greatest strength, actually.

    These days it can be almost as strict as you want it to be, but it’s always been a “loose” enough language that you can implement things that work in very fragile ways and iterate at incredible speed.

    When I am designing PoC microservices that will eventually end up running as Go or Rust, I often start with a prototype in PHP.

hparadiz 17 hours ago

Now just need to figure out how to compile PHP with PHP.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection