about summary refs log tree commit diff
path: root/src/libsyntax
AgeCommit message (Collapse)AuthorLines
2018-05-19rustc: introduce {ast,hir}::AnonConst to consolidate so-called "embedded ↵Eduard-Mihai Burtescu-29/+73
constants".
2018-05-18rustc: Disallow modules and macros in expansionsAlex Crichton-5/+56
This commit feature gates generating modules and macro definitions in procedural macro expansions. Custom derive is exempt from this check as it would be a large retroactive breaking change (#50587). It's hoped that we can hopefully stem the bleeding to figure out a better solution here before opening up the floodgates. The restriction here is specifically targeted at surprising hygiene results [1] that result in non-"copy/paste" behavior. Hygiene and procedural macros is intended to be avoided as much as possible for Macros 1.2 by saying everything is "as if you copy/pasted the code", but modules and macros are sort of weird exceptions to this rule that aren't fully fleshed out. [1]: https://github.com/rust-lang/rust/issues/50504#issuecomment-387734625 cc #50504
2018-05-18rustc: Fix joint-ness of stringified token-streamsAlex Crichton-17/+42
This commit fixes `StringReader`'s parsing of tokens which have been stringified through procedural macros. Whether or not a token tree is joint is defined by span information, but when working with procedural macros these spans are often dummy and/or overridden which means that they end up considering all operators joint if they can! The fix here is to track the raw source span as opposed to the overridden span. With this information we can more accurately classify `Punct` structs as either joint or not. Closes #50700
2018-05-18Make `Directory::path` a `Cow`.Nicholas Nethercote-12/+16
Because we create a lot of these in the macro parser, but only very rarely modify them. This speeds up some html5ever runs by 2--3%.
2018-05-18Introduce `MatcherPosHandle`.Nicholas Nethercote-11/+59
This lets us store most `MatcherPos` instances on the stack. This speeds up various runs of html5ever, the best by 3%.
2018-05-18Auto merge of #50307 - petrochenkov:keyhyg2, r=nikomatsakisbors-153/+63
Implement edition hygiene for keywords Determine "keywordness" of an identifier in its hygienic context. cc https://github.com/rust-lang/rust/pull/49611 I've resurrected `proc` as an Edition-2015-only keyword for testing purposes, but it should probably be buried again. EDIT: `proc` is removed again.
2018-05-18Auto merge of #50566 - nnethercote:bump, r=petrochenkovbors-65/+56
Streamline `StringReader::bump` These patches make `bump` smaller and nicer. They speed up most runs for coercions and tuple-stress by 1--3%.
2018-05-17Turn some functions from `token.rs` into methods on `Ident`Vadim Petrochenkov-54/+10
2018-05-17Pass crate editions to macro expansions, update testsVadim Petrochenkov-21/+45
2018-05-17Add two keywords specific to editions 2015 and 2018 respectivelyVadim Petrochenkov-2/+7
2018-05-17Add edition to expansion infoVadim Petrochenkov-4/+12
2018-05-17Move definition of `Edition` from libsyntax to libsyntax_posVadim Petrochenkov-84/+1
2018-05-17Rename trans to codegen everywhere.Irina Popa-2/+2
2018-05-17Change `TokenTreeOrTokenTreeVec` to `TokenTreeOrTokenTreeSlice`.Nicholas Nethercote-19/+19
This avoids a `to_owned` call that can be hot, speeding up the various runs of html5ever by 1--5%, and some runs of crates.io by 2--3%.
2018-05-16Auto merge of #50045 - est31:label_break_value, r=eddybbors-17/+49
Implement label break value (RFC 2046) Implement label-break-value (#48594).
2018-05-16Add feature gate label_break_valueest31-0/+9
2018-05-16label-break-value: Parsing and AST/HIR changesest31-17/+40
2018-05-16Auto merge of #50473 - petrochenkov:pmapi, r=alexcrichtonbors-0/+14
Review proc macro API 1.2 cc https://github.com/rust-lang/rust/issues/38356 Summary of applied changes: - Documentation for proc macro API 1.2 is expanded. - Renamed APIs: `Term` -> `Ident`, `TokenTree::Term` -> `TokenTree::Ident`, `Op` -> `Punct`, `TokenTree::Op` -> `TokenTree::Punct`, `Op::op` -> `Punct::as_char`. - Removed APIs: `Ident::as_str`, use `Display` impl for `Ident` instead. - New APIs (not stabilized in 1.2): `Ident::new_raw` for creating a raw identifier (I'm not sure `new_x` it's a very idiomatic name though). - Runtime changes: - `Punct::new` now ensures that the input `char` is a valid punctuation character in Rust. - `Ident::new` ensures that the input `str` is a valid identifier in Rust. - Lifetimes in proc macros are now represented as two joint tokens - `Punct('\'', Spacing::Joint)` and `Ident("lifetime_name_without_quote")` similarly to multi-character operators. - Stabilized APIs: None yet. A bit of motivation for renaming (although it was already stated in the review comments): - With my compiler frontend glasses on `Ident` is the single most appropriate name for this thing, *especially* if we are doing input validation on construction. `TokenTree::Ident` effectively wraps `token::Ident` or `ast::Ident + is_raw`, its meaning is "identifier" and it's already named `ident` in declarative macros. - Regarding `Punct`, the motivation is that `Op` is actively misleading. The thing doesn't mean an operator, it's neither a subset of operators (there is non-operator punctuation in the language), nor superset (operators can be multicharacter while this thing is always a single character). So I named it `Punct` (first proposed in [the original RFC](https://github.com/rust-lang/rfcs/pull/1566), then [by @SimonSapin](https://github.com/rust-lang/rust/issues/38356#issuecomment-276676526)) , together with input validation it's now a subset of ASCII punctuation character category (`u8::is_ascii_punctuation`).
2018-05-15Represent lifetimes as two joint tokens in proc macrosVadim Petrochenkov-4/+9
2018-05-15proc_macro: Validate inputs to `Punct::new` and `Ident::new`Vadim Petrochenkov-0/+9
2018-05-15Feature gate trivial boundsMatthew Jasper-0/+3
2018-05-14Remove `StringReader::col`.Nicholas Nethercote-7/+13
It only has a single use, within code handling indented block comments. We can replace that with the new `FileMap::col_pos()`, which computes the col position (BytePos instead of CharPos) based on the record of the last newline char (which we already record). This is actually an improvement, because `trim_whitespace_prefix_and_push_line()` was using `col`, which is a `CharPos`, as a slice index, which is a byte/char confusion.
2018-05-14Make `nextnextch()` more closely resemble `nextch()`.Nicholas Nethercote-8/+7
2018-05-13stabilize :lifetimeAlex Burka-19/+3
2018-05-13Macros: Add a 'literal' fragment specifierDan Aloni-13/+59
Implements RFC 1576. See: https://github.com/rust-lang/rfcs/blob/master/text/1576-macros-literal-matcher.md Changes are mostly in libsyntax, docs, and tests. Feature gate is enabled for 1.27.0. Many thanks to Vadim Petrochenkov for following through code reviews and suggestions. Example: ````rust macro_rules! test_literal { ($l:literal) => { println!("literal: {}", $l); }; ($e:expr) => { println!("expr: {}", $e); }; } fn main() { let a = 1; test_literal!(a); test_literal!(2); test_literal!(-3); } ``` Output: ``` expr: 1 literal: 2 literal: -3 ```
2018-05-13Remove `StringReader::terminator`.Nicholas Nethercote-20/+11
It's silly for a hot function like `bump()` to have such an expensive bounds check. This patch replaces terminator with `end_src_index`. Note that the `self.terminator` check in `is_eof()` wasn't necessary because of the way `StringReader` is initialized.
2018-05-13Rename some stuff in `StringReader`.Nicholas Nethercote-29/+24
- `source_text` becomes `src`, matching `FileMap::src`. - `byte_offset()` becomes `src_index()`, which makes it clearer that it's an index into `src`. (Likewise for variables containing `byte_offset` in their name.) This function also now returns a `usize` instead of a `BytePos`, because every callsite immediately converted the `BytePos` to a `usize`.
2018-05-13Tweak naming and ordering in `StringReader::bump()`.Nicholas Nethercote-16/+15
This patch removes the "old"/"new" names in favour of "foo"/"next_foo", which matches the field names. It also moves the setting of `self.{ch,pos,next_pos}` in the common case to the end, so that the meaning of "foo"/"next_foo" is consistent until the end.
2018-05-13Inline `char_at()` and `record_width`.Nicholas Nethercote-0/+1
Because `bump()` is hot.
2018-05-13Add a Rayon thread poolJohn Kåre Alsaker-2/+2
2018-05-12rustc: Allow an edition's feature on that editionAlex Crichton-41/+46
This commit fixes a hard error where the `#![feature(rust_2018_preview)]` feature was forbidden to be mentioned when the `--edition 2018` flag was passed. This instead silently accepts that feature gate despite it not being necessary. It's intended that this will help ease the transition into the 2018 edition as users will, for the time being, start off with the `rust_2018_preview` feature and no longer immediately need to remove it. Closes #50662
2018-05-11Auto merge of #50620 - alexcrichton:change-names-again, r=nikomatsakisbors-2/+2
Rename the 2018 edition lint names * `rust_2018_breakage` -> `rust_2018_compatibility` - the lint for ensuring that your code, in the 2015 edition, is compatible with the 2018 edition's semantics. This is required to pass *before* you enable the 2018 edition. * `rust_2018_migration` -> `rust_2018_idioms` - the lint for writing idiomatic code after you've already enabled the 2018 edition
2018-05-11Auto merge of #50609 - alexcrichton:no-nll-preview, r=nikomatsakisbors-1/+1
Remove `nll` from `rust_2018_preview` NLL isn't quite ready yet so gonna hold off on inserting it into the preview.
2018-05-10Rename the 2018 edition lint namesAlex Crichton-2/+2
* `rust_2018_breakage` -> `rust_2018_compatibility` - the lint for ensuring that your code, in the 2015 edition, is compatible with the 2018 edition's semantics. This is required to pass *before* you enable the 2018 edition. * `rust_2018_migration` -> `rust_2018_idioms` - the lint for writing idiomatic code after you've already enabled the 2018 edition
2018-05-10Fix tuple struct field spansEsteban Küber-1/+1
2018-05-10Remove `nll` from `rust_2018_preview`Alex Crichton-1/+1
NLL isn't quite ready yet so gonna hold off on inserting it into the preview.
2018-05-09Rollup merge of #50525 - nnethercote:lit_token, r=michaelwoeristerkennytm-6/+17
Optimize string handling in lit_token(). In the common case, the string value in a string literal Token is the same as the string value in a string literal LitKind. (The exception is when escapes or \r are involved.) This patch takes advantage of that to avoid calling str_lit() and re-interning the string in that case. This speeds up incremental builds for a few of the rustc-benchmarks, the best by 3%. Benchmarks that got a speedup of 1% or more: ``` coercions avg: -1.1% min: -3.5% max: 0.4% regex-check avg: -1.2% min: -1.5% max: -0.6% futures-check avg: -0.9% min: -1.4% max: -0.3% futures avg: -0.8% min: -1.3% max: -0.3% futures-opt avg: -0.7% min: -1.2% max: -0.1% regex avg: -0.5% min: -1.2% max: -0.1% regex-opt avg: -0.5% min: -1.1% max: -0.1% hyper-check avg: -0.7% min: -1.0% max: -0.3% ```
2018-05-09Optimize string handling in lit_token().Nicholas Nethercote-6/+17
In the common case, the string value in a string literal Token is the same as the string value in a string literal LitKind. (The exception is when escapes or \r are involved.) This patch takes advantage of that to avoid calling str_lit() and re-interning the string in that case. This speeds up incremental builds for a few of the rustc-benchmarks, the best by 3%.
2018-05-07Auto merge of #50454 - Manishearth:edition-preview-fixes, r=alexcrichtonbors-4/+12
Various edition preview fixes Implement a bunch of things discussed in the meeting.
2018-05-06Fix assertion message generationShotaro Yamada-1/+1
2018-05-04Make extern_absolute_paths only work on the new editionManish Goregaokar-2/+4
2018-05-04Make --edition imply the preview flagManish Goregaokar-0/+6
2018-05-04Rename breakage lintsManish Goregaokar-2/+2
2018-05-04Add catch and proc macros to the edition (fixes #50443)Manish Goregaokar-2/+2
2018-05-03Auto merge of #50413 - kennytm:rollup, r=kennytmbors-2/+8
Rollup of 12 pull requests Successful merges: - #50302 (Add query search order check) - #50320 (Fix invalid path generation in rustdoc search) - #50349 (Rename "show type declaration" to "show declaration") - #50360 (Clarify wordings of the `unstable_name_collision` lint.) - #50365 (Use two vectors in nearest_common_ancestor.) - #50393 (Allow unaligned reads in constants) - #50401 (Revert "Implement FromStr for PathBuf") - #50406 (Forbid constructing empty identifiers from concat_idents) - #50407 (Always inline simple BytePos and CharPos methods.) - #50416 (check if the token is a lifetime before parsing) - #50417 (Update Cargo) - #50421 (Fix ICE when using a..=b in a closure.) Failed merges:
2018-05-03Auto merge of #50030 - flip1995:rfc2103, r=petrochenkovbors-84/+166
Implement tool_attributes feature (RFC 2103) cc #44690 This is currently just a rebased and compiling (hopefully) version of #47773. Let's see if travis likes this. I will add the implementation for `tool_lints` this week.
2018-05-03check if the token is a lifetime before parsingrleungx-2/+8
2018-05-03Auto merge of #50391 - nnethercote:escape_unicode, r=eddybbors-11/+5
Use escape_default() for strings in LitKind::token(). This avoids converting every char to \u{...} form, which bloats the resulting strings unnecessarily. It also provides consistency with the existing escape_default() calls in LitKind::token() used for raw string literals, char literals, and raw byte char literals. There are two benefits from this change. - Compilation is faster. Most of the rustc-perf benchmarks see a non-trivial speedup, particularly for incremental rebuilds, with the best speedup over 13%, and multiple others over 10%. - Generated rlibs are smaller. An extreme example is libfutures.rlib, which shrinks from 2073306 bytes to 1765927 bytes, a 15% reduction. r? @jseyfried <details><summary>Here are full numbers for all the rustc-perf runs where the improvement was > 1%.</summary> ``` regex-check avg: -11.1% min: -13.4% max: -5.5% futures-check avg: -7.6% min: -11.4% max: -3.5% futures-opt avg: -6.3% min: -10.3% max: -2.3% futures avg: -6.6% min: -10.3% max: -2.8% regex-opt avg: -4.7% min: -10.2% max: -0.4% regex avg: -5.3% min: -10.2% max: -1.2% hyper-check avg: -4.8% min: -6.6% max: -2.7% encoding-check avg: -4.1% min: -5.5% max: -2.5% issue-46449-check avg: -4.7% min: -5.2% max: -4.1% clap-rs-check avg: -2.9% min: -5.2% max: -1.1% hyper avg: -3.0% min: -5.1% max: -0.8% parser-check avg: -4.2% min: -4.9% max: -3.2% hyper-opt avg: -2.6% min: -4.9% max: -0.3% encoding-opt avg: -2.3% min: -4.6% max: -0.5% encoding avg: -2.5% min: -4.4% max: -0.6% issue-46449 avg: -2.3% min: -4.4% max: -1.8% issue-46449-opt avg: -1.7% min: -4.3% max: -0.9% clap-rs-opt avg: -1.6% min: -4.2% max: -0.2% serde-check avg: -1.4% min: -4.1% max: -0.2% clap-rs avg: -1.6% min: -3.9% max: -0.7% unify-linearly-check avg: -3.2% min: -3.7% max: -2.7% serde avg: -1.1% min: -3.5% max: -0.1% regression-31157-check avg: -2.6% min: -3.4% max: -1.6% helloworld-check avg: -2.5% min: -3.4% max: -0.6% serde-opt avg: -1.3% min: -3.3% max: -0.5% tokio-webpush-simple-check avg: -2.4% min: -3.2% max: -1.8% piston-image-check avg: -1.7% min: -3.2% max: -0.9% deeply-nested-opt avg: -1.5% min: -3.0% max: -0.6% deeply-nested-check avg: -1.9% min: -2.9% max: -0.4% deeply-nested avg: -1.9% min: -2.9% max: -1.2% syn-check avg: -1.8% min: -2.8% max: -0.6% coercions avg: -0.5% min: -2.8% max: 0.4% syn-opt avg: -0.9% min: -2.4% max: -0.1% syn avg: -1.1% min: -2.2% max: -0.3% parser-opt avg: -1.9% min: -2.1% max: -1.6% parser avg: -1.9% min: -2.1% max: -1.6% style-servo-check avg: -1.3% min: -2.0% max: -0.8% regression-31157-opt avg: -0.8% min: -2.0% max: 0.0% piston-image avg: -0.7% min: -1.8% max: -0.2% piston-image-opt avg: -0.6% min: -1.8% max: -0.0% regression-31157 avg: -1.0% min: -1.7% max: -0.3% html5ever-opt avg: -0.6% min: -1.5% max: -0.1% unify-linearly-opt avg: -1.3% min: -1.5% max: -1.1% unify-linearly avg: -1.3% min: -1.4% max: -1.2% tokio-webpush-simple-opt avg: -0.4% min: -1.2% max: -0.0% helloworld-opt avg: -1.0% min: -1.1% max: -0.6% helloworld avg: -1.0% min: -1.1% max: -0.7% inflate-opt avg: -0.3% min: -1.1% max: 0.1% html5ever-check avg: -0.6% min: -1.0% max: -0.3% inflate-check avg: -0.3% min: -1.0% max: -0.1% ``` </details>
2018-05-03Auto merge of #50378 - varkor:repr-align-max-29, r=eddybbors-4/+15
Reduce maximum repr(align(N)) to 2^29 The current maximum `repr(align(N))` alignment is larger than the maximum alignment accepted by LLVM, which can cause issues for huge values of `N`, as seen in #49492. Fixes #49492. r? @rkruppe
2018-05-03Remove parse::escape_default().Nicholas Nethercote-7/+3
str::escape_default() can be used instead.