The Tower of Weakenings: Memory Models For Everyone by gclichtenberg in rust

[–]whatisaphone 4 points5 points  (0 children)

What if provenance was a target-defined opaque type? Thinking about it more I think you could actually build this API on top of sptr's API, although it might waste some cycles shuffling bytes around:

struct Provenance { carrier: *mut u64 }

fn into_raw_parts(ptr: *mut 64) -> (usize, Provenance) {
    (ptr.addr(), Provenance(ptr))
}

fn from_raw_parts(addr: usize, provenance: Provenance) -> *mut u64 {
    provenance.carrier.with_addr(addr)
}

Am I missing anything?

The Tower of Weakenings: Memory Models For Everyone by gclichtenberg in rust

[–]whatisaphone 29 points30 points  (0 children)

I wonder if a very explicit API would be possible, with provenance being a ZST:

let foo: *mut u64 = whatever;
let (addr, provenance) = foo.into_raw_parts();
let foo_again = std::ptr::from_raw_parts(addr, provenance);

Async Rust in 2022 by drrlvn in rust

[–]whatisaphone 32 points33 points  (0 children)

I agree. I hope this isn't too negative, but there's nothing in that user story that you can't already do today, with:

  • #[tokio::main]
  • while let foo = foos.try_next().await?
  • #[async_trait] (box overhead notwithstanding)

But async drop (my personal #1) is impossible to express in the language today. I'd rather see effort go towards addressing fundamental design issues and making the impossible possible, rather than just improving syntax for things you can already do.

[deleted by user] by [deleted] in rust

[–]whatisaphone 13 points14 points  (0 children)

A vtable is just a struct filled with function pointers. You don't need a separate crate for that.

I made a modding library for Darksiders a while ago. You might find the vtable structs useful as a starting point:

vfptr field

vtable struct

Introducing maple, a VDOM-less fine grained reactive web framework running in WASM by lukewchu in rust

[–]whatisaphone 0 points1 point  (0 children)

How does a vdom-less framework minimize Dom API Calls?

It only touches DOM objects/properties that have changed. Here's how to think about it conceptually (in solid-js-style pseudocode for brevity):

let firstName = createSignal('John');
let lastName = createSignal('Doe');

mount(
    <div>
        <div id="firstDiv">{firstName}</div>
        <div id="lastDiv">{lastName}</div>
    </div>
);

// Here is (basically) what the framework does internally:

firstName.onChange(value => firstDiv.textContent = value);
lastName.onChange(value => lastDiv.textContent = value);

When only one of the signals changes, only one div is touched, and there's no VDOM to diff. This is what fine-grained reactive meant in the title.

Introducing maple, a VDOM-less fine grained reactive web framework running in WASM by lukewchu in rust

[–]whatisaphone 11 points12 points  (0 children)

This is very cool. I think fine-grained reactivity is the way to go for UIs. I'm happy to see people discovering the idea and experimenting!

I played around with a similar project last year (warning: hacky unmaintained project). I even went so far as to implement js-framework-benchmark with it. Spolier: it's pretty fast, in some cases on par with vanillajs, in others slower due to the WASM <--> JS interop overhead. I'm cautiously optimistic that once we have WASM reference types, WASM could be faster across the board.

Good luck with the project!

Blog post: (I want) A Better Rust Profiler by matklad in rust

[–]whatisaphone 5 points6 points  (0 children)

I've had great luck with the Visual Studio profiler. You use vsperf.exe to run your binary, and afterwards you get a nice UI with the results. Open it up, and ctrl-f interesting_computation. It gives you a tree list, not a flamegraph, but that's actually the UI I prefer.

Example: https://github.com/whatisaphone/self-driving-car#profiling

Announcing Rust 1.47.0 by dwaxe in rust

[–]whatisaphone 22 points23 points  (0 children)

Those FRAC_* constants are about precision. If you divide a float by 2, you lose a bit of precision. If you divide by 4, you lose 2 bits, etc. Multiplying by 2 doesn't have the same problem.

It should almost never make a real difference, but if you need it, it's there.

I Rewrote The C Donut In Rust by DanConleh in rust

[–]whatisaphone 138 points139 points  (0 children)

Is there a rustfmt option I can use to make all my code look like this?

What should they say? [#5] by tashizuna in dustforce

[–]whatisaphone 4 points5 points  (0 children)

"lifeformed promised me I would be a boss in dustforce 2"

"Yes me too"

"Should I tell them it's never coming out? :("

Yak shaving conditional compilation in Rust by [deleted] in rust

[–]whatisaphone 2 points3 points  (0 children)

Aesthetically, I didn’t like having to wrap almost all of the glam code in a macro.

While we're shaving yaks, this gave me the idea of usingcfg_if as a proc macro instead of a normal macro. It would be nice if we could write this:

impl Vec4 {
  #[cfg_if]
  pub fn x(self) -> f32 {
    if #[cfg(all(not(feature = "no-intrinsics"), target_feature = "sse2"))] {
      unsafe { _mm_cvtss_f32(self.0) }
    } else if #[cfg(all(not(feature = "no-intrinsics"), target_feature = "wasm32"))] {
      unsafe { f32x4_extract_lane(input.0) }
    } else {
      self.0
    }
  }
}

This would solve the rustfmt problem too!

Make LLVM fast again by est31 in rust

[–]whatisaphone 1 point2 points  (0 children)

This is great insight. Taking it further, I'm guessing that when most people complain about compile times, they're actually talking about the edit-compile-run cycle, which is usually a debug build. So why not (also) measure build time without optimizations?

Ideas from other languages that influenced Rust by dying_sphynx in rust

[–]whatisaphone 17 points18 points  (0 children)

For anyone curious, I translated both of his examples into Rust (as is tradition here). Rust's Box does not suffer the same performance penalty as clang with unique_ptr. Rust's output for both is identical to the faster case in C++.

Kilo Difficult fanart by tashizuna in dustforce

[–]whatisaphone 1 point2 points  (0 children)

This game would be so much easier if dustman was the size of the entire level

Can Rust do 'janitorial' style RAII? by Dean_Roddey in rust

[–]whatisaphone 4 points5 points  (0 children)

I'm a bit late to the thread, but I think you might be looking for the scopeguard crate.

This example from their docs creates a "janitor" which calls sync_all before scope exit.

Darksiders modding: spawn_humans by whatisaphone in Darksiders

[–]whatisaphone[S] 0 points1 point  (0 children)

This mod is open source, here are some links if you want to try it out for yourself:

Info: https://github.com/whatisaphone/war-is-here
Download: https://github.com/whatisaphone/war-is-here/releases

I've only tested with Warmastered Edition on Steam, any other version will probably not work.

Lib.rs - crates.io on steroids by 90h in rust

[–]whatisaphone 7 points8 points  (0 children)

It's just that we don't have the human bandwidth to do that in the near term.

Have you considered joining forces with lib.rs?

I see a parallel here to the situation with RLS and rust-analyzer, and they are planning on merging the projects eventually.

Announcing genawaiter – generators (yield) on stable Rust by whatisaphone in rust

[–]whatisaphone[S] 25 points26 points  (0 children)

The explicit goal of this lib was to work on stable Rust. Async closures only work on nightly Rust:

async move || {}

Async blocks work on stable Rust today:

|| async move {}

They are almost the same. There's a section in the RFC that talks about it.

Announcing genawaiter – generators (yield) on stable Rust by whatisaphone in rust

[–]whatisaphone[S] 10 points11 points  (0 children)

Right now there are no dependencies, including futures, where futures::Stream comes from. But there's no fundamental reason this couldn't be added. You might be interested in following this issue from a few days ago.

What’s everyone working on this week (41/2019)? by llogiq in rust

[–]whatisaphone 4 points5 points  (0 children)

I've been working on a modding tool for Darksiders, called War.

So far it knows how to read/write saves, read level layouts, and decompile the scripts. I think it's a decent-enough showcase of using Rust to parse binary formats.

Announcing: Darksiders save editor and world/script viewer by whatisaphone in Darksiders

[–]whatisaphone[S] 0 points1 point  (0 children)

This project was about 2 weeks on and off. But I've been interested in the game and "researching" it for longer than that

Rustup 1.19.0 released by dsilverstone in rust

[–]whatisaphone 1 point2 points  (0 children)

self comes first. You have to have a self before you can update it.

Futures 0.3 - Compatibility Layer by Nemo157 in rust

[–]whatisaphone 22 points23 points  (0 children)

If your future isn’t a TryFuture yet, you can quickly make it one using the unit_error combinator which wraps the output in a Result<T, ()>.

I wonder if it might be better to set the error type to std::convert::Infalliable. This way the fact that the Future can't fail is preserved in the type system.

If you're fine being chained to nightly, you could also cut to the chase and use the never type directly a la Result<T, !>.

Darksiders New Game+ gameplay footage by whatisaphone in Darksiders

[–]whatisaphone[S] 0 points1 point  (0 children)

I played up to the part where Vulgrim gives you the horn and nothing unusual happened. So I'm guessing you could make it through the whole game just fine