-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
librustc_codegen_llvm: Use slices in preference to 0-terminated strings #69779
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @ecstatic-morse (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
}; | ||
// When empty, linkage_name field is omitted, | ||
// which is what we want for no_mangle statics | ||
let linkage_name = linkage_name.as_deref().unwrap_or(""); |
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.
Are the semantics of a null pointer vs an empty string documented somewhere?
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.
Both a null pointer and an empty string will create a StringRef representing an
empty sequence of bytes. At this point they are still distinguishable by
looking at the data pointer, although it would unusual to do so in StringRef
based API.
In this case, Name and LinkageName are turned into canonical MDStrings which
remove the distinction completely:
static MDString *getCanonicalMDString(LLVMContext &Context, StringRef S) {
if (S.empty())
return nullptr;
return MDString::get(Context, S);
}
Assuming the RefCell borrow order gets sorted out, this looks good to me. I'll r? @eddyb in case they want to review, since I don't own this code. In the future, it would be nice if you mentioned stuff like the invariants/constructors for |
r? @eddyb |
cc @nagisa @nikic @hanna-kruppe (Should we have a "LLVM team" for a ping like this?) |
src/rustllvm/RustWrapper.cpp
Outdated
LLVMRustDIBuilderRef Builder, | ||
const char *Filename, size_t FilenameLen, | ||
const char *Directory, size_t DirectoryLen) { | ||
return wrap(Builder->createFile({Filename, FilenameLen}, |
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.
Would it be perhaps be better to be explicit about what type (StringRef
) is being created here? I'd find StringRef { Filename, FilenameLen }
significantly easier to read (applies across this file).
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.
Repalced with StringRef(Name, NameLen)
which I feel is more common in LLVM itself.
Additionally whenever possible match C API provided by the LLVM.
Rebased and converted two remaining uses of 0-terminated strings in debuginfo codegen: r? @nagisa |
@bors r+ |
📌 Commit e54a829 has been approved by |
🌲 The tree is currently closed for pull requests below priority 1000, this pull request will be tested once the tree is reopened |
librustc_codegen_llvm: Use slices in preference to 0-terminated strings Additionally whenever possible match C API provided by the LLVM.
librustc_codegen_llvm: Use slices in preference to 0-terminated strings Additionally whenever possible match C API provided by the LLVM.
Rollup of 6 pull requests Successful merges: - #69201 (Permit attributes on 'if' expressions) - #69402 (Extend search) - #69519 ( Don't use static crt by default when build proc-macro) - #69685 (unix: Don't override existing SIGSEGV/BUS handlers) - #69762 (Ensure that validity only raises validity errors) - #69779 (librustc_codegen_llvm: Use slices in preference to 0-terminated strings) Failed merges: r? @ghost
librustc_codegen_llvm: Use slices in preference to 0-terminated strings Additionally whenever possible match C API provided by the LLVM.
Rollup of 6 pull requests Successful merges: - #69201 (Permit attributes on 'if' expressions) - #69685 (unix: Don't override existing SIGSEGV/BUS handlers) - #69762 (Ensure that validity only raises validity errors) - #69779 (librustc_codegen_llvm: Use slices in preference to 0-terminated strings) - #69801 (rustc_parse: Remove `Parser::normalized(_prev)_token`) - #69842 (Add more regression tests) Failed merges: r? @ghost
Additionally whenever possible match C API provided by the LLVM.