Skip to content

Commit 066f0b0

Browse files
lu-zeroalexcrichton
authored andcommitted
Update proc macro2 (#455)
* Update to proc_macro2 0.4 and related * Update to proc_macro2 0.4 and related * Update to proc_macro2 0.4 and related * Add proc_macro_gen feature * Update to the new rustfmt cli * A few proc-macro2 stylistic updates * Disable RUST_BACKTRACE by default * Allow rustfmt failure for now * Disable proc-macro2 nightly feature in verify-x86 Currently this causes bugs on nightly due to upstream rustc bugs, this should be temporary * Attempt to thwart mergefunc * Use static relocation model on i686
1 parent e715c93 commit 066f0b0

File tree

10 files changed

+89
-68
lines changed

10 files changed

+89
-68
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ matrix:
4848
before_script:
4949
- rustup component add rustfmt-preview
5050
script:
51-
- cargo fmt --all -- --write-mode=diff
51+
- cargo fmt --all -- --check
5252
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
5353
script: |
5454
cargo install clippy
5555
cargo clippy --all -- -D clippy-pedantic
5656
allow_failures:
5757
- env: CLIPPY=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
58+
- env: RUSTFMT=On TARGET=x86_64-unknown-linux-gnu NO_ADD=1
5859

5960
before_install:
6061
# FIXME (travis-ci/travis-ci#8920) shouldn't be necessary...

ci/run.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -ex
77
# Tests are all super fast anyway, and they fault often enough on travis that
88
# having only one thread increases debuggability to be worth it.
99
export RUST_TEST_THREADS=1
10-
export RUST_BACKTRACE=full
10+
#export RUST_BACKTRACE=full
1111
#export RUST_TEST_NOCAPTURE=1
1212

1313
RUSTFLAGS="$RUSTFLAGS --cfg stdsimd_strict"
@@ -28,6 +28,15 @@ case ${TARGET} in
2828
powerpc64-*)
2929
export STDSIMD_DISABLE_ASSERT_INSTR=1
3030
;;
31+
32+
# On 32-bit use a static relocation model which avoids some extra
33+
# instructions when dealing with static data, notably allowing some
34+
# instruction assertion checks to pass below the 20 instruction limit. If
35+
# this is the default, dynamic, then too many instructions are generated
36+
# when we assert the instruction for a function and it causes tests to fail.
37+
i686-* | i586-*)
38+
export RUSTFLAGS="${RUSTFLAGS} -C relocation-model=static"
39+
;;
3140
*)
3241
;;
3342
esac

crates/assert-instr-macro/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ proc-macro = true
88
test = false
99

1010
[dependencies]
11-
proc-macro2 = { version = "0.3", features = ["nightly"] }
12-
quote = "0.5"
13-
syn = { version = "0.13", features = ["full"] }
11+
proc-macro2 = { version = "0.4", features = ["nightly"] }
12+
quote = "0.6"
13+
syn = { version = "0.14", features = ["full"] }

crates/assert-instr-macro/src/lib.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ pub fn assert_instr(
4848
use quote::ToTokens;
4949
let instr_str = instr
5050
.clone()
51-
.into_tokens()
51+
.into_token_stream()
5252
.to_string()
5353
.replace('.', "_")
5454
.replace(|c: char| c.is_whitespace(), "");
55-
let assert_name = syn::Ident::from(
56-
&format!("assert_{}_{}", name.as_ref(), instr_str)[..],
55+
let assert_name = syn::Ident::new(
56+
&format!("assert_{}_{}", name, instr_str),
57+
name.span(),
5758
);
58-
let shim_name = syn::Ident::from(format!("{}_shim", name.as_ref()));
59+
let shim_name = syn::Ident::new(&format!("{}_shim", name), name.span());
5960
let mut inputs = Vec::new();
6061
let mut input_vals = Vec::new();
6162
let ret = &func.decl.output;
@@ -64,7 +65,7 @@ pub fn assert_instr(
6465
syn::FnArg::Captured(ref c) => c,
6566
ref v => panic!(
6667
"arguments must not have patterns: `{:?}`",
67-
v.clone().into_tokens()
68+
v.clone().into_token_stream()
6869
),
6970
};
7071
let ident = match capture.pat {
@@ -74,7 +75,7 @@ pub fn assert_instr(
7475
match invoc
7576
.args
7677
.iter()
77-
.find(|a| a.0 == ident.as_ref())
78+
.find(|a| *ident == a.0)
7879
{
7980
Some(&(_, ref tts)) => {
8081
input_vals.push(quote! { #tts });
@@ -95,7 +96,7 @@ pub fn assert_instr(
9596
.expect("attr.path.segments.first() failed")
9697
.value()
9798
.ident
98-
.as_ref()
99+
.to_string()
99100
.starts_with("target")
100101
})
101102
.collect::<Vec<_>>();
@@ -108,15 +109,27 @@ pub fn assert_instr(
108109
} else {
109110
syn::LitStr::new("C", proc_macro2::Span::call_site())
110111
};
112+
let shim_name_str = format!("{}{}", shim_name, assert_name);
111113
let to_test = quote! {
112114
#attrs
113115
unsafe extern #abi fn #shim_name(#(#inputs),*) #ret {
116+
// The compiler in optimized mode by default runs a pass called
117+
// "mergefunc" where it'll merge functions that look identical.
118+
// Turns out some intrinsics produce identical code and they're
119+
// folded together, meaning that one just jumps to another. This
120+
// messes up our inspection of the disassembly of this function and
121+
// we're not a huge fan of that.
122+
//
123+
// To thwart this pass and prevent functions from being merged we
124+
// generate some code that's hopefully very tight in terms of
125+
// codegen but is otherwise unique to prevent code from being
126+
// folded.
127+
::stdsimd_test::_DONT_DEDUP = #shim_name_str;
114128
#name(#(#input_vals),*)
115129
}
116130
};
117131

118-
let tts: TokenStream = quote_spanned! {
119-
proc_macro2::Span::call_site() =>
132+
let tts: TokenStream = quote! {
120133
#[test]
121134
#[allow(non_snake_case)]
122135
#maybe_ignore
@@ -169,7 +182,7 @@ where
169182
T: Clone + IntoIterator,
170183
T::Item: quote::ToTokens,
171184
{
172-
fn to_tokens(&self, tokens: &mut quote::Tokens) {
185+
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
173186
for item in self.0.clone() {
174187
item.to_tokens(tokens);
175188
}

crates/coresimd/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#![allow(dead_code)]
1111
#![allow(unused_features)]
1212
#![feature(const_fn, link_llvm_intrinsics, platform_intrinsics, repr_simd,
13-
simd_ffi, asm,
13+
simd_ffi, asm, proc_macro_gen,
1414
integer_atomics, stmt_expr_attributes, core_intrinsics,
1515
crate_in_paths, no_core, attr_literals, rustc_attrs, stdsimd,
1616
staged_api, core_float, core_slice_ext, align_offset,

crates/simd-test-macro/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ proc-macro = true
88
test = false
99

1010
[dependencies]
11-
proc-macro2 = { version = "0.3", features = ["nightly"] }
12-
quote = "0.5"
11+
proc-macro2 = { version = "0.4", features = ["nightly"] }
12+
quote = "0.6"

crates/simd-test-macro/src/lib.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern crate quote;
1212

1313
use std::env;
1414

15-
use proc_macro2::{Literal, Span, Term, TokenStream, TokenTree};
15+
use proc_macro2::{Literal, Span, Ident, TokenStream, TokenTree};
1616

1717
fn string(s: &str) -> TokenTree {
1818
Literal::string(s).into()
@@ -29,11 +29,11 @@ pub fn simd_test(
2929
panic!("expected #[simd_test(enable = \"feature\")]");
3030
}
3131
match &tokens[0] {
32-
TokenTree::Term(tt) if tt.to_string() == "enable" => {}
32+
TokenTree::Ident(tt) if tt.to_string() == "enable" => {}
3333
_ => panic!("expected #[simd_test(enable = \"feature\")]"),
3434
}
3535
match &tokens[1] {
36-
TokenTree::Op(tt) if tt.op() == '=' => {}
36+
TokenTree::Punct(tt) if tt.as_char() == '=' => {}
3737
_ => panic!("expected #[simd_test(enable = \"feature\")]"),
3838
}
3939
let enable_feature = match &tokens[2] {
@@ -53,9 +53,9 @@ pub fn simd_test(
5353
let item = TokenStream::from(item);
5454
let name = find_name(item.clone());
5555

56-
let name: TokenStream = name.as_str().parse().expect(&format!(
56+
let name: TokenStream = name.to_string().parse().expect(&format!(
5757
"failed to parse name: {}",
58-
name.clone().as_str()
58+
name.to_string()
5959
));
6060

6161
let target = env::var("TARGET")
@@ -87,9 +87,9 @@ pub fn simd_test(
8787
}
8888
t => panic!("unknown target: {}", t),
8989
};
90-
let macro_test = proc_macro2::Term::new(macro_test, Span::call_site());
90+
let macro_test = Ident::new(macro_test, Span::call_site());
9191

92-
let mut cfg_target_features = quote::Tokens::new();
92+
let mut cfg_target_features = TokenStream::empty();
9393
use quote::ToTokens;
9494
for feature in target_features {
9595
let q = quote_spanned! {
@@ -119,18 +119,18 @@ pub fn simd_test(
119119
ret.into()
120120
}
121121

122-
fn find_name(item: TokenStream) -> Term {
122+
fn find_name(item: TokenStream) -> Ident {
123123
let mut tokens = item.into_iter();
124124
while let Some(tok) = tokens.next() {
125-
if let TokenTree::Term(word) = tok {
126-
if word.as_str() == "fn" {
125+
if let TokenTree::Ident(word) = tok {
126+
if word == "fn" {
127127
break;
128128
}
129129
}
130130
}
131131

132132
match tokens.next() {
133-
Some(TokenTree::Term(word)) => word,
133+
Some(TokenTree::Ident(word)) => word,
134134
_ => panic!("failed to find function name"),
135135
}
136136
}

crates/stdsimd-test/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,6 @@ pub fn assert_skip_test_ok(name: &str) {
405405
name
406406
);
407407
}
408+
409+
// See comment in `assert-instr-macro` crate for why this exists
410+
pub static mut _DONT_DEDUP: &'static str = "";

crates/stdsimd-verify/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ version = "0.1.0"
44
authors = ["Alex Crichton <alex@alexcrichton.com>"]
55

66
[dependencies]
7-
proc-macro2 = { version = "0.3", features = ["nightly"] }
8-
quote = "0.5"
9-
syn = { version = "0.13", features = ["full"] }
7+
proc-macro2 = "0.4"
8+
quote = "0.6"
9+
syn = { version = "0.14", features = ["full"] }
1010

1111
[lib]
1212
proc-macro = true

crates/stdsimd-verify/src/lib.rs

+31-36
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ use std::io::Read;
1212
use std::path::Path;
1313

1414
use proc_macro::TokenStream;
15-
use quote::Tokens;
16-
17-
macro_rules! my_quote {
18-
($($t:tt)*) => (quote_spanned!(proc_macro2::Span::call_site() => $($t)*))
19-
}
2015

2116
#[proc_macro]
2217
pub fn x86_functions(input: TokenStream) -> TokenStream {
@@ -56,7 +51,7 @@ pub fn x86_functions(input: TokenStream) -> TokenStream {
5651
let functions = functions
5752
.iter()
5853
.map(|&(ref f, path)| {
59-
let name = f.ident;
54+
let name = &f.ident;
6055
// println!("{}", name);
6156
let mut arguments = Vec::new();
6257
for input in f.decl.inputs.iter() {
@@ -67,19 +62,19 @@ pub fn x86_functions(input: TokenStream) -> TokenStream {
6762
arguments.push(to_type(ty));
6863
}
6964
let ret = match f.decl.output {
70-
syn::ReturnType::Default => my_quote! { None },
65+
syn::ReturnType::Default => quote! { None },
7166
syn::ReturnType::Type(_, ref t) => {
7267
let ty = to_type(t);
73-
my_quote! { Some(#ty) }
68+
quote! { Some(#ty) }
7469
}
7570
};
7671
let instrs = find_instrs(&f.attrs);
7772
let target_feature = match find_target_feature(&f.attrs) {
78-
Some(i) => my_quote! { Some(#i) },
79-
None => my_quote! { None },
73+
Some(i) => quote! { Some(#i) },
74+
None => quote! { None },
8075
};
8176
let required_const = find_required_const(&f.attrs);
82-
my_quote! {
77+
quote! {
8378
Function {
8479
name: stringify!(#name),
8580
arguments: &[#(#arguments),*],
@@ -93,43 +88,43 @@ pub fn x86_functions(input: TokenStream) -> TokenStream {
9388
})
9489
.collect::<Vec<_>>();
9590

96-
let ret = my_quote! { #input: &[Function] = &[#(#functions),*]; };
91+
let ret = quote! { #input: &[Function] = &[#(#functions),*]; };
9792
// println!("{}", ret);
9893
ret.into()
9994
}
10095

101-
fn to_type(t: &syn::Type) -> Tokens {
96+
fn to_type(t: &syn::Type) -> proc_macro2::TokenStream {
10297
match *t {
103-
syn::Type::Path(ref p) => match extract_path_ident(&p.path).as_ref() {
104-
"__m128" => my_quote! { &M128 },
105-
"__m128d" => my_quote! { &M128D },
106-
"__m128i" => my_quote! { &M128I },
107-
"__m256" => my_quote! { &M256 },
108-
"__m256d" => my_quote! { &M256D },
109-
"__m256i" => my_quote! { &M256I },
110-
"__m64" => my_quote! { &M64 },
111-
"bool" => my_quote! { &BOOL },
112-
"f32" => my_quote! { &F32 },
113-
"f64" => my_quote! { &F64 },
114-
"i16" => my_quote! { &I16 },
115-
"i32" => my_quote! { &I32 },
116-
"i64" => my_quote! { &I64 },
117-
"i8" => my_quote! { &I8 },
118-
"u16" => my_quote! { &U16 },
119-
"u32" => my_quote! { &U32 },
120-
"u64" => my_quote! { &U64 },
121-
"u8" => my_quote! { &U8 },
122-
"CpuidResult" => my_quote! { &CPUID },
98+
syn::Type::Path(ref p) => match extract_path_ident(&p.path).to_string().as_ref() {
99+
"__m128" => quote! { &M128 },
100+
"__m128d" => quote! { &M128D },
101+
"__m128i" => quote! { &M128I },
102+
"__m256" => quote! { &M256 },
103+
"__m256d" => quote! { &M256D },
104+
"__m256i" => quote! { &M256I },
105+
"__m64" => quote! { &M64 },
106+
"bool" => quote! { &BOOL },
107+
"f32" => quote! { &F32 },
108+
"f64" => quote! { &F64 },
109+
"i16" => quote! { &I16 },
110+
"i32" => quote! { &I32 },
111+
"i64" => quote! { &I64 },
112+
"i8" => quote! { &I8 },
113+
"u16" => quote! { &U16 },
114+
"u32" => quote! { &U32 },
115+
"u64" => quote! { &U64 },
116+
"u8" => quote! { &U8 },
117+
"CpuidResult" => quote! { &CPUID },
123118
s => panic!("unspported type: {}", s),
124119
},
125120
syn::Type::Ptr(syn::TypePtr { ref elem, .. })
126121
| syn::Type::Reference(syn::TypeReference { ref elem, .. }) => {
127122
let tokens = to_type(&elem);
128-
my_quote! { &Type::Ptr(#tokens) }
123+
quote! { &Type::Ptr(#tokens) }
129124
}
130125
syn::Type::Slice(_) => panic!("unsupported slice"),
131126
syn::Type::Array(_) => panic!("unsupported array"),
132-
syn::Type::Tuple(_) => my_quote! { &TUPLE },
127+
syn::Type::Tuple(_) => quote! { &TUPLE },
133128
_ => panic!("unsupported type"),
134129
}
135130
}
@@ -145,7 +140,7 @@ fn extract_path_ident(path: &syn::Path) -> syn::Ident {
145140
syn::PathArguments::None => {}
146141
_ => panic!("unsupported path that has path arguments"),
147142
}
148-
path.segments.first().unwrap().value().ident
143+
path.segments.first().unwrap().value().ident.clone()
149144
}
150145

151146
fn walk(root: &Path, files: &mut Vec<(syn::File, String)>) {

0 commit comments

Comments
 (0)