Commit graph

185 commits

Author SHA1 Message Date
bors
68655029d4 Auto merge of #60730 - matthewjasper:optimize-false-edges, r=pnkfelix
Optimize matches

Attempt to fix or improve #60571

This is breaking some diagnostics because the MIR for match arms isn't in source order any more.

cc @centril
2019-06-16 09:30:34 +00:00
Mazdak Farrokhzad
be09427b11
Rollup merge of #61813 - matthewjasper:remove-unnecessary-symbol-ops, r=petrochenkov
Remove some unnecessary symbol interner ops

* Don't gensym symbols that don't need to worry about colliding with other symbols
* Use symbol constants instead of interning string literals in a few places.
* Don't generate a module in `__register_diagnostic`

r? @petrochenkov
2019-06-15 17:45:02 +02:00
Matthew Jasper
5c84cd37cb Use sym constansts for PrimitiveTypeTable keys 2019-06-14 18:54:58 +01:00
Matthew Jasper
4e212c6ddc Avoid some unnecessary symbol interner operations 2019-06-14 18:54:58 +01:00
Matthew Jasper
ef1fc86b52 Call str::eq and <[T]>::eq for match comparisons
We used to call the less efficient `<&str>::eq` and `<&[T]>::eq`.
2019-06-13 21:05:21 +01:00
bors
3f511ade5b Auto merge of #60669 - c410-f3r:attrs-fn, r=petrochenkov
Allow attributes in formal function parameters

Implements https://github.com/rust-lang/rust/issues/60406.

This is my first contribution to the compiler and since this is a large and complex project, I am not fully aware of the consequences of the changes I have made.

**TODO**

- [x] Forbid some built-in attributes.
- [x] Expand cfg/cfg_attr
2019-06-12 07:38:01 +00:00
Mazdak Farrokhzad
d78260d781
Rollup merge of #61568 - Mark-Simulacrum:symbol-fmt-macros, r=estebank
Use Symbol, Span in libfmt_macros

I'm not super happy with this, personally, but I think it might be a decent start -- happy to take suggestions as to how to expand this or change things further.

r? @estebank

Fixes #60795
2019-06-12 04:22:47 +02:00
Michael Bradshaw
dac1c6a731 Implement RFC 2645 (transparent enums and unions)
Tracking issue: #60405
2019-06-10 22:07:24 -07:00
Mark Rousskov
dc13072b7b Use Symbol for named arguments in fmt_macros 2019-06-09 13:45:16 -06:00
Caio
1eaaf440d5 Allow attributes in formal function parameters 2019-06-09 07:58:40 -03:00
Vadim Petrochenkov
ea4ad555d7 Introduce #[rustc_dummy] attribute and use it in tests
Unlike other built-in attributes, this attribute accepts any input
2019-06-08 23:55:25 +03:00
Vadim Petrochenkov
74a6d1c821 Turn #[allocator] into a built-in attribute and rename it to #[rustc_allocator] 2019-06-08 23:55:25 +03:00
bors
c1c60d292e Auto merge of #61209 - matthewjasper:const-tuple-constructors, r=oli-obk
Make tuple constructors real const fns

Mir construction special cases `Ctor(...)` to be lowered as `Ctor { 0: ... }`, which means this doesn't come up much in practice, but it seems inconsistent not to allow this.

r? @oli-obk
2019-06-07 09:41:06 +00:00
Matthew Jasper
0d75ab2293 Make constructors actually be const functions 2019-06-06 17:20:06 +01:00
Vadim Petrochenkov
ff40e37b98 Some code cleanup and tidy/test fixes 2019-06-06 14:04:02 +03:00
Vadim Petrochenkov
f745e5f9b6 syntax: Remove duplicate span from token::Ident 2019-06-06 14:04:02 +03:00
Alexander Regueiro
c105c28de0 Fixed rebase fallout. 2019-06-05 21:09:27 +01:00
Oliver Scherer
d6ca34c9d2 Use Symbol more in lint APIs 2019-05-27 12:28:54 +02:00
Nicholas Nethercote
33a3206dc5 Use Symbol equality in may_begin_with and parse_nt. 2019-05-27 14:05:05 +10:00
Nicholas Nethercote
8ae01a9008 Use Symbol equality in is_ident_named. 2019-05-27 14:05:05 +10:00
Nicholas Nethercote
9c7d28d4fd Pre-intern "0", "1", ..., "9", and use where appropriate. 2019-05-27 13:58:38 +10:00
Nicholas Nethercote
58c68d00fd Pass symbols to ExtCtxt::std_path instead of strings.
Because this function is hot.

Also remove the dead `ty_option` function.
2019-05-27 13:58:38 +10:00
Nicholas Nethercote
26451ef7b5 Avoid unnecessary internings.
Most involving `Symbol::intern` on string literals.
2019-05-27 13:58:38 +10:00
Nicholas Nethercote
6c0ff3dd97 Avoid interning in resolve_place_op.
This function is hot for `keccak`.
2019-05-27 13:58:38 +10:00
Nicholas Nethercote
e396f99255 Don't arena-allocate static symbols.
It's just a waste of memory. This also gets rid of the special case for
"".
2019-05-24 20:11:52 +10:00
Vadim Petrochenkov
90d15e7704 syntax: Some code cleanup 2019-05-23 12:46:41 +03:00
bors
15ccaf7791 Auto merge of #60740 - petrochenkov:kw, r=nnethercote
Simplify use of keyword symbols

They mirror non-keyword symbols now (see https://github.com/rust-lang/rust/pull/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.
2019-05-23 01:50:55 +00:00
Vadim Petrochenkov
a1885cdba3 Restore the old behavior of the rustdoc keyword check + Fix rebase 2019-05-22 20:20:12 +03:00
Vadim Petrochenkov
c389a39c97 Eliminate unnecessary Ident::with_empty_ctxts 2019-05-22 19:48:56 +03:00
Vadim Petrochenkov
59a382122f Simplify use of keyword symbols 2019-05-22 19:48:56 +03:00
Michael Bradshaw
a31dc8e3b1 Allow null-pointer-optimized enums in FFI if their underlying representation is FFI safe
This allows types like Option<NonZeroU8> to be used in FFI without triggering the improper_ctypes lint. This works by changing the is_repr_nullable_ptr function to consider an enum E to be FFI-safe if:

- E has no explicit #[repr(...)].
- It only has two variants.
- One of those variants is empty (meaning it has no fields).
- The other variant has only one field.
- That field is one of the following:
  - &T
  - &mut T
  - extern "C" fn
  - core::num::NonZero*
  - core::ptr::NonNull<T>
  - #[repr(transparent)] struct wrapper around one of the types in this list.
- The size of E and its field are both known and are both the same size (implying E is participating in the nonnull optimization).
2019-05-22 07:24:28 -07:00
Mazdak Farrokhzad
44cb86bdc8
Rollup merge of #61003 - nnethercote:rm-InternedString-PartialEq-impls, r=petrochenkov
Remove impls for `InternedString`/string equality.

`Symbol` received the same treatment in #60630.

Also, we can derive `PartialEq` for `InternedString`.

r? @petrochenkov
2019-05-22 03:47:41 +02:00
John Kåre Alsaker
a1f2dceaeb Move edition outside the hygiene lock and avoid accessing it 2019-05-21 18:17:05 +02:00
Nicholas Nethercote
b557567c35 Remove impls for InternedString/string equality.
`Symbol` received the same treatment in #60630.

Also, we can derive `PartialEq` for `InternedString`.
2019-05-21 20:08:33 +10:00
bors
50a0defd5a Auto merge of #60903 - nnethercote:mv-gensyms-from-Symbol-to-Ident, r=petrochenkov
Move gensym operations from `Symbol` to `Ident`

Gensyms are always at the `Ident` level, and long-term we probably want to record gensym-ness in hygiene data.

r? @petrochenkov
2019-05-21 06:37:03 +00:00
Nicholas Nethercote
88d29992bd Remove Symbol::gensym(). 2019-05-20 14:46:55 +10:00
Nicholas Nethercote
e57c0dbeb7 Eliminate Symbol::gensymed. 2019-05-20 14:46:30 +10:00
Nicholas Nethercote
f6637f3fcc Move is_gensymed from Symbol to Ident.
Note that the `is_gensymed` call on `primitive_types` is unnecessary
because that table only contains the name of primitive types (e.g.
`i32`) and never contains gensyms.
2019-05-20 14:46:30 +10:00
bors
caef1e833f Auto merge of #60815 - nnethercote:use-Symbol-more-2, r=petrochenkov
Use `Symbol` even more

These patches simplify the code a bit (fewer conversions) and also speed things up a bit (fewer `with_interner` calls).

r? @petrochenkov
2019-05-20 03:36:43 +00:00
Nicholas Nethercote
c06cdbeac5 Introduce LocalInternedString::intern.
`LocalInternedString::intern(x)` is preferable to
`Symbol::intern(x).as_str()`, because the former involves one call to
`with_interner` while the latter involves two.
2019-05-20 09:17:02 +10:00
Nicholas Nethercote
257eaf523f Introduce InternedString::intern.
`InternedString::intern(x)` is preferable to
`Symbol::intern(x).as_interned_str()`, because the former involves one
call to `with_interner` while the latter involves two.

The case within InternedString::decode() is particularly hot, and this
change reduces the number of `with_interner` calls by up to 13%.
2019-05-20 09:17:00 +10:00
Matthew Jasper
6bb3980e7a Stop using gensyms in HIR lowering
These names aren't ever handled by resolve, so there's no reason to
make them gensyms.
2019-05-19 13:00:28 +01:00
Nicholas Nethercote
4ab5fe3f97 Avoid unnecessary interning in DefPathData::as_interned_str(). 2019-05-17 20:10:52 +10:00
Nicholas Nethercote
86cc326d06 Avoid unnecessary interning in Ident::from_str() calls.
A lot of these static symbols are pre-interned.
2019-05-17 20:10:50 +10:00
Nicholas Nethercote
be3724fb7c Change rustc::util::common::FN_OUTPUT_NAME to a Symbol. 2019-05-17 20:04:20 +10:00
Pulkit Goyal
65d09ea468 Move box from the stable keyword to unstable keywords list
Fixes #60849
2019-05-15 16:22:39 +03:00
Nicholas Nethercote
999c1fc281 Remove the equality operation between Symbol and strings.
And also the equality between `Path` and strings, because `Path` is made
up of `Symbol`s.
2019-05-13 09:31:30 +10:00
Nicholas Nethercote
79602c87b5 Rename syntax::symbol::symbols as syntax::symbol::sym.
Because it's going to be used a lot.
2019-05-13 09:26:43 +10:00
Nicholas Nethercote
a8245f5a38 Add lots of static Symbols.
These will be used in the subsequent commits. Many of them are
attributes.

The commit also adds the ability to handle symbols that aren't
identifiers (e.g. "proc-macro").
2019-05-13 09:26:43 +10:00
bors
b8e0d0a2aa Auto merge of #60700 - petrochenkov:preintern, r=nnethercote
syntax_pos: Optimize symbol interner pre-filling slightly

r? @nnethercote
2019-05-11 06:42:36 +00:00
Vadim Petrochenkov
aeee1fb1f2 syntax_pos: Optimize symbol interner pre-filling slightly 2019-05-10 17:08:22 +03:00
Nicholas Nethercote
e53bb1aefb Reduce Symbol's interface slightly. 2019-05-10 15:59:13 +10:00
Nicholas Nethercote
cb7eacb1d2 Remove the From<InternedString> for String impl.
It's not used.
2019-05-10 15:59:13 +10:00
Nicholas Nethercote
0e27c36145 Add various comments.
Lots of details I wish I'd known when I first looked at this code.
2019-05-10 15:59:12 +10:00
Nicholas Nethercote
c2cae7bbc3 Avoid recursion in de-gensym functions. 2019-05-10 15:59:12 +10:00
Nicholas Nethercote
8c465b4efa Add InternedString::with2.
This lets comparisons occur with a single access to the interner,
instead of two.
2019-05-10 15:59:05 +10:00
Taylor Cramer
fe8760cb84 Implement built-in await syntax
Adds support for .await under the existing async_await feature gate.
Moves macro-like await! syntax to the await_macro feature gate.
Removes support for `await` as a non-keyword under the `async_await`
feature.
2019-05-07 14:45:53 -07:00
John Kåre Alsaker
b82ab24bbf Preallocate BUILTIN_ATTRIBUTES symbols and use a hash map instead of looping 2019-04-15 15:20:05 +02:00
John Kåre Alsaker
f598091c05 Use colon for keyword defs 2019-04-15 07:23:04 +02:00
John Kåre Alsaker
baebf79057 Move modules outside the proc macro 2019-04-15 07:23:04 +02:00
John Kåre Alsaker
61a7a60d45 Make check_name generic 2019-04-15 07:23:02 +02:00
John Kåre Alsaker
10855a36b5 Use a proc macro to declare preallocated symbols 2019-04-15 07:23:01 +02:00
krk
8f3fd85da4 Add missing backtick to Symbol documentation. 2019-04-14 14:27:54 +02:00
John Kåre Alsaker
438f6b04c6 Fix lifetime on LocalInternedString::get function 2019-03-31 03:11:55 +02:00
Vadim Petrochenkov
30d5dc9a0a Do not encode gensymed imports in metadata 2019-03-19 22:50:46 +03:00
Vadim Petrochenkov
6ad55b3dec syntax: Introduce Ident::can_be_raw 2019-03-16 23:13:15 +03:00
Alexander Regueiro
c3e182cf43 rustc: doc comments 2019-02-10 23:42:32 +00:00
Taiki Endo
6413480adf libsyntax_pos => 2018 2019-02-04 03:42:27 +09:00
John Kåre Alsaker
975eb312ef Use multiple threads by default. Limits tests to one thread. Do some renaming. 2019-01-28 16:24:33 +01:00
Mazdak Farrokhzad
c4f6ef25d2 remove extern_in_paths. 2019-01-13 14:18:00 +01:00
Mark Rousskov
2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
kennytm
dadf7fcc2d
Rollup merge of #56699 - nnethercote:SymbolIndex, r=oli-obk
Use a `newtype_index!` within `Symbol`.

This shrinks `Option<Symbol>` from 8 bytes to 4 bytes, which shrinks
`Token` from 24 bytes to 16 bytes. This reduces instruction counts by up
to 1% across a range of benchmarks.

r? @oli-obk
2018-12-14 22:10:09 +08:00
Alex Crichton
cf47a19305 Bump to 1.33.0
* Update bootstrap compiler
* Update version to 1.33.0
* Remove some `#[cfg(stage0)]` annotations

Actually updating the version number is blocked on updating Cargo
2018-12-12 08:09:26 -08:00
Nicholas Nethercote
0f68749260 Use a newtype_index! within Symbol.
This shrinks `Option<Symbol>` from 8 bytes to 4 bytes, which shrinks
`Token` from 24 bytes to 16 bytes. This reduces instruction counts by up
to 1% across a range of benchmarks.
2018-12-12 08:38:08 +11:00
Alexander Regueiro
ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
bors
4bb5d35659 Auto merge of #56392 - petrochenkov:regensym, r=oli-obk
Delay gensym creation for "underscore items" (`use foo as _`/`const _`) until name resolution

So they cannot be cloned by macros. See https://github.com/rust-lang/rust/pull/56303 for the discussion.

Mostly fix cross-crate use of underscore items by inverting the "gensyms are lost in metadata" bug as described in https://github.com/rust-lang/rust/pull/56303#issuecomment-442464695.
Fix unused import warnings for single-segment imports (first commit) and `use crate_name as _` imports (as specified in https://github.com/rust-lang/rust/pull/56303#issuecomment-442274118).
Prohibit accidentally implemented `static _: TYPE = EXPR;` (cc https://github.com/rust-lang/rust/pull/55983).
Add more tests for `use foo as _` imports.
2018-12-06 15:08:11 +00:00
Vadim Petrochenkov
d08f7dcdca Address review comments 2018-12-04 01:13:03 +03:00
Vadim Petrochenkov
08f8faedd0 syntax: Rename some keywords
`CrateRoot` -> `PathRoot`, `::` doesn't necessarily mean crate root now
`SelfValue` -> `SelfLower`, `SelfType` -> `SelfUpper`, both `self` and `Self` can be used in type and value namespaces now
2018-12-04 00:30:27 +03:00
Vadim Petrochenkov
101467c152 syntax: dyn is a used keyword now 2018-12-04 00:30:27 +03:00
Vadim Petrochenkov
2d4b633be3 Delay gensym creation for "underscore items" until name resolution
Prohibit `static _`
Fis unused import warnings for `use foo as _`
Add more tests for `use foo as _`
2018-12-02 15:42:30 +03:00
kennytm
bdb901c865
Rollup merge of #56336 - nnethercote:clean-up-pp, r=nikomatsakis
Clean up and streamline the pretty-printer

Some minor improvements.
2018-12-01 02:03:43 +08:00
Nicholas Nethercote
787959c20d Use Cow in Token::String.
`Printer::word` takes a `&str` and converts it into a `String`, which
causes an allocation. But that allocation is rarely necessary, because
`&str` is almost always a `&'static str` or a `String` that won't be
used again.

This commit changes `Token::String` so it holds a `Cow<'static, str>`
instead of a `String`, which avoids a lot of allocations.
2018-11-29 17:12:18 +11:00
Vadim Petrochenkov
dae4c7b1ff resolve: Implement edition hygiene for imports and absolute paths
Use per-span hygiene in a few other places in resolve
Prefer `rust_2015`/`rust_2018` helpers to comparing editions
2018-11-27 00:32:30 +03:00
Oliver Scherer
3c9258e604 Prefer Default::default over FxHash*::default in struct constructors 2018-10-19 14:34:44 +02:00
varkor
cb594cf373 Treat dyn as a keyword in the 2018 edition 2018-09-16 23:34:42 +01:00
bors
35bf1ae257 Auto merge of #52602 - scottmcm:tryblock-expr, r=nikomatsakis
Implement try block expressions

I noticed that `try` wasn't a keyword yet in Rust 2018, so...

~~Fix​es https://github.com/rust-lang/rust/issues/52604~~ That was fixed by PR https://github.com/rust-lang/rust/pull/53135
cc https://github.com/rust-lang/rust/issues/31436 https://github.com/rust-lang/rust/issues/50412
2018-08-23 11:46:24 +00:00
Scott McMurray
91967a8f16 Put try in the reserved list, not the in-use list 2018-08-19 16:53:41 -07:00
Scott McMurray
1c906093f9 Add try to syntax_pos as an edition-2018-only keyword 2018-08-19 16:30:53 -07:00
Matthias Krüger
71120ef1e5 Fix typos found by codespell. 2018-08-19 17:41:28 +02:00
Oliver Schneider
53d2ebb0ad Implement existential types 2018-07-18 10:53:08 +02:00
Vadim Petrochenkov
84f1bc8b66 Address comments 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov
99ecdb3f5f hygiene: Implement transparent marks 2018-06-30 01:53:32 +03:00
Vadim Petrochenkov
d7072b5bb4 Fix rebase 2018-06-28 11:04:51 +03:00
Vadim Petrochenkov
c5454c04bc Use Idents for lifetimes in HIR 2018-06-28 11:04:50 +03:00
Havvy
ebc315bbbb Implement RFC 2421, 'Keyword unreservations (pure, sizeof, alignof, offsetof)' 2018-06-09 14:15:57 -07:00
Guillaume Gomez
ebee483e24 Add doc keyword support 2018-06-04 09:51:41 +02:00
Vadim Petrochenkov
1e4269cb83 Add Ident::as_str helper 2018-05-26 15:20:23 +03:00
Vadim Petrochenkov
dae5f05f43 Remove the proc keyword again 2018-05-17 23:13:09 +03:00
Vadim Petrochenkov
c4352ff198 Turn some functions from token.rs into methods on Ident 2018-05-17 23:13:09 +03:00
Vadim Petrochenkov
f89e356245 Add two keywords specific to editions 2015 and 2018 respectively 2018-05-17 23:13:09 +03:00