ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
jcroisant has quit [Quit: Connection closed for inactivity]
jcroisant has joined #rust-embedded
Foxyloxy has quit [Read error: Connection reset by peer]
whitequark[cis] has quit [Quit: Reconnecting]
whitequark[cis] has joined #rust-embedded
whitequark[cis] has quit [Client Quit]
whitequark[cis] has joined #rust-embedded
jonored[m] has quit [Quit: Bridge terminating on SIGTERM]
Kin-o-matix[m] has quit [Quit: Bridge terminating on SIGTERM]
JamesMunns[m] has quit [Quit: Bridge terminating on SIGTERM]
_catircservices has quit [Quit: Bridge terminating on SIGTERM]
dngrs[m] has quit [Quit: Bridge terminating on SIGTERM]
Kert[m] has quit [Quit: Bridge terminating on SIGTERM]
Mathias[m] has quit [Quit: Bridge terminating on SIGTERM]
LeandroMarceddu[ has quit [Quit: Bridge terminating on SIGTERM]
GrantM11235[m] has quit [Quit: Bridge terminating on SIGTERM]
doodspav[m] has quit [Quit: Bridge terminating on SIGTERM]
Alex[m] has quit [Quit: Bridge terminating on SIGTERM]
Ralith has quit [Quit: Bridge terminating on SIGTERM]
i509vcb[m] has quit [Quit: Bridge terminating on SIGTERM]
TomB[m] has quit [Quit: Bridge terminating on SIGTERM]
KevinPFleming[m] has quit [Quit: Bridge terminating on SIGTERM]
whitequark[cis] has quit [Quit: Bridge terminating on SIGTERM]
_catircservices has joined #rust-embedded
jcroisant has quit [Quit: Connection closed for inactivity]
_catircservices has quit [Quit: Bridge terminating on SIGTERM]
_catircservices has joined #rust-embedded
Foxyloxy has joined #rust-embedded
jason-kairos[m] has joined #rust-embedded
<jason-kairos[m]> I thought primitive types always had their functions.
<jason-kairos[m]> use core::f32::* maybe if I understand correctly
JamesMunns[m] has joined #rust-embedded
<JamesMunns[m]> floats are like the one exeception
<JamesMunns[m]> https://github.com/rust-lang/rust/issues/137578 tracks it a bit more
<jason-kairos[m]> I'm not exactly sure how to work around this. I expect to have those functions.
<jason-kairos[m]> * I'm not exactly sure how to work around this. I had expected to have those functions.
<JamesMunns[m]> yeah I don't know where this is currently at
<JamesMunns[m]> core::f32::abs(...) maybe?
<jason-kairos[m]> it doesn't appear in the docs, but I will try
<JamesMunns[m]> Yeah, I'm not sure the right way to invoke it, I know it got merged recently, but it definitely looks awkward
<JamesMunns[m]> what version of rust are you using?
<jason-kairos[m]> rustc 1.88.0
<JamesMunns[m]> hmmm.
<jason-kairos[m]> It's weird, many of the discussions make it seem like I shouldn't need to use an external crate. But maybe I do...
<jason-kairos[m]> I suppose it currently is an unstable feature, and previous discussions are out of date.
<jason-kairos[m]> `libm::fabsf(123.0);` vs `f32::abs(123.0)`
<jason-kairos[m]> I wonder if I could rename the libm stuff into live in a module called f32 without breaking everything?
<jason-kairos[m]> I'm not sure if f32 is special or not
<jason-kairos[m]> * I'm not sure if the f32:: prefix is special or not
<jason-kairos[m]> I had given up on using the libm functions since they were too different
<jason-kairos[m]> maybe I need to switch to unstable to expose the feature
<jason-kairos[m]> core_float_math is missing the log function... I didn't expect that.
<jason-kairos[m]> anyone ever got a warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts in a cargo test executable?
therealprof[m] has joined #rust-embedded
<therealprof[m]> Hm, it should be possible to add. Not sure why it's not part of the first batch.
<jason-kairos[m]> it's got debug symbols.
<jason-kairos[m]> nevermind, needs to be launched with rust-gdb wrapper
<therealprof[m]> therealprof[m]: The log functions are intrinsics already so it's not quite clear to me why they couldn't be added to the primitive types in core.
jcroisant has joined #rust-embedded
diondokter[m] has joined #rust-embedded
<diondokter[m]> Following from my ramblings on the socials: https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/String.20interning.20.26.20deferred.20formatting
<diondokter[m]> I think it might be possible to add string interning and deferred formatting to Rust
dirbaio[m] has joined #rust-embedded
<dirbaio[m]> how close do you think it could get to defmt's code size?
dne has quit [Remote host closed the connection]
dne has joined #rust-embedded
<diondokter[m]> <dirbaio[m]> how close do you think it could get to defmt's code size?
<diondokter[m]> I think it'll be a little worse. But not much tbh
<dirbaio[m]> Core fmt makes heavy use of dyn
<dirbaio[m]> That's a big reason why it bloata
<dirbaio[m]> s/bloata/bloats/
<dirbaio[m]> It's not just the strings
<diondokter[m]> Only the Write trait is used as dyn
<dirbaio[m]> Yeah, and it's a major optimization barrier
<diondokter[m]> Hmmm, I don't see that getting in the way here tbh
<diondokter[m]> If you never format a float, that code will not be there
<diondokter[m]> The only thing not happening is inlining between the transport layer and formatting
<dirbaio[m]> for example you're calling s.interned() in write_str there
<dirbaio[m]> that's after the dyn call
<dirbaio[m]> the compiler only knows s is a constant before the dyn call
<diondokter[m]> Hmmm, that might be true yes
<dirbaio[m]> so you might have to call .interned() somehow before the dyn call (?)
<dirbaio[m]> but then how does the caller know if the Write impl wants interned string numbers or full fat strings?
<diondokter[m]> dirbaio[m]: Yeah, maybe it could do that using the new `write_primitive` function
<diondokter[m]> dirbaio[m]: You could put that in the FormattingOptions that's already passed around everything that touches fmt
<diondokter[m]> * passed around to everything that
<dirbaio[m]> that's info passed from caller to callee
<dirbaio[m]> this is the other way around
<dirbaio[m]> there's Write impls that want classic full strings, and there's Write impls that want interned strings.
<dirbaio[m]> how does the compiler know which one is it when codegening a write!()?
<dirbaio[m]> it doesn't, it just sees it's writing into a dyn Write
<dirbaio[m]> so it can't possibly know to leave out the full fat string because i't not needed here
<diondokter[m]> The `write!` macro calls the `write_fmt` function. From there the rest of the formatting happens.
<diondokter[m]> The deferred Write impl would need to set the flag there
<dirbaio[m]> flags at runtime won't work, the compiler needs to know at compile time whether full strings are needed or not
<diondokter[m]> You mean, before anything passes the dyn boundary, right?
<dirbaio[m]> yea
<dirbaio[m]> but I don't see how could it possibly wokr
<dirbaio[m]> s/```//
<dirbaio[m]> the writer.needs_full_strings() condition is itself a dyn call so the compiler can't predict it, so the final asm will contain both branches of the if, including the full string
<diondokter[m]> Hmmm... you might be right yeah
<dirbaio[m]> it is possible for the compiler to devirtualize then inline then dead-code-eliminate but it's not guaranteed..
<dirbaio[m]> maybe you can make it instead a Cargo feature in core or something, to switch the whole compilation to "use interned strings only" mode
<dirbaio[m]> but then things like write!() into a heapless string would break
<diondokter[m]> dirbaio[m]: I've thought about something like that. But that won't work
<diondokter[m]> dirbaio[m]: Yeah this
<dirbaio[m]> tldr I don't see how can you mix interned and noninterned writers in the same compilatino
<dirbaio[m]> s/compilatino/compilation 🥲/
<diondokter[m]> Hmmmm... I need to think about it more it seems
<diondokter[m]> Deferred formatting is still possible though
<diondokter[m]> But getting that properly optimized may also be complicated by dyn
<dirbaio[m]> yeah...
<diondokter[m]> Here's a fun fact btw: Rust fmt is made for performance, right?
<diondokter[m]> If you format a float, say `12.34`, that will result in 3 calls to the `write_str` function with: "12", "." and "34"
<diondokter[m]> I get why, but it seems silly :P
<dirbaio[m]> lol
<dirbaio[m]> i don't want to discourage you but
<diondokter[m]> Haha
<dirbaio[m]> if the goal is to fix the defmt/fmt ecosystem split
<dirbaio[m]> this has to match defmt in code size
<dirbaio[m]> which ... yeah
<diondokter[m]> I disagree. It's all about pros and cons. If fmt was only 10% of its current size, I don't think defmt would've existed (or at least been so prolific)
<dirbaio[m]> we don't live in that timeline tho :D
TomB[m] has joined #rust-embedded
<TomB[m]> dictionary formatting is always useful for small devices, even when you have compact string formatting code
<TomB[m]> at least from what I've seen in Zephyr, the string formatting stuff adds up fast
i509vcb[m] has joined #rust-embedded
<i509vcb[m]> Compile time reflection for fmt like in facet is a neat idea but the facet types are huge
<i509vcb[m]> I think on aarch64 the main Facet type is 200+ bytes per type
<i509vcb[m]> I think the issue there is facet is trying to do a everything on a single type, which means a single usage pulls in hundreds of bytes of metadata that isn't needed or used likely.