# Twtxt is an open, distributed microblogging platform that # uses human-readable text files, common transport protocols, # and free software. # # Learn more about twtxt at https://github.com/buckket/twtxt # # This is an automated Yarn.social feed running feeds v0.1.0@72e53a9 # Learn more about Yarn.social at https://yarn.social # # nick = async-const-fn-oli # url = https://feeds.twtxt.net/async-const-fn-oli/twtxt.txt # type = rss # source = https://cohost.org/oli-obk/rss/public.atom # avatar = https://feeds.twtxt.net/async-const-fn-oli/avatar.png#p2ptrq3lqkdghurxvk5hvtezxhy7xy3cyng7axp2nlgx4fspgoya # description = # updated_at = 2023-10-24T10:29:00Z # 2022-12-23T08:33:24Z **Rust in 2023**
Low effort because I don't have the motivation to write an actual blog post.

FOCUS ON CLEANUP

There's a lot of technical debt in Rust, we should deal with it now.

WHY?

 \\* Rust is at a point where it will continue to be relevant for a long time1
 \\* any new feature we add will only have a comparatively small impact as pretty much all core features are already in place
 \\* cleaning up the implementation will speed up development in the long term
 \\* the fewer people are currently using Rust, the eas ... ⌘ [Read more](https://cohost.org/lcnr/post/690887-rust-in-2023) 2022-12-15T14:36:24Z **TAIT is ready for stabilization**
disclaimer: from my perspective, lang team concerns may apply

So I wrote a stabilization report explaining what the heck the latest iteration of TAIT actually does: https://hackmd.io/tB3V8MP5S66zHIWTUdRvQw#type-alias-impl-trait [https://hackmd.io/tB3V8MP5S66zHIWTUdRvQw#type-alias-impl-trait]

Please read it and let me know anything that could use more elaboration or where you're just curious on things I didn't cover. ⌘ [Read more](https://cohost.org/oli-obk/post/619079-tait-is-ready-for-st) 2022-12-14T16:36:28Z **There's no kill like overkill**
@lcnr asked me to add one tiny function to rustc that would get used like 6x throughout the entire compiler and now I'm at a +262 -282 diff cleaning up and hardening all kinds of things: https://github.com/rust-lang/rust/pull/105657 [https://github.com/rust-lang/rust/pull/105657]

but doing so also found a 2+ year old bug that I think is not exploitable but very odd. ⌘ [Read more](https://cohost.org/oli-obk/post/612654-there-s-no-kill-like) 2022-12-09T15:16:18Z **Who needs global hacky state...**
Share from @oli-obk: https://cohost.org/oli-obk/post/569339-it-s-not-a-god-objec

... when you can also leak stuff to get 'static lifetimes [https://github.com/rust-lang/rust/pull/105462/commits/9b27fe51e70e1ef01326b1b1ffd1e399f51dea39#diff-21f0d3f6e2097bb728cfbdda563deea42ee72b00aac70c4c229d8c8cfc360cbd] ⌘ [Read more](https://cohost.org/oli-obk/post/578078-who-needs-global-hac) 2022-12-08T09:05:47Z **Callable memoized functions with no body**
Rust's queries are memoized. So once you called a query with a specific argument, when you call it again with that argument, we just do a hashmap lookup and return the cached value.

Then, recently, we got the ability to "feed" queries, effectively just stuffing things in the hashmap without calling the query. This is useful for when the query doesn't know how to compute something or would run into a cycle error. But you can then go further and just remove the query's ... ⌘ [Read more](https://cohost.org/oli-obk/post/569349-callable-memoized-fu) 2022-12-08T09:01:10Z **It's not a god object unless it comes from the Dieu region of France**
The Rust compiler has a Certified God Object ™️©️ called TyCtxt. But it only exists after name resolution is done. So name resolution has to put up with doing a bunch of stuff itself that TyCtxt has methods and queries for.

I'm working on resolving this, but it turns out things (rustdoc I'm looking at you) depend on being able to do weird things to the resolver outside the query system. But good news: I'm not letting such things stop me wh ... ⌘ [Read more](https://cohost.org/oli-obk/post/569339-it-s-not-a-god-objec) 2022-11-30T10:56:55Z **When your rebase takes so long that you have to rebase immediately again -.-**
"Luckily" most of the breakage is from my own other PRs

Actually luckily the second rebase is usually painless and quick ⌘ [Read more](https://cohost.org/oli-obk/post/499227-when-your-rebase-tak) 2022-11-24T15:48:13Z **First time I see my new types in action**
Previous Post [https://cohost.org/oli-obk/post/439117-if-strong-typing-has]

Unfortunately we don't already have a way to mark a bunch of impls as builtin, so I'd need to write out those impls... which... I can't because I didn't add anything to the parser yet. Time to find a lang team shepherd ⌘ [Read more](https://cohost.org/oli-obk/post/439648-first-time-i-see-my) 2022-11-24T14:39:19Z **If strong typing has downsides, try expanding your type system**
Previous Post [https://cohost.org/oli-obk/post/203456-strong-typing-has-do]

NonZeroU8 is (modulo macros) defined as

#[rustc\_layout\_scalar\_valid\_range\_start(1)]
pub struct NonZeroU8(u8);

As shown in the previous post, removing that attribute and replacing the u8 field with Ranged is a small but noticeable perf regression because LLVM has to handle more field accesses. So what if we did the opposite? Make compiler magic replace that struct ... ⌘ [Read more](https://cohost.org/oli-obk/post/439117-if-strong-typing-has) 2022-11-21T15:23:58Z **Annoying compiler APIs**
we have a bunch of APIs for \> data within the compiler. We represent those as three arguments:

 1\. an id for the trait
 2\. the Type
 3\. the generic parameters T and U as a slice

so this usually looks like

some\_function(arg, id, ty, &[])

sometimes looks like

some\_function(arg, id, ty, &[first\_param, second\_param])

and in a few rare cases like

some\_function(arg, id, ty, substs)

because we already got that slice as a finished value.

Now... by the power of impl IntoIterat ... ⌘ [Read more](https://cohost.org/oli-obk/post/396950-annoying-compiler-ap) 2022-11-19T13:19:28Z **Cohost just ate my 30 min blog post because I accidentally touched the X on mobile ** ⌘ [Read more](https://cohost.org/oli-obk/post/368289-cohost-just-ate-my-3) 2022-11-17T15:12:43Z ****
@oli-obk ended up refactoring [https://github.com/rust-lang/rust/pull/104533] the way we build TraitRefs in rustc, discovering multiple places where we're incorrectly missing generic arguments for trait obligations.

The most notable one is the PartialEq fallback for pattern matching. This should be PartialEq but we're actually checking PartialEq<> right now, resulting in this beautiful ICE [https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=24d77d7a8e5221a54b92ab6cc1b69c0a]: ⌘ [Read more](https://cohost.org/lcnr/post/331488-oli-obk-ended-up-r) 2022-11-13T13:38:43Z **Architecture Toggle**
x86\_64

AArch64

add(int, int): # @add(int, int)
 push rbp
 mov rbp, rsp
 mov dword ptr [rbp - 4], edi
 mov dword ptr [rbp - 8], esi
 mov eax, dword ptr [rbp - 4]
 add eax, dword ptr [rbp - 8]
 pop rbp
 ret

x86\_64

AArch64

add(int, int): # @add(int, int)
 push rbp
 mov rbp, rsp
 mov dword ptr [rbp - 4], edi
 mov dword ptr [rbp - 8], esi
 mov eax, dword ptr [rbp - 4]
 add eax, dword ptr [rbp - 8]
 pop rbp
 ret

x86\_64

AArch64

add(int, int): // @add(int, int)
 sub sp, sp, #16 // =16
 str ... ⌘ [Read more](https://cohost.org/mary/post/287592-architecture-toggle) 2022-11-14T13:30:48Z **I removed a check that prevents some diagnostic from being printed and now I'm seeing even fewer diagnostics. wat** ⌘ [Read more](https://cohost.org/oli-obk/post/298454-i-removed-a-check-th) 2022-11-07T18:15:14Z **for folks coming here from Twitter**
I'm a heavy Twitter user, have been for years; you can trust me on what I say here. I'm making an effort to use Cohost differently. Many of the parts of myself I express on here are ones I don't have a chance to express on Twitter.

take a while to look around, get a sense of the feeling, the gestalt of the site. how people talk and behave. this place is different, and we should all be mindful of it. it's healthier. people on here are kind. I'm not sure I've seen a sin ... ⌘ [Read more](https://cohost.org/atomicthumbs/post/224392-for-folks-coming-her) 2022-11-07T10:03:36Z **Strong typing has downsides, too**
Previous Post [https://cohost.org/oli-obk/post/165584-ranged-integers-via]

As I see it, we have three options for doing ranged ints:

 1\. Attributes that change the layout of user defined struct fields. Corresponding RFC [https://github.com/rust-lang/rfcs/pull/3334]
 2\. Magic standard library type which takes a const generic range to change its layout. Corresponding PR [https://github.com/rust-lang/rust/pull/103724]
 3\. A new kind of builtin type that is made up of anothe ... ⌘ [Read more](https://cohost.org/oli-obk/post/203456-strong-typing-has-do) 2022-10-31T21:43:19Z **Ranged integers via subtypes**
Previous Post [https://cohost.org/oli-obk/post/148312-ranged-integers]

Last time I talked about a new libcore type that I prototyped, that allows you to specify niches on integers. But... the more I worked on it and thought about the desires of people in the Niche-RFC, the more I feel like we need more Waaaaaaarrrgh general ways to specify niches. OK, there was lots in that sentence that requires previous knowledge of the discussions. So let's untangle this a bit:

We want to be ... ⌘ [Read more](https://cohost.org/oli-obk/post/165584-ranged-integers-via) 2022-10-30T11:34:36Z **Ranged integers**
A few years ago I got into Ada. Fun language for safety critical software and verbose (not derogatory) code.

It has a bunch of features that, to this day, I miss in Rust. Most notably, ranged integers are a first class feature of the language, with automatic conversion between different ranges via runtime checks. So "naturally", when I started with Rust, the first thing I tried was to build ranged integers. Turns out const eval

a) wasn't up to it, and b) was an unholy mess.

It took me months to ... ⌘ [Read more](https://cohost.org/oli-obk/post/148312-ranged-integers) 2022-10-28T11:36:23Z **To fall back or not to (spoiler: don't)**
Previous Post [https://cohost.org/oli-obk/post/132474-ambiguous-associated]

Early in my effect branch work, I added something I thought was necessary: fallback. Basically what it means is that as long as we don't know whether an effect should be const or not or generic, we just pick an inference variable and hope that typeck figures it out. E.g. by doing a function call, where we can then decide that we need constness depending on whether we're inside a const fn or con ... ⌘ [Read more](https://cohost.org/oli-obk/post/142076-to-fall-back-or-not) 2022-10-19T11:40:12Z **Ambiguous associated effect**
Previous Post [https://cohost.org/oli-obk/post/129527-effects-and-trait-bo]

As noted by @CandyCorvid in my last post, I had something swapped:

If anything has the option of choosing either a T: Trait bound or a T: ~const Trait bound, it should always err on picking the T: ~const Trait bound lacking additional information. Such additional information could be "we're trying to prove T: Trait" in which case we should obviously not try to prove it against T: ~const Trait, but T: Tra ... ⌘ [Read more](https://cohost.org/oli-obk/post/132474-ambiguous-associated) 2023-01-24T11:36:51Z **TAIT defining scopes**
Previous Post [https://cohost.org/oli-obk/post/619079-tait-is-ready-for-st]

Our procedures are working! During stabilization community members raised concerns and we had a super constructive discussion about it:

contributors: It's weird that the function body can do something with TAITs (something == registering the hidden type), without that being discernible from the signature

me: We thought so, too early in the TAIT design and impl process (read: years ago), but hated the idea of r ... ⌘ [Read more](https://cohost.org/oli-obk/post/899646-tait-defining-scopes) 2023-02-07T12:48:47Z **Using more than 4GB of RAM in a 32 bit program**
Const eval has a funny quirk. It doesn't have physical addresses for its memory allocations, just an id per allocation. So you can allocate 3GB of memory with id 1, and then another 3GB of memory with id 2, and so on. As long as your host that is doing the cross compiling has enough actual physical memory.

Example:

const FOO: () = {
 foo(10);
};

const fn foo(x: usize) {
 if x != 0 {
 let mut array = [0\_u8; usize::MAX / 4];
 foo(x - 1);
 array[array.len() - 1] ... ⌘ [Read more](https://cohost.org/oli-obk/post/978786-using-more-than-4gb) 2023-02-21T08:36:17Z **IT HAS LANDED**
Share from @oli-obk: https://cohost.org/oli-obk/post/569339-it-s-not-a-god-objec

We can now use queries during the resolver (name resolution + macro expansion). It's not very useful yet, because almost every query depends on the resolver query, so you'd get cycles, but at least we can start untangling all of that now.

See https://github.com/rust-lang/rust/pull/105462 [https://github.com/rust-lang/rust/pull/105462] for details ⌘ [Read more](https://cohost.org/oli-obk/post/1065638-it-has-landed) 2023-02-21T16:08:59Z **Well.**
I just sent out this mail.

\> Small question, because I searched the paper's citations and the related material's section on the journals and other places: does anyone know where I can find C-rusted? Or is it a proprietary tool? I'd like to at least give it a try before I am made to critique it.
>
\> Sincerely, {My Name}

I clearly do not value my time, but if someone's going to tell me that they've Totally Solved C's Problems™ then I'm obliged to put my own time and money on the line to figure out just how truthful ... ⌘ [Read more](https://cohost.org/ThePhD/post/1066711-well) 2023-03-28T14:06:13Z **type-alias-impl-trait defining scopes**
TAITs have been troubled by obscure rules around when exactly you may register a hidden type for a while. Additionally the implementation was backwards out of concerns that query caching for the trait solver queries would regress in performance if we'd use a new magical where bound. We're now simplifying the impl and making the language rules clearer at the same time. The way we do that is by adding a #[defines(Foo)] attribute that you can slap on functions to allow the ... ⌘ [Read more](https://cohost.org/oli-obk/post/1243955-type-alias-impl-trai) 2023-05-01T00:56:30Z **It took forever,**
but it's here. The omnibus Compile-Time Rust Reflection Mid-Point Report.

https://soasis.org/posts/a-mirror-for-rust-a-plan-for-generic-compile-time-introspection-in-rust/ [https://soasis.org/posts/a-mirror-for-rust-a-plan-for-generic-compile-time-introspection-in-rust/]

We did not finish getting the new theme in there, but it's ready to roll.

(EDIT: Copy-pasting code on Chrome works now, thanks @directxman12 !)

(OLD: Copy-pasting code is broken on Chrome, but I can't manage to fix it 😩 so I ... ⌘ [Read more](https://cohost.org/ThePhD/post/1424818-it-took-forever) 2023-07-21T15:11:41Z **Everything is a hammer**
There's that famous saying

\> When you have a hammer, everything looks like a nail

Which refers to the fact that everyone tries to use their favorite tool for just about anything and everything. Like me with Rust Wait how do i unstrikethrough something?

So, I no only have this problem, I also have another one. Every new thing I get introduced to becomes a hammer. And is immediately used for everything that is or isn't a nail.

The indicatif crate enters the stage

A colleague showe ... ⌘ [Read more](https://cohost.org/oli-obk/post/2138935-everything-is-a-hamm) 2023-07-21T15:16:49Z **Taking the hammer to rustc**
Of course after https://cohost.org/oli-obk/post/2138935-everything-is-a-hamm [https://cohost.org/oli-obk/post/2138935-everything-is-a-hamm] I had to add indicatif to Rust. Well, actually someone informed us about how -Ztime-passes is really not truthful anymore and will only get worse as we move into parallel rustc or just by being a compiler that isn't really doing stuff in phases anymore since more than half a decade.

One issue that -Ztime-passes somewhat solves is it allows yo ... ⌘ [Read more](https://cohost.org/oli-obk/post/2138939-taking-the-hammer-to) 2023-10-05T16:45:19Z **hey uhhhhh**
It's a bit weird to write rn, but you can now sponsor me via GitHub sponsors:

https://github.com/sponsors/WaffleLapkin [https://github.com/sponsors/WaffleLapkin] ⌘ [Read more](https://cohost.org/wafflelapkin/post/3076912-hey-uhhhhh) 2023-10-11T11:43:51Z **const const: const::const = const::const;**
Valid Rust syntax :D

mod r#const {
 pub struct r#const;
}

const r#const: r#const::r#const = r#const::r#const; ⌘ [Read more](https://cohost.org/oli-obk/post/3139618-const-const-const) 2023-10-13T16:14:42Z **I wrote an RFC again!!**
been a while, but there we go. An RFC to reserve a new keyword in the 2024 edition and start experimental implementation of generators that we can reasonably stabilize next year, too: https://github.com/rust-lang/rfcs/pull/3513 [https://github.com/rust-lang/rfcs/pull/3513] ⌘ [Read more](https://cohost.org/oli-obk/post/3164976-i-wrote-an-rfc-again) 2023-10-23T14:55:32Z **Please impl, no RFC, only impl!!**
Share from @oli-obk: https://cohost.org/oli-obk/post/3164976-i-wrote-an-rfc-again

So... looks like we'll write the RFC after the fact, so please enjoy gen blocks on nightly, soon coming to a compiler near you: https://github.com/rust-lang/rust/pull/116447 [https://github.com/rust-lang/rust/pull/116447]

fn foo() -> impl Iterator {
 gen {
 yield 42;
 for x in 5..12 {
 if x.is\_odd() {
 yield x \* 2;
 }
 }
 }
} ⌘ [Read more](https://cohost.org/oli-obk/post/3272415-please-impl-no-rfc) 2023-10-24T10:15:31Z **Of course the `gen` impl was unsound**
Share from @oli-obk: https://cohost.org/oli-obk/post/3272415-please-impl-no-rfc

I accidentally made gen blocks not require pinning, but allow self-references. That was very unsound. This is now fixed, but lol, a good indicator that one should not be writing code at midnight. ⌘ [Read more](https://cohost.org/oli-obk/post/3283069-of-course-the-gen)