diff options
Diffstat (limited to 'crates/proc_macro_srv')
-rw-r--r-- | crates/proc_macro_srv/Cargo.toml | 6 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/dylib.rs | 6 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/rustc_server.rs | 46 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt | 8 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/utils.rs | 3 |
5 files changed, 53 insertions, 16 deletions
diff --git a/crates/proc_macro_srv/Cargo.toml b/crates/proc_macro_srv/Cargo.toml index 83f9ead17..4c1b3036a 100644 --- a/crates/proc_macro_srv/Cargo.toml +++ b/crates/proc_macro_srv/Cargo.toml | |||
@@ -11,8 +11,8 @@ doctest = false | |||
11 | 11 | ||
12 | [dependencies] | 12 | [dependencies] |
13 | object = { version = "0.23", default-features = false, features = ["std", "read_core", "elf", "macho", "pe"] } | 13 | object = { version = "0.23", default-features = false, features = ["std", "read_core", "elf", "macho", "pe"] } |
14 | libloading = "0.6.0" | 14 | libloading = "0.7.0" |
15 | memmap = "0.7" | 15 | memmap2 = "0.2.0" |
16 | 16 | ||
17 | tt = { path = "../tt", version = "0.0.0" } | 17 | tt = { path = "../tt", version = "0.0.0" } |
18 | mbe = { path = "../mbe", version = "0.0.0" } | 18 | mbe = { path = "../mbe", version = "0.0.0" } |
@@ -20,7 +20,7 @@ proc_macro_api = { path = "../proc_macro_api", version = "0.0.0" } | |||
20 | test_utils = { path = "../test_utils", version = "0.0.0" } | 20 | test_utils = { path = "../test_utils", version = "0.0.0" } |
21 | 21 | ||
22 | [dev-dependencies] | 22 | [dev-dependencies] |
23 | cargo_metadata = "0.12.2" | 23 | cargo_metadata = "0.13" |
24 | 24 | ||
25 | # used as proc macro test targets | 25 | # used as proc macro test targets |
26 | serde_derive = "1.0.106" | 26 | serde_derive = "1.0.106" |
diff --git a/crates/proc_macro_srv/src/dylib.rs b/crates/proc_macro_srv/src/dylib.rs index 4e719f3aa..28a6ee547 100644 --- a/crates/proc_macro_srv/src/dylib.rs +++ b/crates/proc_macro_srv/src/dylib.rs | |||
@@ -7,7 +7,7 @@ use std::{ | |||
7 | }; | 7 | }; |
8 | 8 | ||
9 | use libloading::Library; | 9 | use libloading::Library; |
10 | use memmap::Mmap; | 10 | use memmap2::Mmap; |
11 | use object::Object; | 11 | use object::Object; |
12 | use proc_macro_api::ProcMacroKind; | 12 | use proc_macro_api::ProcMacroKind; |
13 | 13 | ||
@@ -60,7 +60,7 @@ fn find_registrar_symbol(file: &Path) -> io::Result<Option<String>> { | |||
60 | /// It seems that on Windows that behaviour is default, so we do nothing in that case. | 60 | /// It seems that on Windows that behaviour is default, so we do nothing in that case. |
61 | #[cfg(windows)] | 61 | #[cfg(windows)] |
62 | fn load_library(file: &Path) -> Result<Library, libloading::Error> { | 62 | fn load_library(file: &Path) -> Result<Library, libloading::Error> { |
63 | Library::new(file) | 63 | unsafe { Library::new(file) } |
64 | } | 64 | } |
65 | 65 | ||
66 | #[cfg(unix)] | 66 | #[cfg(unix)] |
@@ -71,7 +71,7 @@ fn load_library(file: &Path) -> Result<Library, libloading::Error> { | |||
71 | const RTLD_NOW: c_int = 0x00002; | 71 | const RTLD_NOW: c_int = 0x00002; |
72 | const RTLD_DEEPBIND: c_int = 0x00008; | 72 | const RTLD_DEEPBIND: c_int = 0x00008; |
73 | 73 | ||
74 | UnixLibrary::open(Some(file), RTLD_NOW | RTLD_DEEPBIND).map(|lib| lib.into()) | 74 | unsafe { UnixLibrary::open(Some(file), RTLD_NOW | RTLD_DEEPBIND).map(|lib| lib.into()) } |
75 | } | 75 | } |
76 | 76 | ||
77 | struct ProcMacroLibraryLibloading { | 77 | struct ProcMacroLibraryLibloading { |
diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs index e6006a3c8..952b4a97f 100644 --- a/crates/proc_macro_srv/src/rustc_server.rs +++ b/crates/proc_macro_srv/src/rustc_server.rs | |||
@@ -10,10 +10,10 @@ | |||
10 | 10 | ||
11 | use crate::proc_macro::bridge::{self, server}; | 11 | use crate::proc_macro::bridge::{self, server}; |
12 | 12 | ||
13 | use std::collections::{Bound, HashMap}; | 13 | use std::collections::HashMap; |
14 | use std::hash::Hash; | 14 | use std::hash::Hash; |
15 | use std::iter::FromIterator; | 15 | use std::iter::FromIterator; |
16 | use std::str::FromStr; | 16 | use std::ops::Bound; |
17 | use std::{ascii, vec::IntoIter}; | 17 | use std::{ascii, vec::IntoIter}; |
18 | 18 | ||
19 | type Group = tt::Subtree; | 19 | type Group = tt::Subtree; |
@@ -277,6 +277,42 @@ impl server::FreeFunctions for Rustc { | |||
277 | } | 277 | } |
278 | } | 278 | } |
279 | 279 | ||
280 | fn subtree_replace_token_ids_with_unspecified(subtree: tt::Subtree) -> tt::Subtree { | ||
281 | tt::Subtree { | ||
282 | delimiter: subtree.delimiter.map(|d| tt::Delimiter { id: tt::TokenId::unspecified(), ..d }), | ||
283 | token_trees: subtree | ||
284 | .token_trees | ||
285 | .into_iter() | ||
286 | .map(|t| token_tree_replace_token_ids_with_unspecified(t)) | ||
287 | .collect(), | ||
288 | } | ||
289 | } | ||
290 | |||
291 | fn token_tree_replace_token_ids_with_unspecified(tt: tt::TokenTree) -> tt::TokenTree { | ||
292 | match tt { | ||
293 | tt::TokenTree::Leaf(leaf) => { | ||
294 | tt::TokenTree::Leaf(leaf_replace_token_ids_with_unspecified(leaf)) | ||
295 | } | ||
296 | tt::TokenTree::Subtree(subtree) => { | ||
297 | tt::TokenTree::Subtree(subtree_replace_token_ids_with_unspecified(subtree)) | ||
298 | } | ||
299 | } | ||
300 | } | ||
301 | |||
302 | fn leaf_replace_token_ids_with_unspecified(leaf: tt::Leaf) -> tt::Leaf { | ||
303 | match leaf { | ||
304 | tt::Leaf::Literal(lit) => { | ||
305 | tt::Leaf::Literal(tt::Literal { id: tt::TokenId::unspecified(), ..lit }) | ||
306 | } | ||
307 | tt::Leaf::Punct(punct) => { | ||
308 | tt::Leaf::Punct(tt::Punct { id: tt::TokenId::unspecified(), ..punct }) | ||
309 | } | ||
310 | tt::Leaf::Ident(ident) => { | ||
311 | tt::Leaf::Ident(tt::Ident { id: tt::TokenId::unspecified(), ..ident }) | ||
312 | } | ||
313 | } | ||
314 | } | ||
315 | |||
280 | impl server::TokenStream for Rustc { | 316 | impl server::TokenStream for Rustc { |
281 | fn new(&mut self) -> Self::TokenStream { | 317 | fn new(&mut self) -> Self::TokenStream { |
282 | Self::TokenStream::new() | 318 | Self::TokenStream::new() |
@@ -286,7 +322,8 @@ impl server::TokenStream for Rustc { | |||
286 | stream.is_empty() | 322 | stream.is_empty() |
287 | } | 323 | } |
288 | fn from_str(&mut self, src: &str) -> Self::TokenStream { | 324 | fn from_str(&mut self, src: &str) -> Self::TokenStream { |
289 | Self::TokenStream::from_str(src).expect("cannot parse string") | 325 | let (subtree, _) = mbe::parse_to_token_tree(src).expect("cannot parse string"); |
326 | TokenStream::with_subtree(subtree_replace_token_ids_with_unspecified(subtree)) | ||
290 | } | 327 | } |
291 | fn to_string(&mut self, stream: &Self::TokenStream) -> String { | 328 | fn to_string(&mut self, stream: &Self::TokenStream) -> String { |
292 | stream.to_string() | 329 | stream.to_string() |
@@ -505,8 +542,7 @@ impl server::Literal for Rustc { | |||
505 | } | 542 | } |
506 | } | 543 | } |
507 | 544 | ||
508 | let text = | 545 | let text = def_suffixed_integer! {kind, u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize}; |
509 | def_suffixed_integer! {kind, u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128}; | ||
510 | 546 | ||
511 | Literal { text: text.into(), id: tt::TokenId::unspecified() } | 547 | Literal { text: text.into(), id: tt::TokenId::unspecified() } |
512 | } | 548 | } |
diff --git a/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt b/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt index e6fd21610..ea34e688f 100644 --- a/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt +++ b/crates/proc_macro_srv/src/tests/fixtures/test_serialize_proc_macro.txt | |||
@@ -59,7 +59,7 @@ SUBTREE $ | |||
59 | IDENT _serde 4294967295 | 59 | IDENT _serde 4294967295 |
60 | PUNCH : [joint] 4294967295 | 60 | PUNCH : [joint] 4294967295 |
61 | PUNCH : [alone] 4294967295 | 61 | PUNCH : [alone] 4294967295 |
62 | IDENT export 4294967295 | 62 | IDENT __private 4294967295 |
63 | PUNCH : [joint] 4294967295 | 63 | PUNCH : [joint] 4294967295 |
64 | PUNCH : [alone] 4294967295 | 64 | PUNCH : [alone] 4294967295 |
65 | IDENT Ok 4294967295 | 65 | IDENT Ok 4294967295 |
@@ -72,7 +72,7 @@ SUBTREE $ | |||
72 | IDENT _serde 4294967295 | 72 | IDENT _serde 4294967295 |
73 | PUNCH : [joint] 4294967295 | 73 | PUNCH : [joint] 4294967295 |
74 | PUNCH : [alone] 4294967295 | 74 | PUNCH : [alone] 4294967295 |
75 | IDENT export 4294967295 | 75 | IDENT __private 4294967295 |
76 | PUNCH : [joint] 4294967295 | 76 | PUNCH : [joint] 4294967295 |
77 | PUNCH : [alone] 4294967295 | 77 | PUNCH : [alone] 4294967295 |
78 | IDENT Err 4294967295 | 78 | IDENT Err 4294967295 |
@@ -85,7 +85,7 @@ SUBTREE $ | |||
85 | IDENT _serde 4294967295 | 85 | IDENT _serde 4294967295 |
86 | PUNCH : [joint] 4294967295 | 86 | PUNCH : [joint] 4294967295 |
87 | PUNCH : [alone] 4294967295 | 87 | PUNCH : [alone] 4294967295 |
88 | IDENT export 4294967295 | 88 | IDENT __private 4294967295 |
89 | PUNCH : [joint] 4294967295 | 89 | PUNCH : [joint] 4294967295 |
90 | PUNCH : [alone] 4294967295 | 90 | PUNCH : [alone] 4294967295 |
91 | IDENT Err 4294967295 | 91 | IDENT Err 4294967295 |
@@ -120,7 +120,7 @@ SUBTREE $ | |||
120 | IDENT _serde 4294967295 | 120 | IDENT _serde 4294967295 |
121 | PUNCH : [joint] 4294967295 | 121 | PUNCH : [joint] 4294967295 |
122 | PUNCH : [alone] 4294967295 | 122 | PUNCH : [alone] 4294967295 |
123 | IDENT export 4294967295 | 123 | IDENT __private 4294967295 |
124 | PUNCH : [joint] 4294967295 | 124 | PUNCH : [joint] 4294967295 |
125 | PUNCH : [alone] 4294967295 | 125 | PUNCH : [alone] 4294967295 |
126 | IDENT Result 4294967295 | 126 | IDENT Result 4294967295 |
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs index 196abb8fc..22813052d 100644 --- a/crates/proc_macro_srv/src/tests/utils.rs +++ b/crates/proc_macro_srv/src/tests/utils.rs | |||
@@ -8,6 +8,7 @@ use test_utils::assert_eq_text; | |||
8 | 8 | ||
9 | mod fixtures { | 9 | mod fixtures { |
10 | use cargo_metadata::Message; | 10 | use cargo_metadata::Message; |
11 | use std::path::PathBuf; | ||
11 | use std::process::Command; | 12 | use std::process::Command; |
12 | 13 | ||
13 | // Use current project metadata to get the proc-macro dylib path | 14 | // Use current project metadata to get the proc-macro dylib path |
@@ -24,7 +25,7 @@ mod fixtures { | |||
24 | if artifact.target.kind.contains(&"proc-macro".to_string()) { | 25 | if artifact.target.kind.contains(&"proc-macro".to_string()) { |
25 | let repr = format!("{} {}", crate_name, version); | 26 | let repr = format!("{} {}", crate_name, version); |
26 | if artifact.package_id.repr.starts_with(&repr) { | 27 | if artifact.package_id.repr.starts_with(&repr) { |
27 | return artifact.filenames[0].clone(); | 28 | return PathBuf::from(&artifact.filenames[0]); |
28 | } | 29 | } |
29 | } | 30 | } |
30 | } | 31 | } |