diff --git a/CHANGELOG.md b/CHANGELOG.md index cf056950..48bb561f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +**Features**: + +- Replace internal usage of `LazyCell` by `OnceCell` and make `SourceBundleDebugSession`: `Send`, `Sync` and `AsSelf`. ([#767](https://github.com/getsentry/symbolic/pull/767)) + ## 12.0.0 **Features**: diff --git a/symbolic-debuginfo/Cargo.toml b/symbolic-debuginfo/Cargo.toml index 2bcf3e8d..68c0ef68 100644 --- a/symbolic-debuginfo/Cargo.toml +++ b/symbolic-debuginfo/Cargo.toml @@ -25,7 +25,7 @@ default = ["breakpad", "elf", "macho", "ms", "ppdb", "sourcebundle", "js", "wasm # Breakpad text format parsing and processing breakpad = ["nom", "nom-supreme", "regex"] # DWARF processing. -dwarf = ["gimli", "lazycell"] +dwarf = ["gimli", "once_cell"] # ELF reading elf = [ "dwarf", @@ -53,7 +53,7 @@ ms = [ "goblin/pe32", "goblin/pe64", "goblin/std", - "lazycell", + "once_cell", "parking_lot", "pdb-addr2line", "scroll", @@ -65,7 +65,7 @@ ppdb = [ # Source bundle creation sourcebundle = [ "lazy_static", - "lazycell", + "once_cell", "parking_lot", "regex", "serde_json", @@ -94,7 +94,7 @@ gimli = { version = "0.27.0", optional = true, default-features = false, feature ] } goblin = { version = "0.6.0", optional = true, default-features = false } lazy_static = { version = "1.4.0", optional = true } -lazycell = { version = "1.2.1", optional = true } +once_cell = { version = "1.17.1", optional = true } nom = { version = "7.0.0", optional = true } nom-supreme = { version = "0.8.0", optional = true } parking_lot = { version = "0.12.0", optional = true } diff --git a/symbolic-debuginfo/src/dwarf.rs b/symbolic-debuginfo/src/dwarf.rs index d41a335e..3b9228d2 100644 --- a/symbolic-debuginfo/src/dwarf.rs +++ b/symbolic-debuginfo/src/dwarf.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use fallible_iterator::FallibleIterator; use gimli::read::{AttributeValue, Error as GimliError, Range}; use gimli::{constants, DwarfFileType, UnitSectionOffset}; -use lazycell::LazyCell; +use once_cell::sync::OnceCell; use thiserror::Error; use symbolic_common::{AsSelf, Language, Name, NameMangling, SelfCell}; @@ -1109,7 +1109,7 @@ impl<'data> DwarfSections<'data> { struct DwarfInfo<'data> { inner: DwarfInner<'data>, headers: Vec>, - units: Vec>>>, + units: Vec>>>, symbol_map: SymbolMap<'data>, address_offset: i64, kind: ObjectKind, @@ -1153,7 +1153,7 @@ impl<'d> DwarfInfo<'d> { // Prepare random access to unit headers. let headers = inner.units().collect::>()?; - let units = headers.iter().map(|_| LazyCell::new()).collect(); + let units = headers.iter().map(|_| OnceCell::new()).collect(); Ok(DwarfInfo { inner, @@ -1173,7 +1173,7 @@ impl<'d> DwarfInfo<'d> { None => return Ok(None), }; - let unit_opt = cell.try_borrow_with(|| { + let unit_opt = cell.get_or_try_init(|| { // Parse the compilation unit from the header. This requires a top-level DIE that // describes the unit itself. For some older DWARF files, this DIE might be missing // which causes gimli to error out. We prefer to skip them silently as this simply marks diff --git a/symbolic-debuginfo/src/ppdb.rs b/symbolic-debuginfo/src/ppdb.rs index 17fefb84..aef77e9d 100644 --- a/symbolic-debuginfo/src/ppdb.rs +++ b/symbolic-debuginfo/src/ppdb.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use std::fmt; use std::iter; -use lazycell::LazyCell; +use once_cell::sync::OnceCell; use symbolic_common::{Arch, CodeId, DebugId}; use symbolic_ppdb::EmbeddedSource; use symbolic_ppdb::{Document, FormatError, PortablePdb}; @@ -143,7 +143,7 @@ impl fmt::Debug for PortablePdbObject<'_> { /// A debug session for a Portable PDB object. pub struct PortablePdbDebugSession<'data> { ppdb: PortablePdb<'data>, - sources: LazyCell>>, + sources: OnceCell>>, } #[derive(Debug, Clone)] @@ -156,7 +156,7 @@ impl<'data> PortablePdbDebugSession<'data> { fn new(ppdb: &'_ PortablePdb<'data>) -> Result { Ok(PortablePdbDebugSession { ppdb: ppdb.clone(), - sources: LazyCell::new(), + sources: OnceCell::new(), }) } @@ -196,7 +196,7 @@ impl<'data> PortablePdbDebugSession<'data> { &self, path: &str, ) -> Result>, FormatError> { - let sources = self.sources.borrow_with(|| self.init_sources()); + let sources = self.sources.get_or_init(|| self.init_sources()); match sources.get(path) { None => Ok(None), Some(PPDBSource::Embedded(source)) => source.get_contents().map(|bytes| { diff --git a/symbolic-debuginfo/src/sourcebundle.rs b/symbolic-debuginfo/src/sourcebundle.rs index d79cbc89..44839d40 100644 --- a/symbolic-debuginfo/src/sourcebundle.rs +++ b/symbolic-debuginfo/src/sourcebundle.rs @@ -51,7 +51,7 @@ use std::io::{BufReader, BufWriter, Read, Seek, Write}; use std::path::Path; use std::sync::Arc; -use lazycell::LazyCell; +use once_cell::sync::OnceCell; use parking_lot::Mutex; use regex::Regex; use serde::{Deserialize, Deserializer, Serialize}; @@ -676,7 +676,7 @@ impl<'data> SourceBundle<'data> { Ok(SourceBundleDebugSession { manifest: self.manifest.clone(), archive: self.archive.clone(), - indexed_files: LazyCell::new(), + indexed_files: OnceCell::new(), }) } @@ -802,7 +802,7 @@ enum FileKey<'a> { pub struct SourceBundleDebugSession<'data> { manifest: Arc, archive: Arc>>>, - indexed_files: LazyCell, Arc>>, + indexed_files: OnceCell, Arc>>, } impl<'data> SourceBundleDebugSession<'data> { @@ -820,7 +820,7 @@ impl<'data> SourceBundleDebugSession<'data> { /// Get the indexed file mapping. fn indexed_files(&self) -> &HashMap> { - self.indexed_files.borrow_with(|| { + self.indexed_files.get_or_init(|| { let files = &self.manifest.files; let mut rv = HashMap::with_capacity(files.len()); @@ -928,6 +928,14 @@ impl<'data, 'session> DebugSession<'session> for SourceBundleDebugSession<'data> } } +impl<'slf, 'data: 'slf> AsSelf<'slf> for SourceBundleDebugSession<'data> { + type Ref = SourceBundleDebugSession<'slf>; + + fn as_self(&'slf self) -> &Self::Ref { + unsafe { std::mem::transmute(self) } + } +} + /// An iterator over source files in a SourceBundle object. pub struct SourceBundleFileIterator<'s> { files: std::collections::btree_map::Values<'s, String, SourceFileInfo>, @@ -1362,6 +1370,12 @@ mod tests { Ok(()) } + #[test] + fn debugsession_is_sendsync() { + fn is_sendsync() {} + is_sendsync::(); + } + #[test] fn test_source_descriptor() -> Result<(), SourceBundleError> { let mut writer = Cursor::new(Vec::new());