From 7dd526ad8f2f0e275aa1575a845038544e24bfee Mon Sep 17 00:00:00 2001 From: Will Li Date: Wed, 27 Nov 2024 08:33:40 -0800 Subject: [PATCH] Use freeze_error over anyhow Summary: Actually use freeze_error implemented in the diff before to replace anyhow. Sorry for the big diff but it's mostly just a string replacement. I will try to point out the interesting changes in the comments Reviewed By: JakobDegen Differential Revision: D63779558 fbshipit-source-id: 2b77ddeeb46073e9d0d08d5683476552360c4572 --- starlark/src/environment/modules.rs | 5 +- starlark/src/environment/slots.rs | 3 +- starlark/src/eval/compiler/def.rs | 3 +- starlark/src/eval/runtime/params/spec.rs | 1 + starlark/src/eval/runtime/slots.rs | 1 + starlark/src/stdlib/partial.rs | 5 +- starlark/src/tests/derive/docs.rs | 1 + starlark/src/tests/derive/freeze/basic.rs | 1 + starlark/src/tests/derive/freeze/bounds.rs | 2 + starlark/src/tests/derive/freeze/enums.rs | 1 + starlark/src/tests/derive/freeze/identity.rs | 1 + starlark/src/tests/derive/freeze/validator.rs | 2 + .../tests/derive/freeze/validator_order.rs | 4 +- starlark/src/tests/freeze_access_value.rs | 3 +- starlark/src/tests/interop.rs | 3 +- starlark/src/tests/uncategorized.rs | 3 +- starlark/src/tests/util.rs | 1 + starlark/src/values/freeze.rs | 56 ++++++++++--------- starlark/src/values/frozen_ref.rs | 3 +- starlark/src/values/layout/avalue.rs | 32 ++++++----- starlark/src/values/layout/complex.rs | 5 +- starlark/src/values/layout/heap/heap_type.rs | 3 +- starlark/src/values/layout/typed.rs | 3 +- starlark/src/values/layout/typed/string.rs | 3 +- starlark/src/values/layout/value.rs | 3 +- starlark/src/values/layout/value_captured.rs | 3 +- starlark/src/values/layout/vtable.rs | 5 +- starlark/src/values/traits.rs | 5 +- starlark/src/values/types/any_complex.rs | 4 +- starlark/src/values/types/dict/value.rs | 3 +- .../src/values/types/enumeration/enum_type.rs | 3 +- .../src/values/types/enumeration/value.rs | 1 + starlark/src/values/types/exported_name.rs | 3 +- starlark/src/values/types/function.rs | 1 + starlark/src/values/types/namespace/value.rs | 1 + starlark/src/values/types/record/field.rs | 1 + starlark/src/values/types/record/instance.rs | 1 + .../src/values/types/record/record_type.rs | 3 +- starlark/src/values/types/set/value.rs | 3 +- starlark/src/values/types/string/iter.rs | 1 + starlark/src/values/types/structs/value.rs | 1 + starlark/src/values/types/type_instance_id.rs | 1 + starlark/src/values/typing/callable.rs | 3 +- .../values/typing/type_compiled/compiled.rs | 1 + .../values/typing/type_compiled/matchers.rs | 1 + starlark/src/values/value_of_unchecked.rs | 3 +- starlark_bin/bin/bazel.rs | 2 +- starlark_bin/bin/eval.rs | 2 +- starlark_derive/src/freeze.rs | 7 ++- 49 files changed, 132 insertions(+), 75 deletions(-) diff --git a/starlark/src/environment/modules.rs b/starlark/src/environment/modules.rs index 0dabaf26f..7fdc12c14 100644 --- a/starlark/src/environment/modules.rs +++ b/starlark/src/environment/modules.rs @@ -52,6 +52,7 @@ use crate::values::layout::heap::heap_type::HeapKind; use crate::values::layout::heap::profile::aggregated::AggregateHeapProfileInfo; use crate::values::layout::heap::profile::aggregated::RetainedHeapProfile; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenHeapRef; @@ -139,7 +140,7 @@ impl FrozenModule { /// /// This function does not return an error, /// but we prefer not to panic if there's some high level logic error. - pub fn from_globals(globals: &Globals) -> anyhow::Result { + pub fn from_globals(globals: &Globals) -> FreezeResult { let module = Module::new(); module.frozen_heap.add_reference(globals.heap()); @@ -406,7 +407,7 @@ impl Module { } /// Freeze the environment, all its value will become immutable afterwards. - pub fn freeze(self) -> anyhow::Result { + pub fn freeze(self) -> FreezeResult { let Module { names, slots, diff --git a/starlark/src/environment/slots.rs b/starlark/src/environment/slots.rs index 25151cb88..15be74dfc 100644 --- a/starlark/src/environment/slots.rs +++ b/starlark/src/environment/slots.rs @@ -22,6 +22,7 @@ use allocative::Allocative; use dupe::Dupe; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::Value; @@ -86,7 +87,7 @@ impl<'v> MutableSlots<'v> { .collect() } - pub(crate) fn freeze(self, freezer: &Freezer) -> anyhow::Result { + pub(crate) fn freeze(self, freezer: &Freezer) -> FreezeResult { let slots = self.0.into_inner().freeze(freezer)?; Ok(FrozenSlots(slots)) } diff --git a/starlark/src/eval/compiler/def.rs b/starlark/src/eval/compiler/def.rs index 051e774ea..1a0483cfc 100644 --- a/starlark/src/eval/compiler/def.rs +++ b/starlark/src/eval/compiler/def.rs @@ -90,6 +90,7 @@ use crate::values::frozen_ref::AtomicFrozenRefOption; use crate::values::function::FUNCTION_TYPE; use crate::values::typing::type_compiled::compiled::TypeCompiled; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenRef; @@ -600,7 +601,7 @@ impl<'v> Def<'v> { impl<'v> Freeze for Def<'v> { type Frozen = FrozenDef; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let parameters = self.parameters.freeze(freezer)?; let parameter_types = self.parameter_types.freeze(freezer)?; let return_type = self.return_type.freeze(freezer)?; diff --git a/starlark/src/eval/runtime/params/spec.rs b/starlark/src/eval/runtime/params/spec.rs index 5263ed614..4f06ca1a7 100644 --- a/starlark/src/eval/runtime/params/spec.rs +++ b/starlark/src/eval/runtime/params/spec.rs @@ -52,6 +52,7 @@ use crate::typing::ParamIsRequired; use crate::typing::Ty; use crate::values::dict::Dict; use crate::values::dict::DictRef; +use crate::values::FreezeResult; use crate::values::Heap; use crate::values::StringValue; use crate::values::Value; diff --git a/starlark/src/eval/runtime/slots.rs b/starlark/src/eval/runtime/slots.rs index e521ace86..d24f5a8d3 100644 --- a/starlark/src/eval/runtime/slots.rs +++ b/starlark/src/eval/runtime/slots.rs @@ -23,6 +23,7 @@ use starlark_derive::VisitSpanMut; use crate as starlark; use crate::eval::bc::stack_ptr::BcSlot; use crate::values::Freeze; +use crate::values::FreezeResult; /// Not captured. #[derive( diff --git a/starlark/src/stdlib/partial.rs b/starlark/src/stdlib/partial.rs index e0b6fbe62..f34e689c7 100644 --- a/starlark/src/stdlib/partial.rs +++ b/starlark/src/stdlib/partial.rs @@ -44,6 +44,7 @@ use crate::values::function::FUNCTION_TYPE; use crate::values::layout::typed::string::StringValueLike; use crate::values::types::tuple::value::Tuple; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenStringValue; use crate::values::FrozenValue; @@ -132,14 +133,14 @@ starlark_complex_values!(Partial); impl<'v> Freeze for Partial<'v> { type Frozen = FrozenPartial; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(FrozenPartial { func: self.func.freeze(freezer)?, pos: freezer.freeze(self.pos)?, named: self.named.try_map(|x| x.freeze(freezer))?, names: self .names - .into_try_map(|(s, x)| anyhow::Ok((s, x.freeze(freezer)?)))?, + .into_try_map(|(s, x)| Ok((s, x.freeze(freezer)?)))?, names_index: self.names_index, }) } diff --git a/starlark/src/tests/derive/docs.rs b/starlark/src/tests/derive/docs.rs index 3842a355a..f50b4dfdd 100644 --- a/starlark/src/tests/derive/docs.rs +++ b/starlark/src/tests/derive/docs.rs @@ -37,6 +37,7 @@ use crate::environment::MethodsBuilder; use crate::environment::MethodsStatic; use crate::starlark_complex_value; use crate::starlark_simple_value; +use crate::values::FreezeResult; use crate::values::StarlarkValue; use crate::values::ValueLike; diff --git a/starlark/src/tests/derive/freeze/basic.rs b/starlark/src/tests/derive/freeze/basic.rs index b2b9a908a..2b9de21ba 100644 --- a/starlark/src/tests/derive/freeze/basic.rs +++ b/starlark/src/tests/derive/freeze/basic.rs @@ -17,6 +17,7 @@ use crate as starlark; use crate::values::Freeze; +use crate::values::FreezeResult; #[derive(Freeze)] #[allow(dead_code)] diff --git a/starlark/src/tests/derive/freeze/bounds.rs b/starlark/src/tests/derive/freeze/bounds.rs index f7c8b8e7b..854716352 100644 --- a/starlark/src/tests/derive/freeze/bounds.rs +++ b/starlark/src/tests/derive/freeze/bounds.rs @@ -17,6 +17,8 @@ use crate as starlark; use crate::values::Freeze; +use crate::values::FreezeError; +use crate::values::FreezeResult; trait Bound<'x> {} diff --git a/starlark/src/tests/derive/freeze/enums.rs b/starlark/src/tests/derive/freeze/enums.rs index 5f3b11f26..3434d1701 100644 --- a/starlark/src/tests/derive/freeze/enums.rs +++ b/starlark/src/tests/derive/freeze/enums.rs @@ -18,6 +18,7 @@ use starlark_derive::Freeze; use crate as starlark; +use crate::values::FreezeResult; #[allow(dead_code)] // If it compiles, it works. #[derive(Freeze)] diff --git a/starlark/src/tests/derive/freeze/identity.rs b/starlark/src/tests/derive/freeze/identity.rs index 5f0e09ab2..26834f972 100644 --- a/starlark/src/tests/derive/freeze/identity.rs +++ b/starlark/src/tests/derive/freeze/identity.rs @@ -20,6 +20,7 @@ use starlark::values::Freeze; use crate as starlark; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; diff --git a/starlark/src/tests/derive/freeze/validator.rs b/starlark/src/tests/derive/freeze/validator.rs index c528bb4f5..05c291e28 100644 --- a/starlark/src/tests/derive/freeze/validator.rs +++ b/starlark/src/tests/derive/freeze/validator.rs @@ -17,6 +17,8 @@ use crate as starlark; use crate::values::Freeze; +use crate::values::FreezeError; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; diff --git a/starlark/src/tests/derive/freeze/validator_order.rs b/starlark/src/tests/derive/freeze/validator_order.rs index 4f1d0cc32..bf07f3651 100644 --- a/starlark/src/tests/derive/freeze/validator_order.rs +++ b/starlark/src/tests/derive/freeze/validator_order.rs @@ -17,6 +17,8 @@ use crate as starlark; use crate::values::Freeze; +use crate::values::FreezeError; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; @@ -27,7 +29,7 @@ struct FreezeSentinel { impl Freeze for FreezeSentinel { type Frozen = Self; - fn freeze(self, _: &Freezer) -> anyhow::Result { + fn freeze(self, _: &Freezer) -> FreezeResult { assert!(!self.frozen); Ok(Self { frozen: true }) } diff --git a/starlark/src/tests/freeze_access_value.rs b/starlark/src/tests/freeze_access_value.rs index 465845ea9..d805b72e0 100644 --- a/starlark/src/tests/freeze_access_value.rs +++ b/starlark/src/tests/freeze_access_value.rs @@ -17,6 +17,7 @@ use crate::values::list::ListRef; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenValue; @@ -30,7 +31,7 @@ struct Test { impl<'v> Freeze for Test> { type Frozen = Test; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let test = Test { field: self.field.freeze(freezer)?, }; diff --git a/starlark/src/tests/interop.rs b/starlark/src/tests/interop.rs index 54048fc3e..75d308d9d 100644 --- a/starlark/src/tests/interop.rs +++ b/starlark/src/tests/interop.rs @@ -42,6 +42,7 @@ use crate::values::none::NoneType; use crate::values::types::exported_name::ExportedName; use crate::values::types::exported_name::MutableExportedName; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::NoSerialize; use crate::values::StarlarkValue; use crate::values::Value; @@ -149,7 +150,7 @@ fn test_load_symbols() { } #[test] -fn test_load_public_symbols_does_not_reexport() -> anyhow::Result<()> { +fn test_load_public_symbols_does_not_reexport() -> starlark::Result<()> { let mut a = Assert::new(); let module_b = a.module("b", "x = 5"); diff --git a/starlark/src/tests/uncategorized.rs b/starlark/src/tests/uncategorized.rs index 83336029d..7e467214d 100644 --- a/starlark/src/tests/uncategorized.rs +++ b/starlark/src/tests/uncategorized.rs @@ -41,6 +41,7 @@ use crate::tests::util::trim_rust_backtrace; use crate::values::list_or_tuple::UnpackListOrTuple; use crate::values::none::NoneType; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::Heap; use crate::values::NoSerialize; @@ -736,7 +737,7 @@ fn test_label_assign() { impl<'v> Freeze for Wrapper<'v> { type Frozen = FrozenWrapper; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(FrozenWrapper) } } diff --git a/starlark/src/tests/util.rs b/starlark/src/tests/util.rs index 57133b357..127c6e03a 100644 --- a/starlark/src/tests/util.rs +++ b/starlark/src/tests/util.rs @@ -27,6 +27,7 @@ use crate as starlark; use crate::any::ProvidesStaticType; use crate::values::AllocFrozenValue; use crate::values::AllocValue; +use crate::values::FreezeResult; use crate::values::FrozenHeap; use crate::values::FrozenValue; use crate::values::Heap; diff --git a/starlark/src/values/freeze.rs b/starlark/src/values/freeze.rs index d6b04849a..6c42a7de9 100644 --- a/starlark/src/values/freeze.rs +++ b/starlark/src/values/freeze.rs @@ -26,6 +26,7 @@ use starlark_map::small_set::SmallSet; use starlark_map::Hashed; use starlark_syntax::slice_vec_ext::VecExt; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenStringValue; use crate::values::FrozenValue; @@ -43,6 +44,7 @@ use crate::values::Value; /// # struct AdditionalData; /// /// use starlark::values::Freeze; +/// use starlark::values::FreezeResult; /// /// #[derive(Freeze)] /// struct MyType { @@ -62,13 +64,13 @@ pub trait Freeze { /// Note during freeze, `Value` objects in `Self` might be already special forward-objects, /// trying to unpack these objects will crash the process. /// So the function is only allowed to access `Value` objects after it froze them. - fn freeze(self, freezer: &Freezer) -> anyhow::Result; + fn freeze(self, freezer: &Freezer) -> FreezeResult; } impl Freeze for String { type Frozen = String; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -76,7 +78,7 @@ impl Freeze for String { impl Freeze for i32 { type Frozen = i32; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -84,7 +86,7 @@ impl Freeze for i32 { impl Freeze for u32 { type Frozen = u32; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -92,7 +94,7 @@ impl Freeze for u32 { impl Freeze for i64 { type Frozen = i64; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -100,7 +102,7 @@ impl Freeze for i64 { impl Freeze for u64 { type Frozen = u64; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -108,7 +110,7 @@ impl Freeze for u64 { impl Freeze for usize { type Frozen = usize; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -116,7 +118,7 @@ impl Freeze for usize { impl Freeze for bool { type Frozen = bool; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -124,7 +126,7 @@ impl Freeze for bool { impl<'v, T: 'static> Freeze for marker::PhantomData<&'v T> { type Frozen = PhantomData<&'static T>; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result> { + fn freeze(self, _freezer: &Freezer) -> FreezeResult> { Ok(marker::PhantomData) } } @@ -135,7 +137,7 @@ where { type Frozen = Vec; - fn freeze(self, freezer: &Freezer) -> anyhow::Result> { + fn freeze(self, freezer: &Freezer) -> FreezeResult> { self.into_try_map(|v| v.freeze(freezer)) } } @@ -146,7 +148,7 @@ where { type Frozen = T::Frozen; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { self.into_inner().freeze(freezer) } } @@ -157,7 +159,7 @@ where { type Frozen = UnsafeCell; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(UnsafeCell::new(self.into_inner().freeze(freezer)?)) } } @@ -168,7 +170,7 @@ where { type Frozen = Option; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { self.into_inner().freeze(freezer) } } @@ -179,7 +181,7 @@ where { type Frozen = Box; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(Box::new((*self).freeze(freezer)?)) } } @@ -190,7 +192,7 @@ where { type Frozen = Box<[T::Frozen]>; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { self.into_vec() .into_try_map(|v| v.freeze(freezer)) .map(|v| v.into_boxed_slice()) @@ -203,7 +205,7 @@ where { type Frozen = Option; - fn freeze(self, freezer: &Freezer) -> anyhow::Result> { + fn freeze(self, freezer: &Freezer) -> FreezeResult> { self.map(|v| v.freeze(freezer)).transpose() } } @@ -211,7 +213,7 @@ where impl Freeze for Hashed { type Frozen = Hashed; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { // `freeze` must not change hash. Ok(Hashed::new_unchecked( self.hash(), @@ -227,7 +229,7 @@ where { type Frozen = SmallMap; - fn freeze(self, freezer: &Freezer) -> anyhow::Result> { + fn freeze(self, freezer: &Freezer) -> FreezeResult> { let mut new = SmallMap::with_capacity(self.len()); for (key, value) in self.into_iter_hashed() { let hash = key.hash(); @@ -247,7 +249,7 @@ where { type Frozen = SmallSet; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let mut new = SmallSet::with_capacity(self.len()); for value in self.into_iter_hashed() { let value = value.freeze(freezer)?; @@ -261,7 +263,7 @@ where impl<'v> Freeze for Value<'v> { type Frozen = FrozenValue; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { freezer.freeze(self) } } @@ -269,7 +271,7 @@ impl<'v> Freeze for Value<'v> { impl Freeze for FrozenValue { type Frozen = FrozenValue; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } @@ -277,7 +279,7 @@ impl Freeze for FrozenValue { impl<'v> Freeze for StringValue<'v> { type Frozen = FrozenStringValue; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { self.freeze(freezer) } } @@ -285,7 +287,7 @@ impl<'v> Freeze for StringValue<'v> { impl Freeze for () { type Frozen = (); - fn freeze(self, _freezer: &Freezer) -> anyhow::Result<()> { + fn freeze(self, _freezer: &Freezer) -> FreezeResult<()> { Ok(()) } } @@ -293,7 +295,7 @@ impl Freeze for () { impl Freeze for (A,) { type Frozen = (A::Frozen,); - fn freeze(self, freezer: &Freezer) -> anyhow::Result<(A::Frozen,)> { + fn freeze(self, freezer: &Freezer) -> FreezeResult<(A::Frozen,)> { Ok((self.0.freeze(freezer)?,)) } } @@ -301,7 +303,7 @@ impl Freeze for (A,) { impl Freeze for (A, B) { type Frozen = (A::Frozen, B::Frozen); - fn freeze(self, freezer: &Freezer) -> anyhow::Result<(A::Frozen, B::Frozen)> { + fn freeze(self, freezer: &Freezer) -> FreezeResult<(A::Frozen, B::Frozen)> { Ok((self.0.freeze(freezer)?, self.1.freeze(freezer)?)) } } @@ -309,7 +311,7 @@ impl Freeze for (A, B) { impl Freeze for (A, B, C) { type Frozen = (A::Frozen, B::Frozen, C::Frozen); - fn freeze(self, freezer: &Freezer) -> anyhow::Result<(A::Frozen, B::Frozen, C::Frozen)> { + fn freeze(self, freezer: &Freezer) -> FreezeResult<(A::Frozen, B::Frozen, C::Frozen)> { Ok(( self.0.freeze(freezer)?, self.1.freeze(freezer)?, @@ -324,7 +326,7 @@ impl Freeze for (A, B, C, D) { fn freeze( self, freezer: &Freezer, - ) -> anyhow::Result<(A::Frozen, B::Frozen, C::Frozen, D::Frozen)> { + ) -> FreezeResult<(A::Frozen, B::Frozen, C::Frozen, D::Frozen)> { Ok(( self.0.freeze(freezer)?, self.1.freeze(freezer)?, diff --git a/starlark/src/values/frozen_ref.rs b/starlark/src/values/frozen_ref.rs index c1628373d..6a0c26098 100644 --- a/starlark/src/values/frozen_ref.rs +++ b/starlark/src/values/frozen_ref.rs @@ -32,6 +32,7 @@ use dupe::Copy_; use dupe::Dupe_; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::Trace; use crate::values::Tracer; @@ -167,7 +168,7 @@ where impl<'f, T: 'f + ?Sized> Freeze for FrozenRef<'f, T> { type Frozen = Self; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } diff --git a/starlark/src/values/layout/avalue.rs b/starlark/src/values/layout/avalue.rs index 331faa4db..c491d357e 100644 --- a/starlark/src/values/layout/avalue.rs +++ b/starlark/src/values/layout/avalue.rs @@ -50,6 +50,8 @@ use crate::values::types::list::value::ListData; use crate::values::types::tuple::value::FrozenTuple; use crate::values::types::tuple::value::Tuple; use crate::values::ComplexValue; +use crate::values::FreezeError; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::StarlarkValue; @@ -117,7 +119,7 @@ pub(crate) trait AValue<'v>: Sized + 'v { unsafe fn heap_freeze( me: *mut AValueRepr, freezer: &Freezer, - ) -> anyhow::Result; + ) -> FreezeResult; unsafe fn heap_copy(me: *mut AValueRepr, tracer: &Tracer<'v>) -> Value<'v>; @@ -221,7 +223,7 @@ impl<'v, T: StarlarkValue<'v>> AValue<'v> for AValueBasic { unsafe fn heap_freeze( _me: *mut AValueRepr, _freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { unreachable!("Basic types don't appear in the heap") } unsafe fn heap_copy( @@ -252,7 +254,7 @@ impl<'v> AValue<'v> for StarlarkStrAValue { unsafe fn heap_freeze( me: *mut AValueRepr, freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { debug_assert!( (*me).payload.len() > 1, "short strings are allocated statically" @@ -303,7 +305,7 @@ impl<'v> AValue<'v> for AValueTuple { unsafe fn heap_freeze( me: *mut AValueRepr, freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { debug_assert!( (*me).payload.len() != 0, "empty tuple is allocated statically" @@ -373,7 +375,7 @@ impl<'v> AValue<'v> for AValueFrozenTuple { unsafe fn heap_freeze( _me: *mut AValueRepr, _freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { panic!("already frozen"); } @@ -403,7 +405,7 @@ impl<'v> AValue<'v> for AValueList { unsafe fn heap_freeze( me: *mut AValueRepr, freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { let content = (*me).payload.0.content(); if content.is_empty() { @@ -452,7 +454,7 @@ impl<'v> AValue<'v> for AValueFrozenList { unsafe fn heap_freeze( _me: *mut AValueRepr, _freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { panic!("already frozen"); } @@ -483,7 +485,7 @@ impl<'v> AValue<'v> for AValueArray { unsafe fn heap_freeze( _me: *mut AValueRepr, _freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { panic!("arrays should not be frozen") } @@ -538,7 +540,7 @@ impl<'v, T: Debug + 'static> AValue<'v> for AValueAnyArray { unsafe fn heap_freeze( _me: *mut AValueRepr, _freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { panic!("AnyArray for now can only be allocated in FrozenHeap"); } @@ -570,7 +572,7 @@ where unsafe fn heap_freeze_simple_impl<'v, A>( me: *mut AValueRepr, freezer: &Freezer, -) -> anyhow::Result +) -> FreezeResult where A: AValue<'v, ExtraElem = ()>, { @@ -599,7 +601,7 @@ impl> AValue<'static> for AValueSimple { unsafe fn heap_freeze( me: *mut AValueRepr, freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { if let Some(f) = try_freeze_static::(me) { return Ok(f); } @@ -655,7 +657,7 @@ where unsafe fn heap_freeze( me: *mut AValueRepr, freezer: &Freezer, - ) -> anyhow::Result { + ) -> FreezeResult { if let Some(f) = try_freeze_static::(me) { return Ok(f); } @@ -703,8 +705,10 @@ where unsafe fn heap_freeze( _me: *mut AValueRepr, _freezer: &Freezer, - ) -> anyhow::Result { - Err(AValueError::CannotBeFrozen(type_name::()).into()) + ) -> FreezeResult { + Err(FreezeError::new( + AValueError::CannotBeFrozen(type_name::()).to_string(), + )) } unsafe fn heap_copy( diff --git a/starlark/src/values/layout/complex.rs b/starlark/src/values/layout/complex.rs index 2ef54ced2..252f83276 100644 --- a/starlark/src/values/layout/complex.rs +++ b/starlark/src/values/layout/complex.rs @@ -31,6 +31,8 @@ use crate::values::type_repr::StarlarkTypeRepr; use crate::values::AllocValue; use crate::values::ComplexValue; use crate::values::Freeze; +use crate::values::FreezeError; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValueTyped; use crate::values::StarlarkValue; @@ -175,8 +177,9 @@ where { type Frozen = FrozenValueTyped<'static, T::Frozen>; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { FrozenValueTyped::new_err(self.0.freeze(freezer)?) + .map_err(|e| FreezeError::new(format!("{e}"))) } } diff --git a/starlark/src/values/layout/heap/heap_type.rs b/starlark/src/values/layout/heap/heap_type.rs index 1595bc191..384db78e4 100644 --- a/starlark/src/values/layout/heap/heap_type.rs +++ b/starlark/src/values/layout/heap/heap_type.rs @@ -86,6 +86,7 @@ use crate::values::string::str_type::StarlarkStr; use crate::values::AllocFrozenValue; use crate::values::AllocValue; use crate::values::ComplexValue; +use crate::values::FreezeResult; use crate::values::FrozenRef; use crate::values::FrozenStringValue; use crate::values::FrozenValueOfUnchecked; @@ -562,7 +563,7 @@ impl Freezer { } /// Freeze a nested value while freezing yourself. - pub fn freeze(&self, value: Value) -> anyhow::Result { + pub fn freeze(&self, value: Value) -> FreezeResult { // Case 1: We have our value encoded in our pointer if let Some(x) = value.unpack_frozen() { return Ok(x); diff --git a/starlark/src/values/layout/typed.rs b/starlark/src/values/layout/typed.rs index 0386a688b..e8009e745 100644 --- a/starlark/src/values/layout/typed.rs +++ b/starlark/src/values/layout/typed.rs @@ -52,6 +52,7 @@ use crate::values::type_repr::StarlarkTypeRepr; use crate::values::AllocFrozenValue; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenRef; @@ -97,7 +98,7 @@ unsafe impl<'v, 'f, T: StarlarkValue<'f>> Trace<'v> for FrozenValueTyped<'f, T> impl> Freeze for FrozenValueTyped<'static, T> { type Frozen = Self; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(self) } } diff --git a/starlark/src/values/layout/typed/string.rs b/starlark/src/values/layout/typed/string.rs index 474452c17..a2734ba5f 100644 --- a/starlark/src/values/layout/typed/string.rs +++ b/starlark/src/values/layout/typed/string.rs @@ -33,6 +33,7 @@ use crate::sealed::Sealed; use crate::values::layout::static_string::VALUE_EMPTY_STRING; use crate::values::string::str_type::StarlarkStr; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::FrozenValueTyped; @@ -122,7 +123,7 @@ impl FrozenStringValue { impl<'v> StringValue<'v> { /// Convert a value to a [`FrozenStringValue`] using a supplied [`Freezer`]. - pub fn freeze(self, freezer: &Freezer) -> anyhow::Result { + pub fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(unsafe { FrozenStringValue::new_unchecked(freezer.freeze(self.to_value())?) }) } diff --git a/starlark/src/values/layout/value.rs b/starlark/src/values/layout/value.rs index 03e6e2276..6b21068a3 100644 --- a/starlark/src/values/layout/value.rs +++ b/starlark/src/values/layout/value.rs @@ -116,6 +116,7 @@ use crate::values::types::list::value::FrozenListData; use crate::values::types::num::value::NumRef; use crate::values::types::tuple::value::FrozenTuple; use crate::values::types::tuple::value::Tuple; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenRef; use crate::values::FrozenStringValue; @@ -827,7 +828,7 @@ impl<'v> Value<'v> { } /// Convert a value to a [`FrozenValue`] using a supplied [`Freezer`]. - pub fn freeze(self, freezer: &Freezer) -> anyhow::Result { + pub fn freeze(self, freezer: &Freezer) -> FreezeResult { freezer.freeze(self) } diff --git a/starlark/src/values/layout/value_captured.rs b/starlark/src/values/layout/value_captured.rs index d58869a27..eeb4cd9b6 100644 --- a/starlark/src/values/layout/value_captured.rs +++ b/starlark/src/values/layout/value_captured.rs @@ -31,6 +31,7 @@ use starlark_derive::Trace; use crate as starlark; use crate::any::ProvidesStaticType; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::StarlarkValue; @@ -75,7 +76,7 @@ impl<'v> ValueCaptured<'v> { impl<'v> Freeze for ValueCaptured<'v> { type Frozen = FrozenValueCaptured; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(FrozenValueCaptured(self.0.get().freeze(freezer)?)) } } diff --git a/starlark/src/values/layout/vtable.rs b/starlark/src/values/layout/vtable.rs index fc2506cc6..2a55776fd 100644 --- a/starlark/src/values/layout/vtable.rs +++ b/starlark/src/values/layout/vtable.rs @@ -50,6 +50,7 @@ use crate::values::layout::value_alloc_size::ValueAllocSize; use crate::values::starlark_type_id::StarlarkTypeId; use crate::values::traits::StarlarkValueVTable; use crate::values::traits::StarlarkValueVTableGet; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenStringValue; use crate::values::FrozenValue; @@ -124,7 +125,7 @@ pub(crate) struct AValueVTable { // `AValue` pub(crate) is_str: bool, memory_size: fn(StarlarkValueRawPtr) -> ValueAllocSize, - heap_freeze: fn(StarlarkValueRawPtr, &Freezer) -> anyhow::Result, + heap_freeze: fn(StarlarkValueRawPtr, &Freezer) -> FreezeResult, heap_copy: for<'v> fn(StarlarkValueRawPtr, &Tracer<'v>) -> Value<'v>, // `StarlarkValue` supertraits. @@ -300,7 +301,7 @@ impl<'v> AValueDyn<'v> { } #[inline] - pub(crate) unsafe fn heap_freeze(self, freezer: &Freezer) -> anyhow::Result { + pub(crate) unsafe fn heap_freeze(self, freezer: &Freezer) -> FreezeResult { (self.vtable.heap_freeze)(self.value, freezer) } diff --git a/starlark/src/values/traits.rs b/starlark/src/values/traits.rs index 253e1919b..03beb61cd 100644 --- a/starlark/src/values/traits.rs +++ b/starlark/src/values/traits.rs @@ -85,6 +85,7 @@ use crate::values::ValueError; /// use starlark::values::Coerce; /// use starlark::values::ComplexValue; /// use starlark::values::Freeze; +/// use starlark::values::FreezeResult; /// use starlark::values::Freezer; /// use starlark::values::FrozenValue; /// use starlark::values::NoSerialize; @@ -120,7 +121,7 @@ use crate::values::ValueError; /// /// impl<'v> Freeze for One<'v> { /// type Frozen = FrozenOne; -/// fn freeze(self, freezer: &Freezer) -> anyhow::Result { +/// fn freeze(self, freezer: &Freezer) -> FreezeResult { /// Ok(OneGen(self.0.freeze(freezer)?)) /// } /// } @@ -128,7 +129,6 @@ use crate::values::ValueError; /// /// The [`starlark_complex_value!`](crate::starlark_complex_value!) requires that /// the type have an instance for `Coerce`, then the macro defines two type aliases. -/// /// ``` /// # use crate::starlark::values::*; /// # #[derive(Debug, Trace)] @@ -145,7 +145,6 @@ use crate::values::ValueError; /// [`AllocFrozenValue`](crate::values::AllocFrozenValue) for the frozen one, and /// [`UnpackValue`](crate::values::UnpackValue) for the non-frozen one. /// It also defines the methods: -/// /// ``` /// # use crate::starlark::values::*; /// # use std::cell::RefMut; diff --git a/starlark/src/values/types/any_complex.rs b/starlark/src/values/types/any_complex.rs index cd6a6ff8a..fb7d19162 100644 --- a/starlark/src/values/types/any_complex.rs +++ b/starlark/src/values/types/any_complex.rs @@ -30,6 +30,7 @@ use crate as starlark; use crate::any::ProvidesStaticType; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Heap; use crate::values::StarlarkValue; use crate::values::Trace; @@ -114,6 +115,7 @@ mod tests { use crate::values::list::AllocList; use crate::values::types::any_complex::StarlarkAnyComplex; use crate::values::Freeze; + use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenStringValue; use crate::values::FrozenValue; @@ -131,7 +133,7 @@ mod tests { impl<'v> Freeze for UnfrozenData<'v> { type Frozen = FrozenData; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(FrozenData { string: self.string.freeze(freezer)?, other: freezer.freeze(self.other)?, diff --git a/starlark/src/values/types/dict/value.rs b/starlark/src/values/types/dict/value.rs index d7874ae86..f3306784d 100644 --- a/starlark/src/values/types/dict/value.rs +++ b/starlark/src/values/types/dict/value.rs @@ -58,6 +58,7 @@ use crate::values::types::dict::dict_type::DictType; use crate::values::AllocFrozenValue; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenStringValue; @@ -309,7 +310,7 @@ impl FrozenDictData { impl<'v> Freeze for DictGen>> { type Frozen = DictGen; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let content = self.0.into_inner().content.freeze(freezer)?; Ok(DictGen(FrozenDictData { content })) } diff --git a/starlark/src/values/types/enumeration/enum_type.rs b/starlark/src/values/types/enumeration/enum_type.rs index 168f1ebac..f8771b10c 100644 --- a/starlark/src/values/types/enumeration/enum_type.rs +++ b/starlark/src/values/types/enumeration/enum_type.rs @@ -58,6 +58,7 @@ use crate::values::list::AllocList; use crate::values::types::type_instance_id::TypeInstanceId; use crate::values::typing::type_compiled::type_matcher_factory::TypeMatcherFactory; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::Heap; @@ -137,7 +138,7 @@ pub struct EnumTypeGen { impl<'v> Freeze for EnumTypeGen> { type Frozen = EnumTypeGen; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let EnumTypeGen { id, ty_enum_data: ty_enum_type, diff --git a/starlark/src/values/types/enumeration/value.rs b/starlark/src/values/types/enumeration/value.rs index 1310b1b99..a68ff9db2 100644 --- a/starlark/src/values/types/enumeration/value.rs +++ b/starlark/src/values/types/enumeration/value.rs @@ -41,6 +41,7 @@ use crate::typing::Ty; use crate::values::enumeration::enum_type::EnumType; use crate::values::enumeration::enum_type::FrozenEnumType; use crate::values::types::type_instance_id::TypeInstanceId; +use crate::values::FreezeResult; use crate::values::StarlarkValue; use crate::values::Value; use crate::values::ValueLifetimeless; diff --git a/starlark/src/values/types/exported_name.rs b/starlark/src/values/types/exported_name.rs index 5677ae0c8..d0d8a8ab2 100644 --- a/starlark/src/values/types/exported_name.rs +++ b/starlark/src/values/types/exported_name.rs @@ -30,6 +30,7 @@ use either::Either; use crate as starlark; use crate::any::ProvidesStaticType; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::Trace; @@ -132,7 +133,7 @@ pub struct FrozenExportedName { impl Freeze for MutableExportedName { type Frozen = FrozenExportedName; - fn freeze(self, _freezer: &Freezer) -> anyhow::Result { + fn freeze(self, _freezer: &Freezer) -> FreezeResult { Ok(FrozenExportedName { name: self.name.into_inner(), }) diff --git a/starlark/src/values/types/function.rs b/starlark/src/values/types/function.rs index 01062417e..948da84a0 100644 --- a/starlark/src/values/types/function.rs +++ b/starlark/src/values/types/function.rs @@ -47,6 +47,7 @@ use crate::values::typing::type_compiled::compiled::TypeCompiled; use crate::values::AllocFrozenValue; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::FrozenHeap; use crate::values::FrozenRef; use crate::values::FrozenValue; diff --git a/starlark/src/values/types/namespace/value.rs b/starlark/src/values/types/namespace/value.rs index f1cd866c9..c16bd3a2c 100644 --- a/starlark/src/values/types/namespace/value.rs +++ b/starlark/src/values/types/namespace/value.rs @@ -37,6 +37,7 @@ use crate::starlark_complex_value; use crate::typing::Ty; use crate::util::arc_str::ArcStr; use crate::values::types::namespace::typing::TyNamespace; +use crate::values::FreezeResult; use crate::values::FrozenValue; use crate::values::Heap; use crate::values::StarlarkValue; diff --git a/starlark/src/values/types/record/field.rs b/starlark/src/values/types/record/field.rs index 7bd467039..2ae581aca 100644 --- a/starlark/src/values/types/record/field.rs +++ b/starlark/src/values/types/record/field.rs @@ -33,6 +33,7 @@ use crate::coerce::Coerce; use crate::starlark_complex_value; use crate::typing::Ty; use crate::values::typing::type_compiled::compiled::TypeCompiled; +use crate::values::FreezeResult; use crate::values::StarlarkValue; use crate::values::ValueLifetimeless; use crate::values::ValueLike; diff --git a/starlark/src/values/types/record/instance.rs b/starlark/src/values/types/record/instance.rs index b67d11108..40b9e8b48 100644 --- a/starlark/src/values/types/record/instance.rs +++ b/starlark/src/values/types/record/instance.rs @@ -40,6 +40,7 @@ use crate::values::record::record_type::FrozenRecordType; use crate::values::record::record_type::RecordType; use crate::values::types::type_instance_id::TypeInstanceId; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Heap; use crate::values::StarlarkValue; use crate::values::Trace; diff --git a/starlark/src/values/types/record/record_type.rs b/starlark/src/values/types/record/record_type.rs index 771462d6a..8a02590eb 100644 --- a/starlark/src/values/types/record/record_type.rs +++ b/starlark/src/values/types/record/record_type.rs @@ -61,6 +61,7 @@ use crate::values::record::Record; use crate::values::types::type_instance_id::TypeInstanceId; use crate::values::typing::type_compiled::type_matcher_factory::TypeMatcherFactory; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::StarlarkValue; @@ -185,7 +186,7 @@ impl<'v> RecordType<'v> { impl<'v> Freeze for RecordType<'v> { type Frozen = FrozenRecordType; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(FrozenRecordType { id: self.id, fields: self.fields.freeze(freezer)?, diff --git a/starlark/src/values/types/set/value.rs b/starlark/src/values/types/set/value.rs index f8d6e296d..6170e5f2f 100644 --- a/starlark/src/values/types/set/value.rs +++ b/starlark/src/values/types/set/value.rs @@ -44,6 +44,7 @@ use crate::values::type_repr::SetType; use crate::values::type_repr::StarlarkTypeRepr; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenValue; use crate::values::Heap; @@ -131,7 +132,7 @@ unsafe impl<'v> Coerce> for FrozenSetData {} // TODO Add optimizations not to allocate empty set. impl<'v> Freeze for MutableSet<'v> { type Frozen = SetGen; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let content = self.0.into_inner().content.freeze(freezer)?; Ok(SetGen(FrozenSetData { content })) } diff --git a/starlark/src/values/types/string/iter.rs b/starlark/src/values/types/string/iter.rs index a953d45e5..ba8159110 100644 --- a/starlark/src/values/types/string/iter.rs +++ b/starlark/src/values/types/string/iter.rs @@ -28,6 +28,7 @@ use crate as starlark; use crate::any::ProvidesStaticType; use crate::coerce::Coerce; use crate::values::typing::iter::StarlarkIter; +use crate::values::FreezeResult; use crate::values::Heap; use crate::values::StarlarkValue; use crate::values::StringValue; diff --git a/starlark/src/values/types/structs/value.rs b/starlark/src/values/types/structs/value.rs index f0169e323..1863b2820 100644 --- a/starlark/src/values/types/structs/value.rs +++ b/starlark/src/values/types/structs/value.rs @@ -45,6 +45,7 @@ use crate::util::arc_str::ArcStr; use crate::values::comparison::compare_small_map; use crate::values::comparison::equals_small_map; use crate::values::structs::unordered_hasher::UnorderedHasher; +use crate::values::FreezeResult; use crate::values::FrozenStringValue; use crate::values::FrozenValue; use crate::values::Heap; diff --git a/starlark/src/values/types/type_instance_id.rs b/starlark/src/values/types/type_instance_id.rs index a06c8e143..b5e9583a0 100644 --- a/starlark/src/values/types/type_instance_id.rs +++ b/starlark/src/values/types/type_instance_id.rs @@ -23,6 +23,7 @@ use dupe::Dupe; use starlark_derive::Freeze; use crate as starlark; +use crate::values::FreezeResult; /// Globally unique identifier for a type, like record type or enum type. #[derive( diff --git a/starlark/src/values/typing/callable.rs b/starlark/src/values/typing/callable.rs index 4ba65f4a6..c11774b78 100644 --- a/starlark/src/values/typing/callable.rs +++ b/starlark/src/values/typing/callable.rs @@ -48,6 +48,7 @@ use crate::values::typing::TypeCompiled; use crate::values::AllocFrozenValue; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenValue; @@ -284,7 +285,7 @@ impl AllocFrozenValue impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> Freeze for StarlarkCallable<'v, P, R> { type Frozen = FrozenStarlarkCallable; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { Ok(FrozenStarlarkCallable::unchecked_new( self.0.freeze(freezer)?, )) diff --git a/starlark/src/values/typing/type_compiled/compiled.rs b/starlark/src/values/typing/type_compiled/compiled.rs index f6cb1b55a..69bb3db8e 100644 --- a/starlark/src/values/typing/type_compiled/compiled.rs +++ b/starlark/src/values/typing/type_compiled/compiled.rs @@ -54,6 +54,7 @@ use crate::values::typing::type_compiled::matchers::IsAny; use crate::values::AllocValue; use crate::values::Demand; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::FrozenHeap; use crate::values::FrozenValue; use crate::values::Heap; diff --git a/starlark/src/values/typing/type_compiled/matchers.rs b/starlark/src/values/typing/type_compiled/matchers.rs index 606f27424..ab8aa6250 100644 --- a/starlark/src/values/typing/type_compiled/matchers.rs +++ b/starlark/src/values/typing/type_compiled/matchers.rs @@ -34,6 +34,7 @@ use crate::values::tuple::value::Tuple; use crate::values::types::int::int_or_big::StarlarkIntRef; use crate::values::typing::type_compiled::matcher::TypeMatcher; use crate::values::typing::type_compiled::matcher::TypeMatcherBox; +use crate::values::FreezeResult; use crate::values::UnpackValue; use crate::values::Value; diff --git a/starlark/src/values/value_of_unchecked.rs b/starlark/src/values/value_of_unchecked.rs index ed03db5aa..77787a75b 100644 --- a/starlark/src/values/value_of_unchecked.rs +++ b/starlark/src/values/value_of_unchecked.rs @@ -33,6 +33,7 @@ use crate::values::type_repr::StarlarkTypeRepr; use crate::values::AllocFrozenValue; use crate::values::AllocValue; use crate::values::Freeze; +use crate::values::FreezeResult; use crate::values::Freezer; use crate::values::FrozenHeap; use crate::values::FrozenValue; @@ -141,7 +142,7 @@ where impl Freeze for ValueOfUncheckedGeneric { type Frozen = ValueOfUncheckedGeneric; - fn freeze(self, freezer: &Freezer) -> anyhow::Result { + fn freeze(self, freezer: &Freezer) -> FreezeResult { let frozen = self.0.freeze(freezer)?; Ok(ValueOfUncheckedGeneric::new(frozen)) } diff --git a/starlark_bin/bin/bazel.rs b/starlark_bin/bin/bazel.rs index 2077de69a..000876f97 100644 --- a/starlark_bin/bin/bazel.rs +++ b/starlark_bin/bin/bazel.rs @@ -194,7 +194,7 @@ impl BazelContext { let module = AstModule::parse_file(x, &dialect).into_anyhow_result()?; eval.eval_module(module, &globals).into_anyhow_result()?; } - env.freeze() + Ok(env.freeze()?) }) .collect::>()?; diff --git a/starlark_bin/bin/eval.rs b/starlark_bin/bin/eval.rs index 0595aeb34..d4a2b54bb 100644 --- a/starlark_bin/bin/eval.rs +++ b/starlark_bin/bin/eval.rs @@ -112,7 +112,7 @@ impl Context { let module = AstModule::parse_file(x, &dialect).into_anyhow_result()?; eval.eval_module(module, &globals).into_anyhow_result()?; } - env.freeze() + Ok(env.freeze()?) }) .collect::>()?; diff --git a/starlark_derive/src/freeze.rs b/starlark_derive/src/freeze.rs index 30e548759..5cc546f01 100644 --- a/starlark_derive/src/freeze.rs +++ b/starlark_derive/src/freeze.rs @@ -120,7 +120,10 @@ fn derive_freeze_impl(input: DeriveInput) -> syn::Result { let validate_body = match validator { Some(validator) => quote_spanned! { span=> - #validator(&frozen)?; + match #validator(&frozen) { + Ok(v) => v, + Err(e) => return std::result::Result::Err(FreezeError::new(e.to_string())) + }; }, None => quote_spanned! { span=> }, }; @@ -137,7 +140,7 @@ fn derive_freeze_impl(input: DeriveInput) -> syn::Result { impl #impl_params starlark::values::Freeze for #name #input_params #bounds_body { type Frozen = #name #output_params; #[allow(unused_variables)] - fn freeze(self, freezer: &starlark::values::Freezer) -> anyhow::Result { + fn freeze(self, freezer: &starlark::values::Freezer) -> FreezeResult { let frozen = #body; #validate_body std::result::Result::Ok(frozen)