Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

tokio-trace: Should the call site struct be provided by lib vs. generated by macro? #149

Open
carllerche opened this issue Nov 29, 2018 · 1 comment
Labels
area/macros Related to macros

Comments

@carllerche
Copy link
Collaborator

It looks like tokio-trace could provide a GeneratedCallsite struct:

struct GeneratedCallsite {
    pub interest: AtomicUsize,
    // ... whatever else
}

and the macro could initialize a static one for the span.

I wonder how that would impact compile times.

@hawkw hawkw added the area/macros Related to macros label Nov 30, 2018
@hawkw
Copy link
Owner

hawkw commented Dec 4, 2018

@carllerche the reason the Callsite impl is generated by the macro is because otherwise, there would be a cyclic dependency between the metadata and the callsite. Constructing a Meta requires a reference to a callsite (to get the identifier), but the Callsite impl is required to provide a metadata() function returning a reference to the metadata.

The macro gets around this by creating a static for the metadata and returning a reference to it. However, if we had a single impl of Callsite for GeneratedCallsite, the metadata would have to be stored as a field on the GeneratedCallsite, since we can't refer to the static (which is generated per callsite by the macro) by name. Unfortunately, this would mean that we can't construct a Callsite without the Meta, but we also couldn't construct a Meta without a callsite.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/macros Related to macros
Projects
None yet
Development

No branches or pull requests

2 participants