Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion third_party/starlark/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions third_party/starlark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ version = "1.5.4"
version = "1.0"
features = ["derive"]

[dependencies.serde_json]
package = "braintrust_serde_json"
[dependencies.braintrust_serde_json]
git = "https://github.com/braintrustdata/serde-json.git"
rev = "905b790b50e8922370f3e73ef93d7d5fb7010edc"
rev = "e329686d4b1eb6cc1a430266741904b6dc4051e1"
features = ["arbitrary_precision"]

[dependencies.starlark_derive]
Expand Down
70 changes: 35 additions & 35 deletions third_party/starlark/src/stdlib/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ use crate::values::dict::AllocDict;
use crate::values::type_repr::StarlarkTypeRepr;
use crate::values::types::int::int_or_big::StarlarkInt;

impl StarlarkTypeRepr for serde_json::Number {
impl StarlarkTypeRepr for braintrust_serde_json::Number {
type Canonical = Either<i32, f64>;

fn starlark_type_repr() -> Ty {
Either::<i32, f64>::starlark_type_repr()
}
}

impl<'a> StarlarkTypeRepr for &'a serde_json::Number {
type Canonical = serde_json::Number;
impl<'a> StarlarkTypeRepr for &'a braintrust_serde_json::Number {
type Canonical = braintrust_serde_json::Number;

fn starlark_type_repr() -> Ty {
serde_json::Number::starlark_type_repr()
braintrust_serde_json::Number::starlark_type_repr()
}
}

impl<'v, 'a> AllocValue<'v> for &'a serde_json::Number {
impl<'v, 'a> AllocValue<'v> for &'a braintrust_serde_json::Number {
fn alloc_value(self, heap: Heap<'v>) -> Value<'v> {
if let Some(x) = self.as_u64() {
heap.alloc(x)
Expand All @@ -70,15 +70,15 @@ impl<'v, 'a> AllocValue<'v> for &'a serde_json::Number {
}
}

impl<'v> AllocValue<'v> for serde_json::Number {
impl<'v> AllocValue<'v> for braintrust_serde_json::Number {
fn alloc_value(self, heap: Heap<'v>) -> Value<'v> {
// If you follow this hint, it becomes infinite recursion
#[allow(clippy::needless_borrows_for_generic_args)]
heap.alloc(&self)
}
}

impl<'a> AllocFrozenValue for &'a serde_json::Number {
impl<'a> AllocFrozenValue for &'a braintrust_serde_json::Number {
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
if let Some(x) = self.as_u64() {
heap.alloc(x)
Expand All @@ -94,70 +94,70 @@ impl<'a> AllocFrozenValue for &'a serde_json::Number {
}
}

impl AllocFrozenValue for serde_json::Number {
impl AllocFrozenValue for braintrust_serde_json::Number {
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
// If you follow this hint, it becomes infinite recursion
#[allow(clippy::needless_borrows_for_generic_args)]
heap.alloc(&self)
}
}

impl<'a, K: StarlarkTypeRepr, V: StarlarkTypeRepr> StarlarkTypeRepr for &'a serde_json::Map<K, V> {
type Canonical = <serde_json::Map<K, V> as StarlarkTypeRepr>::Canonical;
impl<'a, K: StarlarkTypeRepr, V: StarlarkTypeRepr> StarlarkTypeRepr for &'a braintrust_serde_json::Map<K, V> {
type Canonical = <braintrust_serde_json::Map<K, V> as StarlarkTypeRepr>::Canonical;

fn starlark_type_repr() -> Ty {
AllocDict::<SmallMap<K, V>>::starlark_type_repr()
}
}

impl<K: StarlarkTypeRepr, V: StarlarkTypeRepr> StarlarkTypeRepr for serde_json::Map<K, V> {
impl<K: StarlarkTypeRepr, V: StarlarkTypeRepr> StarlarkTypeRepr for braintrust_serde_json::Map<K, V> {
type Canonical = <SmallMap<K, V> as StarlarkTypeRepr>::Canonical;

fn starlark_type_repr() -> Ty {
AllocDict::<SmallMap<K, V>>::starlark_type_repr()
}
}

impl<'a, 'v> AllocValue<'v> for &'a serde_json::Map<String, serde_json::Value> {
impl<'a, 'v> AllocValue<'v> for &'a braintrust_serde_json::Map<String, braintrust_serde_json::Value> {
fn alloc_value(self, heap: Heap<'v>) -> Value<'v> {
// For some reason `IntoIter` is implemented only for `String, Value` parameters,
// so this implementation is limited.
heap.alloc(AllocDict(self))
}
}

impl<'v> AllocValue<'v> for serde_json::Map<String, serde_json::Value> {
impl<'v> AllocValue<'v> for braintrust_serde_json::Map<String, braintrust_serde_json::Value> {
fn alloc_value(self, heap: Heap<'v>) -> Value<'v> {
// If you follow this hint, it becomes infinite recursion
#[allow(clippy::needless_borrows_for_generic_args)]
heap.alloc(&self)
}
}

impl<'a> AllocFrozenValue for &'a serde_json::Map<String, serde_json::Value> {
impl<'a> AllocFrozenValue for &'a braintrust_serde_json::Map<String, braintrust_serde_json::Value> {
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
heap.alloc(AllocDict(self.iter().map(|(k, v)| (k.as_str(), v))))
}
}

impl AllocFrozenValue for serde_json::Map<String, serde_json::Value> {
impl AllocFrozenValue for braintrust_serde_json::Map<String, braintrust_serde_json::Value> {
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
// If you follow this hint, it becomes infinite recursion
#[allow(clippy::needless_borrows_for_generic_args)]
heap.alloc(&self)
}
}

impl<'a> StarlarkTypeRepr for &'a serde_json::Value {
type Canonical = <serde_json::Value as StarlarkTypeRepr>::Canonical;
impl<'a> StarlarkTypeRepr for &'a braintrust_serde_json::Value {
type Canonical = <braintrust_serde_json::Value as StarlarkTypeRepr>::Canonical;

fn starlark_type_repr() -> Ty {
// Any.
Value::starlark_type_repr()
}
}

impl StarlarkTypeRepr for serde_json::Value {
impl StarlarkTypeRepr for braintrust_serde_json::Value {
type Canonical = <FrozenValue as StarlarkTypeRepr>::Canonical;

fn starlark_type_repr() -> Ty {
Expand All @@ -166,41 +166,41 @@ impl StarlarkTypeRepr for serde_json::Value {
}
}

impl<'v, 'a> AllocValue<'v> for &'a serde_json::Value {
impl<'v, 'a> AllocValue<'v> for &'a braintrust_serde_json::Value {
fn alloc_value(self, heap: Heap<'v>) -> Value<'v> {
match self {
serde_json::Value::Null => Value::new_none(),
serde_json::Value::Bool(x) => Value::new_bool(*x),
serde_json::Value::Number(x) => heap.alloc(x),
serde_json::Value::String(x) => heap.alloc(x.as_str()),
serde_json::Value::Array(x) => heap.alloc(x.as_slice()),
serde_json::Value::Object(x) => heap.alloc(x),
braintrust_serde_json::Value::Null => Value::new_none(),
braintrust_serde_json::Value::Bool(x) => Value::new_bool(*x),
braintrust_serde_json::Value::Number(x) => heap.alloc(x),
braintrust_serde_json::Value::String(x) => heap.alloc(x.as_str()),
braintrust_serde_json::Value::Array(x) => heap.alloc(x.as_slice()),
braintrust_serde_json::Value::Object(x) => heap.alloc(x),
}
}
}

impl<'v> AllocValue<'v> for serde_json::Value {
impl<'v> AllocValue<'v> for braintrust_serde_json::Value {
fn alloc_value(self, heap: Heap<'v>) -> Value<'v> {
// If you follow this hint, it becomes infinite recursion
#[allow(clippy::needless_borrows_for_generic_args)]
heap.alloc(&self)
}
}

impl<'a> AllocFrozenValue for &'a serde_json::Value {
impl<'a> AllocFrozenValue for &'a braintrust_serde_json::Value {
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
match self {
serde_json::Value::Null => FrozenValue::new_none(),
serde_json::Value::Bool(x) => FrozenValue::new_bool(*x),
serde_json::Value::Number(x) => heap.alloc(x),
serde_json::Value::String(x) => heap.alloc(x.as_str()),
serde_json::Value::Array(x) => heap.alloc(x.as_slice()),
serde_json::Value::Object(x) => heap.alloc(x),
braintrust_serde_json::Value::Null => FrozenValue::new_none(),
braintrust_serde_json::Value::Bool(x) => FrozenValue::new_bool(*x),
braintrust_serde_json::Value::Number(x) => heap.alloc(x),
braintrust_serde_json::Value::String(x) => heap.alloc(x.as_str()),
braintrust_serde_json::Value::Array(x) => heap.alloc(x.as_slice()),
braintrust_serde_json::Value::Object(x) => heap.alloc(x),
}
}
}

impl AllocFrozenValue for serde_json::Value {
impl AllocFrozenValue for braintrust_serde_json::Value {
fn alloc_frozen_value(self, heap: &FrozenHeap) -> FrozenValue {
// If you follow this hint, it becomes infinite recursion
#[allow(clippy::needless_borrows_for_generic_args)]
Expand All @@ -219,7 +219,7 @@ pub(crate) fn json(globals: &mut GlobalsBuilder) {
#[starlark(require = pos)] x: &str,
heap: Heap<'v>,
) -> anyhow::Result<Value<'v>> {
Ok(heap.alloc(serde_json::from_str::<serde_json::Value>(x)?))
Ok(heap.alloc(braintrust_serde_json::from_str::<braintrust_serde_json::Value>(x)?))
}
}

Expand Down
8 changes: 4 additions & 4 deletions third_party/starlark/src/values/layout/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,12 +879,12 @@ impl<'v> Value<'v> {
///
/// Return an error if the value or any contained value does not support conversion to JSON.
pub fn to_json(self) -> anyhow::Result<String> {
serde_json::to_string(&self).map_err(|e| anyhow::anyhow!(e))
braintrust_serde_json::to_string(&self).map_err(|e| anyhow::anyhow!(e))
}

/// Convert the value to JSON value.
pub fn to_json_value(self) -> anyhow::Result<serde_json::Value> {
serde_json::to_value(self).map_err(|e| anyhow::anyhow!(e))
pub fn to_json_value(self) -> anyhow::Result<braintrust_serde_json::Value> {
braintrust_serde_json::to_value(self).map_err(|e| anyhow::anyhow!(e))
}

/// Forwards to [`StarlarkValue::set_attr`].
Expand Down Expand Up @@ -1562,7 +1562,7 @@ mod tests {
fn test_to_json_value() {
let value = assert::pass("{'a': 10}");
assert_eq!(
serde_json::json!({"a": 10}),
braintrust_serde_json::json!({"a": 10}),
value.value().to_json_value().unwrap()
);
}
Expand Down
2 changes: 1 addition & 1 deletion third_party/starlark/src/values/types/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Serialize for StarlarkBigInt {
serializer.serialize_u64(u)
} else {
let number_str = self.value.to_string();
let number = serde_json::Number::from_str(&number_str).map_err(|e| {
let number = braintrust_serde_json::Number::from_str(&number_str).map_err(|e| {
serde::ser::Error::custom(format!("Failed to create JSON number: {}", e))
})?;
number.serialize(serializer)
Expand Down
Loading