Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider an API to reset thread-local Span data #414

Closed
dtolnay opened this issue Oct 10, 2023 · 2 comments · Fixed by #438
Closed

Consider an API to reset thread-local Span data #414

dtolnay opened this issue Oct 10, 2023 · 2 comments · Fixed by #438

Comments

@dtolnay
Copy link
Owner

dtolnay commented Oct 10, 2023

Basically truncate this thing:

proc-macro2/src/fallback.rs

Lines 323 to 325 in fecb02d

#[cfg(all(span_locations, not(fuzzing)))]
thread_local! {
static SOURCE_MAP: RefCell<SourceMap> = RefCell::new(SourceMap {

Resetting would be a claim that all currently existing non-call-site spans on the current thread are no longer in use, or it's okay if methods like line/column and source_text crash or produce wrong results.

A workload that involves parsing all versions of all crates on a thread pool of 64 threads would need this, because otherwise our 32-bit positions would overflow. See #413 (comment).

@buchgr
Copy link
Contributor

buchgr commented Jan 17, 2024

Adding such an API would be much appreciated. My workload is similar to what you described in your comment. David, did you already have an API in mind? I'd be happy to file a PR.

Also for my understanding: The idea behind the thread-local source map is to avoid a ref on Span to safe bytes?

@dtolnay
Copy link
Owner Author

dtolnay commented Jan 18, 2024

Something like proc_macro2::invalidate_current_thread_spans() with a realistic code example.

The idea behind the thread-local source map is to avoid a ref on Span to safe bytes?

Span needs to be Copy and 'static. I don't know any other way to implement that, regardless of how many bytes big Span is.

buchgr added a commit to buchgr/proc-macro2 that referenced this issue Jan 18, 2024
buchgr added a commit to buchgr/proc-macro2 that referenced this issue Jan 18, 2024
buchgr added a commit to buchgr/proc-macro2 that referenced this issue Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants