News for hackers. Stuff that matters.
Re:My experience crafting an interpreter with Rust (2021) by chc4 on Saturday March 25, 2023 @07:30PM (#35308706)
Not only does it not have computed goto (almost no languages do, tbh), it also doesn't have guaranteed tall-call elimination or allow you to use the GHC calling convention. Which are more egregious, imo.
Re:My experience crafting an interpreter with Rust (2021) by LoganDark on Saturday March 25, 2023 @07:43PM (#35308797)
Why is the lack of "GHC calling convention" egregious? I've never heard this before as an argument against Rust.
Re:My experience crafting an interpreter with Rust (2021) by margorczynski on Saturday March 25, 2023 @08:32PM (#35309208)
I was looking for that (tail recursion) and it seems the story and feature request goes back years ago and still hasn't been added. Somewhere someone wrote that the issue is with LLVM but can't the tail call be transformed to an iteration before that?
Re:My experience crafting an interpreter with Rust (2021) by shadowofneptune on Saturday March 25, 2023 @08:55PM (#35309388)
The most practical uses of recursive functions are those that cannot be easily eliminated. For an interpreter, it could mean dozens of functions all calling each other in a pattern determined at runtime.

The issue used to be with LLVM, yes, but that appears to be solved (see Clang's 'musttail' attribute). Instead it's more about language design. Constructors, destructors, and all of the fancy language features Rust has must work with this new feature, with no changes being visible elsewhere.

Re:My experience crafting an interpreter with Rust (2021) by User23 on Saturday March 25, 2023 @11:42PM (#35310621)
Tail call optimization isn’t just for recursive functions. Any tail call can be optimized to little more than a jump, which makes implementing threaded code or similar much nicer. Your compiled code will just push the instruction pointer along an array of opcodes in a tight loop with no function call overhead.
Re:My experience crafting an interpreter with Rust (2021) by shadowofneptune on Sunday March 26, 2023 @01:21AM (#35311271)
Exactly, though I do not see how it is not an example of recursion.
Re:My experience crafting an interpreter with Rust (2021) by bmitc on Saturday March 25, 2023 @08:54PM (#35309375)
> it also doesn't have guaranteed tall-call elimination

I had no idea about that. Is there a specific reason why that choice was made?

Re:My experience crafting an interpreter with Rust (2021) by pornel on Saturday March 25, 2023 @09:02PM (#35309447)
AFAIK guaranteed TCE wasn't supported in LLVM at all when Rust was still being designed and considered adding it. Support for musttail in LLVM has been added relatively recently.

WASM doesn't support guaranteed TCE yet (it's a proposal), and that's an important target for Rust.

https://github.com/rust-lang/rfcs/issues/2691

Re:My experience crafting an interpreter with Rust (2021) by kzrdude on Sunday March 26, 2023 @07:38AM (#35313363)
`become` is still a reserved keyword for this in Rust, so there's that.