Live data from Hacker News

How Our Rust-to-Zig Rewrite Is Going

rtfeldman.com

311–320 of 336 posts

Re: How Our Rust-to-Zig Rewrite Is Going

#311
post #309

Earlier quoted context omitted.

so yes it is possible to detect those patterns and ban them as unsafe, and have a"safety checked alternative. clr does this currently: https://github.com/ityonemo/clr#safety-oriented-architecture

It's possible to detect and ban the version of the problematic pattern that I made as short and simple as possible to illustrate the point, sure. I'm general though, I don't believe it is practical to do so. Not without every library being designed with the checker in mind and annotated to more precisely describe their APIs. Which is why I'm not surprised to see the limitations.md that seems to exclude all the hard c…

did you miss this part?

> planned to be addressed

i have in mind a strategy to address all of them. this is a side project, a proof of concept, i have other things going on in my life. i dont chip away at it every week.

you make, without any evidence ("Obviously"), an assertion that "it would look like another language". so far if anything applying zig clr would push a user to write more idiomatically ziggy code, away from idiomatically c-ish code. i dont see why continuing with clr wouldn't go further along that trend. so consider what is "obvious" to you might just be flat out wrong.

> It might be an interesting language worth exploring.

worth how much? youre welcome to sponsor my exploration and put your money where your mouth is:

https://buymeacoffee.com/vidalalabs

Re: How Our Rust-to-Zig Rewrite Is Going

#312
post #309

Earlier quoted context omitted.

It's possible to detect and ban the version of the problematic pattern that I made as short and simple as possible to illustrate the point, sure. I'm general though, I don't believe it is practical to do so. Not without every library being designed with the checker in mind and annotated to more precisely describe their APIs. Which is why I'm not surprised to see the limitations.md that seems to exclude all the hard c…

did you miss this part? > planned to be addressed i have in mind a strategy to address all of them. this is a side project, a proof of concept, i have other things going on in my life. i dont chip away at it every week. you make, without any evidence ("Obviously"), an assertion that "it would look like another language". so far if anything applying zig clr would push a user to write more idiomatically ziggy code, awa…

I wish them the best of luck, but I don't expect them to succeed, and unspecified plans don't constitute a demonstration of feasibility. Plenty of people have made plans to solve unsolvable problems in the past, me included. I strongly suspect that that is the case here (or that they're willing to iterate away from zig).

The evidence is the amount that rust had to iterate on the underlying language to make the borrow checker work well. Something it had the freedom to do since it was co-designing the language and linter.

Edit: Didn't realize this was your project (responded before you added the donation link) - I would have worded my response slightly differently but my opinion is unchanged. Seriously mean it with the best of luck getting this to work.

Re: How Our Rust-to-Zig Rewrite Is Going

#313
post #249

Earlier quoted context omitted.

different preferences i guess. i much prefer language stability. the idea that i should have to test my code with every python version out there for example is disturbing, but there are tools to do exactly that. they should not be needed.

The solution to this is editions/epochs, like Rust. You can set your project to the 2025 edition and be sure that, even if future versions introduce breaking changes, they will not affect your project; it will continue to compile as before.

You can continue to compile as before by using a previous version of the Zig compiler. You even get a 100% byte-for-byte match with reproducible builds.

Why are we so obsessed with updating dependencies, and at the same time, not willing to put in the work to update our own code?

The result of Zig’s approach is that the ecosystem of packages is very active, quickly updating to use the latest language features, and with a good foundation of tests that catch regressions.

Re: How Our Rust-to-Zig Rewrite Is Going

#314
Just reading the HN comments I found most interesting is that Rust and Zig have future improvement that related to each other's strong point.

Rust will be getting faster Build time in 2026 and 2027+. This post shows incremental build went from 10s to 3s in 18 months. And lots of improvement coming as well. While it may not be 35ms in Zig but it is not too far to imagine Rust could have 1s or even sub second incremental build in next 2-3 years.

On the other hand Zig is getting more tooling for memory safety. Opening Access to IR and even other ( although non official ) side project to have borrow checking implemented.

That is on top of the subject languages ROC, which for whatever reason really hit the "friendly" part for a functional language.

Re: How Our Rust-to-Zig Rewrite Is Going

#315

Earlier quoted context omitted.

Allocations are less of a problem than aliases. Without affine/linear ownership - solving the aliasing problem is the Halting Problem. Rust didn't invent Affine Ownership just to make Rust hard. It did it because it's one of the only ways to have memory safety without a GC.

1. rust didnt invent affine ownership. 2. It's possible to bolt on to other languages (see ada). zig in particular is easy (disclaimer: i think, i haven't implemented it yet)

> zig in particular is easy (disclaimer: i think, i haven't implemented it yet)

I guess it's "easy" compared to other languages - but if you think it's "easy", we have different definitions of "easy".

You could implement it, but it would look like efforts in Rust to get SPARK-like safety, and SPARK itself. It will essentially be a different language.

You will not be able to work seamlessly with any regular Zig code. That may or may not be a problem if you're willing to assume you can just use it all unsafely and it works enough that things are fine.

That's somewhat analogous to unsafe Rust. The difference with unsafe Rust is... That's a very small fraction of what you're using, not the vast majority of what you use.

When you use a Rust crate - you generally do not expect that it could have infinite race conditions. It may have some unsafe code, but that should be the exception, not the norm.

By all means, please build it. I'd consider using it [=

Re: How Our Rust-to-Zig Rewrite Is Going

#316
post #168

Tangentially relates, but if any Roc devs are around I'm curious about the use cases for Roc. It's supposed to be a scripting language right you embed into your C ABI right? Do you see it competing with WASM for the plugin use case (i.e. a really large Roc platform)? Why would an app author prefer to expose a Roc layer to their app rather than a WASM layer? With a WASM layer, plugin devs can write in any language. An…

> If any Roc devs are around I'm curious about the use cases for Roc.

It's a general functional programming language that's interested in the constraints and state control properties but not really in the dogma/traditions. As a specific example, it has a for loop statement that doesn't return anything just because sometimes the algorithm is easier to express imperatively. That said, it really is functional, mutating functions/methods require a `!` suffix and `->` (pure) vs `=>` (not) is distinguished in the type system and enforced. The language is fully decidable so type annotations are optional with the arguable exception of the built-in Serde which needs a concrete type to encode/decode. It's also pretty fast, like in the Go range.

I think it has the best error handling of any language in the ~3 dozen I've tried. It's Rust style in general with `Result` renamed to `Try` but the error side of `Try` is an open tag set and can just aggregate so you get the nice parts of the Rust error experience without the downsides. As an example, a coeffect (effectful input) from an example on my server platform:

    book! = |req| {
        body : { id : I64 }
        body = Req.json_body!(req)?
        rows = Sql.query!(req.ctx, db_path, "SELECT id, title, author, year FROM books WHERE id = ?", [Integer(body.id)])?
        row = Sql.first(rows) ? |_| NotFound("book ${body.id.to_str()} not found")
        book = decode_book(row)?
        Ok(book)
    }
The full set of errors covers malformed utf8, missing/wrong type for id, db errors, the custom NotFound with message, and missing/changed db columns and these plus all the other errors across the app get rolled up and handled in one spot by the error mapping function which rolls the input errors to 400, a 404 for the NotFound, 500s in general in a big match. I have more compact ways to express this in the platform (sqlx) but those don't show off the error handling as nicely.

All in all, it's pretty much just a nice hosted language for doing things.

> Do you see it competing with WASM for the plugin use case?

It's mostly competing with Lua and friends but the host is a platform and not an embedder so the Roc goes on the outside and produces the binary. Roc is particularly well suited for compiling to wasm because all the effects coming from the host is shared. This is actually one of my primary interests in Roc but I haven't really harassed the Roc team about it because they've been busy with the rewrite and wasm module specs have been WIP.

> Why would an app author prefer to expose a Roc layer to their app rather than a WASM layer?

No need for the relatively large WASM runtime would be one of the first ones but Roc isn't really designed to be embedded. I expect to mainly use Roc for app level code on top of Rust for systems level code. I could write app-level Rust but I like functional programming, GC (refcount) is convenient, the error handling is nice, no annotations are nice, super fast compiles are nice, etc.

> Do you see it competing with Gleam for server side http code? Do you see it competing with Elm for client side code?

Sure. As mentioned, I'm experimenting with a server platform that uses pure handlers plus an effect system. I have a RealWorld implementation and in casual benchmarking on my M1 laptop I get 69k req/s for the article endpoint (serialization bound) and 10k going through the article_list endpoint (sqlite bound, 4 table join). The framework also has full and automatic cache invalidation so if I turn on caching I hit 120-140k req/s on both endpoints with no other code changes.

As for GUI stuff, I'm working on a platform (Clay+Solid2) but I don't see any particular reason it wouldn't work.

Re: How Our Rust-to-Zig Rewrite Is Going

#317

Earlier quoted context omitted.

The solution to this is editions/epochs, like Rust. You can set your project to the 2025 edition and be sure that, even if future versions introduce breaking changes, they will not affect your project; it will continue to compile as before.

You can continue to compile as before by using a previous version of the Zig compiler. You even get a 100% byte-for-byte match with reproducible builds. Why are we so obsessed with updating dependencies, and at the same time, not willing to put in the work to update our own code? The result of Zig’s approach is that the ecosystem of packages is very active, quickly updating to use the latest language features, and wi…

Why are we so obsessed with updating dependencies, and at the same time, not willing to put in the work to update our own code?

because i want to benefit from the improvements/bug fixes in the dependencies, whereas updating my own code does not bring any improvements (unless it is taking advantage of a new feature in the dependencies) and for a large project can be very expensive.

more practically for my work, i need to be able to compile my application with a compiler that is actively supported, but i have no budget to rewrite old code just because the compiler developers decided to break old functionality.

Re: How Our Rust-to-Zig Rewrite Is Going

#318
post #168

Tangentially relates, but if any Roc devs are around I'm curious about the use cases for Roc. It's supposed to be a scripting language right you embed into your C ABI right? Do you see it competing with WASM for the plugin use case (i.e. a really large Roc platform)? Why would an app author prefer to expose a Roc layer to their app rather than a WASM layer? With a WASM layer, plugin devs can write in any language. An…

> If any Roc devs are around I'm curious about the use cases for Roc. It's a general functional programming language that's interested in the constraints and state control properties but not really in the dogma/traditions. As a specific example, it has a for loop statement that doesn't return anything just because sometimes the algorithm is easier to express imperatively. That said, it really is functional, mutating…

Thank you grayrest- I didn't realize Roc had to be the one that produced the binary.

Could you go into a little more detail about how you decide to split what's in your Rust platform vs your Roc application?

Re: How Our Rust-to-Zig Rewrite Is Going

#319

Earlier quoted context omitted.

1. rust didnt invent affine ownership. 2. It's possible to bolt on to other languages (see ada). zig in particular is easy (disclaimer: i think, i haven't implemented it yet)

> zig in particular is easy (disclaimer: i think, i haven't implemented it yet) I guess it's "easy" compared to other languages - but if you think it's "easy", we have different definitions of "easy". You could implement it, but it would look like efforts in Rust to get SPARK-like safety, and SPARK itself. It will essentially be a different language. You will not be able to work seamlessly with any regular Zig code.…

> You will not be able to work seamlessly with any regular Zig code. That may or may not be a problem if you're willing to assume you can just use it all unsafely and it works enough that things are fine.

that may be true, but it seems "not". to date, all of the patterns in zig-clr nudge you towards idiomatic zig and not away from it. i run tests on not-my-code (an unaltered version of an existing zig project -- you can see it's vendored in the "vendored/validate"), and it passes. still working through forestmq.

and I'm planning a mechanism to let you reach into a function and "oracle" its safety parameters, probably most useful when someone else has written code that you know is ok but you cant tell them "hey make this work to pass my linter"

Also remember that zig compiles as a single compilation unit so even if you draw in zig dependencies, unless they are hidden behind a .so, zig-clr will analyze the dependency code too.

Re: How Our Rust-to-Zig Rewrite Is Going

#320
post #287

Earlier quoted context omitted.

TBH, physics limits how latency-sensitive weapons systems need to be and you can largely just disable the GC in these contexts. They use CPUs from the 1990s to do hypersonic terminal guidance. You don’t have to do any performance engineering for many latency-sensitive weapon systems. Could probably write it in Javascript. For throughput-optimized systems, some of which are real-time, you never see a GC. That loss in…

Throughput-optimized systems like HFT? https://www.lmax.com/exchange/technology No, you could not guide battleship weapons in Javascriptt https://www.lockheedmartin.com/en-us/products/aegis-combat-s... https://dl.acm.org/doi/abs/10.1145/2402709.2402699 And no they don't disable the GC, they have real time GC implementations, https://www.ptc.com/en/products/developer-tools/perc

I think you may be confused about what "throughput-optimized" means. HFT is not throughput-optimized by definition. The LMAX link literally says it is a latency-optimized system. An optimal throughput-optimized system has unbounded worst-case latency -- the opposite of "latency-optimized".

None of those links contradict anything I wrote, I am already familiar with all of them.

Post reply on HN