-
Notifications
You must be signed in to change notification settings - Fork 13.3k
coverage: Don't convert filename/symbol strings to CString
for FFI
#114005
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
Conversation
r? @jackh726 (rustbot has picked a reviewer for you, use r? to override) |
@rustbot label +A-code-coverage |
My original goal was just to store symbols in the filenames set, and only convert to But after digging deeper, I found that the C++ code didn't really need nul-terminated strings at all. |
pointers.as_ptr(), | ||
pointers.len(), | ||
lengths.as_ptr(), | ||
lengths.len(), |
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 added a separate length parameter for the string lengths, so that on the Rust side it's clear that we aren't accidentally omitting the length part of a pointer/length argument pair.
The C++ code then verifies that the two lengths are the same, as they always should be.
let c_filename = CString::new(file_name.to_string()) | ||
.expect("null error converting filename to C string"); | ||
debug!(" file_id: {} = '{:?}'", current_file_id, c_filename); | ||
let (filenames_index, _) = self.filenames.insert_full(c_filename); |
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.
Notice that the old code here needs to convert every filename (Symbol
) into a CString
to insert it into the set of filenames, even though there will usually already be a duplicate entry (created by another function in the same source file).
Symbols are already naturally good for checking whether two strings are identical, so it makes sense to use symbols as set entries, and then only resolve them to strings later when we actually need to pass those strings through FFI.
318d478
to
a4e08cf
Compare
c77ce64
to
df18f3d
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (a9b2c6a): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 632.053s -> 631.684s (-0.06%) |
LLVM APIs are usually perfectly happy to accept pointer/length strings, as long as we supply a suitable length value when creating a
StringRef
orstd::string
.This lets us avoid quite a few intermediate
CString
copies during coverage codegen. It also lets us use anIndexSet<Symbol>
(instead of anIndexSet<CString>
) when building the deduplicated filename table.