Readit News logoReadit News
abendstolz commented on Roto: A Compiled Scripting Language for Rust   blog.nlnetlabs.nl/introdu... · Posted by u/gbxyz
ori_b · 3 months ago
This language looks a lot like Rust. Why not dlopen() a Rust shared library instead? The implementation would be about as complicated, but it would be a well known language that's fully integrated with a large library ecosystem, well defined build and package set, rather than some custom one-off thing with no ecosystem. Going your own way means your users have to re-invent the wheel for themselves every time.

With Rust's safety, it's not even that bad to re-open and re-load the binary when it changes; the big footgun with dlopen is use-after-free.

abendstolz · 3 months ago
Don't rust shared libraries have the problem of no stable rust ABI? So you either use the C ABI or you use some crate to create a stable rust ABI, because otherwise a shared lib compiled with rust compiler 1.x.y on system a isn't guaranteed to work with the binary compiled on the same system with another compiler... or on another system with the same compiler version.

Right?

abendstolz commented on Roto: A Compiled Scripting Language for Rust   blog.nlnetlabs.nl/introdu... · Posted by u/gbxyz
zamalek · 3 months ago
Alternatively, whenever designing a scripting/plugin host make sure to support plugin-hosting-plugins. That way you could have the Roto plugin host complied to wasm.
abendstolz · 3 months ago
Sounds interesting but at the same time a bit complex.

I assume you wouldn't ship the whole plugin runtime for each plugin that wants to host another plugin?!

abendstolz commented on Roto: A Compiled Scripting Language for Rust   blog.nlnetlabs.nl/introdu... · Posted by u/gbxyz
bobajeff · 3 months ago
This sounds like a good approach to overcoming rusts slow compile times and lack of dynamic linking. One thing I'm concerned about with this path is what about hot reloading and fast script running? Doesn't everything in the wasm component model need to be compiled first? I imagine that would remove some of the advantages to using a scripting language like JavaScript or Python.
abendstolz · 3 months ago
You're right. Hot reloading isn't done by default.

I manually compile a plugin and in my system I can "refresh" a plugin and even say "activate version 1.1 of the plugin" or "activate version 1.2" of the plugin etc.

But that's something I had to build myself and is not built into wasmtime itself.

abendstolz commented on Roto: A Compiled Scripting Language for Rust   blog.nlnetlabs.nl/introdu... · Posted by u/gbxyz
90s_dev · 3 months ago
How is that not also stringly typed?
abendstolz · 3 months ago

                match Plugin::instantiate_async(&mut store, &component, &linker).await {
                    Ok(plugin) => {
                        match plugin
                            .plugin_guest_oncallback()
                            .call_ontimedcallback(&mut store, &callback_name)
                            .await
                        {
                            Ok(()) => debug!("Successfully called oncallback for {plugin_path:?}"),
                            Err(e) => warn!("Failed to call oncallback for {plugin_path:?}: {e}"),
                        }
                    }
                    Err(e) => {
                        error!("Failed to call oncallback for {plugin_path:?}!: {e}");
                    }
                }
See the "call_ontimedcallback"? It's not a string. The compiler ensures it exists on the Plugin type generated from the .wit file.

If of course I put a wasm file in the plugin folder that doesn't adhere to that definition, that wasm file isn't considered a plugin.

abendstolz commented on Roto: A Compiled Scripting Language for Rust   blog.nlnetlabs.nl/introdu... · Posted by u/gbxyz
abendstolz · 3 months ago
Very cool!

But I prefer the wasmtime webassembly component model approach these days.

Built a plugin system with that, which has one major upside in my book:

No stringly function invocation.

Instead of run_function("my-function-with-typo") I have a instantiated_plugin.my_function call, where I can be sure that if the plugin has been instantiated, it does have that function.

abendstolz commented on Go Replaces Interface{} with 'Any'   github.com/golang/go/comm... · Posted by u/brosciencecode
meowface · 4 years ago
My favorite has become just making the version number the release date.
abendstolz · 4 years ago
For binaries, I agree. For libs, I prefer semver
abendstolz commented on Lapce – Fast and Powerful Code Editor written in Rust   github.com/lapce/lapce... · Posted by u/agluszak
spyremeown · 4 years ago
Hi, thanks for writing some free software!

I'm not a Rust person, how do you install this? Is it something like "rustc install" or something like that?

Thanks!

abendstolz · 4 years ago
abendstolz commented on Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility   github.com/nuta/kerla... · Posted by u/Klasiaster
schuyler2d · 4 years ago
Result is part of core [0]. Result data and/or errors can be stack-only data. The parent was just saying that many people that say they want to guard against out-of-memory issues aren't cognizant of just how difficult that is.

Add to that that several operating systems will lie about whether you're out of memory, so the 'error' or failure will often not be on the Result() value but come in a SIGKILL instead, it's just adding complexity.

People that are actually worried about it and no how to deal with it, will be coding with a different style and can use the alloc library where/when they need to. (at least when it gets stabilized in Rust)

[0] https://doc.rust-lang.org/core/result/

abendstolz · 4 years ago
Thanks for correcting my error.

I've never checked core before, so I did when checking up for this discussion.

I somehow missed Result. Silly me didn't search on that page, but ofc I found it on std

https://doc.rust-lang.org/std/result/index.html

Also thanks for clarifying that values of Result can be stack-only!

abendstolz commented on Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility   github.com/nuta/kerla... · Posted by u/Klasiaster
cormacrelf · 4 years ago
It has nothing to do with Result, whatsoever. Result does not allocate. If you used a Result that way, you could certainly try to "gracefully" handle the allocation failure, but if you think it would be easy, you would be wrong. As Tialaramex said, you are probably just going to make the problem worse because it is very difficult to ensure you do not attempt to allocate during allocation-failure-recovery. Rustc doesn't and can't really check this for you.

It actually has to do with `panic!(...)`. When you use `unwrap()`/`expect("...")`, you use the panic macro under the hood; parts of the panicking infrastructure use a boxed trait object which could contain a static string or formatted String or anything else really. The box can allocate if it is not a ZST. I believe the alloc crate's default handler tries to avoid this kind of thing, so that it can't fail to allocate AGAIN in the failure-handling routine. It will likely do a better job than you could.

This is a live issue at the moment, so to go into any more detail I'd have to read a bunch of recent Rust issues/PRs.

abendstolz · 4 years ago
Thanks for the thorough explanation!
abendstolz commented on Kerla: Monolithic kernel in Rust, aiming for Linux ABI compatibility   github.com/nuta/kerla... · Posted by u/Klasiaster
tialaramex · 4 years ago
> it would allow me to additionally log something

If you don't have any memory your allocations are all failing. When you assemble the log message, the allocation needed to do that fails. Bang, double fault.

Now, often people don't really mean they want allocations to be able to fail generally, they're just thinking about that code they wrote that reads an entire file into RAM. If it was a 100GB file that would be a bad idea. But the best answer is: Guard the allocation you're actually worried about, don't ladle this into the fast path everybody has to deal with on every allocation.

abendstolz · 4 years ago
Mhm, thanks.

It never occurred to me (being in non-embedded land) that returning an enum as the error or a &'static str instead of a heap structure like String, could also fail.

Seeing that Result isn't part of core, but of std, this makes sense.

Just to tickle my nerve though: theoretically speaking, with your example, it would work, right?

I couldn't allocate 100GB (because OOM or not even enough RAM to begin with) but it could be that the system can allocate the needed memory for error message just fine.

Very interesting.

u/abendstolz

KarmaCake day35June 19, 2020View Original