diff options
author | Edwin Cheng <[email protected]> | 2020-03-26 16:41:44 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2020-03-26 16:46:40 +0000 |
commit | db162df264a222021dbc7f1f93af94029f3948d9 (patch) | |
tree | 86f91e30f85c2c4f5faa5054b84265ddb64636d5 | |
parent | 72e68d0caf6e813a19a8d434fb650574b73dbc0a (diff) |
Remove deps on tt_mbe
-rw-r--r-- | Cargo.lock | 3 | ||||
-rw-r--r-- | crates/ra_db/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_db/src/input.rs | 23 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/proc_macro.rs | 5 | ||||
-rw-r--r-- | crates/ra_mbe/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_proc_macro/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/lib.rs | 44 | ||||
-rw-r--r-- | crates/ra_tt/src/lib.rs | 15 |
10 files changed, 58 insertions, 49 deletions
diff --git a/Cargo.lock b/Cargo.lock index bb39fe225..b9f58a074 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -926,9 +926,9 @@ name = "ra_db" | |||
926 | version = "0.1.0" | 926 | version = "0.1.0" |
927 | dependencies = [ | 927 | dependencies = [ |
928 | "ra_cfg", | 928 | "ra_cfg", |
929 | "ra_proc_macro", | ||
930 | "ra_prof", | 929 | "ra_prof", |
931 | "ra_syntax", | 930 | "ra_syntax", |
931 | "ra_tt", | ||
932 | "relative-path", | 932 | "relative-path", |
933 | "rustc-hash", | 933 | "rustc-hash", |
934 | "salsa", | 934 | "salsa", |
@@ -1086,7 +1086,6 @@ dependencies = [ | |||
1086 | name = "ra_proc_macro" | 1086 | name = "ra_proc_macro" |
1087 | version = "0.1.0" | 1087 | version = "0.1.0" |
1088 | dependencies = [ | 1088 | dependencies = [ |
1089 | "ra_mbe", | ||
1090 | "ra_tt", | 1089 | "ra_tt", |
1091 | ] | 1090 | ] |
1092 | 1091 | ||
diff --git a/crates/ra_db/Cargo.toml b/crates/ra_db/Cargo.toml index 82fd842a6..8ab409158 100644 --- a/crates/ra_db/Cargo.toml +++ b/crates/ra_db/Cargo.toml | |||
@@ -15,5 +15,5 @@ rustc-hash = "1.1.0" | |||
15 | ra_syntax = { path = "../ra_syntax" } | 15 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_cfg = { path = "../ra_cfg" } | 16 | ra_cfg = { path = "../ra_cfg" } |
17 | ra_prof = { path = "../ra_prof" } | 17 | ra_prof = { path = "../ra_prof" } |
18 | ra_proc_macro = { path = "../ra_proc_macro" } | 18 | ra_tt = { path = "../ra_tt" } |
19 | test_utils = { path = "../test_utils" } | 19 | test_utils = { path = "../test_utils" } |
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 65b553a9f..5ddce98c6 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -10,6 +10,7 @@ use std::{ | |||
10 | fmt, ops, | 10 | fmt, ops, |
11 | path::{Path, PathBuf}, | 11 | path::{Path, PathBuf}, |
12 | str::FromStr, | 12 | str::FromStr, |
13 | sync::Arc, | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | use ra_cfg::CfgOptions; | 16 | use ra_cfg::CfgOptions; |
@@ -19,7 +20,7 @@ use rustc_hash::FxHashSet; | |||
19 | 20 | ||
20 | use crate::{RelativePath, RelativePathBuf}; | 21 | use crate::{RelativePath, RelativePathBuf}; |
21 | use fmt::Display; | 22 | use fmt::Display; |
22 | use ra_proc_macro::ProcMacro; | 23 | use ra_tt::TokenExpander; |
23 | 24 | ||
24 | /// `FileId` is an integer which uniquely identifies a file. File paths are | 25 | /// `FileId` is an integer which uniquely identifies a file. File paths are |
25 | /// messy and system-dependent, so most of the code should work directly with | 26 | /// messy and system-dependent, so most of the code should work directly with |
@@ -117,7 +118,20 @@ impl Display for CrateName { | |||
117 | } | 118 | } |
118 | 119 | ||
119 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | 120 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
120 | pub struct ProcMacroId(pub usize); | 121 | pub struct ProcMacroId(pub u32); |
122 | |||
123 | #[derive(Debug, Clone)] | ||
124 | pub struct ProcMacro { | ||
125 | pub name: SmolStr, | ||
126 | pub expander: Arc<dyn TokenExpander>, | ||
127 | } | ||
128 | |||
129 | impl Eq for ProcMacro {} | ||
130 | impl PartialEq for ProcMacro { | ||
131 | fn eq(&self, other: &ProcMacro) -> bool { | ||
132 | self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander) | ||
133 | } | ||
134 | } | ||
121 | 135 | ||
122 | #[derive(Debug, Clone, PartialEq, Eq)] | 136 | #[derive(Debug, Clone, PartialEq, Eq)] |
123 | pub struct CrateData { | 137 | pub struct CrateData { |
@@ -171,8 +185,11 @@ impl CrateGraph { | |||
171 | cfg_options: CfgOptions, | 185 | cfg_options: CfgOptions, |
172 | env: Env, | 186 | env: Env, |
173 | extern_source: ExternSource, | 187 | extern_source: ExternSource, |
174 | proc_macro: Vec<ProcMacro>, | 188 | proc_macro: Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)>, |
175 | ) -> CrateId { | 189 | ) -> CrateId { |
190 | let proc_macro = | ||
191 | proc_macro.into_iter().map(|(name, it)| ProcMacro { name, expander: it }).collect(); | ||
192 | |||
176 | let data = CrateData { | 193 | let data = CrateData { |
177 | root_file_id: file_id, | 194 | root_file_id: file_id, |
178 | edition, | 195 | edition, |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 5829ae465..a06f59c14 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -15,7 +15,6 @@ pub use crate::{ | |||
15 | FileId, ProcMacroId, SourceRoot, SourceRootId, | 15 | FileId, ProcMacroId, SourceRoot, SourceRootId, |
16 | }, | 16 | }, |
17 | }; | 17 | }; |
18 | pub use ra_proc_macro::ProcMacro; | ||
19 | pub use relative_path::{RelativePath, RelativePathBuf}; | 18 | pub use relative_path::{RelativePath, RelativePathBuf}; |
20 | pub use salsa; | 19 | pub use salsa; |
21 | 20 | ||
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 9b46431cb..8fe3f8617 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -12,7 +12,7 @@ use hir_expand::{ | |||
12 | }; | 12 | }; |
13 | use ra_cfg::CfgOptions; | 13 | use ra_cfg::CfgOptions; |
14 | use ra_db::{CrateId, FileId, ProcMacroId}; | 14 | use ra_db::{CrateId, FileId, ProcMacroId}; |
15 | use ra_syntax::{ast, SmolStr}; | 15 | use ra_syntax::ast; |
16 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
17 | use test_utils::tested_by; | 17 | use test_utils::tested_by; |
18 | 18 | ||
@@ -59,8 +59,8 @@ pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> Cr | |||
59 | .enumerate() | 59 | .enumerate() |
60 | .map(|(idx, it)| { | 60 | .map(|(idx, it)| { |
61 | // FIXME: a hacky way to create a Name from string. | 61 | // FIXME: a hacky way to create a Name from string. |
62 | let name = tt::Ident { text: SmolStr::new(&it.name()), id: tt::TokenId::unspecified() }; | 62 | let name = tt::Ident { text: it.name.clone(), id: tt::TokenId::unspecified() }; |
63 | (name.as_name(), ProcMacroExpander::new(def_map.krate, ProcMacroId(idx))) | 63 | (name.as_name(), ProcMacroExpander::new(def_map.krate, ProcMacroId(idx as u32))) |
64 | }) | 64 | }) |
65 | .collect(); | 65 | .collect(); |
66 | 66 | ||
diff --git a/crates/ra_hir_expand/src/proc_macro.rs b/crates/ra_hir_expand/src/proc_macro.rs index 296325b05..4d270e0de 100644 --- a/crates/ra_hir_expand/src/proc_macro.rs +++ b/crates/ra_hir_expand/src/proc_macro.rs | |||
@@ -23,9 +23,10 @@ impl ProcMacroExpander { | |||
23 | let krate_graph = db.crate_graph(); | 23 | let krate_graph = db.crate_graph(); |
24 | let proc_macro = krate_graph[self.krate] | 24 | let proc_macro = krate_graph[self.krate] |
25 | .proc_macro | 25 | .proc_macro |
26 | .get(self.proc_macro_id.0) | 26 | .get(self.proc_macro_id.0 as usize) |
27 | .clone() | 27 | .clone() |
28 | .ok_or_else(|| mbe::ExpandError::ConversionError)?; | 28 | .ok_or_else(|| mbe::ExpandError::ConversionError)?; |
29 | proc_macro.custom_derive(tt) | 29 | |
30 | proc_macro.expander.expand(&tt, None).map_err(mbe::ExpandError::from) | ||
30 | } | 31 | } |
31 | } | 32 | } |
diff --git a/crates/ra_mbe/src/lib.rs b/crates/ra_mbe/src/lib.rs index 6a9037bfc..535b7daa0 100644 --- a/crates/ra_mbe/src/lib.rs +++ b/crates/ra_mbe/src/lib.rs | |||
@@ -28,6 +28,13 @@ pub enum ExpandError { | |||
28 | BindingError(String), | 28 | BindingError(String), |
29 | ConversionError, | 29 | ConversionError, |
30 | InvalidRepeat, | 30 | InvalidRepeat, |
31 | ProcMacroError(tt::ExpansionError), | ||
32 | } | ||
33 | |||
34 | impl From<tt::ExpansionError> for ExpandError { | ||
35 | fn from(it: tt::ExpansionError) -> Self { | ||
36 | ExpandError::ProcMacroError(it) | ||
37 | } | ||
31 | } | 38 | } |
32 | 39 | ||
33 | pub use crate::syntax_bridge::{ | 40 | pub use crate::syntax_bridge::{ |
diff --git a/crates/ra_proc_macro/Cargo.toml b/crates/ra_proc_macro/Cargo.toml index a0fbb442d..bc2c37296 100644 --- a/crates/ra_proc_macro/Cargo.toml +++ b/crates/ra_proc_macro/Cargo.toml | |||
@@ -10,4 +10,3 @@ doctest = false | |||
10 | 10 | ||
11 | [dependencies] | 11 | [dependencies] |
12 | ra_tt = { path = "../ra_tt" } | 12 | ra_tt = { path = "../ra_tt" } |
13 | ra_mbe = { path = "../ra_mbe" } \ No newline at end of file | ||
diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index b7fb641c3..5e21dd487 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs | |||
@@ -5,56 +5,29 @@ | |||
5 | //! is used to provide basic infrastructure for communication between two | 5 | //! is used to provide basic infrastructure for communication between two |
6 | //! processes: Client (RA itself), Server (the external program) | 6 | //! processes: Client (RA itself), Server (the external program) |
7 | 7 | ||
8 | use ra_mbe::ExpandError; | 8 | use ra_tt::{SmolStr, Subtree}; |
9 | use ra_tt::Subtree; | ||
10 | use std::{ | 9 | use std::{ |
11 | path::{Path, PathBuf}, | 10 | path::{Path, PathBuf}, |
12 | sync::Arc, | 11 | sync::Arc, |
13 | }; | 12 | }; |
14 | 13 | ||
15 | trait ProcMacroExpander: std::fmt::Debug + Send + Sync + std::panic::RefUnwindSafe { | ||
16 | fn custom_derive(&self, subtree: &Subtree, derive_name: &str) -> Result<Subtree, ExpandError>; | ||
17 | } | ||
18 | |||
19 | #[derive(Debug, Clone, PartialEq, Eq)] | 14 | #[derive(Debug, Clone, PartialEq, Eq)] |
20 | pub struct ProcMacroProcessExpander { | 15 | pub struct ProcMacroProcessExpander { |
21 | process: Arc<ProcMacroProcessSrv>, | 16 | process: Arc<ProcMacroProcessSrv>, |
17 | name: SmolStr, | ||
22 | } | 18 | } |
23 | 19 | ||
24 | impl ProcMacroExpander for ProcMacroProcessExpander { | 20 | impl ra_tt::TokenExpander for ProcMacroProcessExpander { |
25 | fn custom_derive( | 21 | fn expand( |
26 | &self, | 22 | &self, |
27 | _subtree: &Subtree, | 23 | _subtree: &Subtree, |
28 | _derive_name: &str, | 24 | _attr: Option<&Subtree>, |
29 | ) -> Result<Subtree, ExpandError> { | 25 | ) -> Result<Subtree, ra_tt::ExpansionError> { |
30 | // FIXME: do nothing for now | 26 | // FIXME: do nothing for now |
31 | Ok(Subtree::default()) | 27 | Ok(Subtree::default()) |
32 | } | 28 | } |
33 | } | 29 | } |
34 | 30 | ||
35 | #[derive(Debug, Clone)] | ||
36 | pub struct ProcMacro { | ||
37 | expander: Arc<dyn ProcMacroExpander>, | ||
38 | name: String, | ||
39 | } | ||
40 | |||
41 | impl Eq for ProcMacro {} | ||
42 | impl PartialEq for ProcMacro { | ||
43 | fn eq(&self, other: &ProcMacro) -> bool { | ||
44 | self.name == other.name && Arc::ptr_eq(&self.expander, &other.expander) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | impl ProcMacro { | ||
49 | pub fn name(&self) -> String { | ||
50 | self.name.clone() | ||
51 | } | ||
52 | |||
53 | pub fn custom_derive(&self, subtree: &Subtree) -> Result<Subtree, ExpandError> { | ||
54 | self.expander.custom_derive(subtree, &self.name) | ||
55 | } | ||
56 | } | ||
57 | |||
58 | #[derive(Debug, Clone, PartialEq, Eq)] | 31 | #[derive(Debug, Clone, PartialEq, Eq)] |
59 | pub struct ProcMacroProcessSrv { | 32 | pub struct ProcMacroProcessSrv { |
60 | path: PathBuf, | 33 | path: PathBuf, |
@@ -76,7 +49,10 @@ impl ProcMacroClient { | |||
76 | ProcMacroClient::Dummy | 49 | ProcMacroClient::Dummy |
77 | } | 50 | } |
78 | 51 | ||
79 | pub fn by_dylib_path(&self, _dylib_path: &Path) -> Vec<ProcMacro> { | 52 | pub fn by_dylib_path( |
53 | &self, | ||
54 | _dylib_path: &Path, | ||
55 | ) -> Vec<(SmolStr, Arc<dyn ra_tt::TokenExpander>)> { | ||
80 | // FIXME: return empty for now | 56 | // FIXME: return empty for now |
81 | vec![] | 57 | vec![] |
82 | } | 58 | } |
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 1e2fb8b91..1015ce0a6 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -14,9 +14,12 @@ macro_rules! impl_froms { | |||
14 | } | 14 | } |
15 | } | 15 | } |
16 | 16 | ||
17 | use std::fmt; | 17 | use std::{ |
18 | fmt::{self, Debug}, | ||
19 | panic::RefUnwindSafe, | ||
20 | }; | ||
18 | 21 | ||
19 | use smol_str::SmolStr; | 22 | pub use smol_str::SmolStr; |
20 | 23 | ||
21 | /// Represents identity of the token. | 24 | /// Represents identity of the token. |
22 | /// | 25 | /// |
@@ -184,3 +187,11 @@ impl Subtree { | |||
184 | } | 187 | } |
185 | 188 | ||
186 | pub mod buffer; | 189 | pub mod buffer; |
190 | |||
191 | #[derive(Debug, PartialEq, Eq)] | ||
192 | pub enum ExpansionError {} | ||
193 | |||
194 | pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe { | ||
195 | fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) | ||
196 | -> Result<Subtree, ExpansionError>; | ||
197 | } | ||