Skip to content
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

Autodoc: only group structs under "namespaces" #20509

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

ianprime0509
Copy link
Contributor

The old heuristic of checking only for the number of fields has the downside of classifying all opaque types, such as std.c.FILE, as "namespaces" rather than "types".

Before:

std.c before this change

After:

std.c after this change

@rohlem
Copy link
Contributor

rohlem commented Jul 5, 2024

I personally exclusively use opaque for declaration containers, because instantiating them isn't sensible, and opaque forbids direct instantiations.
From what I understand this new heuristic implies that opaque types never count as namespaces anymore,
instead encouraging users to use struct for namespaces even if instantiating them isn't meaningful/sensible.
Is there a reason we want to encourage this stylistically?

Then again, I don't have a better heuristic to offer; the actual criterion for whether opaque is used as a type is whether T is ever used as a pointee in *T or not.
Technically we only know this to be false for uninstantiable types, meaning all namespaces should really be stateless enum-s or union-s.
I think the cleanest solution would be to re-introduce a namespace type (previously only available via file-scopes before #1047),
but having such a type just for documentation purposes might be considered not useful enough to model it in the language.

@ianprime0509
Copy link
Contributor Author

@rohlem Yes, that's correct: with this change, only structs will be eligible to be classified as "namespaces" on their parent container's page.

My main argument in favor of treating struct as the default "namespace container" is that that's what you get when you use a separate file for grouping declarations. It's true that it's nonsensical to instantiate a struct that's only supposed to be used as a namespace, but that's already possible for all existing namespaces which are created using files (e.g. const s: std = .{} is technically legal).

Additionally, this seems to be the dominant style at least within the current compiler and standard library code: as a first approximation, if we assume that namespace names are snake_case (following the style guide), then the following regexes can be used to find examples:

The old heuristic of checking only for the number of fields has the
downside of classifying all opaque types, such as `std.c.FILE`, as
"namespaces" rather than "types".
@ianprime0509 ianprime0509 force-pushed the autodoc-only-struct-ns branch from c1bd9b0 to a2307af Compare July 8, 2024 02:15
@andrewrk
Copy link
Member

andrewrk commented Jul 9, 2024

Nice, thanks!

@andrewrk andrewrk merged commit 2511830 into ziglang:master Jul 9, 2024
10 checks passed
@ianprime0509 ianprime0509 deleted the autodoc-only-struct-ns branch July 12, 2024 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants