# 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-01-24T11:43:25Z # 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)