Skip to content

Commit 098532b

Browse files
committed
Remove proc-macro-hack and use our own slightly-less-hacky hack
1 parent 156e6e1 commit 098532b

File tree

6 files changed

+26
-17
lines changed

6 files changed

+26
-17
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ name = "bench"
1515
path = "./benchmarks/bench.rs"
1616

1717
[features]
18-
default = ["rustpython-vm/use-proc-macro-hack"]
1918
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
2019
freeze-stdlib = ["rustpython-vm/freeze-stdlib"]
2120

derive/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ edition = "2018"
1010
[lib]
1111
proc-macro = true
1212

13-
[features]
14-
default = ["proc-macro-hack"]
15-
1613
[dependencies]
1714
syn = { version = "0.15.29", features = ["full"] }
1815
quote = "0.6.11"
1916
proc-macro2 = "0.4.27"
2017
rustpython-compiler = { path = "../compiler", version = "0.1.1" }
2118
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
22-
proc-macro-hack = { version = "0.5", optional = true }
2319
maplit = "1.0"

derive/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ pub fn pystruct_sequence(attr: TokenStream, item: TokenStream) -> TokenStream {
5353
result_to_tokens(pyclass::impl_pystruct_sequence(attr, item))
5454
}
5555

56-
#[cfg_attr(feature = "proc-macro-hack", proc_macro_hack::proc_macro_hack)]
57-
#[cfg_attr(not(feature = "proc-macro-hack"), proc_macro)]
56+
fn result_to_tokens_expr(result: Result<TokenStream2, Diagnostic>) -> TokenStream {
57+
result_to_tokens(result.map(|out_expr| {
58+
quote::quote! {
59+
macro_rules! __proc_macro_call {
60+
() => {{ #out_expr }};
61+
}
62+
}
63+
}))
64+
}
65+
66+
#[proc_macro]
5867
pub fn py_compile_bytecode(input: TokenStream) -> TokenStream {
59-
result_to_tokens(compile_bytecode::impl_py_compile_bytecode(input.into()))
68+
result_to_tokens_expr(compile_bytecode::impl_py_compile_bytecode(input.into()))
6069
}

vm/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ edition = "2018"
99
include = ["src/**/*.rs", "Cargo.toml", "build.rs", "Lib/**/*.py"]
1010

1111
[features]
12-
default = ["rustpython-parser", "rustpython-compiler", "use-proc-macro-hack"]
12+
default = ["rustpython-parser", "rustpython-compiler"]
1313
vm-tracing-logging = []
1414
flame-it = ["flame", "flamer"]
15-
use-proc-macro-hack = ["proc-macro-hack", "rustpython-derive/proc-macro-hack"]
1615
freeze-stdlib = []
1716

1817
[dependencies]
@@ -60,7 +59,6 @@ unicode-casing = "0.1"
6059
unic = "0.9"
6160
unic-common = "0.9"
6261
maplit = "1.0"
63-
proc-macro-hack = { version = "0.5", optional = true }
6462
bitflags = "1.1"
6563
libc = "0.2"
6664
nix = "0.15.0"

vm/src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)]
1414
#![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/master/logo.png")]
1515
#![doc(html_root_url = "https://docs.rs/rustpython-vm/")]
16-
#![cfg_attr(not(feature = "use-proc-macro-hack"), feature(proc_macro_hygiene))]
1716

1817
#[cfg(feature = "flame-it")]
1918
#[macro_use]
@@ -37,9 +36,19 @@ extern crate self as rustpython_vm;
3736

3837
pub use rustpython_derive::*;
3938

40-
#[cfg(feature = "use-proc-macro-hack")]
41-
#[proc_macro_hack::proc_macro_hack]
42-
pub use rustpython_derive::py_compile_bytecode;
39+
#[doc(hidden)]
40+
pub use rustpython_derive::py_compile_bytecode as _py_compile_bytecode;
41+
42+
#[macro_export]
43+
macro_rules! py_compile_bytecode {
44+
($($arg:tt)*) => {{
45+
#[macro_use]
46+
mod __m {
47+
$crate::_py_compile_bytecode!($($arg)*);
48+
}
49+
__proc_macro_call!()
50+
}};
51+
}
4352

4453
//extern crate eval; use eval::eval::*;
4554
// use py_code_object::{Function, NativeType, PyCodeObject};

0 commit comments

Comments
 (0)