-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Redesign How Autodoc Works #19208
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
Redesign How Autodoc Works #19208
Conversation
does the interactive source listings also close #18587 ? |
Does that mean it no longer uses relies on If it is still using You can use a Service Worker to override the For indexing, separately, you can have a cron job run ~daily that generates the static versions of all the HTML pages and saves the output. Can probably reuse the code from the service worker to do this, as it's a similar operation |
No, it's still a location.hash based system.
What's the problem statement? |
Having the generated urls be pathnames instead of the hash structure allows for better Google etc. search Generating
instead of
would be ideal |
except for the tar format being correct
This time, unlike the old implementation, it properly does autodoc generation during the compilation pipeline, saving time.
It's always a good day when you get to use File.writeFileAll 😎
Provides a convenient way to spawn a new thread that bypasses a thread pool. Appropriate when the spawned thread delegates all of its work.
since we have `zig std` now to fill that role.
this is now the default
Another note about this is it also makes search bar suggestions based on history a little better. Ime, FF tends to not push results if hash based routing is used but it does push more results when path based routing is used. |
03da623
to
9a52100
Compare
upstream commit 1f921d540e1a8bb40839be30239019c820eb663d after this branch is merged, ziglang/zig becomes the new repository for this code.
A lot of these "shorthand" doc comments were redundant, low quality filler content. Better to let the actual modules speak for themselves with top level doc comments rather than trying to document their aliases.
9a52100
to
aa852f7
Compare
Fixes a merge conflict with one of mlugg's recent branches.
Here is a link to play with the new implementation: https://andrewkelley.me/temp/autodoc-preview-1397342/index.html |
Probably unwanted behavior: std.mem.doNotOptimizeAway includes links to std.mem.builtin.zig_backend, but because std.mem.builtin.zig_backend is part of std.mem.builtin, which is |
that corresponds to this follow-up issue:
|
Just curious, why did you choose to compile stdlib in the browser using wasm, as opposed to in the server itself, and serve the resulting I see this benefit so far:
Are there more? |
iiuc it was so that once u visit https://ziglang.org/documentation/master/std/ or any other hosted version you'd have all the info after page load and would be able to view everything even if u lost internet after that point |
This branch deletes the Autodoc implementation and replaces it with a new one.
High Level Strategy
The old implementation looked like this:
After compilation (sizes are for standard library documentation):
Total output size: 47M (5.7M gzipped)
src/Autodoc.zig
processed ZIR code, outputting JSON data for a web application to consume. This resulted in a lot of code ineffectively trying to reconstruct the AST from no-longer-available data.lib/docs/commonmark.js
was a third-party markdown implementation that supported too many features; for example I don't want it to be possible to have HTML tags in doc comments, because that would make source code uglier. Only markdown that looks good both as source and rendered should be allowed.lib/docs/ziglexer.js
was an implementation of Zig language tokenization in JavaScript, despite Zig already exposing its own tokenizer in the standard library. When I saw this added to the zig project, a little part of me died inside.src/autodoc/render_source.zig
was a tool that converted .zig files to a syntax-highlighted but non-interactive .zig.html files.The new implementation looks like this:
After compilation (sizes are for standard library documentation):
Total output size: 12M (2.3M gzipped)
As you can see, it is both dramatically simpler in terms of implementation as well as build artifacts. Now there are exactly 4 files instead of approximately one gajillion, with a 4x reduction in total file size of the generated web app.
However, not only is it simpler, it's actually more powerful than the old system, because instead of processing ZIR, this system processes the source files directly, meaning it has 100% of the information and never needs to piece anything together backwards.
This strategy uses a WebAssembly module written in Zig. This allows it to reuse components from the compiler, such as the tokenizer, parser, and other utilities for operating on Zig code.
The sources.tar file, after being decompressed by the HTTP layer, is fed directly into the wasm module's memory. The tar file is parsed using std.tar and source files are parsed in place, with some additional computations added to hash tables on the side.
There is room for introducing worker threads to speed up the parsing, although single-threaded it's already so fast that it doesn't really seem necessary.
Zig Installation
Before this branch, a Zig installation comes with a
docs/std/
directory that contains those 47M of output artifacts mentioned above.This branch removes those artifacts from Zig installations, instead offering the
zig std
command, which hosts std lib autodocs and spawns a browser window to view them. When this command is activated,lib/compiler/std-docs.zig
is compiled from source to perform this operation (#19063).The HTTP server creates the requested files on the fly, including rebuilding main.wasm if any of its source files changed, and constructing sources.tar, meaning that any source changes to the documented files, or to the autodoc system itself are immediately reflected when viewing docs. Prefixing the URL with
/debug
results in a debug build of the WebAssembly module.This means contributors can test changes to Zig standard library documentation, as well as autodocs functionality, by pressing refresh in their browser window.
In total, the Zig installation size is reduced from 317M to 268M (-15%).
Time to Build the Compiler
Since many lines were deleted from the compiler, we might hope for it to compile faster.
Not much difference here.
A ReleaseSmall build of the compiler shrinks from 10M to 9.8M (-1%).
Time to Build Autodocs
Autodocs generation is now done properly as part of the pipeline of the compiler rather than tacked on at the end. It also no longer has any dependencies on other parts of the pipeline.
This is how long it now takes to generate standard library documentation:
Regressed Features
New Features
Reliable Linkification
This stems from the fact that with full source files we have all the information, and can write more robust code to look up identifiers from the context they occur in.
Interactive Source Listings
Press
u
to go to source code for any declaration:The links take you to the API page for that specific link by changing the location hash.
Embedded Source Listings
Search Includes Doc Comments
Pretty straightforward. The current autodoc seems to not support this for some reason.
Planning to also add struct field names, struct field docs, parameter names, and parameter docs to this.
Error Set View
Merged error sets are detected:
Errors that come from other declarations are linked:
Errors are also shown on function view:
Correct Type Detection
Previous implementation guesses wrong on the type of
options
as well asDynLib
.Correct Implementation of Scroll History
See andrewrk/autodoc@6d96a63
Follow-Up Work
I do not consider these to be merge blockers.
missing_feature_url_escape
)#std.time
)type
, categorize it as a type despite its valueArrayList(T)
std.log.Level
)std.array_hash_map.ArrayHashMap.count
)@imports
into links, but keep same syntax highlighting#std.os.system.fd_t
)#std.array_hash_map.ArrayHashMapUnmanaged.count
)closes #3403
closes #13512
closes #15865
closes #16490
closes #16728
closes #16741
closes #16763
closes #16898
closes #17061