News for hackers. Stuff that matters.
Re:Swift is a more convenient Rust by zozbot234 on Friday September 06, 2024 @06:44AM (#41464855)
The whole point of Haskell as a programming language is to have lazy evaluation be the default. This comes with boxing data objects everywhere, which is the opposite of a focus on low-level performance. Haskell does support using strict, unboxed data but it's clunky and not the default. (Also, recent versions of Rust have now added support for "plug-in" laziness via the type constructors LazyCell<> and LazyLock<>.)
Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @06:50AM (#41464889)
I’m aware of how boxing works in GHC, I learned it from Simon Marlowe.

I don’t mean to be obtuse but I don’t see what that has to do with linear typing as a fucking weird mandatory default?

Re:Swift is a more convenient Rust by the_duke on Friday September 06, 2024 @07:12AM (#41465030)
Why should every language occupy the same design space?

Rust was shaped by Mozilla wanting a language to replace parts of Firefox with. A language that is low-level enough to give very high performance, enforces correctness through the type system, and yet has many abstractions so it feels modern and convenient to use.

Rust doesn't have any automatic allocations. You can wrap every type in `Arc<Mutex<T>>` and treat it like a very verbose Python, but that's the programmers choice.

The design decisions have been validated by the success of Rust in certain domains.

There is a reason why more than one programming language exists...

Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @07:18AM (#41465057)
I think Rust is cool!

If it wasn’t actively seeking world domination I’d be like, cool let’s use that sometimes.

Rust is so hell bent on a Rust monoculture ranging from stuff like TRACTOR to actively opposing interop that a few of us who know our shit have to be like “easy now” once in a while.

I’m trying to decide between tiktoken and sentencepiece for a new vocabulary at the moment, and it would be easier in some ways to go with tiktoken.

But I want it to run faster than a fart at inference time, which means I’m linking libtorch, which means I’m writing C++.

And fuck, link to Rust from C++? Let’s take another look at the Google stuff.

Re:Swift is a more convenient Rust by tialaramex on Friday September 06, 2024 @08:13AM (#41465443)
> If it wasn’t actively seeking world domination I’d be like, cool let’s use that sometimes.

Hylo specifically says it intends "world domination" (next year in fact, having apparently completed all the delayed 2023 goals and also all its 2024 goals this year, I guess maybe they're going to do it all in December?)

But I don't really see this from Rust. I'm sure Hylo's "world domination" is a joke, but, so is the "Rust Evangelism Strike Force". Rust people I've interacted with strike me as very much more accepting of the "better tool" theory than of some weird cult or panacea. When somebody in a Rust forum says (e.g. about JPEG XL) "Ooh we should use Rust" and I say "No, WUFFS. This problem is what WUFFS is for" the responses tend to be a mix of "Yeah, I guess" and "I didn't know that existed. Thanks for the link" rather than cultist denial.

Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @08:24AM (#41465514)
Haha we’ve tangled before and in my experience when the Rust evangelism strike force is on the case discretion is the better part of valor.

I admire both the technical sophistication and passion you folks bring to the table, the one true language thing just isn’t my bag. I pine for the Halcyon days when HN was run by the Rust people rather than the LLM idiots.

Keep doing what you’re doing, one hacker to another.

Re:Swift is a more convenient Rust by zozbot234 on Friday September 06, 2024 @07:36AM (#41465178)
> to actively opposing interop

Rust just uses the C ABI for interop (including interop with Rust code that might not be part of the same build, such as dynamically-linked program objects). So you just have to come up with a plain C API for the interface and write wrappers on both sides of the divide that reference the C API. There are crates that will help with this, even achieving something like a "stable ABI" for Rust interop.

(And we'll probably see some work into interop with Swift itself (which has a stable ABI of its own) once there's enough interest in that as a memory safe language.)

Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @07:53AM (#41465307)
It’s doable!

But bindgen/cbindgen/cxx/etc exist for a reason: it hurts like a root canal.

In my particular case, tiktoken is substantially like 600 lines of Rust. If I have a deadline do I fuck with the linker or just write it again? I’m marshaling std::string here, fuck let’s just write it.

What I’m not going to re-write because I’m not a magnificent maniac like geohotz? I’m not going to rewrite libtorch. Which is written in C++ like all the software you can’t really live without.

Re:Swift is a more convenient Rust by zozbot234 on Friday September 06, 2024 @07:00AM (#41464950)
I'm not sure what's supposed to be especially weird about linear typing (or rather, uniqueness typing which is what Rust ultimately relies on). If you want to see the use of such types in a language that's clearly even less "convenient" and more principled than Rust, you can look at Austral https://austral-lang.org/
Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @07:04AM (#41464981)
I think I’m going to be a hard pass on a language more militant about BDSM type system level memory management than Rust.
Re:Swift is a more convenient Rust by farmeroy on Friday September 06, 2024 @02:57PM (#41468789)
Is their code linter called whippy?
Re:Swift is a more convenient Rust by bananapub on Friday September 06, 2024 @06:51AM (#41464893)
perhaps a dumb question, but why does laziness imply boxing? or does 'boxing' in haskell mean something other than 'embed a simple bit of data in a fancy thing on the heap'?
Re:Swift is a more convenient Rust by throwaway17_17 on Friday September 06, 2024 @09:14AM (#41465897)
I seem to be missing the implication as well. I am under the impression that Haskell relies on boxed values primarily due to its parametric polymorphism. There is a Simon Peyton Jones talk somewhere discussing the acrobatic GHC requires for the type theory to deal with unboxed types and their implicit requirement for an alternative Kind at the type level.

The laziness as a default just makes boxing closure values a sensible default, when the type system requires the boxing of everything in general.

Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @10:51AM (#41466758)
On everything from the JVM to GHC to v8 there is a critical distinction between the semantics of a boxed type and the practical outcome on the gear. Every managed language runtime done by pros (and those all are, I should have said the CLR too) will quietly unbox in all the easy cases and some of the hard ones.

Parametric polymorphism is kind of orthogonal to that. It’s related I guess. It can involve some kind of runtime dispatch, but usually that gets JITed or inlined or whatever unless you really insult the compiler.

And even full frontal invokedynamic it’s still like, is it in the BTB and the I-cache? Ok well we’re still doing business.

Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @06:54AM (#41464920)
A dramatic over-simplification is that a lazy value referenced by some continuation/thunk is hard to stack allocate in-situ.

Now GHC does stack allocate, but it’s hard to count on without really aggressive hinting.

Re:Swift is a more convenient Rust by the_duke on Friday September 06, 2024 @07:19AM (#41465066)
Funnily enough Rust supports exactly that pretty well with async.

An `async {}` block is not evaluated, but converted into a generator/state machine that lives on the stack, and that has to be advanced by calling a poll method. You can move it to the heap , but that does not happen automatically.

Sharing of values is obviously much more awkward due to mutability and no automatic cloning though.

Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @07:32AM (#41465149)
I know how it works though I remain unconvinced that rustc is dealing with the same scope of problem as GHC in the general case.

But to be clear, anyone with the username the_duke is probably really cool, and you clearly know your stuff as well as having style, so count me as a fan.

Re:Swift is a more convenient Rust by bananapub on Friday September 06, 2024 @07:33AM (#41465159)
ah, right, laziness can cause the control flow to become extremely complicated - makes sense, thanks!
Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @07:44AM (#41465237)
Also true! And in very real sense literally what I meant.

But not so much in the conditional branch sense of the phrase “control flow”.

More like, I’ve got a bunch of references and one of them is a reference to a function I might evaluate, damn, I need that reference and the transitive closure of everything it knows about, all of which are probably on the heap.

Re:Swift is a more convenient Rust by zozbot234 on Friday September 06, 2024 @07:55AM (#41465319)
The proper name for this is a "space leak". Also known as: "you wanted a banana, but what you got was a gorilla holding the banana and the entire jungle". This is of course pretty much the opposite of low-level "performance" - and it's also the kind of problem that tracing garbage collection was actually designed to address when first developed.
Re:Swift is a more convenient Rust by benreesman on Friday September 06, 2024 @08:10AM (#41465416)
Fake news and FUD and other balderdash.

A space leak, much like any memory leak is when you or the compiler or the runtime or whoever misplaces such reference.

GHC having a closure in scope in no way immediately means there is a space leak. Plenty of Haskell code that compiles to thunks will run all day in an amortized fixed-size heap.

Much like Erlang, which is what Joe Armstrong had designed before he said the thing about jungles you’ve quoted.

And it is in no way difficult or even really rare to drop an Arc in a table and leak all over the place.

Rust has all the same computer science problems as anything else. Full stop.