Skip to content

std.c reorganization #20679

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

Merged
merged 4 commits into from
Jul 19, 2024
Merged

std.c reorganization #20679

merged 4 commits into from
Jul 19, 2024

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Jul 19, 2024

It is now composed of these main sections:

  • Declarations that are shared among all operating systems.
  • Declarations that have the same name, but different type signatures depending on the operating system. Often multiple operating systems share the same type signatures however.
  • Declarations that are specific to a single operating system.
    • These are imported one per line so you can see where they come from, protected by a comptime block inside the OS-specific file to prevent accessing the wrong one.
  • A namespace called private at the bottom that is a bag of decls for logic above to pick and choose from.

Closes #19352 by changing the convention for nonexisting symbols from @compileError to making types void and functions {}, so that it becomes possible to update @hasDecl sites to use @TypeOf(f) != void or T != void. Happily, this ended up removing some duplicate logic and update some bitrotted feature detection checks.

A handful of types have been modified to gain namespacing, type safety, and conform to field naming conventions. This is a breaking change.

Oh, and the last usage of usingnamespace site is eliminated (related: #20663).

I do apologize for doing this in one massive commit. It was going to be an enormous slog to do it symbols at a time, so I went with a batch strategy. I also didn't come up with the final organization ideas until I was partway through the changes.

@andrewrk andrewrk requested a review from kprotty as a code owner July 19, 2024 06:48
@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. standard library This issue involves writing Zig code for the standard library. release notes This PR should be mentioned in the release notes. labels Jul 19, 2024
andrewrk added 2 commits July 19, 2024 00:30
It is now composed of these main sections:
* Declarations that are shared among all operating systems.
* Declarations that have the same name, but different type signatures
  depending on the operating system. Often multiple operating systems
  share the same type signatures however.
* Declarations that are specific to a single operating system.
  - These are imported one per line so you can see where they come from,
    protected by a comptime block to prevent accessing the wrong one.

Closes #19352 by changing the convention to making types `void` and
functions `{}`, so that it becomes possible to update `@hasDecl` sites
to use `@TypeOf(f) != void` or `T != void`. Happily, this ended up
removing some duplicate logic and update some bitrotted feature
detection checks.

A handful of types have been modified to gain namespacing and type
safety. This is a breaking change.

Oh, and the last usage of `usingnamespace` site is eliminated.
@Rexicon226 Rexicon226 mentioned this pull request Jul 19, 2024
4 tasks
* common symbols are now public from std.c even if they live in
  std.posix
* LOCK is now one of the common symbols since it is the same on 100% of
  operating systems.
* flock is now void value on wasi and windows
* std.fs.Dir now uses flock being void as feature detection, avoiding
  trying to call it on wasi and windows
@andrewrk andrewrk merged commit 0d1db79 into master Jul 19, 2024
10 checks passed
@andrewrk andrewrk deleted the std.c-reorg branch July 19, 2024 23:30
rootbeer added a commit to rootbeer/zig that referenced this pull request Jul 22, 2024
PR ziglang#20679 ("std.c reorganization")
switched feature-detection code to use "T != void" checks in place of
"@hasDecl".  However, the std.posix.system struct is empty, so
compile-time feature detection against symbols in there (specifically
`std.posix.system.ucontext_t` in this case), fail at compile time on
freestanding targets.

This PR adds a void ucontext_t into the std.posix.system default.

This PR also adds pseudo-"freestanding" variation of the StackIterator
"unwind" test.  It is sort of hacky (its freestanding, but assumes it can
invoke a Linux exit syscall), but it does detect this problem.

Fixes ziglang#20710
rootbeer added a commit to rootbeer/zig that referenced this pull request Jul 22, 2024
PR ziglang#20679 ("std.c reorganization")
switched feature-detection code to use "T != void" checks in place of
"@hasDecl".  However, the std.posix.system struct is empty, so
compile-time feature detection against symbols in there (specifically
`std.posix.system.ucontext_t` in this case), fail at compile time on
freestanding targets.

This PR adds a void ucontext_t into the std.posix.system default.

This PR also adds pseudo-"freestanding" variation of the StackIterator
"unwind" test.  It is sort of hacky (its freestanding, but assumes it can
invoke a Linux exit syscall), but it does detect this problem.

Fixes ziglang#20710
andrewrk pushed a commit that referenced this pull request Jul 23, 2024
PR #20679 ("std.c reorganization")
switched feature-detection code to use "T != void" checks in place of
"@hasDecl".  However, the std.posix.system struct is empty, so
compile-time feature detection against symbols in there (specifically
`std.posix.system.ucontext_t` in this case), fail at compile time on
freestanding targets.

This PR adds a void ucontext_t into the std.posix.system default.

This PR also adds pseudo-"freestanding" variation of the StackIterator
"unwind" test.  It is sort of hacky (its freestanding, but assumes it can
invoke a Linux exit syscall), but it does detect this problem.

Fixes #20710
linusg added a commit to linusg/zigline that referenced this pull request Jul 24, 2024
linusg added a commit to linusg/zigline that referenced this pull request Jul 24, 2024
alimpfard pushed a commit to alimpfard/zigline that referenced this pull request Jul 24, 2024
SammyJames pushed a commit to SammyJames/zig that referenced this pull request Aug 7, 2024
PR ziglang#20679 ("std.c reorganization")
switched feature-detection code to use "T != void" checks in place of
"@hasDecl".  However, the std.posix.system struct is empty, so
compile-time feature detection against symbols in there (specifically
`std.posix.system.ucontext_t` in this case), fail at compile time on
freestanding targets.

This PR adds a void ucontext_t into the std.posix.system default.

This PR also adds pseudo-"freestanding" variation of the StackIterator
"unwind" test.  It is sort of hacky (its freestanding, but assumes it can
invoke a Linux exit syscall), but it does detect this problem.

Fixes ziglang#20710
igor84 pushed a commit to igor84/zig that referenced this pull request Aug 11, 2024
PR ziglang#20679 ("std.c reorganization")
switched feature-detection code to use "T != void" checks in place of
"@hasDecl".  However, the std.posix.system struct is empty, so
compile-time feature detection against symbols in there (specifically
`std.posix.system.ucontext_t` in this case), fail at compile time on
freestanding targets.

This PR adds a void ucontext_t into the std.posix.system default.

This PR also adds pseudo-"freestanding" variation of the StackIterator
"unwind" test.  It is sort of hacky (its freestanding, but assumes it can
invoke a Linux exit syscall), but it does detect this problem.

Fixes ziglang#20710
philip-peterson pushed a commit to quine-global/ncdu that referenced this pull request Mar 5, 2025
Part of the reorganization of `std.c` namespace.
See ziglang/zig#20679 .

Signed-off-by: Eric Joldasov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. release notes This PR should be mentioned in the release notes. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

don't do feature detection with @hasDecl
1 participant