Back to Browse

Compile Time Crimes

4.2K views
Nov 13, 2024
36:31

*We shouldn't have to, but it turns out we can* James explains how to combine macros and const-fns to work around limitations of what is possible at compile time, and how to do extremely wasteful calculations at compile time to deduplicate lists of things to make embedded systems go brrr Visit https://sdr-podcast.com/episodes/compile-time-crimes to see the show notes and transcript! Sponsor: CodeCrafters is a service for learning programming skills by doing. Visit our referral link at https://app.codecrafters.io/join?via=sdr-pod to start your free trial. If you upgrade, you'll get a discount and a portion of the sale will support this podcast. [00:00:00] Intro [00:01:35] Postcard RPC and needed trickery [00:03:35] Problem: de-duplicating lists [00:06:48] Proc/decl macros only work with tokens [00:09:11] What about const fn? [00:10:51] Problem: there's no alloc in const (yet) [00:12:04] Time for a code example [00:15:21] This is the compiler's problem, not my runtime code's problem [00:17:01] const LIST_WITH_DUPES [00:18:16] That's not quite what we want [00:19:28] Write a function that extracts the uniques from the option array [00:20:48] Now we have a whole list of consts [00:22:05] Declarative macro: input as an ident [00:24:11] Limitations and room for improvement [00:26:51] Can we take this further? [00:28:11] The process on how to get a list of lists [00:30:17] Nerd snipe: Huffman coding [00:31:38] Make sure it can never be misunderstood [00:33:45] Internet of things & chips in everything # Show Notes - Cleanfeed https://cleanfeed.net/ - Postcard-RPC https://crates.io/crates/postcard-rpc and the SDR episode "Talking to Microcontrollers with Postcard-RPC" https://sdr-podcast.com/episodes/postcard-rpc/ - Disney animation "Paperman" https://en.wikipedia.org/wiki/Paperman and the trailer on YouTube https://www.youtube.com/watch?v=mM6cLnscmO8 - HashSet https://doc.rust-lang.org/std/collections/struct.HashSet.html - Declarative macros https://doc.rust-lang.org/reference/macros-by-example.html or "Macros by example" - Procedural macros https://doc.rust-lang.org/reference/procedural-macros.html - tokens https://en.wikipedia.org/wiki/Lexical_analysis - syn https://docs.rs/syn/latest/syn/ and Amos' take on X https://x.com/fasterthanlime/status/1795107832276148541 - Abstract syntax tree AST https://en.wikipedia.org/wiki/Abstract_syntax_tree - const fn, Oli Scherer oli-obk https://github.com/oli-obk - Zig https://en.wikipedia.org/wiki/Zig_programming_language and its `comptime` https://zig.guide/language-basics/comptime/, Miri https://github.com/rust-lang/miri - Departure Mono font https://departuremono.com/ - `Ord` trait https://doc.rust-lang.org/std/cmp/trait.Ord.html - MaybeUninit arrays https://github.com/rust-lang/rust/issues/96097 - Enums with "niche" representations https://rust-lang.github.io/unsafe-code-guidelines/layout/enums.html#discriminant-elision-on-option-like-enums - rubicon https://crates.io/crates/rubicon and the SDR episode "Fixing build times with rubicon https://sdr-podcast.com/episodes/dynamic-linking/ - perfect hashing https://en.wikipedia.org/wiki/Perfect_hash_function, Huffman coding https://en.wikipedia.org/wiki/Huffman_coding, UTF-8 https://en.wikipedia.org/wiki/UTF-8 - Deflate aka Flate https://en.wikipedia.org/wiki/Deflate, LZ4 compression algorithm https://en.wikipedia.org/wiki/LZ4_compression_algorithm - Internet of things https://en.wikipedia.org/wiki/Internet_of_things, MacBook M4 chips https://www.apple.com/newsroom/2024/10/new-macbook-pro-features-m4-family-of-chips-and-apple-intelligence/ - AppleTalk https://en.wikipedia.org/wiki/AppleTalk

Download

0 formats

No download links available.

Compile Time Crimes | NatokHD