Uh oh!
There was an error while loading. Please reload this page.
std: fuck usingnamespace - #19214
Conversation
Rexicon226
commented
Mar 7, 2024
ci failure: #19089 |
mlugg
commented
Mar 7, 2024
Whoops, I accidentally flipped the conditions in that commit. |
7431524 to
3c37d31Comparerofrol
commented
Mar 7, 2024
Why fuck? |
mlugg
commented
Mar 7, 2024
The PR title is kind of a joke, but: the |
This is a trivial change - this code did `usingnamespace` into an otherwise empty namespace, so the outer namespace was just unnecessary. Eliminates one more usage of `usingnamespace` from the standard library.
This usage of `usingnamespace` was removed fairly trivially - the resulting code is, IMO, more clear. Eliminates one more usage of `usingnamespace` from the standard library.
Searching GitHub indicated that the only use of these types in the wild is support in getty-zig, and testing for that support. This eliminates 3 more uses of usingnamespace from the standard library, and removes some unnecessarily complex generic code.
Eliminates one more usage of `usingnamespace` from the standard library.
I have no idea why this was even here... Eliminates one more usage of `usingnamespace` from the standard library. 5 remain.
Thanks to Zig's lazy analysis, it's fine for these symbols to be declared on platform they won't exist on. This is already done in several places in this file; e.g. `pthread` functions are declared unconditionally. Eliminates one more usage of `usingnamespace` from the standard library. 4 remain.
Some of the structs I shuffled around might be better namespaced under CONTEXT, I'm not sure. However, for now, this approach preserves backwards compatibility. Eliminates one more usage of `usingnamespace` from the standard library. 3 remain.
* `linux.IO_Uring` -> `linux.IoUring` to align with naming conventions. * All functions `io_uring_prep_foo` are now methods `prep_foo` on `io_uring_sqe`, which is in a file of its own. * `SubmissionQueue` and `CompletionQueue` are namespaced under `IoUring`. This is a breaking change. The new file and namespace layouts are more idiomatic, and allow us to eliminate one more usage of `usingnamespace` from the standard library. 2 remain.
mlugg
commented
Mar 8, 2024
@mitchellh and @kprotty (best ping determined from blame), I notice that libxev and tigerbeetle are two notable consumers of our io_uring API; do the changes I've made here look reasonable? It's just some renames and small reshuffles.
|
I'd argue that Edit: And then maybe instead of calling them |
mlugg
commented
Mar 8, 2024
I agree that would probably make sense, but it can be a future enhancement. For now, I'm more concerned with validating that this new API - mainly motivated by the removal of this |
Jarred-Sumner
commented
Mar 8, 2024
This is probably the wrong issue to mention this but I’d be really sad if usingnamespace is removed from Zig without an adequate replacement. We use it frequently in Bun for interface boundaries between different parts of the codebase and for ergonomically mixing handwritten code with generated code. I definitely agree it’s not perfect, but removing it without addressing any of the problems it solves would not be better for Zig’s users. |
kprotty
commented
Mar 8, 2024
The io_uring refactors seem fine (namespacing |
mlugg
commented
Mar 8, 2024
Okay, I'm going to go ahead with this one - the breakages are pretty trivial, and I have the Protty Stamp Of Approval (tm). I agree with the other proposed changes to the io_uring API, but they can be handled at a later date. |
mitchellh
commented
Mar 8, 2024
Re: libxev. I'm sure it'll be fine 😄 I'll report back if I run into any issues upgrading to nightly. |
silversquirl
commented
Mar 8, 2024
@Jarred-Sumner For mixing generated and handwritten code, you can make your generator use a file like this as a template: pubconstFoo=struct {
// GENERATED:Foopubfnfoo(self: Foo) void {
// ...
}
};
pubconstBar=struct {
// GENERATED:Barpubfnbar(self: Bar) void {
// ...
}
};Instead of outputting full structs, it simply replaces the |
Jarred-Sumner
commented
Mar 9, 2024
While yes it is possible to do that, it's hard to see how that is better than |
perillo
commented
Mar 10, 2024
@mlugg Commit 17f83ac removed |
As someone who has spend a fair amount of time building editor auto-complete for Rust, I am 0.85 sure that removal of That being said, yes, removing The source code generation problem doesn't seem insurmountable to me. I'd say that any of the following solutions would work okay, if not perfect, in practice:
Again, these all are work-around, and |
Jarred-Sumner
commented
Mar 11, 2024
You certainly know more about editor autocomplete than I do and that makes sense. I'm more concerned by the mixin-shaped hole removing usingnamespace would leave (interface boundaries). Rust-like Traits, Go-like interfaces, or TypeScript-like interfaces (semantic analysis validates, but compiles equivalently to |
matklad
commented
Mar 11, 2024
Yeah, "mixings" argument feels stronger to me than "source code generation" one! I don't have any particular insights here though! |
blblack
commented
Mar 18, 2024
@mlugg I tried to naively remove Before I was relying on the platform-conditional declaration via I suppose one answer would be to move the list of supporting platforms to a conditional over the test code, but that doesn't quite feel right, either. If another new platform is added which happens to have this call, the plumbing would work thanks to the universal declaration, but the tests would be skipping this new platform and nobody may notice or care. I also naively tried something like this: ... but this still results in the declaration existing, it just happens to have an undefined value. |
blblack
commented
Mar 18, 2024
I guess the other reasonable alternative would be to stop trying to be so DRY in |
blblack
commented
Mar 18, 2024
Hmm, how horrible would it be for the language to just have an explicit way to say that a block doesn't create a new scope, and thus is only useful for condition/looping/etc. For example: |
nektro
commented
Mar 18, 2024
that's precisely what |
blblack
commented
Mar 18, 2024
Kinda, but not precisely. |
see title