-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Implement RFC 2011 (nicer assert messages) #48973
Conversation
92bf267
to
1a2577d
Compare
I think function call arguments could be captured, too. There's no difference between |
Highfive failed to assign a reviewer, assigning one randomly from the libs team. r? @dtolnay |
☔ The latest upstream changes (presumably #48684) made this pull request unmergeable. Please resolve the merge conflicts. |
I thought so too, but realized that they are different after trying to implement. let x = &mut Foo;
let y = &mut Foo;
let _ = bar(x); // x is reborrowed
println!("{:?}", x);
let _ = x + y; // x is consumed
// println!("{:?}", x); // "use of moved value: `x`" This is problematic because my strategy to capture an intermediate value by-value is to replace a expression with
which always consumes the expression. |
b386e12
to
63b84e8
Compare
Ping from triage, @dtolnay ! Will you have time to review this in the near future? |
☔ The latest upstream changes (presumably #49308) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to look at the implementation of Context::generate but here are some comments regarding the rest.
src/libcore/lib.rs
Outdated
#[unstable(feature = "generic_assert_internals", issue = "44838")] | ||
impl<T> Debug for DebugFallback<T> { | ||
default fn fmt(&self, f: &mut Formatter) -> fmt::Result { | ||
f.write_str(self.alt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for self.value to be Unevaluated here? If so, I would expect this to print "(unevaluated)"
even for non-Debug types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, this needs to be
match self.value {
Value | NotCopy => alt,
Unevaluated => "(unevaluated)",
}
src/libsyntax_ext/assert.rs
Outdated
@@ -86,7 +761,7 @@ fn escape_format_string(s: &str) -> String { | |||
|
|||
#[test] | |||
fn test_escape_format_string() { | |||
assert!(escape_format_string(r"foo{}\") == r"foo{{}}\\"); | |||
assert!(escape_format_string("foo{}") == "foo{{}}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change necessary? The implementation of escape_format_string
has not changed.
src/libsyntax_ext/assert.rs
Outdated
/// True if `||` or `&&` are contained in this tree. | ||
contains_lazy: bool, | ||
/// True if by-value captures are contained in this tree. | ||
contains_by_ref: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field name contradicts the doc comment (by-ref vs by-value).
To help review, would you be able to share what src/libsyntax_ext/assert_tests.rs looks like after macro expansion? |
https://gist.github.com/sinkuu/ba6abd95cb55e839ae33cb022410bb36 |
@dtolnay I guess that your review comments are addressed. Mind doing another review? |
@@ -208,3 +208,87 @@ pub use coresimd::simd; | |||
#[unstable(feature = "stdsimd", issue = "48556")] | |||
#[cfg(not(stage0))] | |||
pub use coresimd::arch; | |||
|
|||
// FIXME: move to appropriate location |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to libcore/asserting.rs (by analogy with runtime support for panicking in libcore/panicking.rs).
Thanks! I would be comfortable accepting this if for now we make it expand exactly the old way in release mode. Later we can debate what changes it makes sense to apply in release mode. |
Is this insta-stable? I have no strong opinion but maybe it's good to have a feature flag to switch between new and old behaviour. Regarding the performance concern, does it make sense to have a perf run (while we have this enabled as default)? |
#49071 (comment) applies to this PR, too:( I believe "plain text fallback" described in RFC2011 cannot be implmented without this specialization ( |
This RFC can be backward compatible only if the broader specialization is used; do you think we can use that here? Is there a soundness issue? cc @nikomatsakis Back to the implementation itself, can we track the evaluated status by using a counter? Short circuits has a defined ordering, and presumably computing that at codegen time allows better optimization. |
I'm not sure whether if I get what you mean. Maybe listing all evaluation states and have branches of |
Sounds like you're right. Never mind then. |
☔ The latest upstream changes (presumably #49154) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm not sure if my input is still needed, can you clarify? =) |
@nikomatsakis As we are using a variant of specialization that isn't going to be stabilized, we need your input on whether it's acceptable to use such specialization or not. Also see #49071 which tries to achieve a similar specialization. |
I will reopen once the discussion about sound specialization settles. |
#44838
Detailed designs
🚲 🏠 What should be captured? (Current implementation captures operands of unary and binary operators.) How should the panic message look like?
Performance
Now
assert
expands to some amount of code, and this may slow down compilation and execution. We need to test performance difference and see if it have to fall back to the original behavior whennot(debug_assertions)
.