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

feat: std::hint::black_box function. #6529

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

Conversation

aakoshh
Copy link
Contributor

@aakoshh aakoshh commented Nov 15, 2024

Description

Problem*

Resolves #6471

Summary*

Added a std::hint Noir module with a black_box builtin function that is treated during SSA optimisation steps as if it could potentially have side effects, which prevents the value it is applied to from being simplified to a known value and the instruction from being removed.

Additional Context

Using a builtin rather than foreign so that this can be called from non-Brillig code.

I added an Intrinsic::Hint because Intrinsic::BlackBox was already taken; perhaps Intrinsic::AsWitness could be moved into Hint as well (not that it matters, but the comments call it a hint too).

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@aakoshh aakoshh marked this pull request as draft November 15, 2024 16:46
@aakoshh aakoshh marked this pull request as ready for review November 15, 2024 17:05
@aakoshh aakoshh requested a review from a team November 15, 2024 17:07
Copy link
Member

Choose a reason for hiding this comment

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

Can you add some tests to check how it handles arrays, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good shout, the slice tests uncovered a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some tests with mutable references but that doesn't work very well. I left some comments about scenarios that didn't work out, let me know if you think there's anything we can do about them.

@TomAFrench
Copy link
Member

I'd like to take another look at this today after scrum

@aakoshh
Copy link
Contributor Author

aakoshh commented Nov 25, 2024

@TomAFrench have you had a chance to look at this?

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.

Add equivalent to Rust's std::hint::blackbox
2 participants