Commit Graph

1102 Commits

Author SHA1 Message Date
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
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