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

Add context for more "strict undefined behavior" cases #627

Merged

Conversation

fasterthanlime
Copy link
Contributor

...and make it hard to forget to add context again.

This hit us in https://github.com/axodotdev/cargo-dist when trying to enable strict undefined behavior.

The change I do care about is using ctx_ok! in all branches of the vm evaluation.

I added a little trick where the ok! macro is shadowed, so if you accidentally use it again, rustc will yell at you:

CleanShot 2024-10-31 at 17 09 49@2x

Other ideas include.. shadowing ok! in the first place and changing every ctx_ok! invocation back to ok!, but eh, I had to pick one. Feel free to pick your favorite / take over this PR / do whatever it takes to get this merged, all I care is that our errors have debug info :) Thanks!

@fasterthanlime fasterthanlime force-pushed the keep-ctx-undefined-behavior branch from 0d428c9 to a7b0df9 Compare October 31, 2024 16:45
@@ -306,7 +318,7 @@ impl<'env> Vm<'env> {
Instruction::EmitRaw(val) => {
// this only produces a format error, no need to attach
// location information.
ok!(out.write_str(val).map_err(Error::from));
ctx_ok!(out.write_str(val).map_err(Error::from));
Copy link
Owner

Choose a reason for hiding this comment

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

This case is intentionally bypassing ctx_ok! as you can see from the comment. This is done for performance reasons.

@@ -279,6 +279,18 @@ impl<'env> Vm<'env> {
};
}

#[allow(unused_macros)]
Copy link
Owner

Choose a reason for hiding this comment

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

While I think this is a nice idea, at least the raw case should be allowed to use the ok! macro as mentioned. I would probably just not do the ok! macro here. Particularly with the fixes to ? this codebase will avoid the ok! and some! macros in the future anyways.

...and make it hard to forget to add context again
@fasterthanlime fasterthanlime force-pushed the keep-ctx-undefined-behavior branch from a7b0df9 to 3b9ff86 Compare October 31, 2024 17:20
@fasterthanlime
Copy link
Contributor Author

@mitsuhiko Thanks for the review! I removed the ok-shadowing and let EmitRaw use it — it's now just 3 occurences of ok=>ctx_ok

fasterthanlime added a commit to axodotdev/cargo-dist that referenced this pull request Oct 31, 2024
For now, this depends on a branch of minijinja, until
<mitsuhiko/minijinja#627> lands
@mitsuhiko mitsuhiko merged commit e327577 into mitsuhiko:main Oct 31, 2024
fasterthanlime added a commit to axodotdev/cargo-dist that referenced this pull request Oct 31, 2024
For now, this depends on a branch of minijinja, until
<mitsuhiko/minijinja#627> lands
fasterthanlime added a commit to axodotdev/cargo-dist that referenced this pull request Nov 1, 2024
For now, this depends on a branch of minijinja, until
<mitsuhiko/minijinja#627> lands
fasterthanlime added a commit to axodotdev/cargo-dist that referenced this pull request Nov 1, 2024
For now, this depends on a branch of minijinja, until
<mitsuhiko/minijinja#627> lands
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.

2 participants