-
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
Rename LocalInternedString
and more
#65776
Rename LocalInternedString
and more
#65776
Conversation
I mentioned elsewhere my suggestion of |
if &*name == "rust_eh_personality" || | ||
&*name == "rust_eh_register_frames" || | ||
&*name == "rust_eh_unregister_frames" { | ||
if name == "rust_eh_personality" || |
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.
Should these be sym::
s?
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.
We can probably replace most string literals with valid literals in them, in the compiler, with sym::
s.
I'd try this if I was in front of my laptop:
rg '"[_a-zA-Z][_a-zA-Z0-9]*"' src/lib*
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.
rust_eh_personality
already is a symbol. We could add the other two. For all potential static symbols there is a decision about whether the identifier is hot enough or frequently used enough for it to be worthwhile, and that decision is not always clear-cut.
"Intern all the static strings" is a possibility, but it would add a lot more due to functions like this one:
rust/src/librustdoc/clean/cfg.rs
Lines 337 to 402 in 10a52c2
let n = &*name.as_str(); | |
let human_readable = match (n, value) { | |
("unix", None) => "Unix", | |
("windows", None) => "Windows", | |
("debug_assertions", None) => "debug-assertions enabled", | |
("target_os", Some(os)) => match &*os.as_str() { | |
"android" => "Android", | |
"dragonfly" => "DragonFly BSD", | |
"emscripten" => "Emscripten", | |
"freebsd" => "FreeBSD", | |
"fuchsia" => "Fuchsia", | |
"haiku" => "Haiku", | |
"ios" => "iOS", | |
"l4re" => "L4Re", | |
"linux" => "Linux", | |
"macos" => "macOS", | |
"netbsd" => "NetBSD", | |
"openbsd" => "OpenBSD", | |
"redox" => "Redox", | |
"solaris" => "Solaris", | |
"windows" => "Windows", | |
_ => "", | |
}, | |
("target_arch", Some(arch)) => match &*arch.as_str() { | |
"aarch64" => "AArch64", | |
"arm" => "ARM", | |
"asmjs" => "JavaScript", | |
"mips" => "MIPS", | |
"mips64" => "MIPS-64", | |
"msp430" => "MSP430", | |
"powerpc" => "PowerPC", | |
"powerpc64" => "PowerPC-64", | |
"s390x" => "s390x", | |
"sparc64" => "SPARC64", | |
"wasm32" => "WebAssembly", | |
"x86" => "x86", | |
"x86_64" => "x86-64", | |
_ => "", | |
}, | |
("target_vendor", Some(vendor)) => match &*vendor.as_str() { | |
"apple" => "Apple", | |
"pc" => "PC", | |
"rumprun" => "Rumprun", | |
"sun" => "Sun", | |
"fortanix" => "Fortanix", | |
_ => "" | |
}, | |
("target_env", Some(env)) => match &*env.as_str() { | |
"gnu" => "GNU", | |
"msvc" => "MSVC", | |
"musl" => "musl", | |
"newlib" => "Newlib", | |
"uclibc" => "uClibc", | |
"sgx" => "SGX", | |
_ => "", | |
}, | |
("target_endian", Some(endian)) => return write!(fmt, "{}-endian", endian), | |
("target_pointer_width", Some(bits)) => return write!(fmt, "{}-bit", bits), | |
("target_feature", Some(feat)) => | |
if self.1 { | |
return write!(fmt, "<code>{}</code>", feat); | |
} else { | |
return write!(fmt, "target feature <code>{}</code>", feat); | |
}, | |
_ => "", | |
}; |
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 should add: I have already converted all the static identifiers that I though were worth converting. Other people may reasonably think that more should be converted.)
/// operation because it requires locking the symbol interner. | ||
pub fn as_str(self) -> LocalInternedString { | ||
/// Convert the name to a `SymbolStr`. This is a slowish operation because | ||
/// it requires locking the symbol interner. |
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.
cc @Manishearth could elsa
have a FrozenIndexSet
that is also thread-safe without a lock?
In this case, just a Sync
FrozenVec
might be enough.
Can I please not be the reviewer? =D It appears @estebank is. :) |
Indeed, I mixed up GitHub's "assignees" and "reviewers" fields. @estebank is the reviewer. |
@bors r+ rollup=never |
📌 Commit 7a466f070585c2f399b3980e1fe6b7e0c721c989 has been approved by |
☔ The latest upstream changes (presumably #65718) made this pull request unmergeable. Please resolve the merge conflicts. |
It makes the relationship with `Symbol` clearer. The `Str` suffix matches the existing `Symbol::as_str()` method nicely, and is also consistent with it being a wrapper of `&str`.
Including removing a bunch of unnecessary `.as_str()` calls, and a bunch of unnecessary sigils.
Because it's highly magical, which goes against the goal of keeping `SymbolStr` simple. Plus it's only used in a handful of places that only require minor changes.
7a466f0
to
d0db290
Compare
I rebased. @bors r=estebank |
📌 Commit d0db290 has been approved by |
⌛ Testing commit d0db290 with merge 0afc234c654c32d457d73f5c454b89455918dfaa... |
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 |
💔 Test failed - checks-azure |
No Tools Breakage Week is over, or close enough that by the time this gets through the queue it will be. @bors r=estebank |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit d0db290 has been approved by |
…ing-and-more, r=estebank Rename `LocalInternedString` and more This PR renames `LocalInternedString` as `SymbolStr`, removes an unnecessary `impl` from it, improves comments, and cleans up some `SymbolStr` uses. r? @estebank
Rollup of 9 pull requests Successful merges: - #65776 (Rename `LocalInternedString` and more) - #65973 (caller_location: point to macro invocation sites, like file!/line!, and use in core::panic!.) - #66015 (librustc_lexer: Refactor the module) - #66062 (Configure LLVM module PIC level) - #66086 (bump smallvec to 1.0) - #66092 (Use KERN_ARND syscall for random numbers on NetBSD, same as FreeBSD.) - #66103 (Add target thumbv7neon-unknown-linux-musleabihf) - #66133 (Update the bundled `wasi-libc` repository) - #66139 (use American spelling for `pluralize!`) Failed merges: r? @ghost
@bors rollup=maybe |
rustup rust-lang/rust#65776 changelog: none
AFAICT these changes are required based on the changes `LocalInternedString` and `SymbolStr` in rust-lang/rust#65776
This PR renames
LocalInternedString
asSymbolStr
, removes an unnecessaryimpl
from it, improves comments, and cleans up someSymbolStr
uses.r? @estebank