-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std: fuck usingnamespace #19214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std: fuck usingnamespace #19214
Conversation
ci failure: #19089 |
Whoops, I accidentally flipped the conditions in that commit. |
7431524
to
3c37d31
Compare
Why fuck? |
The PR title is kind of a joke, but: the |
3c37d31
to
c8880df
Compare
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.
c8880df
to
265f42d
Compare
@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 |
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 |
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. |
The io_uring refactors seem fine (namespacing |
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. |
Re: libxev. I'm sure it'll be fine 😄 I'll report back if I run into any issues upgrading to nightly. |
@Jarred-Sumner For mixing generated and handwritten code, you can make your generator use a file like this as a template: pub const Foo = struct {
// GENERATED:Foo
pub fn foo(self: Foo) void {
// ...
}
};
pub const Bar = struct {
// GENERATED:Bar
pub fn bar(self: Bar) void {
// ...
}
}; Instead of outputting full structs, it simply replaces the |
what's the planned new syntax replacing usingnamesapces? |
While yes it is possible to do that, it's hard to see how that is better than |
@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 |
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 |
Yeah, "mixings" argument feels stronger to me than "source code generation" one! I don't have any particular insights here though! |
@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. |
I guess the other reasonable alternative would be to stop trying to be so DRY in |
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:
|
that's precisely what |
Kinda, but not precisely. |
see title