231 Commits

Author SHA1 Message Date
Andrew Kelley
6e4fff6ba6 move installation logic to the build script where it belongs
* 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-22 00:16:27 -07:00
Josh Wolfe
8924f81d8c
std.json: Unify stringify and writeStream (#16405) 2023-07-21 19:56:46 -04:00
Loris Cro
426e737292 autodoc: avoid recursing reference loops in call instructions 2023-07-21 18:45:50 +02:00
Andrew Kelley
d5d067211b Autodoc: fix crash on new InternPool addition 2023-07-18 23:45:47 -07:00
Loris Cro
a187141056
Autodoc tokenizer (#16409)
* 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-14 16:27:09 +02:00
Ian Johnson
91daf1c8d8 Autodoc: implement boolean operations 2023-07-06 17:28:11 +02:00
Loris Cro
28ad74e8a6 autodoc: wire in js tokenizer to frontend 2023-07-03 19:18:44 +02:00
Loris Cro
97a1b046ea autodoc: fix scoring bug when matching full decl name 2023-07-01 17:38:18 +02:00
Emile Badenhorst
35a8e8a06c
Fixed Autodoc rendering of @truncate builtin (#16263)
* 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-07-01 16:43:17 +02:00
Krzysztof Wolicki
0c1bfe271e autodoc: Correct a comment about types from std.builtin 2023-06-28 19:03:24 +02:00
Krzysztof Wolicki
2984a75804 autodoc: Try to handle all InternPool.Index types good enough 2023-06-28 19:03:24 +02:00
Krzysztof Wolicki
7f648c297e autodoc: Added u0, i0 to correctly indexed types 2023-06-27 19:07:39 +02:00
mlugg
f26dda2117 all: migrate code to new cast builtin syntax
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
2023-06-24 16:56:39 -07:00
mlugg
be0c69957e compiler: remove destination type from cast builtins
Resolves: #5909
2023-06-24 16:47:49 -07:00
Eric Joldasov
50339f595a all: zig fmt and rename "@XToY" to "@YFromX"
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:42 -07:00
Eric Joldasov
a6c8ee5231 compiler: rename "@XToY" to "@YFromX", zig fmt: rewrite them
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-19 12:34:24 -07:00
Krzysztof Wolicki
e7fd70a951 autodoc: Handle more InternPool.Index types properly in Autodoc 2023-06-18 14:07:09 +00:00
mlugg
2af5bd8aa8 Autodoc: fix crash when walking @min/@max with two operands
This was causing CI failures after the previous commit.
2023-06-16 13:44:25 -07:00
mlugg
85e94fed1e
Eliminate switch_cond[_ref] ZIR tags
This finishes the process of consolidating switch expressions in ZIR
into as simple and compact a representation as is possible. There are
now just two ZIR tags dedicated to switch expressions: switch_block and
switch_block_ref, with the latter being for an operand passed by
reference.
2023-06-13 12:55:15 +01:00
mlugg
54460e39ac Autodoc: make it work under InternPool 2023-06-11 22:04:15 -07:00
Andrew Kelley
9aec2758cc stage2: start the InternPool transition
Instead of doing everything at once which is a hopelessly large task,
this introduces a piecemeal transition that can be done in small
increments at a time.

This is a minimal changeset that keeps the compiler compiling. It only
uses the InternPool for a small set of types.

Behavior tests are not passing.

Air.Inst.Ref and Zir.Inst.Ref are separated into different enums but
compile-time verified to have the same fields in the same order.

The large set of changes is mainly to deal with the fact that most Type
and Value methods now require a Module to be passed in, so that the
InternPool object can be accessed.
2023-06-10 20:40:03 -07:00
Andrew Kelley
629f0d23b5
Merge pull request #15579 from squeek502/mem-delimiters
Split `std.mem.split` and `tokenize` into `sequence`, `any`, and `scalar` versions
2023-06-03 13:51:02 -07:00
mlugg
38b83d9d93 Zir: eliminate field_call_bind and field_call_bind_named
This commit removes the `field_call_bind` and `field_call_bind_named` ZIR
instructions, replacing them with a `field_call` instruction which does the bind
and call in one.

`field_call_bind` is an unfortunate instruction. It's tied into one very
specific usage pattern - its result can only be used as a callee. This means
that it creates a value of a "pseudo-type" of sorts, `bound_fn` - this type used
to exist in Zig, but now we just hide it from the user and have AstGen ensure
it's only used in one way. This is quite silly - `Type` and `Value` should, as
much as possible, reflect real Zig types and values.

It makes sense to instead encode the `a.b()` syntax as its own ZIR instruction,
so that's what we do here. This commit introduces a new instruction,
`field_call`. It's like `call`, but rather than a callee ref, it contains a ref
to the object pointer (`&a` in `a.b()`) and the string field name (`b`). This
eliminates `bound_fn` from the language, and slightly decreases the size of
generated ZIR - stats below.

This commit does remove a few usages which used to be allowed:
- `@field(a, "b")()`
- `@call(.auto, a.b, .{})`
- `@call(.auto, @field(a, "b"), .{})`

These forms used to work just like `a.b()`, but are no longer allowed. I believe
this is the correct choice for a few reasons:
- `a.b()` is a purely *syntactic* form; for instance, `(a.b)()` is not valid.
  This means it is *not* inconsistent to not allow it in these cases; the
  special case here isn't "a field access as a callee", but rather this exact
  syntactic form.
- The second argument to `@call` looks much more visually distinct from the
  callee in standard call syntax. To me, this makes it seem strange for that
  argument to not work like a normal expression in this context.
- A more practical argument: it's confusing! `@field` and `@call` are used in
  very different contexts to standard function calls: the former normally hints
  at some comptime machinery, and the latter that you want more precise control
  over parts of a function call. In these contexts, you don't want implicit
  arguments adding extra confusion: you want to be very explicit about what
  you're doing.

Lastly, some stats. I mentioned before that this change slightly reduces the
size of ZIR - this is due to two instructions (`field_call_bind` then `call`)
being replaced with one (`field_call`). Here are some numbers:

+--------------+----------+----------+--------+
| File         | Before   | After    | Change |
+--------------+----------+----------+--------+
| Sema.zig     | 4.72M    | 4.53M    | -4%    |
| AstGen.zig   | 1.52M    | 1.48M    | -3%    |
| hash_map.zig | 283.9K   | 276.2K   | -3%    |
| math.zig     | 312.6K   | 305.3K   | -2%    |
+--------------+----------+----------+--------+
2023-05-20 12:27:48 -07:00
Ryan Liptak
2129f28953 Update all std.mem.split calls to their appropriate function
Everywhere that can now use `splitScalar` should get a nice little performance boost.
2023-05-13 13:45:05 -07:00
Josh Wolfe
018b743c7a
std: Rewrite low-level json api to support streaming (#15602) 2023-05-13 14:31:53 -04:00
Andrew Kelley
7f7bd206dc
Merge pull request #15519 from dweiller/issue-15482
Optimize lowering of `s[start..][0..len]`
2023-05-11 08:59:44 -07:00
Loris Cro
5512455974
Merge pull request #15637 from der-teufel-programming/autodoc-layouts
autodoc: Add layout to Struct and Union to handle packed and extern
2023-05-11 17:46:29 +02:00
Loris Cro
2d2d79a05b autodoc: fix crash when call syntax has complex callee expression 2023-05-10 21:07:40 +02:00
Krzysztof Wolicki
b7ba9aa892 autodoc: Add layout to Struct and Union to properly display packed and extern;
Make rendering of types in exprName more similar to zig fmt
2023-05-10 01:53:00 +02:00
Krzysztof Wolicki
a714f07022 autodoc: Fix tag type for unions; Fix backing int for packed structs 2023-05-09 10:52:51 +02:00
Krzysztof Wolicki
b488f97e92 autodoc: Analyze and expose backing integer types for packed structs 2023-05-08 22:34:46 +02:00
dweiller
2c5924c59a autodoc: fix support for slice_length ZIR instruction 2023-05-07 15:55:21 +10:00
dweiller
64e319f555 add optional sentinel to slice_length ZIR 2023-05-07 15:55:21 +10:00
dweiller
2c2a0402c6 autodoc: implement slice_length case in walkInstruction 2023-05-07 15:55:20 +10:00
dweiller
a62b5d84d8 zir: add slice_length tag 2023-05-07 15:55:20 +10:00
Krzysztof Wolicki
c40a1ee224 autodoc: Add gathering of top-level doc comments for imported files 2023-05-06 02:51:53 +02:00
Krzysztof Wolicki
c63338712e autodoc: Save switches as comptimeExpr with the code instead of analyzing it deeply;
simplified getBlockSource;
2023-05-05 02:41:23 +02:00
Krzysztof Wolicki
e363ffad90 autodoc: Better comptimeExpr code for blocks 2023-05-05 01:46:19 +02:00
Loris Cro
13aaa16ab2
Merge pull request #15478 from der-teufel-programming/autodoc-decltests
autodoc: Gather and display decltests
2023-04-29 18:23:18 +02:00
Krzysztof Wolicki
aa51a5c557 autodoc: Gather and display decltests 2023-04-29 00:54:23 +02:00
Andrew Kelley
42973d73e6 compiler: use @memcpy instead of std.mem.copy 2023-04-28 13:24:43 -07:00
Loris Cro
b294bff1a8
Autodoc: new decl search system (#15475)
New search system is based on a Radix Tree. The Radix Tree contains a shallow list of all decl names (ie no paths), plus some suffixes, split by following the official style guide (eg "HashMapUnmanaged" also produces "MapUnmanaged" and "Unmanaged", same with snake_case and camelCase names).

Additionally, the search system uses the decl graph data to recognize hierarchical relationships between decls, allowing you to zero on a target namespace for search. As an example "fs create" will score highe all things related to the creation of files and directories inside of `std.fs`, while still showing (but with lower score) matches from `std.Bulild`. 

As another example "fs windows" will prioritize windows-related results in `std.fs`, while "windows fs" will prioritize fs-related results in `std.windows`.
2023-04-26 18:17:20 +02:00
Loris Cro
015ea6fd6c
Merge branch 'master' into autodoc-pkg-mod 2023-04-25 20:03:53 +02:00
zooster
bc8e1e1de4
Improvements to docs and text
* docs(std.math): elaborate on difference between absCast and absInt

* docs(std.rand.Random.weightedIndex): elaborate on likelihood

I think this makes it easier to understand.

* langref: add small reminder

* docs(std.fs.path.extension): brevity

* docs(std.bit_set.StaticBitSet): mention the specific types

* std.debug.TTY: explain what purpose this struct serves

This should also make it clearer that this struct is not supposed to provide unrelated terminal manipulation functionality such as setting the cursor position or something because terminals are complicated and we should keep this struct simple and focused on debugging.

* langref(package listing): brevity

* langref: explain what exactly `threadlocal` causes to happen

* std.array_list: link between swapRemove and orderedRemove

Maybe this can serve as a TLDR and make it easier to decide.

* PrefetchOptions.locality: clarify docs that this is a range

This confused me previously and I thought I can only use either 0 or 3.

* fix typos and more

* std.builtin.CallingConvention: document some CCs

* langref: explain possibly cryptic names

I think it helps knowing what exactly these acronyms (@clz and @ctz) and
abbreviations (@popCount) mean.

* variadic function error: add missing preposition

* std.fmt.format docs: nicely hyphenate

* help menu: say what to optimize for

I think this is slightly more specific than just calling it
"optimizations". These are speed optimizations. I used the word
"performance" here.
2023-04-23 21:06:21 +03:00
Krzysztof Wolicki
a260fa8bf2 autodoc: Change package to module to better reflect the new names 2023-04-23 01:02:09 +02:00
Loris Cro
c5fb245f60
Merge branch 'master' into autodoc-src-files-dirs 2023-04-22 19:10:23 +02:00
Krzysztof Wolicki
428f745270 autodoc: Change html file destination dirs
Each file is now saved with its package index in data.json
2023-04-22 02:36:19 +02:00
Krzysztof Wolicki
7e18bd7f71 autodoc: Handle calling conventions better
special case inline cc in exprName
2023-04-21 11:52:07 +02:00
Loris Cro
3d33a09069 autodoc: more support for linking decls in docs & guides 2023-04-17 20:13:08 +02:00
Loris Cro
aa765c1d70 autodoc: add support for defining guide sections
For example:

//!zig-autodoc-section: Advanced Topics
2023-04-15 18:26:53 +02:00