Skip to content

Commit 73bb248

Browse files
committed
fix: undo StringId -> InternalStringId renaming as it breaks FFI
1 parent a662171 commit 73bb248

File tree

13 files changed

+89
-104
lines changed

13 files changed

+89
-104
lines changed

datadog-profiling-ffi/cbindgen.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ renaming_overrides_prefixing = true
8888
"StackTraceId" = "OpaqueStackTraceId"
8989

9090
"GenerationalId_StringId" = "ddog_prof_StringId"
91-
"GenerationalId_InternalStringId" = "ddog_prof_StringId"
9291
"Result_GenerationalIdStringId" = "ddog_prof_StringId_Result"
93-
"Result_GenerationalIdInternalStringId" = "ddog_prof_StringId_Result"
9492
"MutSlice_GenerationalIdStringId" = "ddog_prof_MutSlice_StringId"
95-
"MutSlice_GenerationalIdInternalStringId" = "ddog_prof_MutSlice_StringId"
9693

9794
# StringId is an alias of StringOffset, we need both to be `OpaqueStringId`
9895
# for the current interning API.

datadog-profiling-ffi/src/profiles/interning_api.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::num::NonZeroI64;
66
use super::datatypes::{profile_ptr_to_inner, Profile};
77
use datadog_profiling::{
88
api::ManagedStringId,
9-
collections::identifiable::InternalStringId,
9+
collections::identifiable::StringId,
1010
internal::{
1111
self,
1212
interning_api::{Generation, GenerationalId},
@@ -20,7 +20,7 @@ use ddcommon_ffi::{
2020
use function_name::named;
2121

2222
// Cbindgen was putting invalid C types on the static, this workaround seems to fix it.
23-
type CbindgenIsDumbStringId = GenerationalId<InternalStringId>;
23+
type CbindgenIsDumbStringId = GenerationalId<StringId>;
2424

2525
#[no_mangle]
2626
#[used]
@@ -43,9 +43,9 @@ pub static ddog_INTERNED_EMPTY_STRING: CbindgenIsDumbStringId =
4343
#[named]
4444
pub unsafe extern "C" fn ddog_prof_Profile_intern_function(
4545
profile: *mut Profile,
46-
name: GenerationalId<InternalStringId>,
47-
system_name: GenerationalId<InternalStringId>,
48-
filename: GenerationalId<InternalStringId>,
46+
name: GenerationalId<StringId>,
47+
system_name: GenerationalId<StringId>,
48+
filename: GenerationalId<StringId>,
4949
) -> Result<GenerationalId<InternalFunctionId>> {
5050
wrap_with_ffi_result!({
5151
profile_ptr_to_inner(profile)?.intern_function(name, system_name, filename)
@@ -68,14 +68,14 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_function(
6868
#[named]
6969
pub unsafe extern "C" fn ddog_prof_Profile_intern_label_num(
7070
profile: *mut Profile,
71-
key: GenerationalId<InternalStringId>,
71+
key: GenerationalId<StringId>,
7272
val: i64,
7373
) -> Result<GenerationalId<LabelId>> {
7474
wrap_with_ffi_result!({
7575
profile_ptr_to_inner(profile)?.intern_label_num(
7676
key,
7777
val,
78-
GenerationalId::new_immortal(InternalStringId::ZERO),
78+
GenerationalId::new_immortal(StringId::ZERO),
7979
)
8080
})
8181
}
@@ -96,9 +96,9 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_label_num(
9696
#[named]
9797
pub unsafe extern "C" fn ddog_prof_Profile_intern_label_num_with_unit(
9898
profile: *mut Profile,
99-
key: GenerationalId<InternalStringId>,
99+
key: GenerationalId<StringId>,
100100
val: i64,
101-
unit: GenerationalId<InternalStringId>,
101+
unit: GenerationalId<StringId>,
102102
) -> Result<GenerationalId<LabelId>> {
103103
wrap_with_ffi_result!({ profile_ptr_to_inner(profile)?.intern_label_num(key, val, unit) })
104104
}
@@ -119,8 +119,8 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_label_num_with_unit(
119119
#[named]
120120
pub unsafe extern "C" fn ddog_prof_Profile_intern_label_str(
121121
profile: *mut Profile,
122-
key: GenerationalId<InternalStringId>,
123-
val: GenerationalId<InternalStringId>,
122+
key: GenerationalId<StringId>,
123+
val: GenerationalId<StringId>,
124124
) -> Result<GenerationalId<LabelId>> {
125125
wrap_with_ffi_result!({ profile_ptr_to_inner(profile)?.intern_label_str(key, val) })
126126
}
@@ -214,7 +214,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_location_with_mapping_id(
214214
pub unsafe extern "C" fn ddog_prof_Profile_intern_managed_string(
215215
profile: *mut Profile,
216216
s: ManagedStringId,
217-
) -> Result<GenerationalId<InternalStringId>> {
217+
) -> Result<GenerationalId<StringId>> {
218218
wrap_with_ffi_result!({ profile_ptr_to_inner(profile)?.intern_managed_string(s) })
219219
}
220220

@@ -235,7 +235,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_managed_string(
235235
pub unsafe extern "C" fn ddog_prof_Profile_intern_managed_strings(
236236
profile: *mut Profile,
237237
strings: Slice<ManagedStringId>,
238-
mut out: MutSlice<GenerationalId<InternalStringId>>,
238+
mut out: MutSlice<GenerationalId<StringId>>,
239239
) -> VoidResult {
240240
wrap_with_void_ffi_result!({
241241
anyhow::ensure!(strings.len() == out.len());
@@ -263,8 +263,8 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_mapping(
263263
memory_start: u64,
264264
memory_limit: u64,
265265
file_offset: u64,
266-
filename: GenerationalId<InternalStringId>,
267-
build_id: GenerationalId<InternalStringId>,
266+
filename: GenerationalId<StringId>,
267+
build_id: GenerationalId<StringId>,
268268
) -> Result<GenerationalId<InternalMappingId>> {
269269
wrap_with_ffi_result!({
270270
profile_ptr_to_inner(profile)?.intern_mapping(
@@ -349,7 +349,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_stacktrace(
349349
pub unsafe extern "C" fn ddog_prof_Profile_intern_string(
350350
profile: *mut Profile,
351351
s: CharSlice,
352-
) -> Result<GenerationalId<InternalStringId>> {
352+
) -> Result<GenerationalId<StringId>> {
353353
wrap_with_ffi_result!({ profile_ptr_to_inner(profile)?.intern_string(s.try_to_utf8()?) })
354354
}
355355

@@ -358,8 +358,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_intern_string(
358358
/// # Safety
359359
/// No preconditions
360360
#[no_mangle]
361-
pub unsafe extern "C" fn ddog_prof_Profile_interned_empty_string(
362-
) -> GenerationalId<InternalStringId> {
361+
pub unsafe extern "C" fn ddog_prof_Profile_interned_empty_string() -> GenerationalId<StringId> {
363362
internal::Profile::INTERNED_EMPTY_STRING
364363
}
365364

@@ -380,7 +379,7 @@ pub unsafe extern "C" fn ddog_prof_Profile_interned_empty_string(
380379
pub unsafe extern "C" fn ddog_prof_Profile_intern_strings(
381380
profile: *mut Profile,
382381
strings: Slice<CharSlice>,
383-
mut out: MutSlice<GenerationalId<InternalStringId>>,
382+
mut out: MutSlice<GenerationalId<StringId>>,
384383
) -> VoidResult {
385384
wrap_with_void_ffi_result!({
386385
anyhow::ensure!(strings.len() == out.len());

datadog-profiling/benches/interning_strings.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use datadog_profiling::collections::string_table::wordpress_test_data::WORDPRESS
77
/// This version is the one we used before having datadog-alloc.
88
#[allow(unused)]
99
mod old_version {
10-
use datadog_profiling::collections::identifiable::{FxIndexSet, Id, InternalStringId};
10+
use datadog_profiling::collections::identifiable::{FxIndexSet, Id, StringId};
1111
pub struct StringTable {
1212
strings: FxIndexSet<Box<str>>,
1313
}
@@ -19,7 +19,7 @@ mod old_version {
1919
Self { strings }
2020
}
2121

22-
pub fn intern(&mut self, item: &str) -> InternalStringId {
22+
pub fn intern(&mut self, item: &str) -> StringId {
2323
// For performance, delay converting the [&str] to a [String] until
2424
// after it has been determined to not exist in the set. This avoids
2525
// temporary allocations.
@@ -31,7 +31,7 @@ mod old_version {
3131
index
3232
}
3333
};
34-
InternalStringId::from_offset(index)
34+
StringId::from_offset(index)
3535
}
3636

3737
#[inline]

datadog-profiling/src/collections/identifiable/string_id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use super::*;
55
use datadog_profiling_protobuf::StringOffset;
66

7-
pub type InternalStringId = StringOffset;
7+
pub type StringId = StringOffset;
88

9-
impl Id for InternalStringId {
9+
impl Id for StringId {
1010
type RawId = i64;
1111

1212
fn from_offset(inner: usize) -> Self {

datadog-profiling/src/collections/string_storage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ use std::hash::BuildHasherDefault;
88
use std::num::NonZeroU32;
99
use std::rc::Rc;
1010

11-
use super::identifiable::InternalStringId;
11+
use super::identifiable::StringId;
1212
use super::string_table::StringTable;
1313

1414
#[derive(PartialEq, Debug)]
1515
struct ManagedStringData {
1616
str: Rc<str>,
17-
cached_seq_num: Cell<Option<(InternalCachedProfileId, InternalStringId)>>,
17+
cached_seq_num: Cell<Option<(InternalCachedProfileId, StringId)>>,
1818
usage_count: Cell<u32>,
1919
}
2020

@@ -170,7 +170,7 @@ impl ManagedStringStorage {
170170
id: NonZeroU32,
171171
profile_strings: &mut StringTable,
172172
cached_profile_id: &CachedProfileId,
173-
) -> anyhow::Result<InternalStringId> {
173+
) -> anyhow::Result<StringId> {
174174
let data = self.get_data(id.into())?;
175175

176176
match data.cached_seq_num.get() {

datadog-profiling/src/collections/string_table/mod.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod wordpress_test_data;
77

88
pub use error::*;
99

10-
use crate::collections::identifiable::InternalStringId;
10+
use crate::collections::identifiable::StringId;
1111
use crate::iter::{IntoLendingIterator, LendingIterator};
1212
use datadog_alloc::{AllocError, Allocator, ChainAllocator, VirtualAllocator};
1313
use std::alloc::Layout;
@@ -54,7 +54,7 @@ impl<A: Allocator + Clone> ArenaAllocator for ChainAllocator<A> {}
5454
type Hasher = core::hash::BuildHasherDefault<rustc_hash::FxHasher>;
5555
type HashSet<K> = indexmap::IndexSet<K, Hasher>;
5656

57-
/// Holds unique strings and provides [InternalStringId]s that correspond to the order
57+
/// Holds unique strings and provides [StringId]s that correspond to the order
5858
/// that the strings were inserted.
5959
pub struct StringTable {
6060
/// The bytes of each string stored in `strings` are allocated here.
@@ -121,34 +121,33 @@ impl StringTable {
121121
}
122122

123123
/// Adds the string to the string table if it isn't present already, and
124-
/// returns a [InternalStringId] that corresponds to the order that this string
124+
/// returns a [StringId] that corresponds to the order that this string
125125
/// was originally inserted.
126126
///
127127
/// # Panics
128128
///
129129
/// Panics if an allocator fails, or if the number of strings would exceed
130130
/// [`u32::MAX`].
131-
pub fn intern(&mut self, str: &str) -> InternalStringId {
131+
pub fn intern(&mut self, str: &str) -> StringId {
132132
#[allow(clippy::expect_used)]
133133
self.try_intern(str).expect("failed to intern string")
134134
}
135135

136136
/// Adds the string to the string table if it isn't present already, and
137-
/// returns a [`InternalStringId`] that corresponds to the order that this string
137+
/// returns a [`StringId`] that corresponds to the order that this string
138138
/// was originally inserted.
139139
///
140140
/// Fails if an allocator fails, or if the number of strings would exceed
141141
/// [`u32::MAX`].
142-
pub fn try_intern(&mut self, str: &str) -> Result<InternalStringId, Error> {
142+
pub fn try_intern(&mut self, str: &str) -> Result<StringId, Error> {
143143
let set = &mut self.strings;
144144
match set.get_index_of(str) {
145145
// SAFETY: if it already exists, it must fit in the range.
146-
Some(offset) => Ok(unsafe { InternalStringId::try_from(offset).unwrap_unchecked() }),
146+
Some(offset) => Ok(unsafe { StringId::try_from(offset).unwrap_unchecked() }),
147147
None => {
148148
// No match. Get the current size of the table, which
149149
// corresponds to the StringId it will have when inserted.
150-
let string_id =
151-
InternalStringId::try_from(set.len()).map_err(|_| Error::StorageFull)?;
150+
let string_id = StringId::try_from(set.len()).map_err(|_| Error::StorageFull)?;
152151

153152
// Make a new string in the arena, and fudge its lifetime
154153
// to appease the borrow checker.
@@ -302,11 +301,11 @@ mod tests {
302301
let mut table = StringTable::new();
303302
// The empty string should already be present.
304303
assert_eq!(1, table.len());
305-
assert_eq!(InternalStringId::ZERO, table.intern(""));
304+
assert_eq!(StringId::ZERO, table.intern(""));
306305

307306
// Intern a string literal to ensure ?Sized works.
308307
let string = table.intern("datadog");
309-
assert_eq!(InternalStringId::from_offset(1), string);
308+
assert_eq!(StringId::from_offset(1), string);
310309
assert_eq!(2, table.len());
311310
}
312311

datadog-profiling/src/internal/endpoints.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use super::*;
55

66
pub struct Endpoints {
7-
pub endpoint_label: InternalStringId,
8-
pub local_root_span_id_label: InternalStringId,
9-
pub mappings: FxIndexMap<u64, InternalStringId>,
7+
pub endpoint_label: StringId,
8+
pub local_root_span_id_label: StringId,
9+
pub mappings: FxIndexMap<u64, StringId>,
1010
pub stats: ProfiledEndpointsStats,
1111
}
1212

datadog-profiling/src/internal/function.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use super::*;
88
/// - ids for linked objects use 32-bit numbers instead of 64 bit ones.
99
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
1010
pub struct Function {
11-
pub name: InternalStringId,
12-
pub system_name: InternalStringId,
13-
pub filename: InternalStringId,
11+
pub name: StringId,
12+
pub system_name: StringId,
13+
pub filename: StringId,
1414
}
1515

1616
impl Item for Function {

datadog-profiling/src/internal/label.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ use datadog_profiling_protobuf::{prost_impls, Record, StringOffset};
66

77
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
88
pub enum InternalLabelValue {
9-
Str(InternalStringId),
10-
Num {
11-
num: i64,
12-
num_unit: InternalStringId,
13-
},
9+
Str(StringId),
10+
Num { num: i64, num_unit: StringId },
1411
}
1512

1613
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
1714
pub struct InternalLabel {
18-
key: InternalStringId,
15+
key: StringId,
1916
value: InternalLabelValue,
2017
}
2118

@@ -28,22 +25,22 @@ impl InternalLabel {
2825
matches!(self.value, InternalLabelValue::Str(_))
2926
}
3027

31-
pub fn get_key(&self) -> InternalStringId {
28+
pub fn get_key(&self) -> StringId {
3229
self.key
3330
}
3431

3532
pub fn get_value(&self) -> &InternalLabelValue {
3633
&self.value
3734
}
3835

39-
pub fn num(key: InternalStringId, num: i64, num_unit: InternalStringId) -> Self {
36+
pub fn num(key: StringId, num: i64, num_unit: StringId) -> Self {
4037
Self {
4138
key,
4239
value: InternalLabelValue::Num { num, num_unit },
4340
}
4441
}
4542

46-
pub fn str(key: InternalStringId, v: InternalStringId) -> Self {
43+
pub fn str(key: StringId, v: StringId) -> Self {
4744
Self {
4845
key,
4946
value: InternalLabelValue::Str(v),

datadog-profiling/src/internal/mapping.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ pub struct Mapping {
1818
/// The object this entry is loaded from. This can be a filename on
1919
/// disk for the main binary and shared libraries, or virtual
2020
/// abstractions like "[vdso]".
21-
pub filename: InternalStringId,
21+
pub filename: StringId,
2222

2323
/// A string that uniquely identifies a particular program version
2424
/// with high probability. E.g., for binaries generated by GNU tools,
2525
/// it could be the contents of the .note.gnu.build-id field.
26-
pub build_id: InternalStringId,
26+
pub build_id: StringId,
2727
}
2828

2929
impl Item for Mapping {

0 commit comments

Comments
 (0)