aboutsummaryrefslogtreecommitdiff
path: root/src/Autodoc.zig
AgeCommit message (Collapse)Author
2024-03-10better to use AST than ZIR for doc generationAndrew Kelley
2024-03-06compiler: treat decl_val/decl_ref of potentially generic decls as capturesmlugg
This fixes an issue with the implementation of #18816. Consider the following code: ```zig pub fn Wrap(comptime T: type) type { return struct { pub const T1 = T; inner: struct { x: T1 }, }; } ``` Previously, the type of `inner` was not considered to be "capturing" any value, as `T1` is a decl. However, since it is declared within a generic function, this decl reference depends on the context, and thus should be treated as a capture. AstGen has been augmented to tunnel references to decls through closure when the decl was declared in a potentially-generic context (i.e. within a function).
2024-03-06compiler: change representation of closuresmlugg
This changes the representation of closures in Zir and Sema. Rather than a pair of instructions `closure_capture` and `closure_get`, the system now works as follows: * Each ZIR type declaration (`struct_decl` etc) contains a list of captures in the form of ZIR indices (or, for efficiency, direct references to parent captures). This is an ordered list; indexes into it are used to refer to captured values. * The `extended(closure_get)` ZIR instruction refers to a value in this list via a 16-bit index (limiting this index to 16 bits allows us to store this in `extended`). * `Module.Namespace` has a new field `captures` which contains the list of values captured in a given namespace. This is initialized based on the ZIR capture list whenever a type declaration is analyzed. This change eliminates `CaptureScope` from semantic analysis, which is a nice simplification; but the main motivation here is that this change is a prerequisite for #18816.
2024-03-01Autodoc: handle more direct int value Refsmlugg
2024-03-01Autodoc: do not rely on redundant block within function bodymlugg
2024-02-26move Zir to std.zig.ZirAndrew Kelley
Part of an effort to ship more of the compiler in source form.
2024-02-16Zir: make src_node of type declarations non-optionalmlugg
Previously, the `src_node` field of `struct_decl`, `union_decl`, `enum_decl`, and `opaque_decl` was optional, included in trailing data only if a flag in `Small` was set. However, this was unnecessary logic: AstGen always provided the source node. We can simplify a few bits of logic by making this field non-optional, moving it into non-trailing data. There was one place where the field was actually omitted before: the root struct of a file was at source node 0, so the node was coincidentally elided. Therefore, this commit has a fixed cost of 4 bytes of ZIR per file.
2024-02-16Sema: eliminate `src` fieldmlugg
`sema.src` is a failed experiment. It introduces complexity, and makes often unwarranted assumptions about the existence of instructions providing source locations, requiring an unreasonable amount of caution in AstGen for correctness. Eliminating it simplifies the whole frontend. This required adding source locations to a few instructions, but the cost in ZIR bytes should be counteracted by the other work on this branch.
2024-02-14autodoc: fix analysis of closure_get instructionsLoris Cro
2024-02-04Zir: store extra source hashes required for incrementalmlugg
Also add corresponding invaidation logic to Zcu. Therefore, the only invalidation logic which is not yet in place is `decl_val` dependencies.
2024-01-29fix(autodoc): avoid panic when module not found (#18699)Jiacai Liu
2024-01-23Zir: represent declarations via an instructionmlugg
This commit changes how declarations (`const`, `fn`, `usingnamespace`, etc) are represented in ZIR. Previously, these were represented in the container type's extra data (e.g. as trailing data on a `struct_decl`). However, this introduced the complexity of the ZIR mapping logic having to also correlate some ZIR extra data indices. That isn't really a problem today, but it's tricky for the introduction of `TrackedInst` in the commit following this one. Instead, these type declarations now simply contain a trailing list of ZIR indices to `declaration` instructions, which directly encode all data related to the declaration (including containing the declaration's body). Additionally, the ZIR for `align` etc have been split out into their own bodies. This is not strictly necessary, but it's much simpler to understand for an insignificant cost in bytes, and will simplify the resolution of #131 (where we may need to evaluate the pointer type, including align etc, without immediately evaluating the value body).
2024-01-13autodoc: Rename Module (Compilation Module) to Zcu in preparation for big renameKrzysztof Wolicki
2024-01-08add type safety to ZIR for null terminated stringsAli Chraghi
2024-01-05autodoc: Reimplement array_mul after ZIR changes. Change some `var`s to ↵Krzysztof Wolicki
`const` where possible. (#17939)
2023-11-25convert `toType` and `toValue` to `Type.fromInterned` and `Value.fromInterned`Techatrix
2023-11-19compiler: correct unnecessary uses of 'var'mlugg
2023-11-08Sema: optimize runtime array_mulmlugg
There are two optimizations here, which work together to avoid a pathological case. The first optimization is that AstGen now records the result type of an array multiplication expression where possible. This type is not used according to the language specification, but instead as an optimization. In the expression '.{x} ** 1000', if we know that the result must be an array, then it is much more efficient to coerce the LHS to an array with length 1 before doing the multiplication. Otherwise, we end up with a 1000-element tuple which we must coerce to an array by individually extracting each field. Secondly, the previous logic would repeatedly extract element/field values from the LHS when initializing the result. This is unnecessary: each element must only be extracted once, and the result reused. These changes together give huge improvements to compiler performance on a pathological case: AIR instructions go from 65551 to 15, and total AIR bytes go from 1.86MiB to 264.57KiB. Codegen time spent on this function (in a debug compiler build) goes from minutes to essentially zero. Resolves: #17586
2023-11-07sema: analyze field init bodies in a second passkcbanner
This change allows struct field inits to use layout information of their own struct without causing a circular dependency. `semaStructFields` caches the ranges of the init bodies in the `StructType` trailing data. The init bodies are then resolved by `resolveStructFieldInits`, which is called before the inits are actually required. Within the init bodies, the struct decl's instruction is repurposed to refer to the field type itself. This is to allow us to easily rebuild the inst_map mapping required for the init body instructions to refer to the field type. Thanks to @mlugg for the guidance on this one!
2023-10-30autodoc: Some support for field_call (#16853)Krzysztof Wolicki
* autodoc: Some support for field_call * autodoc: Change handling of field_call to respect tryResolveRefPath, add fieldVal to Expr * autodoc: Fixed errors * autodoc: sync with latest master changes --------- Co-authored-by: Loris Cro <kappaloris@gmail.com>
2023-10-28make Zir.Inst.Index typedAndrew Kelley
This commit starts by making Zir.Inst.Index a nonexhaustive enum rather than a u32 alias for type safety purposes, and the rest of the changes are needed to get everything compiling again.
2023-10-28frontend: make Decl.zir_decl_index typedAndrew Kelley
This field had the wrong type. It's not a `Zir.Inst.Index`, it's actually a `Zir.OptionalExtraIndex`. Also, the former is currently aliased to `u32` while the latter is a nonexhaustive enum that gives us more type checking. This commit is preparation for making this field non-optional. Now it can be changed to `Zir.ExtraIndex` and then the compiler will point out all the places that the non-optional assumption is being violated.
2023-10-22autodoc: Add support for struct_init_empty_ref_result (#17476)Krzysztof Wolicki
2023-10-08CLI: finish updating module API usageAndrew Kelley
Finish the work started in 4c4fb839972f66f55aa44fc0aca5f80b0608c731. Now the compiler compiles again. Wire up dependency tree fetching code in the CLI for `zig build`. Everything is hooked up except for `createDependenciesModule` is not yet implemented.
2023-10-04autodoc: Add handling for array_cat, array_mul, struct_init_empty_result. ↵Krzysztof Wolicki
(#17367) Fix issue with getting docs for src-less types in main.js
2023-09-27Rename `@fabs` to `@abs` and accept integersantlilja
Replaces the @fabs builtin with a new @abs builtins which accepts floats, signed integers and vectors of said types.
2023-09-23compiler: preserve result type information through address-of operatormlugg
This commit introduces the new `ref_coerced_ty` result type into AstGen. This represents a expression which we want to treat as an lvalue, and the pointer will be coerced to a given type. This change gives known result types to many expressions, in particular struct and array initializations. This allows certain casts to work which previously required explicitly specifying types via `@as`. It also eliminates our dependence on anonymous struct types for expressions of the form `&.{ ... }` - this paves the way for #16865, and also results in less Sema magic happening for such initializations, also leading to potentially better runtime code. As part of these changes, this commit also implements #17194 by disallowing RLS on explicitly-typed struct and array initializations. Apologies for linking these changes - it seemed rather pointless to try and separate them, since they both make big changes to struct and array initializations in AstGen. The rationale for this change can be found in the proposal - in essence, performing RLS whilst maintaining the semantics of the intermediary type is a very difficult problem to solve. This allowed the problematic `coerce_result_ptr` ZIR instruction to be completely eliminated, which in turn also simplified the logic for inferred allocations in Sema - thanks to this, we almost break even on line count! In doing this, the ZIR instructions surrounding these initializations have been restructured - some have been added and removed, and others renamed for clarity (and their semantics changed slightly). In order to optimize ZIR tag count, the `struct_init_anon_ref` and `array_init_anon_ref` instructions have been removed in favour of using `ref` on a standard anonymous value initialization, since these instructions are now virtually never used. Lastly, it's worth noting that this commit introduces a slightly strange source of generic poison types: in the expression `@as(*anyopaque, &x)`, the sub-expression `x` has a generic poison result type, despite no generic code being involved. This turns out to be a logical choice, because we don't know the result type for `x`, and the generic poison type represents precisely this case, providing the semantics we need. Resolves: #16512 Resolves: #17194
2023-09-23Autodoc: prevent infinite recursion when resolving parameter typemlugg
Note that this will also be necessary for `switch_block` and `switch_block_ref` once those instructions are correctly implemented.
2023-09-17autodoc: split json payload per fieldLoris Cro
this will make s3 re-enable compression for the stdlib's autodoc and improve loading times (and data usage) for users alongside this commit the deploy script for the official website is also being updated
2023-09-16autodoc: Implement builtin function rendering.Krzysztof Wolicki
Implement unary ops handling. Fix getType in main.js Minor cleanup of builtin function handling.
2023-09-16autodoc: Remove unnecessary Expr tagKrzysztof Wolicki
2023-09-16autodoc: Handle `ref` ZIR instructionKrzysztof Wolicki
2023-09-06fix: panic message typoMustafa Uzun
2023-09-03autodoc: Implement `@call`, `@unionInit`, `@mulAdd` support (#16918)Krzysztof Wolicki
* autodoc: Implement `@call`, `@unionInit`, `@mulAdd` support * autodoc: Implement builtinIndex in ex
2023-09-03autodoc: Implement `a[b]`, `a.?`, and `a.*` (#16863)Krzysztof Wolicki
* autodoc: Implement elem_val_node and basic optional_payload_* * autodoc: Add `.*` loads
2023-08-17Autodoc: fix guide path resolutionIan Johnson
The previous logic was using `root_src_directory` both in constructing the resolved path and as the root when opening the resolved path, which effectively duplicates those path components in the final path.
2023-08-14Autodoc: remove assumption that slice's lhs is always a declRefKrzysztof Wolicki
2023-07-22move installation logic to the build script where it belongsAndrew Kelley
* build.zig: introduce `-Dflat` option which makes the installation match what we want to ship for our download tarballs. This allows deleting a bunch of shell script logic from the CI. - for example it puts the executable directly in prefix/zig rather than prefix/bin/zig and it additionally includes prefix/LICENSE. * build.zig: by default also install std lib documentation to doc/std/ - this can be disabled by `-Dno-autodocs` similar to how there is already `-Dno-langref`. * build.zig: add `std-docs` and `langref` steps which build and install the std lib autodocs and langref to prefix/doc/std and prefix/doc/langref.html, respectively. * std.Build: implement proper handling of `-femit-docs` using the LazyPath system. This is a breaking change. - this is a partial implementation of #16351 * frontend: fixed the handling of Autodocs with regards to caching and putting the artifacts in the proper location to integrate with the build system. - closes #15864 * CI: delete the logic for autodocs since it is now handled by build.zig and is enabled by default. - in the future we should strive to have nearly all the CI shell script logic deleted in favor of `zig build` commands. * CI: pass `-DZIG_NO_LIB=ON`/`-Dno-lib` except for the one command where we want to actually generate the langref and autodocs. Generating the langref takes 14 minutes right now (why?!) so we don't want to do that more times than necessary. * Autodoc: fixed use of a global variable. It works fine as a local variable instead. - note that in the future we will want to make Autodoc run simultaneously using the job system, but for now the principle of YAGNI dictates that we don't have an init()/deinit() API and instead simply call the function that does the things. * Autodoc: only do it when there are no compile errors
2023-07-21std.json: Unify stringify and writeStream (#16405)Josh Wolfe
2023-07-21autodoc: avoid recursing reference loops in call instructionsLoris Cro
2023-07-18Autodoc: fix crash on new InternPool additionAndrew Kelley
2023-07-14Autodoc tokenizer (#16409)Loris Cro
* autodoc: init work to refactor exprName * autodoc: Implement more expressions in exprName refactor * autodoc: more work * autodoc: More exprName to ex refactoring * autodoc: Remove whitespace flag from renderer; Add pre tags in value and variable drawing in renderContainer * autodoc: add inline styling to pre blocks * autodoc: move renderer code to main.js * autodoc: More exprName to ex refactoring; Fn signatures rendered with new code * autodoc: Fix function rendering. Add more things to ex * autodoc: nuke exprName --------- Co-authored-by: Krzysztof Wolicki <der.teufel.mail@gmail.com>
2023-07-06Autodoc: implement boolean operationsIan Johnson
2023-07-03autodoc: wire in js tokenizer to frontendLoris Cro
2023-07-01autodoc: fix scoring bug when matching full decl nameLoris Cro
2023-07-01Fixed Autodoc rendering of @truncate builtin (#16263)Emile Badenhorst
* fixed autodoc rendering of @trucate builtin * Changed to LHS for typeRef * autodoc: fix typeref for `truncate` --------- Co-authored-by: Loris Cro <kappaloris@gmail.com>
2023-06-28autodoc: Correct a comment about types from std.builtinKrzysztof Wolicki
2023-06-28autodoc: Try to handle all InternPool.Index types good enoughKrzysztof Wolicki
2023-06-27autodoc: Added u0, i0 to correctly indexed typesKrzysztof Wolicki
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change