Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Use `Symbol` more #60630
Use `Symbol` more #60630
Conversation
|
@bors try |
Use `Symbol` more A `Symbol` can be equated with a string (e.g. `&str`). This involves a TLS lookup to get the chars (and a Mutex lock in a parallel compiler) and then a char-by-char comparison. This functionality is convenient but avoids one of the main benefits of `Symbol`s, which is fast equality comparisons. This PR removes the `Symbol`/string equality operations, forcing a lot of existing string occurrences to become `Symbol`s. Fortunately, these are almost all static strings (many are attribute names) and we can add static `Symbol`s as necessary, and very little extra interning occurs. The benefits are (a) a slight speedup (possibly greater in a parallel compiler), and (b) the code is a lot more principled about `Symbol` use. The main downside is verbosity, particularly with more `use syntax::symbol::symbols` items. r? @Zoxc
|
bors seems to have gotten stuck @bors try |
|
|
|
@oli-obk I think you have to use |
|
@bors retry |
Use `Symbol` more A `Symbol` can be equated with a string (e.g. `&str`). This involves a TLS lookup to get the chars (and a Mutex lock in a parallel compiler) and then a char-by-char comparison. This functionality is convenient but avoids one of the main benefits of `Symbol`s, which is fast equality comparisons. This PR removes the `Symbol`/string equality operations, forcing a lot of existing string occurrences to become `Symbol`s. Fortunately, these are almost all static strings (many are attribute names) and we can add static `Symbol`s as necessary, and very little extra interning occurs. The benefits are (a) a slight speedup (possibly greater in a parallel compiler), and (b) the code is a lot more principled about `Symbol` use. The main downside is verbosity, particularly with more `use syntax::symbol::symbols` items. r? @Zoxc
|
|
|
|
|
@rust-timer build ce805fd |
|
Success: Queued ce805fd with parent b92d360, comparison URL. |
|
Finished benchmarking try commit ce805fd |
|
I think github is being bugged by time travellers today |
|
One 1.4% perf improvement, many small ones (<1%) |
|
(I haven't done a full review but this does sound like something I've been wanting for a long time) |
|
The |
| } | ||
|
|
||
| // Non-identifer symbols that can be referred to with syntax_pos::nisymbols::*. | ||
| NISymbols { |
petrochenkov
May 9, 2019
Contributor
"Non-identness" doesnt' really matter, entries in the Symbols { ... } block should probably just allow an optional : "non-ident" literal (with everything generated in one mod symbols).
"Non-identness" doesnt' really matter, entries in the Symbols { ... } block should probably just allow an optional : "non-ident" literal (with everything generated in one mod symbols).
nnethercote
May 9, 2019
Author
Contributor
Ah, I didn't realize that was possible. Good suggestion, I will implement it.
Ah, I didn't realize that was possible. Good suggestion, I will implement it.
Zoxc
May 10, 2019
Contributor
I'd like us to have 2 namespaces here, so if you use symbols::a you know you're getting a and not some other identifier. It also ensure there won't be any name conflicts if you add a: "b" and you want to add a later.
We could probably rename symbols to idents in that case.
I'd like us to have 2 namespaces here, so if you use symbols::a you know you're getting a and not some other identifier. It also ensure there won't be any name conflicts if you add a: "b" and you want to add a later.
We could probably rename symbols to idents in that case.
|
So, my primary concern is that we are front-loading interning of about 500 strings and do it in every compilation session even if most of them won't be actually used. Could you measure how much time the UI test suite (a lot of little programs) takes with and without these changes? |
Use `Symbol` more A `Symbol` can be equated with a string (e.g. `&str`). This involves a TLS lookup to get the chars (and a Mutex lock in a parallel compiler) and then a char-by-char comparison. This functionality is convenient but avoids one of the main benefits of `Symbol`s, which is fast equality comparisons. This PR removes the `Symbol`/string equality operations, forcing a lot of existing string occurrences to become `Symbol`s. Fortunately, these are almost all static strings (many are attribute names) and we can add static `Symbol`s as necessary, and very little extra interning occurs. The benefits are (a) a slight speedup (possibly greater in a parallel compiler), and (b) the code is a lot more principled about `Symbol` use. The main downside is verbosity, particularly with more `use syntax::symbol::symbols` items. r? @Zoxc
|
|
Simplify use of keyword symbols They mirror non-keyword symbols now (see #60630). `keywords::MyKeyword.name()` -> `kw::MyKeyword` `keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common) `keywords::Invalid.ident()` -> `Ident::invalid()` (more common) Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated. This means `kw::MyKeyword` can now be used in `match` in particular.
Simplify use of keyword symbols They mirror non-keyword symbols now (see #60630). `keywords::MyKeyword.name()` -> `kw::MyKeyword` `keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common) `keywords::Invalid.ident()` -> `Ident::invalid()` (more common) Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated. This means `kw::MyKeyword` can now be used in `match` in particular.
Simplify use of keyword symbols They mirror non-keyword symbols now (see #60630). `keywords::MyKeyword.name()` -> `kw::MyKeyword` `keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common) `keywords::Invalid.ident()` -> `Ident::invalid()` (more common) Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated. This means `kw::MyKeyword` can now be used in `match` in particular.
Simplify use of keyword symbols They mirror non-keyword symbols now (see #60630). `keywords::MyKeyword.name()` -> `kw::MyKeyword` `keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common) `keywords::Invalid.ident()` -> `Ident::invalid()` (more common) Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated. This means `kw::MyKeyword` can now be used in `match` in particular.
Simplify use of keyword symbols They mirror non-keyword symbols now (see #60630). `keywords::MyKeyword.name()` -> `kw::MyKeyword` `keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common) `keywords::Invalid.ident()` -> `Ident::invalid()` (more common) Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated. This means `kw::MyKeyword` can now be used in `match` in particular.
`Symbol` received the same treatment in rust-lang#60630. Also, we can derive `PartialEq` for `InternedString`.
`Symbol` received the same treatment in rust-lang#60630. Also, we can derive `PartialEq` for `InternedString`.
… r=<try> Remove impls for `InternedString`/string equality. `Symbol` received the same treatment in #60630. Also, we can derive `PartialEq` for `InternedString`. r? @petrochenkov
… r=<try> Remove impls for `InternedString`/string equality. `Symbol` received the same treatment in #60630. Also, we can derive `PartialEq` for `InternedString`. r? @petrochenkov
… r=<try> Remove impls for `InternedString`/string equality. `Symbol` received the same treatment in #60630. Also, we can derive `PartialEq` for `InternedString`. r? @petrochenkov
…alEq-impls, r=petrochenkov Remove impls for `InternedString`/string equality. `Symbol` received the same treatment in rust-lang#60630. Also, we can derive `PartialEq` for `InternedString`. r? @petrochenkov
…alEq-impls, r=petrochenkov Remove impls for `InternedString`/string equality. `Symbol` received the same treatment in rust-lang#60630. Also, we can derive `PartialEq` for `InternedString`. r? @petrochenkov
Simplify use of keyword symbols They mirror non-keyword symbols now (see #60630). `keywords::MyKeyword.name()` -> `kw::MyKeyword` `keywords::MyKeyword.ident()` -> `Ident::with_empty_ctxt(kw::MyKeyword)` (not common) `keywords::Invalid.ident()` -> `Ident::invalid()` (more common) Keywords are simply `Symbol` constants now, the `Keyword` struct is eliminated. This means `kw::MyKeyword` can now be used in `match` in particular.
A
Symbolcan be equated with a string (e.g.&str). This involves aTLS lookup to get the chars (and a Mutex lock in a parallel compiler)
and then a char-by-char comparison. This functionality is convenient but
avoids one of the main benefits of
Symbols, which is fast equalitycomparisons.
This PR removes the
Symbol/string equality operations, forcing a lotof existing string occurrences to become
Symbols. Fortunately, theseare almost all static strings (many are attribute names) and we can add
static
Symbols as necessary, and very little extra interning occurs.The benefits are (a) a slight speedup (possibly greater in a parallel
compiler), and (b) the code is a lot more principled about
Symboluse.The main downside is verbosity, particularly with more
use syntax::symbol::symbolsitems.r? @Zoxc