Commit Graph

1266 Commits

Author SHA1 Message Date
Linus Groh
2088e8dc6f docgen: Rename Action enum values to snake case 2023-05-20 21:58:23 +01:00
Linus Groh
3c1bdc9781 docgen: Rename Code.Id enum values to snake case 2023-05-20 21:56:59 +01:00
Linus Groh
83d419630c docgen: Rename ExpectedOutcome enum values to snake case 2023-05-20 21:55:31 +01:00
Linus Groh
0dfe6233c0 docgen: Rename Tokenizer.State enum values to snake case 2023-05-20 21:53:12 +01:00
Linus Groh
dc4a7188dd docgen: Rename Token.Id enum values to snake case 2023-05-20 21:51:57 +01:00
Roman Frołow
21b7c48043 Add wasi_ prefix to wasm files 2023-05-15 23:34:43 +03:00
notcancername
2ce9122a00 Remove incorrect statements that the source argument to @memcpy needs to be mutable 2023-05-14 04:40:36 -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
Jonta
3062f9b02a Fix typo in langref
- 768 -> 786
- The link seems to be correct
- The link-text points to a seemingly unrelated issue
2023-05-12 13:39:30 +03: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
jcalabro
16314e0e19 Fix langref typo 2023-05-08 19:41:28 +03:00
dweiller
5bb8e9cd97 langref: mention slice-by-length pattern 2023-05-07 15:55:21 +10:00
Arnau
14c68e847a langref: Documented extern "..." use
The use of `extern "..."` for specifying the library that has the definition was undocumented.
Fixes #13906
2023-05-03 08:35:30 +03:00
Andrew Kelley
bd6f01c751 langref: fix compile error 2023-04-25 11:23:41 -07:00
Andrew Kelley
edb5e493e6 update @memcpy to require equal src and dest lens
* Sema: upgrade operands to array pointers if possible when emitting
   AIR.
 * Implement safety checks for length mismatch and aliasing.
 * AIR: make ptrtoint support slice operands. Implement in LLVM backend.
 * C backend: implement new `@memset` semantics. `@memcpy` is not done
   yet.
2023-04-25 11:23:40 -07:00
Andrew Kelley
a5c910adb6 change semantics of @memcpy and @memset
Now they use slices or array pointers with any element type instead of
requiring byte pointers.

This is a breaking enhancement to the language.

The safety check for overlapping pointers will be implemented in a
future commit.

closes #14040
2023-04-25 11:23:40 -07:00
mlugg
35d82d31be Add @inComptime builtin
Resolves: #868
2023-04-23 13:16:42 -07: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
Manlio Perillo
658b4db223
langref: improve for loop documentation
- Add an example of iterating over consecutive integers using the
    range syntax
  - Add an example of iterating over multiple objects
  - Update the "nested break" and "nested continue" tests to use the
    range syntax, instead of a temporary array
2023-04-23 21:00:10 +03:00
Bogdan Romanyuk
316812786c langref: add documentation for noinline keyword 2023-04-23 20:56:06 +03:00
dweiller
68e4a57847 docgen: fix exe_build_err code snippets
Fixes #15297.
2023-04-22 14:30:08 +03:00
mlugg
07b7c3b31b doc: clarifications to comptime section in langref after #14819 2023-04-18 19:57:47 -07:00
Andrew Kelley
d5eab33fd2 docgen: avoid use of --enable-cache 2023-04-11 08:41:52 -07:00
jagt
c964e10821 docgen: add additional_option token; fix wasm-freestanding example
- Fix usage string `--skip-code-test` to `--skip-code-tests`.
- Added a token `{#additonal_option|-rdynamic#}` which introduce arbitrary flag to `build-exe/obj/lib` example.
- Fix wasm freestanding example, it now needs explicit export symbols to work.
2023-03-30 22:56:33 +03:00
Robin Voetter
3357c59ceb new builtins: @workItemId, @workGroupId, @workGroupSize
* @workItemId returns the index of the work item in a work group for a
  dimension.
* @workGroupId returns the index of the work group in the kernel dispatch for a
  dimension.
* @workGroupSize returns the size of the work group for a dimension.

These builtins are mainly useful for GPU backends. They are currently only
implemented for the AMDGCN LLVM backend.
2023-03-30 12:20:24 +03:00
Manlio Perillo
7ca052a6fb docgen: improve the termColor function
Make the termColor function more robust, ensuring that the generated
HTML classes are more consistent and that they are supported in the CSS.

Add documentation about the ANSI codes generated by Zig, and remove the
previous comment with the supported colors.

Improve test coverage for the termColor function, and move the tests at
the end of the file before the printShell tests.

Rename the "term color" test to "term supported colors" and add an
additional "term output from zig" test, using test data generated from
the Zig compiler.

Update the langref.html.in CSS to use the new names and remove incorrect
or obsolete colors like .t0_1, .t37 and .t37_1.

Fix support for the 1m color. Change font-weight to normal for the kbd
element, to avoid both the command (like `zig build-exe`) and the first
line of the error message having a bold font.

Rename the "shell parsed" test to "printShell".
2023-03-27 12:10:49 +02:00
Manlio Perillo
1dd26042cc docgen: remove line support in printShell
Line support in printShell breaks the support to terminal colors, when a
color is active over multiple lines. An example is when printing
reference traces.

Remove line support in printShell, since they are not really necessary
like in printSourceBlock.

In genHtml, remove an empty line when printing the execution of the
executable generated by `zig build-exe`.

Update the "shell parsed" tests.
Remove the call to log.emerg, since it is no longer supported.
Add an extra space after "--build-option1 \", as documented.

Fixes #13280
2023-03-27 12:10:49 +02:00
Phil Eaton
38ee46dda3
Two more examples of possible syntax when dealing with errors (#15042)
Add an example of if with try without else switch; add example of catch with block returning value
2023-03-23 10:06:46 +01:00
r00ster91
8642770eff langref: add missing return types to builtin functions
This should add all remaining missing return types to all builtin
functions.
For @clz, @ctz, and @popCount it uses anytype for the lack of a better
alternative. We already use this return type for other builtin functions in the langref
to indicate that the type is not always the same.
It is not possible to use anytype as the return type for regular
functions but builtin functions are special.
2023-03-21 15:05:57 +02:00
Andrew Kelley
b4d58e93ea make docgen accept --zig-lib-dir 2023-03-16 15:43:51 -07:00
Andrew Kelley
2c491d734e docgen: don't print progress in dumb terminals 2023-03-15 10:48:14 -07:00
Hashi364
4942e4e870
Resolve docs inconsistency with Overflow builtins
In 41 (Undefined Behavior) . 5 (Integer Overflow) . 3 (Builtin Overflow Functions), it is stated that

> These builtins return a bool of whether or not overflow occurred, as well as returning the overflowed bits:
> * @addWithOverflow
> * @subWithOverflow
> * @mulWithOverflow
> * @shlWithOverflow

but in their definition says that it returns a `tuple`/`struct`.

Example;
`@addWithOverflow(a: anytype, b: anytype) struct { @TypeOf(a, b), u1 }`

Co-authored-by: zooster <r00ster91@proton.me>
2023-03-13 14:47:20 +00:00
Techatrix
10c74631b3 langref: add missing comma in assembly expressions 2023-03-12 23:51:46 +02:00
Andrew Kelley
fb04ff45cd langref: small clarification to @trap 2023-03-05 17:11:46 -07:00
Andrew Kelley
e7f128c205
Merge pull request #14782 from r00ster91/trap
add `@trap` builtin
2023-03-04 16:20:31 -05:00
tranquillity-codes
c9d990d790 fix doc Build Mode 2023-03-04 23:13:15 +02:00
r00ster91
65368683ad add @trap builtin
This introduces a new builtin function that compiles down to something that results in an illegal instruction exception/interrupt.
It can be used to exit a program abnormally.

This implements the builtin for all backends.
2023-03-04 12:08:19 +01:00
Andrew Kelley
0bb178bbb2
Merge pull request #14671 from ziglang/multi-object-for
implement multi-object for loops
2023-02-19 10:10:59 -05:00
Tom Read Cutting
346ec15c50
Correctly handle carriage return characters according to the spec (#12661)
* Scan from line start when finding tag in tokenizer

This resolves a crash that can occur for invalid bytes like carriage
returns that are valid characters when not parsed from within literals.

There are potentially other edge cases this could resolve as well, as
the calling code for this function didn't account for any potential
'pending_invalid_tokens' that could be queued up by the tokenizer from
within another state.

* Fix carriage return crash in multiline string

Follow the guidance of #38:

> However CR directly before NL is interpreted as only a newline and not part of the multiline string. zig fmt will delete the CR.

Zig fmt already had code for deleting carriage returns, but would still
crash - now it no longer does so. Carriage returns encountered before
line-feeds are now appropriately removed on program compilation as well.

* Only accept carriage returns before line feeds

Previous commit was much less strict about this, this more closely
matches the desired spec of only allow CR characters in a CRLF pair, but
not otherwise.

* Fix CR being rejected when used as whitespace

Missed this comment from ziglang/zig-spec#83:

> CR used as whitespace, whether directly preceding NL or stray, is still unambiguously whitespace. It is accepted by the grammar and replaced by the canonical whitespace by zig fmt.

* Add tests for carriage return handling
2023-02-19 14:14:03 +02:00
Andrew Kelley
7abeb52abc langref: update to new for loop syntax 2023-02-18 19:20:19 -07:00
Andrew Kelley
552e8095ae update docgen to new for loop syntax 2023-02-18 19:17:21 -07:00
Veikka Tuominen
7199d7c777 split @qualCast into @constCast and @volatileCast 2023-02-15 01:43:57 +02:00
Manlio Perillo
5894be94c8 langref: make more examples testable
Some examples using {#syntax_block|zig|...#} either have a valid syntax
or it is easy to make the syntax valid.  Update these example to use
{#code_begin|syntax|...#}.

Remove extra whitespace in the error_union_parsing_u64.zig example.

Replace size_t with usize in the call_malloc_from_zig.zig example.
2023-02-13 16:21:54 +02:00
ee7
289e8fab79 langref, tools: rename --single-threaded to -fsingle-threaded
Commit 40f5e5dfc6 ("CLI: introduce -fsingle-threaded/
-fno-single-threaded", 2021-12-01) removed the `--single-threaded`
option, but didn't update all mentions of it.

    $ zig version
    0.11.0-dev.1568+c9b957c93
    $ zig build-exe --help | grep single
      -fsingle-threaded         Code assumes there is only one thread
      -fno-single-threaded      Code may not assume there is only one thread
    $ zig build-exe --single-threaded foo.zig
    error: unrecognized parameter: '--single-threaded'
2023-02-04 23:24:07 +02:00
Manlio Perillo
c181ba1022 langref: remove link to closed issue #4026
In the math builtin functions documentation, remove the link to issue
https://github.com/ziglang/zig/issues/4026, since it was closed by
https://github.com/ziglang/zig/pull/11532.
2023-02-03 14:49:17 +02:00
Andrew Kelley
6b7ad22981
Merge pull request #14477 from Vexu/fixes
Improve `@ptrCast` errors, fix some bugs
2023-02-01 23:31:52 -05:00
Josh Holland
1fba88450d langref: add paragraph and examples about indexing non-ASCII strings
PR #10610 addressed most of the points from #1854.  This
additional paragraph and examples covers the OMISSIONS section
clarifying issues about indexing into non-ASCII strings (whether valid
UTF-8 or not).  I think this finally closes #1854.
2023-02-01 21:46:46 +02:00
Andrew Kelley
9a29f4e038 langref updates for new std.Build API 2023-01-31 15:09:35 -07:00
Andrew Kelley
36e2d992dd combine std.build and std.build.Builder into std.Build
I've been wanting to do this for along time.
2023-01-31 15:09:35 -07:00
Andrew Kelley
73cf7b6429 update build.zig API usage 2023-01-31 15:09:35 -07:00
Veikka Tuominen
f16c10a86b implement @qualCast 2023-01-30 18:55:57 +02:00
Veikka Tuominen
a9785fe8ee Sema: add helpful notes to invalid @ptrCast operations
Closes #14474
2023-01-30 15:20:16 +02:00
Manlio Perillo
fcef728b9b langref: make "Type Coercion" subsections more consistent
In the "Type Coercion" section, rename:
  - Coercion Float to Int => Float to Int
  - unions and enums => Unions and Enums
  - tuples to arrays => Tuples to Arrays
2023-01-25 23:29:25 +02:00
Manlio Perillo
21d9f0c2a1 langref: add missing dot at the end of the paragraph
In the "C Variadic Functions" section, add a missing dot at the end of
the paragraph before the test_defining_variadic_function.zig example.
2023-01-25 16:09:17 -05:00
Manlio Perillo
d64dd75e34 langref: update the documentation of @Type
@Type is currently available for Functions.
2023-01-25 18:15:56 +02:00
Manlio Perillo
33e5a84706 langref: improve test_coerce_unions_enums.zig
Add more coercion examples to test_coerce_unions_enums.zig in the
"Type Coercion: unions and enums" section.
2023-01-25 17:03:39 +02:00
Manlio Perillo
8de46d1d7d langref: move paragraph inside the p element
In the "C Translation CLI" section, move the paragraph inside the p
element.

The current HTML is valid, but, as an example, a paragraph outside a p
element is not handled correctly by the browser Inspect tool.
2023-01-25 17:01:43 +02:00
Manlio Perillo
81035b7eb3 langref: remove extra curly bracket in the CSS
In commit 3542dbf0ea (langref: add section numbers) I accidentally
added an extra closing curly bracket at the end of the style element.

Sorry for not validating the HTML file before creating the PR.
2023-01-23 15:51:17 -05:00
Manlio Perillo
ce6de2df82 docgen: make the name required in the Code node
Update the genToc funtion to make the name required in the Code node,
and add an additional optional field for the expected error, to use with
test_err, test_safety and obj_err.

Update langref.html.in to ensure all code blocks have a name that

  - is unique, so that a doctest can be identified by it
  - is descriptive

For test, test_err and test_safefy, ensure that the doctest name starts
with "test_", excluding doctests in the "Zig Test" section and doctests
that are imported by other doctests.

Ensure that the indentation of code_begin and code_end blocks are
consistent.

Fix a typo in pointer_arthemtic.
2023-01-23 15:14:24 +02:00
Andrew Kelley
3cb1ab0e05 langref: point 0.10.0 nav link to 0.10.1 2023-01-22 18:19:26 -07:00
Manlio Perillo
efbb6128bb langref: always start code on a separate line in a syntax_block
In a syntax_block the code always start on a separate code, expect for
C, JavaScript, Peg and with Zig inline assembly.

Ensure that the code starts on a separate line, even in cases where
there is only one line.

Ensure that the end_syntax_block is always on a separate line and that
the indentation is consistent.
2023-01-19 19:10:01 +02:00
Manlio Perillo
72c09b7b3b langref: use the term tuple in the Hello World section
In the Hello World section, replace the term "anonymous struct literal"
with tuple, when documenting the second argument of stdout.print().
2023-01-18 15:33:58 +02:00
Manlio Perillo
06e9b2c4e3 langref: document UTF-8 BOM handling
The current compiler ignores the UTF-8 BOM if it is at the start of the
file, and disallows it anywhere else.  Document it in the Source Encoding
section.
2023-01-17 20:07:53 +02:00
Manlio Perillo
0973f36389 langref: add the new addrspace keyword
Add the new addrspace keyword in the Keyword Reference section, without
documentation.

Move the linksection keyword in order to keep the keywords list sorted.
2023-01-17 20:04:37 +02:00
Manlio Perillo
fde57330fa docgen: improve command-line argument parsing
Implement a simple command-line argument parser, adapted from the Zig
compiler implementation.

Promote the zig positional argument to an option.
2023-01-13 17:24:10 +01:00
Manlio Perillo
c5351a8d49 docgen: remove unnecessary and incorrect deallocations
The deallocations of the process arguments are unnecessary, since the
memory will be deallocated by arena.deinit().

The deallocations are incorrect, since ArgIterator.next() returns a
slice pointing to the iterator's internal buffer, that should be
deallocated with args_it.deinit().
2023-01-13 15:20:00 +01:00
Techatrix
0a8b7ad368
langref: fix unclosed and lonely tag (#14250) 2023-01-10 18:02:29 -05:00
Veikka Tuominen
83fd45d820
Merge pull request #13786 from ziglang/tty-detection
stage2: make --color on affect progress bar too
2023-01-04 16:54:46 +02:00
Veikka Tuominen
95fe23f572 docgen: handle 'K' and 'D' escape codes 2023-01-03 14:03:43 +02:00
Evin Yulo
fc07e1a267 Document tuple syntax
Closes #13837
2023-01-03 13:29:27 +02:00
Veikka Tuominen
8a6295fcba AstGen: make type sentinel expressions implicitly comptime 2022-12-29 12:43:02 +02:00
Veikka Tuominen
622311fb9a update uses of overflow arithmetic builtins 2022-12-27 15:13:14 +02:00
Veikka Tuominen
af9a9a1374 zig fmt: improve handling of comptime tuple fields 2022-12-27 13:52:37 +02:00
zooster
547e3684be langref: more explicitly document how enum overriding works 2022-12-27 12:53:41 +02:00
Veikka Tuominen
0b859831ad update grammar in langref
Closes #14072
2022-12-26 16:36:29 +02:00
Manlio Perillo
3542dbf0ea langref: add section numbers
When reading a document with nested sections, it is not easy to discover
the depth of the current section.

Add support for nested section numbers, from the h2 to the h4 heading,
in the format "lv1. ", "lv1.lv2. ", "lv1.lv2.lv3. ".  The "Zig Version"
and "Table of Content" sections are excluded.

The section numbers are implemented in CSS, with the CSS rules declared
inside a @media rule.  Currently the @media rule targets all media.
2022-12-19 21:51:23 +02:00
Andrew Kelley
aca9c74e80
Merge pull request #13914 from Vexu/variadic
implement defining C variadic functions
2022-12-18 16:24:13 -05:00
Veikka Tuominen
40ed6ae846
Merge pull request #13930 from r00ster91/renamings
std.builtin: renamings
2022-12-18 19:33:15 +02:00
Evin Yulo
9cc49548aa langref: remove incorrect use of term 'literal' 2022-12-18 01:55:09 +02:00
r00ster91
aac2d6b56f std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
r00ster91
7350ea3e2d std.builtin: rename Type.Fn's args to params
This was a poor naming choice; these are parameters, not arguments.
Parameters specify what kind of arguments are expected, whereas the arguments are the actual values passed.
2022-12-17 14:11:33 +01:00
r00ster91
20d3fd901e std.builtin: rename Type.Fn.Param's arg_type to type
It's the type of a parameter, not an argument, but the prefix is redundant either way.
2022-12-17 14:11:33 +01:00
Veikka Tuominen
9bb1104e37 implement defining C variadic functions 2022-12-17 13:22:09 +02:00
Andrew Kelley
6378644d4e
Merge pull request #13907 from Vexu/call-merge
Remove `stack` option from `@call`
2022-12-13 18:15:18 -05:00
Evin Yulo
02b4ea71e3 Improve tagged union documentation
closes #13870
2022-12-13 15:11:43 -05:00
Manlio Perillo
35c6fe665c langref: document extern variadic functions
Add a new subsection within the C section, documenting extern variadic
functions.
2022-12-13 15:09:08 -05:00
Manlio Perillo
6486ee9fc7 langref: remove the trailing slash from the link element
A self-closing tag for void elements like link is only required under
XHTML 1.0.

See https://developer.mozilla.org/en-US/docs/Glossary/Void_element#self-closing_tags.
2022-12-13 15:02:48 -05:00
Manlio Perillo
17d85a72c4
langref: add missing ReleaseSmall when describing unreachable (#13909)
Add a missing ReleaseSmall when describing unreachable in the try
section and the unreachable entry in the Keyword Reference section.

Additionally, transform Debug, ReleaseSafe, ReleaseFast and ReleaseSmall
into links in the try section.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2022-12-13 15:02:17 -05:00
Manlio Perillo
89a9e927ad langref: improve the test_fn_reflection.zig doctest
Currently, the test_fn_reflection.zig doctest has an example of
.Fn.is_var_args.  This example can confuse the reader, since there is no
documentation about variadic functions and is_var_args is mainly used in
the compiler.

Remove the example with .Fn.is_var_args and add instead examples with
.Fn.return_type and .Fn.is_generic.
2022-12-13 15:00:42 -05:00
Manlio Perillo
1d5368fa35 langref: fix the slice_bounds.zig doctest
In the slice_bounds.zig doctest, the code "const slice = array[2..4]" is
incorrect, since the actual type is a pointer to an array, instead of a
slice.

Use a runtime know value to slice the array.
2022-12-13 14:59:46 -05:00
Manlio Perillo
21dafd7a54
langref: update comments in the slices.zig doctest (#13819)
In the slices.zig doctest, the code
`const all_together_slice = all_together[0..]` is incorrect, since the
actual type is a pointer to an array, instead of a slice.

Use a runtime-known value to slice the array.

In the next "slice pointer" test, clarify that slicing a slice to
produce a pointer to an array, requires comptime-known indexes, not just
constant indexes.
2022-12-13 14:58:52 -05:00
Veikka Tuominen
7b2a936173 remove stack option from @call 2022-12-13 12:52:21 +02:00
gettsu
175d018512
langref: avoid use of the term "enum variant" in enums.zig (#13847) 2022-12-12 23:49:42 -05:00
Manlio Perillo
09cc6b4b9e langref: improve the defer section
Split the original `defer.zig` doctest into 3 doctest:

  1. Document the defer keyword
  2. Document that the return statement is not allowed inside a defer
     expression
  3. Document the errdefer keyword

Replace "method" with "expression" in the text `defer method`.
2022-12-12 15:09:45 -05:00
Andrew Kelley
f1f17dc1c7
Merge pull request #13810 from r00ster91/old
Re-enable many previously failing tests and add test coverage
2022-12-10 15:07:51 -05:00
Manlio Perillo
f020734347 langref: remove HTML code from a shell node
Several <em> elements where added inside a shell node in the
Using--target-and--cflags section.  Remove them, since they are not
supposed to be handled by codegen.

For the original commit, see
0c091feb5 (Improve HTML semantics and a11y of language reference).

Fixes #13846
2022-12-10 14:39:40 +02:00
r00ster91
981cfd9c1c behavior and langref: reenable previously-regressed tests on aarch64 and powerpc64le
Closes #3282
2022-12-10 12:34:42 +01:00
Andrew Kelley
7637ac584f
Merge pull request #13821 from Vexu/eliminate-bound-fn
Eliminate `BoundFn` type from the language
2022-12-10 06:14:57 -05:00
Evin Yulo
e4874d842e Remove unneeded else unreachable in docgen.zig
See #707
2022-12-10 05:50:56 -05:00
Veikka Tuominen
9d93b2ccf1 Eliminate BoundFn type from the language
Closes #9484
2022-12-09 20:37:18 -07:00
Evin Yulo
d0172488b2 langref: update anonymous struct naming
Closes #13841
2022-12-09 19:59:47 +02:00
Manlio Perillo
65f35a76f9 langref: consistently use comptime-known and runtime-known 2022-12-09 18:24:40 +02:00
Manlio Perillo
505a21bcc5 langref: link "result location" to the "Result Location Semantics" section 2022-12-09 17:42:25 +02:00
Andrew Kelley
4451786c66 langref: update WASI preopens example 2022-12-06 12:27:28 -07:00
Andrew Kelley
6e52f36d46 langref: eliminate dependencies on stage1
This commit removes async/await/suspend/resume from the language
reference, as that feature does not yet work in the self-hosted
compiler.

We will be regressing this feature temporarily. Users of these language
features should stick with 0.10.x with the `-fstage1` flag until they
are restored.

See tracking issue #6025.
2022-12-01 15:28:44 -07:00
Andrew Kelley
8f079bad1f langref: acknowledge design flaw in the self-hosted compiler
See tracking issue #13724
2022-12-01 00:38:02 -07:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Veikka Tuominen
17ff002bc0 Sema: improve safety panic for access of inactive union field 2022-11-29 21:44:08 +02:00
Jonathan Marler
58d9004cea packed struct fix example and clarify least to most significant ordering
The packed struct example was mistakenly applying endianness where it
shouldn't have been.  This wasn't being caught because we don't currently
test the examples on Big-endian systems.

I updated the test to remove the endianness where it didn't apply, and
added a new part of the test to demonstrate when it would apply.
2022-11-17 12:11:43 +02:00
Stevie Hryciw
32b97df50e langref: add appendix and explain 'container' terminology 2022-11-12 15:42:29 +02:00
Ganesan Rajagopal
88d2e4f66a langref.html.in: Simplify printing types in examples
zig stdlib fmt has a formatter for types which prints the type name.  So,
just use @TypeOf(type) instead of the longer @typeInfo(@TypeOf(type)).
2022-11-07 15:07:21 +02:00
Ali Chraghi
f5f1f8c666 all: rename i386 to x86 2022-11-04 00:09:27 +03:30
Andrew Kelley
0c1701768d Release 0.10.0 2022-10-31 10:24:38 -07:00
Andrew Kelley
a5c96c49d0 langref: mention void{} and empty blocks
closes #11112
closes #12496
2022-10-30 16:33:22 -07:00
Evin Yulo
09a96cdfce Fix #12822: Clarify langref about the behavior of undefined 2022-10-29 17:55:06 -04:00
Andrew Kelley
7d0dc2fd75 docgen: fix not escaping html in shell samples 2022-10-26 16:48:50 -07:00
Ali Chraghi
ca27055cda all: rename @maximum to @max and @minimum to @min 2022-10-18 14:15:16 +03:00
Jacob Young
f9192adaba llvm: fix lowering of non-byte-aligned field pointers
* When a field starts at some bit offset within a byte you need to load
   starting from that byte and shift, not starting from the next byte,
   so a rounded-down divide is required here, not a rounded-up one.
 * Remove paragraph from doc that no longer relates to anything.

Closes #12363
2022-10-15 14:19:40 -04:00
Robin Voetter
fb9a7dad17
add @addrSpaceCast to langref 2022-10-12 20:36:14 +02:00
Andrew Kelley
7ce1ee1bce
Merge pull request #13081 from r00ster91/docs
fix(text): hyphenation and other fixes
2022-10-12 05:26:11 -04:00
Veikka Tuominen
29ae6515f3 AstGen: use 'shadows' instead of 'redeclaration' when names are in different scopes
Closes #8532
2022-10-07 11:04:02 +03:00
r00ster91
654e0b6679 fix(text): hyphenation and other fixes 2022-10-05 21:19:10 +02:00
Andrew Kelley
ff534d2267
Merge pull request #12979 from Vexu/inline-switch
Implement inline switch cases
2022-10-03 23:43:09 -04:00
zooster
8eb96c32e3 docs(langref): fix outdated example 2022-10-03 22:41:48 -04:00
Techatrix
9a2f17f9f9
Docs: clarify unreachable for ReleaseSmall 2022-09-28 13:30:55 +03:00
Veikka Tuominen
17eea918ae langref: document inline switch 2022-09-27 18:33:23 +03:00
Zhora Trush
f7f15e99c4 Fix minor langref typos 2022-09-27 13:22:57 +03:00
Sage Hane
cae76d8293 langref: fix minor format error 2022-09-23 15:58:46 +02:00
John Simon
246a39c10e
langref: remove uses of old function pointer syntax 2022-09-23 12:08:30 +03:00
Eric Joldasov
a86c7b13a3 docgen: add f80 to builtin types 2022-09-14 20:08:34 -04:00
Andrew Kelley
1d041d3a10
Merge pull request #11664 from vincenzopalazzo/macros/docs
docs: add missed docs for some language feature like `defer` and `errdefer`
2022-09-14 19:26:28 -04:00
Veikka Tuominen
349d78a443 validate number literals in AstGen 2022-09-13 20:26:04 -04:00
Veikka Tuominen
e323cf1264 stage2: change how defers are stored in Zir
Storing defers this way has the benefits that the defer doesn't get
analyzed multiple times in AstGen, it takes up less space, and it
makes Sema aware of defers allowing for 'unreachable else prong'
error on error sets in generic code.

The disadvantage is that it is a bit more complex and errdefers with
payloads now emit a placeholder instruction (but those are rare).

Sema.zig before:
  Total ZIR bytes:    3.7794370651245117MiB
  Instructions:       238996 (2.051319122314453MiB)
  String Table Bytes: 89.2802734375KiB
  Extra Data Items:   430144 (1.640869140625MiB)
Sema.zig after:
  Total ZIR bytes:    3.3344192504882812MiB
  Instructions:       211829 (1.8181428909301758MiB)
  String Table Bytes: 89.2802734375KiB
  Extra Data Items:   374611 (1.4290275573730469MiB)
2022-09-12 01:52:44 -04:00
Andrew Kelley
3ee01c14ee std.zig.system.NativeTargetInfo: detection ignores self exe
Before, native glibc and dynamic linker detection attempted to use the
executable's own binary if it was dynamically linked to answer both the
C ABI question and the dynamic linker question. However, this could be
problematic on a system that uses a RUNPATH for the compiler binary,
locking it to an older glibc version, while system binaries such as
/usr/bin/env use a newer glibc version. The problem is that libc.so.6
glibc version will match that of the system while the dynamic linker
will match that of the compiler binary. Executables with these versions
mismatching will fail to run.

Therefore, this commit changes the logic to be the same regardless of
whether the compiler binary is dynamically or statically linked. It
inspects `/usr/bin/env` as an ELF file to find the answer to these
questions, or if there is a shebang line, then it chases the referenced
file recursively. If that does not provide the answer, then the function
falls back to defaults.

This commit also solves a TODO to remove an Allocator parameter to the
detect() function.
2022-09-08 20:52:49 -07:00
Jason Ho
2b92c5a23e
langref: tweak description of []T (#12319)
saying []T is a pointer is confusing because zig docs say there are two types of pointers (*T and [*]T). It is more clear to say that []T is a slice type which contains a [*]T pointer and a length.

Co-authored-by: Philipp Lühmann <47984692+luehmann@users.noreply.github.com>
2022-08-31 21:53:00 -04:00
Henrique Dante de Almeida
ee12264387 docs: Remove mention of type inference on anytype struct fields
It was removed from the language.
2022-08-27 20:34:13 +02:00
Andrew Kelley
2a96209c40
Merge pull request #12574 from Vexu/remove-bit-op-type-param
stage2+stage1: remove type parameter from bit builtins
2022-08-24 15:57:44 -04:00
Will Hawkins
5fd5950c92 Doc: Add hyphenation for top-level doc 2022-08-24 20:00:46 +03:00
Veikka Tuominen
8667d6d61e
Merge pull request #12563 from Vexu/stage2-fixes
Stage2 fixes
2022-08-22 14:32:31 +03:00
Shane Kennedy
cd5a9ba1f4
lagnref: add signed integer repr documentation
Closes #11103
2022-08-22 13:57:51 +03:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Veikka Tuominen
b55a5007fa Sema: fix parameter of type 'T' must be comptime error
Closes #12519
Closes #12505
2022-08-22 11:16:36 +03:00
Andrew Kelley
09ec9b0315 langref: update to new error message 2022-08-19 16:45:15 -07:00
Andrew Kelley
507aae4a1a make self-hosted the default compiler
stage1 is available behind the -fstage1 flag.

closes #89
2022-08-19 16:45:15 -07:00
r00ster91
4ef7d85810 std.fmt: lowercase compile errors
`compileError\("([A-Z])` and `compileError\("\L\1`. It's pretty convenient.
2022-07-27 18:07:53 +03:00
InKryption
a0d3a87ce1 std.fmt: require specifier for unwrapping ?T and E!T 2022-07-26 11:25:49 -07:00
Andrew Kelley
934573fc5d Revert "std.fmt: require specifier for unwrapping ?T and E!T."
This reverts commit 7cbd586ace.

This is causing a fail to build from source:

```
./lib/std/fmt.zig:492:17: error: cannot format optional without a specifier (i.e. {?} or {any})
                @compileError("cannot format optional without a specifier (i.e. {?} or {any})");
                ^
./src/link/MachO/Atom.zig:544:26: note: called from here
                log.debug("  RELA({s}) @ {x} => %{d} in object({d})", .{
                         ^
```

I looked at the code to fix it but none of those args are optionals.
2022-07-24 11:50:10 -07:00
InKryption
7cbd586ace
std.fmt: require specifier for unwrapping ?T and E!T.
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-24 12:01:56 +03:00
InKryption
9555b84ab4 langref: clarify permitted @bitCast usage.
The current phrasing is vague; it is unclear whether it is demonstrating an example of the type of permitted behavior, from which the rule set must be extrapolated, or it is stating that this restriction only applies to the relationship between integers and bare structs.
2022-07-23 14:20:29 +03:00
Allan Regush
9734e643fb
docs: Pointer Arithmetic 2022-07-23 13:57:40 +03:00
Yujiri
577f9fdbae doc/langref: clarify behavior of slicing with constant indexes
Fixes #11219.
2022-07-15 10:17:22 +03:00
Andrew Kelley
1b9a9ee4ba langref: disable an example that regressed from LLVM 14 2022-07-07 12:19:48 -07:00
Pierre Curto
76f8328277 doc: update std.builtin.TypeInfo to std.builtin.Type 2022-06-27 19:48:52 +03:00
r00ster
b3672e0738 Fix grammatical error
Fixes #11675
2022-05-27 01:00:15 -04:00
Vincenzo Palazzo
80f3c8d276
docs: add documentation on errdefer with caputure syntax
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-05-17 21:08:32 +02:00
Vincenzo Palazzo
8328f5ed51
docs: add documentation about return stm in the defer method
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-05-17 18:34:28 +02:00
Koakuma
fb0692334e target: Rename sparcv9 -> sparc64
Rename all references of sparcv9 to sparc64, to make Zig align more with
other projects. Also, added new function to convert glibc arch name to Zig
arch name, since it refers to the architecture as sparcv9.

This is based on the suggestion by @kubkon in PR 11847.
(https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-13 16:43:59 -04:00
Jonathan Marler
9e89000ffc Update usages of process.getEnvMap and change BufMap -> EnvMap where applicable
# Conflicts:
#	lib/std/build/RunStep.zig
2022-05-11 18:40:53 -06:00
Kirk Scheibelhut
67c4b16d6e docs: T.bit_count -> @typeInfo(T).Int.bits
bit_count was removed in #6246
2022-05-10 17:28:44 -04:00
Andrew Kelley
ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00
Andrew Kelley
09f1d62bdf add new builtin function @tan
The reason for having `@tan` is that we already have `@sin` and `@cos`
because some targets have machine code instructions for them, but in the
case that the implementation needs to go into compiler-rt, sin, cos, and
tan all share a common dependency which includes a table of data. To
avoid duplicating this table of data, we promote tan to become a builtin
alongside sin and cos.

ZIR: The tag enum is at capacity so this commit moves
`field_call_bind_named` to be `extended`. I measured this as one of
the least used tags in the zig codebase.

Fix libc math suffix for `f32` being wrong in both stage1 and stage2.
stage1: add missing libc prefix for float functions.
2022-04-27 16:45:23 -07:00
Motiejus Jakštys
6d0283e6bc
[doc update] add size_t (#11482)
For those souls looking for a zig `size_t` equivalent, and not
lucky/educated enough (that was me yesterday) to know it's the same as
`uintptr_t`.

From a recent discussion on IRC.
2022-04-21 14:33:42 -04:00
Cody Tapscott
7b090df668 stdlib std.os: Improve wasi-libc parity for WASI CWD emulation
Two major changes here:
  1. We store the CWD as a simple `[]const u8` and lookup Preopens for
     every absolute or CWD-referenced file operation, based on the
     Preopen with the longest match (i.e. most specific path)
  2. Preorders are normalized to POSIX absolute paths at init time.
     Behavior depends on the "cwd_root" parameter of `initPreopensWasi`:

	`cwd_root` is used for any Preopens that start with "."

	  For example:
            "./foo/bar" - inits to -> "{cwd_root}/foo/bar"
            "foo/bar"   - inits to -> "/foo/bar"
	    "/foo/bar"  - inits to -> "/foo/bar"

        `cwd_root` must be an absolute path.

	Using "/" as `cwd_root` gives behavior similar to wasi-libc.
2022-04-16 18:08:05 +02:00
Kirk Scheibelhut
971ef7b9c2 Remove primitive values from keyword reference
5a53ab28 removed these as keywords, and the Primitive Values section
of the docs already exists to describe them.
2022-04-09 12:48:36 +02:00
Philipp Lühmann
795f075790 langref: rename incorrect expect to assert 2022-04-04 15:44:01 +03:00
dxps
9a127501f6 chore: doc fixes, closes 11091 2022-03-25 11:22:30 +02:00
Robin Voetter
5c3325588e stage1: make type names more unique 2022-03-19 19:40:46 -04:00
Andrew Kelley
f3f5a5d05b stage2: improve @typeName
* make it always return a fully qualified name. stage1 is inconsistent
   about this.
 * AstGen: fix anon_name_strategy to correctly be `func` when anon type
   creation happens in the operand of the return expression.
 * Sema: implement type names for the "function" naming strategy.
 * Put "enum", "union", "opaque", or "struct" in place of "anon" when
   creating respective anonymous Decl names.
 * std.testing: add `expectStringStartsWith`. Didn't end up using it
   after all.

Also this enables the real test runner for stage2 LLVM backend (sans
wasm32) since it works now.
2022-03-18 00:12:22 -07:00
Andrew Kelley
73e51133c3 langref: small clarification of @reduce 2022-03-17 17:22:57 -07:00
Andrew Kelley
d42d31f72f basic language features do not belong in std.meta 2022-03-14 00:11:46 -07:00
Andrew Kelley
627209253c langref: fix a stray anyopaque that should be a void 2022-03-08 14:58:53 -07:00
The Depressed Milkman
cd43f323d2 correct @frameSize() params in documentation
The documentation omitted the primary parameter, making it difficult to
understand what this function actually does.
2022-03-06 10:32:07 +02:00
Exonorid
91a88a789f
Add documentation for common mistakes in errdefer scoping 2022-02-23 14:33:51 +02:00
Veikka Tuominen
c9dde10f86 stage1: improve error message when casting tuples 2022-02-17 17:39:54 +02:00
Andrew Kelley
dc6553d93e CI: update download page and langref for 0.9.1 2022-02-14 20:08:04 -07:00
Andrew Kelley
1e49d1fca8 langref: correct info about type info of declarations 2022-02-14 12:26:55 -07:00
Andrew Kelley
210ee1067b update more API usage of std.Progress
fixes regression introduced in 5a00e24963
2022-02-08 17:49:40 -07:00
Kirk Scheibelhut
71321b6941
Various documentation fixes
Co-authored-by: Kirk Scheibelhut <kjs@scheibo.com>
Co-authored-by: extrasharp <genericpb@gmail.com>
2022-02-04 21:27:50 +02:00
GithubPrankster
23e981bbd1 Correct f80 description 2022-02-02 15:54:30 +02:00
PhaseMage
8a97807d68
Full response file (*.rsp) support
I hit the "quotes in an RSP file" issue when trying to compile gRPC using
"zig cc". As a fun exercise, I decided to see if I could fix it myself.
I'm fully open to this code being flat-out rejected. Or I can take feedback
to fix it up.

This modifies (and renames) _ArgIteratorWindows_ in process.zig such that
it works with arbitrary strings (or the contents of an RSP file).

In main.zig, this new _ArgIteratorGeneral_ is used to address the "TODO"
listed in _ClangArgIterator_.

This change closes #4833.

**Pros:**

- It has the nice attribute of handling "RSP file" arguments in the same way it
  handles "cmd_line" arguments.
- High Performance, minimal allocations
- Fixed bug in previous _ArgIteratorWindows_, where final trailing backslashes
  in a command line were entirely dropped
- Added a test case for the above bug
- Harmonized the _ArgIteratorXxxx._initWithAllocator()_ and _next()_ interface
  across Windows/Posix/Wasi (Moved Windows errors to _initWithAllocator()_
  rather than _next()_)
- Likely perf benefit on Windows by doing _utf16leToUtf8AllocZ()_ only once
  for the entire cmd_line

**Cons:**

- Breaking Change in std library on Windows: Call
  _ArgIterator.initWithAllocator()_ instead of _ArgIterator.init()_
- PhaseMage is new with contributions to Zig, might need a lot of hand-holding
- PhaseMage is a Windows person, non-Windows stuff will need to be double-checked

**Testing Done:**

- Wrote a few new test cases in process.zig
- zig.exe build test -Dskip-release (no new failures seen)
- zig cc now builds gRPC without error
2022-01-30 21:27:52 +02:00
Sage Hane
e288148f60
fs: Use OpenMode enum instead of read/write flags. 2022-01-29 15:52:08 +02:00
Veikka Tuominen
67d04a988a std: add f80 bits 2022-01-28 11:45:04 -07:00
praschke
6d1b1374f7 docs: reorganize @truncate and @intCast for clarity 2022-01-27 19:51:17 +02:00
Philipp Lühmann
db1edb6535 fix precedence in langref or example 2022-01-27 19:39:35 +02:00
Exonorid
3e6952ad16 Added documentation for implicit struct pointer dereferencing 2022-01-27 19:33:07 +02:00
r00ster
dd076d8cba Add missing package to the langref that's always available 2022-01-07 14:18:47 -05:00
ominitay
7e16bb36d8 Change ArgIterator.next() return type
Changes the return type of `ArgIterator.next()` from
`?(NextError![:0]u8)` to `NextError!?[:0]u8`.
2021-12-21 11:15:33 -08:00
John Schmidt
0d09b87c14 Langref: replace mentions of c_void with anyopaque 2021-12-21 11:13:21 -08:00
Andrew Kelley
a18bf7a7bf Release 0.9.0 2021-12-20 13:13:19 -07:00
Andrew Kelley
80b21cef5a langref: fix tidy html error
regressed in 8468b544e8
2021-12-18 23:57:00 -07:00
Isaac Freund
9f9f215305
stage1, stage2: rename c_void to anyopaque (#10316)
zig fmt now replaces c_void with anyopaque to make updating
code easy.
2021-12-19 00:24:45 -05:00
bnprks
8468b544e8
Add Vector documentation (#10303)
* Create Vector language documentation

Main changes to docs:
1. Create brief documentation on Zig vector types with code example
2. Get rid of the SIMD sub-heading under the main Vectors heading,
and update links accordingly
3. Add an example to the `@shuffle` docs
2021-12-18 23:40:57 -05:00
Isaac Freund
516945d7d9
langref: document @prefetch() builtin 2021-12-11 00:29:31 +01:00
Michael Byrne
7e2fae10c9
Add documentation for sentinel-terminated slicing (#10010)
closes #9680
2021-12-03 20:37:48 -05:00
Andrew Kelley
f3edff439e improve detection of how to execute binaries on the host
`getExternalExecutor` is moved from `std.zig.CrossTarget` to
`std.zig.system.NativeTargetInfo.getExternalExecutor`.

The function also now communicates a bit more information about *why*
the host is unable to execute a binary. The CLI is updated to report
this information in a useful manner.

`getExternalExecutor` is also improved to detect such patterns as:
 * x86_64 is able to execute x86 binaries
 * aarch64 is able to execute arm binaries
 * etc.

Added qemu-hexagon support to `getExternalExecutor`.

`std.Target.canExecBinaries` of is removed; callers should use the more
powerful `getExternalExecutor` instead.

Now that `zig test` tries to run the resulting binary no matter what,
this commit has a follow-up change to the build system and docgen to
utilize the `getExternalExecutor` function and pass `--test-no-exec`
in some cases to avoid getting the error.

Additionally:

 * refactor: extract NativePaths and NativeTargetInfo into their own
   files named after the structs.
 * small improvement to langref to reduce the complexity of the `callconv`
   expression in a couple examples.
2021-12-02 21:51:14 -07:00
Lee Cannon
02e5e0ba1f
allocgate: apply missed changes 2021-11-30 23:32:48 +00:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
75548b50ff
allocgate: stage 1 and 2 building 2021-11-30 23:32:47 +00:00
Lee Cannon
85de022c56
allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
Andrew Kelley
902df103c6 std lib API deprecations for the upcoming 0.9.0 release
See #3811
2021-11-30 00:13:07 -07:00