-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Make sure fmt-write-bloat
doesn't vacuously pass on no symbols
#143669
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
Open
jieyouxu
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
jieyouxu:fmt-write-bloat
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,24 +12,90 @@ | |
//! present. | ||
//! | ||
//! Some CI jobs try to run faster by disabling debug assertions (through setting | ||
//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of | ||
//! additional `usize` formatting and padding related symbols. | ||
//! `NO_DEBUG_ASSERTIONS=1`). If std debug assertions are disabled, then we can check for the | ||
//! absence of additional `usize` formatting and padding related symbols. | ||
// ignore-tidy-linelength | ||
|
||
//@ ignore-cross-compile | ||
|
||
use run_make_support::artifact_names::bin_name; | ||
// NOTE: against the GCC codegen backend, the assertion | ||
// `object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms)` fails. | ||
//@ ignore-backends: gcc | ||
|
||
use std::path::Path; | ||
|
||
use run_make_support::env::std_debug_assertions_enabled; | ||
use run_make_support::rustc; | ||
use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil}; | ||
use run_make_support::symbols::object_contains_any_symbol_substring; | ||
use run_make_support::{bin_name, is_windows_msvc, rfs, rustc}; | ||
|
||
fn main() { | ||
rustc().input("main.rs").opt().run(); | ||
// panic machinery identifiers, these should not appear in the final binary | ||
let mut panic_syms = vec!["panic_bounds_check", "Debug"]; | ||
if std_debug_assertions_enabled() { | ||
// if debug assertions are allowed, we need to allow these, | ||
// otherwise, add them to the list of symbols to deny. | ||
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]); | ||
} | ||
assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms)); | ||
|
||
let expect_no_panic_symbols = bin_name("expect_no_panic_symbols"); | ||
let expect_no_panic_symbols = Path::new(&expect_no_panic_symbols); | ||
rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run(); | ||
|
||
let expect_panic_symbols = bin_name("expect_panic_symbols"); | ||
let expect_panic_symbols = Path::new(&expect_panic_symbols); | ||
rustc().input("main.rs").output(&expect_panic_symbols).run(); | ||
|
||
if is_windows_msvc() { | ||
// FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output. | ||
|
||
let expect_no_filecheck_pattern = r#" | ||
CHECK: main | ||
CHECK-NOT: {{.*}}Display{{.*}} | ||
CHECK-NOT: {{.*}}panic_bounds_check{{.*}} | ||
"#; | ||
let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt"); | ||
rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern); | ||
|
||
let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil() | ||
.arg("dump") | ||
.arg("-publics") | ||
.input(expect_no_panic_symbols.with_extension("pdb")) | ||
.run(); | ||
llvm_filecheck() | ||
.patterns(expect_no_filecheck_path) | ||
.stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8()) | ||
.run(); | ||
|
||
// NOTE: on different platforms, they may not go through the same code path. E.g. on | ||
// `i686-msvc`, we do not go through `panic_fmt` (only `panic`). So for the check here we | ||
// only try to match for mangled `core::panicking` module path. | ||
let expect_filecheck_pattern = r#" | ||
CHECK: main | ||
CHECK: {{.*}}core{{.*}}panicking{{.*}} | ||
// _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize... | ||
CHECK: {{.*}}Display{{.*}} | ||
CHECK-NOT: {{.*}}panic_bounds_check{{.*}} | ||
"#; | ||
Comment on lines
+74
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remark: these are by no means pretty, and in the future we almost certainly want our own DIA wrappers in |
||
let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt"); | ||
rfs::write(&expect_filecheck_path, expect_filecheck_pattern); | ||
|
||
let expect_panic_symbols_pdbutil_dump = llvm_pdbutil() | ||
.arg("dump") | ||
.arg("-publics") | ||
.input(expect_panic_symbols.with_extension("pdb")) | ||
.run(); | ||
llvm_filecheck() | ||
.patterns(expect_filecheck_path) | ||
.stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8()) | ||
.run(); | ||
} else { | ||
// At least the `main` symbol (or `_main`) should be present. | ||
assert!(object_contains_any_symbol_substring(&expect_no_panic_symbols, &["main"])); | ||
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &["main"])); | ||
|
||
assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms)); | ||
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remark: ignoring this test for GCC cg backend, I do not feel like investigating why #147819 (comment) when the GCC cg backend is used, we observe some of these panic symbols.
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.
Hm, ok that's fair. It feels like this should ideally work with gcc but that needn't be done now. I just hope this isn't a canary warning us the test is going to be flaky 😛.
Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah, if the test ends up becoming flaky, I honestly rather disable or even remove this entire test. Because this test is exercising panic-machinery related optimizations through indirect implementation details, and checking for what is there and isn't there are IMO equally prone to "no longer testing what it's supposed to test". This is still the case even if we use DIA wrappers :(