tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.36k stars 699 forks source link

tracing: Replace macro-rules with procedural macros #133

Open hawkw opened 5 years ago

hawkw commented 5 years ago

Feature Request

Crates

tracing

Motivation

Now that we are not supporting Rust 1.26.0 as our minimum compatible version, we can ship procedural macros in tracing. Replacing the existing macro_rules macros should improve user-facing error messages, make the macros more maintainable, and make it easier to add new features to them in the future (such as #83).

Proposal

The macros should be in a separate crate, but they should be re-exported by tracing. We should re-implement the existing macro syntax prior to adding any new features, and do that separately as a follow-up.

I think the new macros could live in the existingtracing-proc-macros or tracing-macros crates. Perhaps we should use tracing-macros and move everything currently in tracing-proc-macros there (and rewrite or remove the macros currently in tracing-macros, which are very experimental).

hawkw commented 5 years ago

I believe @Ralith is working on this. My understanding is that it is currently blocked on dtolnay/syn#661.

Ralith commented 5 years ago

I believe @Ralith is working on this. My understanding is that it is currently blocked on dtolnay/syn#661.

This is accurate. If that issue can be fixed, I am otherwise very close to a working prototype of event!().

I think the new macros could live in the existingtracing-proc-macros or tracing-macros crates. Perhaps we should use tracing-macros and move everything currently in tracing-proc-macros there (and rewrite or remove the macros currently in tracing-macros, which are very experimental).

These macros will necessarily rely on proc-macro-hack, which means that they can't be used by downstream code directly from the crate they're implemented in; an intermediate re-exporting crate is always necessary. My understanding is that tokio(-proc)-macros are intended to be user-facing, so we'll still need an internal -impl crate.

Ralith commented 5 years ago

Looks like it might not be a syn issue: https://github.com/dtolnay/proc-macro-hack/issues/34

Ralith commented 5 years ago

Now isolated to a compiler issue: https://github.com/rust-lang/rust/issues/62325

hawkw commented 5 years ago

Thanks for keeping us updated, @Ralith --- great to hear that progress is being made on unblocking this!

hawkw commented 5 years ago

Looks like the compiler bug has been fixed in rust-lang/rust#62393, so hopefully we can move forwards with this once the fix is on stable.