Skip to content

Commit

Permalink
Merge pull request #440 from dtolnay/example
Browse files Browse the repository at this point in the history
Add example code for invalidate_current_thread_spans
  • Loading branch information
dtolnay authored Jan 21, 2024
2 parents 43011bf + 66a3ef0 commit 69fee37
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
rust: [1.56.0, stable, beta]
rust: [1.63.0, stable, beta]
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -78,6 +78,29 @@ jobs:
env:
RUSTFLAGS: -Z allow-features= --cfg procmacro2_backtrace ${{env.RUSTFLAGS}}

msrv:
name: Rust 1.56.0
needs: pre_ci
if: needs.pre_ci.outputs.continue
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
- uses: dtolnay/[email protected]
with:
components: rust-src
- run: cargo check
- run: cargo check --no-default-features
- run: cargo check --features span-locations
- name: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo check
run: cargo check
env:
RUSTFLAGS: --cfg procmacro2_semver_exempt ${{env.RUSTFLAGS}}
- name: RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo check --no-default-features
run: cargo check --no-default-features
env:
RUSTFLAGS: --cfg procmacro2_semver_exempt ${{env.RUSTFLAGS}}

minimal:
name: Minimal versions
needs: pre_ci
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ features = ["span-locations"]
unicode-ident = "1.0"

[dev-dependencies]
flate2 = "1.0"
quote = { version = "1.0", default_features = false }
rayon = "1.0"
rustversion = "1"
tar = "0.4"

[features]
proc-macro = []
Expand Down
44 changes: 44 additions & 0 deletions src/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,50 @@ use core::fmt::{self, Debug};
/// gigabytes). After a wraparound, `Span` methods such as `source_text()` can
/// return wrong data.
///
/// # Example
///
/// As of late 2023, there is 200 GB of Rust code published on crates.io.
/// Looking at just the newest version of every crate, it is 16 GB of code. So a
/// workload that involves parsing it all would overflow a 32-bit source
/// location unless spans are being invalidated.
///
/// ```
/// use flate2::read::GzDecoder;
/// use std::ffi::OsStr;
/// use std::io::{BufReader, Read};
/// use std::str::FromStr;
/// use tar::Archive;
///
/// rayon::scope(|s| {
/// for krate in every_version_of_every_crate() {
/// s.spawn(move |_| {
/// proc_macro2::extra::invalidate_current_thread_spans();
///
/// let reader = BufReader::new(krate);
/// let tar = GzDecoder::new(reader);
/// let mut archive = Archive::new(tar);
/// for entry in archive.entries().unwrap() {
/// let mut entry = entry.unwrap();
/// let path = entry.path().unwrap();
/// if path.extension() != Some(OsStr::new("rs")) {
/// continue;
/// }
/// let mut content = String::new();
/// entry.read_to_string(&mut content).unwrap();
/// match proc_macro2::TokenStream::from_str(&content) {
/// Ok(tokens) => {/* ... */},
/// Err(_) => continue,
/// }
/// }
/// });
/// }
/// });
/// #
/// # fn every_version_of_every_crate() -> Vec<std::fs::File> {
/// # Vec::new()
/// # }
/// ```
///
/// # Panics
///
/// This function is not applicable to and will panic if called from a
Expand Down

0 comments on commit 69fee37

Please sign in to comment.