Skip to content

Rollup of 2 pull requests #59939

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

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
9eb6f32
Use normal newtype_index macro for MIR dataflow
matthewjasper Apr 1, 2019
968ea1c
Mark variables captured by reference as mutable correctly
matthewjasper Apr 4, 2019
63080b3
remove lookup_char_pos_adj
matklad Apr 5, 2019
1c3979c
Add book.toml to tools/unstable, add copy_book_toml to scipt
Apr 6, 2019
5ddb339
Remove copy_book_toml method in favor for copy_recursive
Apr 6, 2019
280277a
path -> from
Apr 6, 2019
442bef7
compiletest normalization: preserve non-JSON lines such as ICEs
RalfJung Apr 7, 2019
0c45546
fix tests
RalfJung Apr 7, 2019
83dcc96
fix output test for backtrace-debuginfo.rs
RalfJung Apr 7, 2019
be83bd5
normalize flags and rustc version in ICE repro
RalfJung Apr 7, 2019
126ac9e
Add test with current behaviour.
davidtwco Apr 7, 2019
34c1572
Change root path for unstable-book
Apr 7, 2019
b8e9da7
`asm!` output can neither be promotable nor const
oli-obk Apr 8, 2019
6b01844
Generalize initial "not const" assignments
oli-obk Apr 8, 2019
ec52065
Explicit promotion is indistinguishable from explicit promotion
oli-obk Apr 8, 2019
d3d5673
Get rid of "is not const" naming
oli-obk Apr 8, 2019
c63b9ff
Pacify tidy
oli-obk Apr 8, 2019
ae4717d
Elaborate on implicit promotability
oli-obk Apr 8, 2019
03727a4
Clean up jobserver integration
Zoxc Apr 8, 2019
724ca05
Exclude profiler-generated symbols from MSVC __imp_-symbol workaround.
michaelwoerister Apr 9, 2019
3a35b7e
normalize away spurious error
RalfJung Apr 9, 2019
8861232
some more tests need normalization
RalfJung Apr 9, 2019
1ad46cd
Fix links on keyword docs.
ehuss Apr 9, 2019
6635fbe
Eliminate `FnBox` usages from libstd.
crlf0710 Apr 9, 2019
2f97552
Re-export NonZero signed variant in std
tesuji Apr 10, 2019
404df31
Update ui test
tesuji Apr 10, 2019
f10394a
Documentation should have proper grammar
oli-obk Apr 10, 2019
acf3ddb
std: Add `{read,write}_vectored` for more types
alexcrichton Apr 10, 2019
825a11e
Fix attributes position in type declaration
GuillaumeGomez Apr 10, 2019
c440c0a
update polonius-engine
Apr 2, 2019
d7f5c50
make duplicate matcher bindings a hard error
mark-i-m Mar 28, 2019
6fd3f5a
forgot one
mark-i-m Apr 11, 2019
7b1df42
Clean up handling of -Zpgo-gen commandline option.
michaelwoerister Apr 10, 2019
22f2afe
Use SecRandomCopyBytes instead of /dev/urandom on MacOS
ebarnard Apr 11, 2019
e149dc0
remove warn
mark-i-m Apr 11, 2019
d84907b
Suggest macro import from crate root.
davidtwco Apr 7, 2019
d589cf9
Handle renamed imports.
davidtwco Apr 7, 2019
7c95540
Handle edge cases.
davidtwco Apr 7, 2019
137ffa1
Improve robustness of nested check.
davidtwco Apr 11, 2019
5158063
Switch to multipart suggestions.
davidtwco Apr 11, 2019
ca1ab3e
In `-Zprint-type-size` output, sort enum variants by size.
nnethercote Apr 12, 2019
633fc9e
Revert PR #59401 to fix issue #59652 (a stable-to-beta regression).
pnkfelix Apr 12, 2019
1ce6645
MaybeUninit: remove deprecated functions
RalfJung Apr 12, 2019
796e6e3
Don't generate empty json variables
GuillaumeGomez Apr 11, 2019
4f28431
Apply resource-suffix to search-index and source-files scripts as well
GuillaumeGomez Apr 7, 2019
7e62052
Use a proc macro to declare preallocated symbols
Zoxc Apr 3, 2019
0e26063
Make check_name generic
Zoxc Apr 5, 2019
9c63475
Ensure the symbols are pure strings
Zoxc Apr 9, 2019
856c8a0
Move modules outside the proc macro
Zoxc Apr 9, 2019
b5f246a
Use colon for keyword defs
Zoxc Apr 9, 2019
fc928a1
Stabilize the `alloc` crate.
SimonSapin Apr 3, 2019
b27bcc0
Fix paste error in split_ascii_whitespace docs.
solson Apr 12, 2019
0a9b214
Exclude some copies of old book editions from search engines
kornelski Apr 12, 2019
8d9c735
Rollup merge of #59612 - matthewjasper:dataflow-usual-newtype-index, …
Centril Apr 13, 2019
84c8966
Rollup merge of #59675 - SimonSapin:stable-alloc, r=alexcrichton
Centril Apr 13, 2019
83da8f4
Rollup merge of #59708 - matthewjasper:double-closure-unused-mut, r=p…
Centril Apr 13, 2019
b15ab20
Rollup merge of #59735 - matklad:deadcode, r=sanxiyn
Centril Apr 13, 2019
edc3979
Rollup merge of #59747 - gruberb:copy-book-toml-unstable-book, r=ehuss
Centril Apr 13, 2019
ad30fd3
Rollup merge of #59796 - oli-obk:const_arg_ice, r=eddyb
Centril Apr 13, 2019
afafbff
Rollup merge of #59804 - Zoxc:cleaner-jobserver, r=alexcrichton
Centril Apr 13, 2019
f8a2d48
Rollup merge of #59818 - crlf0710:eliminate_libstd_fnbox, r=cramertj
Centril Apr 13, 2019
c89a3c9
Rollup merge of #59830 - ehuss:keyword-links, r=Mark-Simulacrum
Centril Apr 13, 2019
1d1693c
Rollup merge of #59835 - lzutao:nonzero-signed, r=Mark-Simulacrum
Centril Apr 13, 2019
09cd478
Rollup merge of #59852 - alexcrichton:more-vectored, r=sfackler
Centril Apr 13, 2019
df31fc6
Rollup merge of #59855 - GuillaumeGomez:fix-attr-position-in-type-dec…
Centril Apr 13, 2019
009a41f
Rollup merge of #59858 - mark-i-m:dup-matcher-bindings-3, r=Centril
Centril Apr 13, 2019
4f34501
Rollup merge of #59879 - ebarnard:patch-1, r=alexcrichton
Centril Apr 13, 2019
2fa3a71
Rollup merge of #59899 - nnethercote:sort-enum-variants-by-size, r=pn…
Centril Apr 13, 2019
f76753c
Rollup merge of #59912 - RalfJung:maybe-uninit, r=Centril
Centril Apr 13, 2019
33561e2
Rollup merge of #59925 - solson:split_ascii_whitespace-docfix, r=Centril
Centril Apr 13, 2019
b613fd2
Rollup merge of #59930 - kornelski:first-robots, r=GuillaumeGomez
Centril Apr 13, 2019
6688e02
Rollup merge of #59655 - Zoxc:symbols, r=petrochenkov
Centril Apr 13, 2019
8443fee
Rollup merge of #59769 - RalfJung:compiletest-normalization, r=alexcr…
Centril Apr 13, 2019
ba4a6e5
Rollup merge of #59776 - GuillaumeGomez:apply-resource-suffix, r=Quie…
Centril Apr 13, 2019
dbaf5fc
Rollup merge of #59784 - davidtwco:issue-59764, r=estebank
Centril Apr 13, 2019
d201ee4
Rollup merge of #59812 - michaelwoerister:profile-gen-msvc-imp, r=ale…
Centril Apr 13, 2019
3c01677
Rollup merge of #59856 - albins:update-polonius, r=nikomatsakis
Centril Apr 13, 2019
86ce22f
Rollup merge of #59874 - michaelwoerister:pgo-updates-1, r=cramertj
Centril Apr 13, 2019
1587ea6
Rollup merge of #59890 - GuillaumeGomez:empty-json-variables, r=Quiet…
Centril Apr 13, 2019
22a6e9e
Rollup merge of #59911 - pnkfelix:revert-pr-59401-to-fix-emit-stack-s…
Centril Apr 13, 2019
30a61c9
Rollup merge of #59937 - Centril:rollup-6pousju, r=Centril
Centril Apr 13, 2019
8cbb829
Rollup merge of #59938 - Centril:rollup-u6r5nca, r=Centril
Centril Apr 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use a proc macro to declare preallocated symbols
  • Loading branch information
Zoxc committed Apr 12, 2019
commit 7e620529e3f3be464e18173b495222ea90b31ccf
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3374,6 +3374,7 @@ dependencies = [
"arena 0.0.0",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_data_structures 0.0.0",
"rustc_macros 0.1.0",
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ use proc_macro::TokenStream;

mod hash_stable;
mod query;
mod symbols;

#[proc_macro]
pub fn rustc_queries(input: TokenStream) -> TokenStream {
query::rustc_queries(input)
}

#[proc_macro]
pub fn symbols(input: TokenStream) -> TokenStream {
symbols::symbols(input)
}

decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive);
173 changes: 173 additions & 0 deletions src/librustc_macros/src/symbols.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
use proc_macro::TokenStream;
use syn::{
Token, Ident, LitStr,
braced, parse_macro_input,
};
use syn::parse::{Result, Parse, ParseStream};
use syn;
use std::collections::HashSet;
use quote::quote;

#[allow(non_camel_case_types)]
mod kw {
syn::custom_keyword!(Keywords);
syn::custom_keyword!(Other);
}

struct Keyword {
name: Ident,
value: LitStr,
}

impl Parse for Keyword {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let name = input.parse()?;
input.parse::<Token![,]>()?;
let value = input.parse()?;
input.parse::<Token![,]>()?;

Ok(Keyword {
name,
value,
})
}
}

struct Symbol(Ident);

impl Parse for Symbol {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let ident: Ident = input.parse()?;
input.parse::<Token![,]>()?;

Ok(Symbol(ident))
}
}

/// A type used to greedily parse another type until the input is empty.
struct List<T>(Vec<T>);

impl<T: Parse> Parse for List<T> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let mut list = Vec::new();
while !input.is_empty() {
list.push(input.parse()?);
}
Ok(List(list))
}
}

struct Input {
keywords: List<Keyword>,
symbols: List<Symbol>,
}

impl Parse for Input {
fn parse(input: ParseStream<'_>) -> Result<Self> {
input.parse::<kw::Keywords>()?;
let content;
braced!(content in input);
let keywords = content.parse()?;

input.parse::<kw::Other>()?;
let content;
braced!(content in input);
let symbols = content.parse()?;

Ok(Input {
keywords,
symbols,
})
}
}

pub fn symbols(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as Input);

let mut keyword_stream = quote! {};
let mut symbols_stream = quote! {};
let mut prefill_stream = quote! {};
let mut from_str_stream = quote! {};
let mut counter = 0u32;
let mut keys = HashSet::<String>::new();

let mut check_dup = |str: &str| {
if !keys.insert(str.to_string()) {
panic!("Symbol `{}` is duplicated", str);
}
};

for keyword in &input.keywords.0 {
let name = &keyword.name;
let value = &keyword.value;
check_dup(&value.value());
prefill_stream.extend(quote! {
#value,
});
keyword_stream.extend(quote! {
pub const #name: Keyword = Keyword {
ident: Ident::with_empty_ctxt(super::Symbol::new(#counter))
};
});
from_str_stream.extend(quote! {
#value => Ok(#name),
});
counter += 1;
}

for symbol in &input.symbols.0 {
let value = &symbol.0;
let value_str = value.to_string();
check_dup(&value_str);
prefill_stream.extend(quote! {
#value_str,
});
symbols_stream.extend(quote! {
pub const #value: Symbol = Symbol::new(#counter);
});
counter += 1;
}

TokenStream::from(quote! {
#[allow(non_upper_case_globals)]
pub mod keywords {
use super::{Symbol, Ident};
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Keyword {
ident: Ident,
}
impl Keyword {
#[inline] pub fn ident(self) -> Ident { self.ident }
#[inline] pub fn name(self) -> Symbol { self.ident.name }
}

#keyword_stream

impl std::str::FromStr for Keyword {
type Err = ();

fn from_str(s: &str) -> Result<Self, ()> {
match s {
#from_str_stream
_ => Err(()),
}
}
}
}

#[allow(non_upper_case_globals)]
pub mod symbols {
use super::Symbol;

#symbols_stream
}

impl Interner {
pub fn fresh() -> Self {
Interner::prefill(&[
#prefill_stream
])
}
}
})
}
6 changes: 6 additions & 0 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ pub struct Path {
pub segments: Vec<PathSegment>,
}

impl PartialEq<Symbol> for Path {
fn eq(&self, symbol: &Symbol) -> bool {
self.segments.len() == 1 && self.segments[0].ident.name.interned() == *symbol
}
}

impl<'a> PartialEq<&'a str> for Path {
fn eq(&self, string: &&'a str) -> bool {
self.segments.len() == 1 && self.segments[0].ident.name == *string
Expand Down
21 changes: 21 additions & 0 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ impl NestedMetaItem {
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
}

/// Returns `true` if this list item is a MetaItem with a name of `name`.
pub fn check_name_symbol(&self, name: Symbol) -> bool {
self.meta_item().map_or(false, |meta_item| meta_item.check_name_symbol(name))
}

/// For a single-segment meta-item returns its name, otherwise returns `None`.
pub fn ident(&self) -> Option<Ident> {
self.meta_item().and_then(|meta_item| meta_item.ident())
Expand Down Expand Up @@ -159,6 +164,18 @@ impl Attribute {
matches
}

/// Returns `true` if the attribute's path matches the argument. If it matches, then the
/// attribute is marked as used.
///
/// To check the attribute name without marking it used, use the `path` field directly.
pub fn check_name_symbol(&self, name: Symbol) -> bool {
let matches = self.path == name;
if matches {
mark_used(self);
}
matches
}

/// For a single-segment attribute returns its name, otherwise returns `None`.
pub fn ident(&self) -> Option<Ident> {
if self.path.segments.len() == 1 {
Expand Down Expand Up @@ -248,6 +265,10 @@ impl MetaItem {
self.path == name
}

pub fn check_name_symbol(&self, name: Symbol) -> bool {
self.path == name
}

pub fn is_value_str(&self) -> bool {
self.value_str().is_some()
}
Expand Down
28 changes: 14 additions & 14 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::tokenstream::TokenTree;
use errors::{DiagnosticBuilder, Handler};
use rustc_data_structures::fx::FxHashMap;
use rustc_target::spec::abi::Abi;
use syntax_pos::{Span, DUMMY_SP};
use syntax_pos::{Span, DUMMY_SP, symbols};
use log::debug;

use std::env;
Expand Down Expand Up @@ -1366,7 +1366,7 @@ impl<'a> Context<'a> {
}
} else if n == "doc" {
if let Some(content) = attr.meta_item_list() {
if content.iter().any(|c| c.check_name("include")) {
if content.iter().any(|c| c.check_name_symbol(symbols::include)) {
gate_feature!(self, external_doc, attr.span,
"#[doc(include = \"...\")] is experimental"
);
Expand Down Expand Up @@ -1648,33 +1648,33 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
// check for gated attributes
self.context.check_attribute(attr, false);

if attr.check_name("doc") {
if attr.check_name_symbol(symbols::doc) {
if let Some(content) = attr.meta_item_list() {
if content.len() == 1 && content[0].check_name("cfg") {
if content.len() == 1 && content[0].check_name_symbol(symbols::cfg) {
gate_feature_post!(&self, doc_cfg, attr.span,
"#[doc(cfg(...))] is experimental"
);
} else if content.iter().any(|c| c.check_name("masked")) {
} else if content.iter().any(|c| c.check_name_symbol(symbols::masked)) {
gate_feature_post!(&self, doc_masked, attr.span,
"#[doc(masked)] is experimental"
);
} else if content.iter().any(|c| c.check_name("spotlight")) {
} else if content.iter().any(|c| c.check_name_symbol(symbols::spotlight)) {
gate_feature_post!(&self, doc_spotlight, attr.span,
"#[doc(spotlight)] is experimental"
);
} else if content.iter().any(|c| c.check_name("alias")) {
} else if content.iter().any(|c| c.check_name_symbol(symbols::alias)) {
gate_feature_post!(&self, doc_alias, attr.span,
"#[doc(alias = \"...\")] is experimental"
);
} else if content.iter().any(|c| c.check_name("keyword")) {
} else if content.iter().any(|c| c.check_name_symbol(symbols::keyword)) {
gate_feature_post!(&self, doc_keyword, attr.span,
"#[doc(keyword = \"...\")] is experimental"
);
}
}
}

match BUILTIN_ATTRIBUTES.iter().find(|(name, ..)| attr.path == name) {
match BUILTIN_ATTRIBUTES.iter().find(|(name, ..)| attr.path == *name) {
Some(&(name, _, template, _)) => self.check_builtin_attribute(attr, name, template),
None => if let Some(TokenTree::Token(_, token::Eq)) = attr.tokens.trees().next() {
// All key-value attributes are restricted to meta-item syntax.
Expand Down Expand Up @@ -1727,7 +1727,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ItemKind::Struct(..) => {
for attr in attr::filter_by_name(&i.attrs[..], "repr") {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name("simd") {
if item.check_name_symbol(symbols::simd) {
gate_feature_post!(&self, repr_simd, attr.span,
"SIMD types are experimental and possibly buggy");
}
Expand All @@ -1738,7 +1738,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ItemKind::Enum(..) => {
for attr in attr::filter_by_name(&i.attrs[..], "repr") {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name("align") {
if item.check_name_symbol(symbols::align) {
gate_feature_post!(&self, repr_align_enum, attr.span,
"`#[repr(align(x))]` on enums is experimental");
}
Expand Down Expand Up @@ -2062,7 +2062,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
// Process the edition umbrella feature-gates first, to ensure
// `edition_enabled_features` is completed before it's queried.
for attr in krate_attrs {
if !attr.check_name("feature") {
if !attr.check_name_symbol(symbols::feature) {
continue
}

Expand Down Expand Up @@ -2107,7 +2107,7 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
}

for attr in krate_attrs {
if !attr.check_name("feature") {
if !attr.check_name_symbol(symbols::feature) {
continue
}

Expand Down Expand Up @@ -2237,7 +2237,7 @@ fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate,
};
if !allow_features {
for attr in &krate.attrs {
if attr.check_name("feature") {
if attr.check_name_symbol(symbols::feature) {
let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)");
span_err!(span_handler, attr.span, E0554,
"#![feature] may not be used on the {} release channel",
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax_pos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ crate-type = ["dylib"]

[dependencies]
serialize = { path = "../libserialize" }
rustc_macros = { path = "../librustc_macros" }
rustc_data_structures = { path = "../librustc_data_structures" }
arena = { path = "../libarena" }
scoped-tls = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#![feature(non_exhaustive)]
#![feature(optin_builtin_traits)]
#![feature(rustc_attrs)]
#![feature(proc_macro_hygiene)]
#![feature(specialization)]
#![feature(step_trait)]

Expand All @@ -32,6 +33,7 @@ mod span_encoding;
pub use span_encoding::{Span, DUMMY_SP};

pub mod symbol;
pub use symbol::symbols;

mod analyze_source_file;

Expand Down
Loading