Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inaccurate documentation in member function mutability. #6065

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/user-guide/03-convenience-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int rs = foo.staticMethod(a,b);

### Mutability of member function

For GPU performance considerations, the `this` argument in a member function is immutable by default. If you modify the content in `this` argument, the modification will be discarded after the call and does not affect the input object. If you intend to define a member function that mutates the object, use `[mutating]` attribute on the member function as shown in the following example.
For GPU performance considerations, the `this` argument in a member function is immutable by default. Attempting to modify `this` will result in a compile error. If you intend to define a member function that mutates the object, use `[mutating]` attribute on the member function as shown in the following example.

```hlsl
struct Foo
Expand All @@ -159,14 +159,14 @@ struct Foo
[mutating]
void setCount(int x) { count = x; }

void setCount2(int x) { count = x; }
// This would fail to compile.
// void setCount2(int x) { count = x; }
}

void test()
{
Foo f;
f.setCount(1); // f.count is 1 after the call.
f.setCount2(2); // f.count is still 1 after the call.
f.setCount(1); // Compiles
}
```

Expand Down