Skip to content

Commit 3125ca9

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Use allocative
Reviewed By: ndmitchell Differential Revision: D41040212 fbshipit-source-id: d3b7748162bda0e630f7d47b2191f6ae0492f49c
1 parent 8e337b3 commit 3125ca9

File tree

17 files changed

+57
-27
lines changed

17 files changed

+57
-27
lines changed

starlark/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ num-traits = "0.2"
6262
inventory = "0.1.10"
6363
clap = { version = "4.0.7", features = ["derive", "wrap_help"] }
6464

65+
allocative.version = "0.2"
66+
# @oss-disable: allocative.path = "../../allocative/allocative"
67+
allocative.features = ["bumpalo"]
68+
6569
[dev-dependencies]
6670
rand = { version = "0.8.4", features = ["small_rng"] }
6771

starlark/src/environment/globals.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::collections::HashMap;
1919
use std::sync::Arc;
2020

21+
use allocative::Allocative;
2122
use derive_more::Display;
2223
use gazebo::prelude::*;
2324
use itertools::Itertools;
@@ -52,7 +53,7 @@ use crate::values::Heap;
5253
use crate::values::Value;
5354

5455
/// The global values available during execution.
55-
#[derive(Clone, Dupe, Debug, Display)]
56+
#[derive(Clone, Dupe, Debug, Display, Allocative)]
5657
#[display(fmt = "globals")]
5758
pub struct Globals(Arc<GlobalsData>);
5859

@@ -61,10 +62,12 @@ pub struct Globals(Arc<GlobalsData>);
6162
#[display(fmt = "methods")]
6263
pub struct Methods(Arc<MethodsData>);
6364

64-
#[derive(Debug)]
65+
#[derive(Debug, Allocative)]
6566
struct GlobalsData {
6667
heap: FrozenHeapRef,
68+
#[allocative(skip)] // TODO(nga): do not skip.
6769
variables: SymbolMap<FrozenValue>,
70+
#[allocative(skip)]
6871
variable_names: Vec<FrozenStringValue>,
6972
docstring: Option<String>,
7073
}

starlark/src/environment/modules.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use std::sync::Arc;
2828
use std::time::Duration;
2929
use std::time::Instant;
3030

31+
use allocative::Allocative;
3132
use derive_more::Display;
3233
use gazebo::any::ProvidesStaticType;
3334
use gazebo::prelude::*;
@@ -74,7 +75,7 @@ enum ModuleError {
7475
/// can be obtained using [`frozen_heap`](FrozenModule::frozen_heap). Be careful not to use
7576
/// these values after the [`FrozenModule`] has been released unless you obtain a reference
7677
/// to the frozen heap.
77-
#[derive(Debug, Clone, Dupe)]
78+
#[derive(Debug, Clone, Dupe, Allocative)]
7879
// We store the two elements separately since the FrozenHeapRef contains
7980
// a copy of the FrozenModuleData inside it.
8081
// Two Arc's should still be plenty cheap enough to qualify for `Dupe`.
@@ -89,7 +90,7 @@ pub struct FrozenModule {
8990
pub(crate) eval_duration: Duration,
9091
}
9192

92-
#[derive(Debug, Clone, Dupe, ProvidesStaticType, Display)]
93+
#[derive(Debug, Clone, Dupe, ProvidesStaticType, Display, Allocative)]
9394
#[display(fmt = "{:?}", self)] // Type should not be user visible
9495
pub(crate) struct FrozenModuleRef(pub(crate) Arc<FrozenModuleData>);
9596

@@ -107,7 +108,7 @@ impl FrozenModuleRef {
107108
}
108109
}
109110

110-
#[derive(Debug)]
111+
#[derive(Debug, Allocative)]
111112
pub(crate) struct FrozenModuleData {
112113
pub(crate) names: FrozenNames,
113114
pub(crate) slots: FrozenSlots,

starlark/src/environment/names.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
use std::cell::RefCell;
1919

20+
use allocative::Allocative;
21+
2022
use crate::collections::Hashed;
2123
use crate::collections::SmallMap;
2224
use crate::environment::slots::ModuleSlotId;
@@ -43,8 +45,11 @@ use crate::values::FrozenStringValue;
4345
#[derive(Debug)]
4446
pub(crate) struct MutableNames(RefCell<SmallMap<FrozenStringValue, (ModuleSlotId, Visibility)>>);
4547

46-
#[derive(Debug)]
47-
pub(crate) struct FrozenNames(SmallMap<FrozenStringValue, (ModuleSlotId, Visibility)>);
48+
#[derive(Debug, Allocative)]
49+
pub(crate) struct FrozenNames(
50+
// TODO(nga): measure.
51+
#[allocative(skip)] SmallMap<FrozenStringValue, (ModuleSlotId, Visibility)>,
52+
);
4853

4954
impl MutableNames {
5055
pub fn new() -> Self {

starlark/src/environment/slots.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::cell::RefCell;
1919
use std::cell::RefMut;
2020

21+
use allocative::Allocative;
2122
use gazebo::prelude::*;
2223

2324
use crate::values::Freezer;
@@ -38,7 +39,7 @@ impl ModuleSlotId {
3839
pub(crate) struct MutableSlots<'v>(RefCell<Vec<Option<Value<'v>>>>);
3940

4041
// Indexed slots of a module. May contain unassigned values as `None`.
41-
#[derive(Debug)]
42+
#[derive(Debug, Allocative)]
4243
pub(crate) struct FrozenSlots(Vec<Option<FrozenValue>>);
4344

4445
impl<'v> MutableSlots<'v> {

starlark/src/eval/runtime/profile/heap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use std::fmt::Debug;
1919

20+
use allocative::Allocative;
2021
use gazebo::dupe::Dupe;
2122

2223
use crate::eval::runtime::profile::data::ProfileData;
@@ -26,7 +27,7 @@ use crate::values::layout::heap::profile::aggregated::AggregateHeapProfileInfo;
2627
use crate::values::Heap;
2728
use crate::values::Value;
2829

29-
#[derive(Copy, Clone, Dupe, Debug)]
30+
#[derive(Copy, Clone, Dupe, Debug, Allocative)]
3031
pub(crate) enum RetainedHeapProfileMode {
3132
Flame,
3233
Summary,

starlark/src/eval/runtime/profile/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use std::fmt::Display;
1919
use std::str::FromStr;
2020

21+
use allocative::Allocative;
2122
use gazebo::dupe::Dupe;
2223

2324
pub(crate) mod bc;
@@ -31,7 +32,7 @@ pub(crate) mod time_flame;
3132
pub(crate) mod typecheck;
3233

3334
/// How to profile starlark code.
34-
#[derive(Debug, PartialEq, Eq, Hash, Clone, Dupe)]
35+
#[derive(Debug, PartialEq, Eq, Hash, Clone, Dupe, Allocative)]
3536
#[non_exhaustive]
3637
pub enum ProfileMode {
3738
/// The heap profile mode provides information about the time spent in each function and allocations

starlark/src/eval/runtime/small_duration.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ use std::ops::AddAssign;
2121
use std::ops::Div;
2222
use std::time::Duration;
2323

24+
use allocative::Allocative;
2425
use gazebo::dupe::Dupe;
2526

2627
/// Slightly faster than `Duration`.
27-
#[derive(Copy, Clone, Dupe, Default, Debug)]
28+
#[derive(Copy, Clone, Dupe, Default, Debug, Allocative)]
2829
pub(crate) struct SmallDuration {
2930
/// `u64::MAX` nanos is 500 years.
3031
pub(crate) nanos: u64,

starlark/src/values/layout/heap/arena.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::ptr;
3636
use std::slice;
3737
use std::time::Instant;
3838

39+
use allocative::Allocative;
3940
use bumpalo::Bump;
4041
use either::Either;
4142
use gazebo::prelude::*;
@@ -74,7 +75,8 @@ pub(crate) const MIN_ALLOC: usize = {
7475
)
7576
};
7677

77-
#[derive(Default)]
78+
#[derive(Default, Allocative)]
79+
// TODO(nga): implement `Allocative` for heap elements.
7880
pub(crate) struct Arena {
7981
/// Arena for things which don't need dropping (e.g. strings)
8082
non_drop: Bump,

starlark/src/values/layout/heap/heap_type.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use std::sync::Arc;
3636
use std::time::Instant;
3737
use std::usize;
3838

39+
use allocative::Allocative;
3940
use either::Either;
4041
use gazebo::cast;
4142
use gazebo::prelude::*;
@@ -129,7 +130,7 @@ pub struct FrozenHeap {
129130

130131
/// `FrozenHeap` when it is no longer modified and can be share between threads.
131132
/// Although, `arena` is not safe to share between threads, but at least `refs` is.
132-
#[derive(Default)]
133+
#[derive(Default, Allocative)]
133134
#[allow(clippy::non_send_fields_in_send_ty)]
134135
struct FrozenFrozenHeap {
135136
arena: Arena,
@@ -161,7 +162,7 @@ impl Debug for FrozenFrozenHeap {
161162
/// A reference to a [`FrozenHeap`] that keeps alive all values on the underlying heap.
162163
/// Note that the [`Hash`] is consistent for a single [`FrozenHeapRef`], but non-deterministic
163164
/// across executions and distinct but observably identical [`FrozenHeapRef`] values.
164-
#[derive(Clone, Dupe, Debug)]
165+
#[derive(Clone, Dupe, Debug, Allocative)]
165166
// The Eq/Hash are by pointer rather than value, since we produce unique values
166167
// given an underlying FrozenHeap.
167168
pub struct FrozenHeapRef(Arc<FrozenFrozenHeap>);

0 commit comments

Comments
 (0)