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

Remove unsafety in ResourceId creation #534

Merged
merged 4 commits into from
Mar 29, 2024
Merged

Conversation

DasLixou
Copy link
Collaborator

@DasLixou DasLixou commented Mar 26, 2024

Make atomic ID_COUNTER increment match xilem style and clear confusion with safety comment

@DasLixou
Copy link
Collaborator Author

Oh wait we increment after.. the comment just irritated me.

@DasLixou DasLixou closed this Mar 26, 2024
@DasLixou DasLixou deleted the patch-1 branch March 28, 2024 11:07
@PoignardAzur
Copy link
Collaborator

I'd actually be okay to merge this after removing the val + 1 part. I think your version is clearer.

@DasLixou DasLixou restored the patch-1 branch March 28, 2024 16:39
@DasLixou DasLixou reopened this Mar 28, 2024
@DasLixou DasLixou changed the title Fix NonZero-unchecked mistake in recording Match atomic increment in recording to be like in xilem and clear safety comment confusion Mar 28, 2024
Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a safety comment to the dangerous initialization spot. If we later add code inbetween the variable initialization and the unsafe block, then it's easier to miss that it is crucial that it is initialized as 1.

src/recording.rs Show resolved Hide resolved
Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather just match Xilem exactly, i.e. use .try_into().unwrap(). This is our only usage of unsafe, which it would be nice to remove.

  • We're nowhere near CPU bottlenecked;
  • this will be called very few times a frame (~15?); and,
  • it is only a single comparison which should be branch predicted well

Also, that title is probably too long. If you apply this suggestion, I'd change it to:

Remove unsafety in ResourceId allocation

@xStrom
Copy link
Member

xStrom commented Mar 28, 2024

Also, that title is probably too long.

Yeah best to keep PR titles at 64 chars or below, otherwise it will be elided in the commit list on the GitHub web interface.

@DasLixou DasLixou changed the title Match atomic increment in recording to be like in xilem and clear safety comment confusion Remove unsafety in ResourceId creation Mar 28, 2024
@DasLixou
Copy link
Collaborator Author

I'm not 100% for removing unsafe "just because it's the only one for now" and it's still safe and safes performance and binary size in theory

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! In this case, the unsafe code was safe for all reasonable scenarios, but it's still good to not get in the habit of using it (and it was technically unsound).

src/recording.rs Outdated Show resolved Hide resolved
Co-authored-by: Daniel McNab <[email protected]>
@xStrom
Copy link
Member

xStrom commented Mar 28, 2024

@DasLixou I sent you a GitHub invite for getting write access to this repo.

We have a policy of PR author pressing the merge button. Once you accept the invite you can press it here.

The reason behind this policy is that sometimes the PR author may want to wait for multiple reviews, or for a review from a specific person. Or they may want to do some final polish.

Sometimes when the PR is very trivial, e.g. just a single typo fix, then it's fine for a reviewer to just merge it.

@DasLixou
Copy link
Collaborator Author

Accepted the invitation, still for some PRs like #516 I just like to have as much reviews and opinions as possible. Also, when I get inactive or something you can just kick me. But is this an indirect call to merge this?

@Philipp-M
Copy link
Contributor

But is this an indirect call to merge this?

It got an approval, so yes?

@xStrom
Copy link
Member

xStrom commented Mar 29, 2024

Yes you can merge this. 🙂

@DasLixou DasLixou added this pull request to the merge queue Mar 29, 2024
Merged via the queue into linebender:main with commit 45bc031 Mar 29, 2024
15 checks passed
@DasLixou DasLixou deleted the patch-1 branch March 29, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants