ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.12k stars 2.49k forks source link

Incorrect documentation for @cmpxchgStrong and @cmpxchgWeak #19979

Open oliver-giersch opened 4 months ago

oliver-giersch commented 4 months ago

Zig Version

0.12.0

Steps to Reproduce and Observed Behavior

The documentation for @cmpxchgStrong and @cmpxchgWeak says:

This function performs a [strong|weak] atomic compare-and-exchange operation, returning `null` if the current value is not the given expected value.
It's the equivalent of this code, except atomic: 

[...]

This is wrong and does not match the behavior of either the builtin nor the code example below these descriptions. I would like to open a PR for this, but I am unsure in which file to implement it, my assumption was doc/langref.html.in but that appears to be auto-generated.

Expected Behavior

I would propose the following wording:

This function performs a [strong|weak] atomic compare-and-exchange operation, returning `null` if the operation was successful and the previous value matched the given expected value.
Otherwise, it returns the actual value.
It's the equivalent of this code, except atomic:

[...]
BratishkaErik commented 4 months ago

I would like to open a PR for this, but I am unsure in which file to implement it, my assumption was doc/langref.html.in but that appears to be auto-generated.

Your assumption was correct, doc/langref.html.in is main template is located (it's not auto-generated) and doc/langref/ is where code examples are located. They are then processed by doctest to add recorded outputs and by docgen to generate final langref.html file. These are from tools/, but build.zig has langref step that calls them automatically.

Pyrolistical commented 4 months ago

Is this duplicate of https://github.com/ziglang/zig/issues/1516 ?