Live data from Hacker News

I let LLMs write an Elixir NIF in C; it mostly worked

overbring.com

51–60 of 73 posts

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#51

Earlier quoted context omitted.

Security is a spectrum. If you totally control the input going into a program, it can be safe even if you didn't test it for memory leaks. The only errors that occur will be truly erroneous, not malicious and for many solutions that's fine. At the very least, it's fine for personal projects which is something I'm getting into more and more: remembering that computers were meant to create convenience, so writing small…

For personal projects, ok security is different. But get out of that, and I'd do it even for that, you need defense in depth. You think you sanitized your input but your C program has a bug and a vulnerability - or your Java program or whatever has bugs. Almost everything has some bugs, and thus your vulnerabilities will hit eventually in your C program, even if you were careful. I'd say absent some temporary hack to…

>The entire data access infrastructure was riddled with memory leaks, strings that were not length limited, input parameters that were not checked or sanitized, etc. I'm sure it was endemic across all components, not just there. We fixed some things, but we found so much shit.

Sounds like the original vibe coding.

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#52
post #9

Earlier quoted context omitted.

I dunno. Depending on the writer and their particularly axe to grind the definition can vary widely. I would like it to mean, "any fixes I needed to make were minimal and not time intensive."

It's more of "yeah it worked, but I had to do a lot of hand-holding" and "it passes the tests but I cannot tell if the code has memory leaks". Actually, I can tell; I ran split on the C source and got things like this: disk_space.c:144:16: Only storage bin.ref_bin (type void *) derived from variable declared in this scope is not released (memory leak) So I'm looking into a Rust version with Rustler now.

I'd also recommend having a look at the Zig library for Elixir. For simple stuff, you can just inline, but support for pretty complex setups too.

Also comes with a built-in BEAM allocator so the runtime properly reports NIF memory consumption.

https://hexdocs.pm/zigler/Zig.html

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#53
I once wrote a little generalized yaml templating processor in Python by using an LLM for assistance. It was working pretty well and passing a lot of the tests that I was throwing at it!

Then I noticed that some of the tests that failed were failing in really odd ways. Upon closer inspection, the generated processor had made lots of crazy assumptions about what it should be doing based upon specific values in yaml keys that were obviously unrelated to instructions.

Yeah, I agree with the author. This stuff can be incredibly useful, but it definitely isn't anything like an AGI in its current form.

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#55
post #2

"it mostly worked" is just a more nuanced way of saying "it didn't work". Apparently the author did eventually get something working, but it is false to say that the LLMs produced a working project.

Ok. But what are you even reacting to? Who is saying that it produced a working product? As you said, the very title of the article acknowledged that it didn’t produce a working product. This is just outrage for the sake of outrage.

> As you said, the very title of the article acknowledged that it didn’t produce a working product.

Then why not say "mostly didn't work"? I read the article and that's the impression I got.

The OP's comment isn't an outage, it's more like you intentionally painted it as an outrage with a comment that reads more like an outrage.

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#56

Earlier quoted context omitted.

I mean, you aren't wrong. I'm looking into converting it into Rust with Rustler right now.

Yep, was wondering why you didn't go down that path in the first place. Seems way safer.

It's because the most familiar thing to me that uses a NIF was Exqlite, so that was my starting point.

Using Rust and Rustler turned out to be way easier and it also now works across Elixir versions 1.14 to 1.18.

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#57
post #54

So all this arose because you didn't read the docs and note that get_disk_info/1 immediately fetches the data when called? The every-30-minutes-by-default checks are for generating "disk usage is high" event conditions.

Thanks, that was not clear to me from skimming the docs.

However, this NIF also returns more fields than the disksup function.

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#58

Earlier quoted context omitted.

Yep, was wondering why you didn't go down that path in the first place. Seems way safer.

It's because the most familiar thing to me that uses a NIF was Exqlite, so that was my starting point. Using Rust and Rustler turned out to be way easier and it also now works across Elixir versions 1.14 to 1.18.

Great outcome :)

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#59
post #52

Earlier quoted context omitted.

It's more of "yeah it worked, but I had to do a lot of hand-holding" and "it passes the tests but I cannot tell if the code has memory leaks". Actually, I can tell; I ran split on the C source and got things like this: disk_space.c:144:16: Only storage bin.ref_bin (type void *) derived from variable declared in this scope is not released (memory leak) So I'm looking into a Rust version with Rustler now.

I'd also recommend having a look at the Zig library for Elixir. For simple stuff, you can just inline, but support for pretty complex setups too. Also comes with a built-in BEAM allocator so the runtime properly reports NIF memory consumption. https://hexdocs.pm/zigler/Zig.html

Thanks, one day I'll look into Zig too, because I've been impressed with what Tigerbeetle has achieved with it! For now, I'm all-in on Elixir.

Re: I let LLMs write an Elixir NIF in C; it mostly worked

#60
post #52

Earlier quoted context omitted.

I'd also recommend having a look at the Zig library for Elixir. For simple stuff, you can just inline, but support for pretty complex setups too. Also comes with a built-in BEAM allocator so the runtime properly reports NIF memory consumption. https://hexdocs.pm/zigler/Zig.html

Thanks, one day I'll look into Zig too, because I've been impressed with what Tigerbeetle has achieved with it! For now, I'm all-in on Elixir.

you can use zigler for a c nif, using easy_c (or c_src) options.

the big advantage is that it will automatically box/unbox to/from c values for you and generate sane error messages (which rustler does not, last i checked) when you pass incompatible terms in to the function.

on the other hand rustler lets you precompile (which is coming in a future version of Zigler)

Post reply on HN