Skip to content

Commit

Permalink
Use freeze_error over anyhow
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Will-MingLun-Li authored and facebook-github-bot committed Nov 27, 2024
1 parent a87c150 commit 7dd526a
Show file tree
Hide file tree
Showing 49 changed files with 132 additions and 75 deletions.
5 changes: 3 additions & 2 deletions starlark/src/environment/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<FrozenModule> {
pub fn from_globals(globals: &Globals) -> FreezeResult<FrozenModule> {
let module = Module::new();

module.frozen_heap.add_reference(globals.heap());
Expand Down Expand Up @@ -406,7 +407,7 @@ impl Module {
}

/// Freeze the environment, all its value will become immutable afterwards.
pub fn freeze(self) -> anyhow::Result<FrozenModule> {
pub fn freeze(self) -> FreezeResult<FrozenModule> {
let Module {
names,
slots,
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/environment/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,7 +87,7 @@ impl<'v> MutableSlots<'v> {
.collect()
}

pub(crate) fn freeze(self, freezer: &Freezer) -> anyhow::Result<FrozenSlots> {
pub(crate) fn freeze(self, freezer: &Freezer) -> FreezeResult<FrozenSlots> {
let slots = self.0.into_inner().freeze(freezer)?;
Ok(FrozenSlots(slots))
}
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/eval/compiler/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -600,7 +601,7 @@ impl<'v> Def<'v> {
impl<'v> Freeze for Def<'v> {
type Frozen = FrozenDef;

fn freeze(self, freezer: &Freezer) -> anyhow::Result<Self::Frozen> {
fn freeze(self, freezer: &Freezer) -> FreezeResult<Self::Frozen> {
let parameters = self.parameters.freeze(freezer)?;
let parameter_types = self.parameter_types.freeze(freezer)?;
let return_type = self.return_type.freeze(freezer)?;
Expand Down
1 change: 1 addition & 0 deletions starlark/src/eval/runtime/params/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions starlark/src/eval/runtime/slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions starlark/src/stdlib/partial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,14 +133,14 @@ starlark_complex_values!(Partial);

impl<'v> Freeze for Partial<'v> {
type Frozen = FrozenPartial;
fn freeze(self, freezer: &Freezer) -> anyhow::Result<Self::Frozen> {
fn freeze(self, freezer: &Freezer) -> FreezeResult<Self::Frozen> {
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,
})
}
Expand Down
1 change: 1 addition & 0 deletions starlark/src/tests/derive/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions starlark/src/tests/derive/freeze/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use crate as starlark;
use crate::values::Freeze;
use crate::values::FreezeResult;

#[derive(Freeze)]
#[allow(dead_code)]
Expand Down
2 changes: 2 additions & 0 deletions starlark/src/tests/derive/freeze/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

use crate as starlark;
use crate::values::Freeze;
use crate::values::FreezeError;
use crate::values::FreezeResult;

trait Bound<'x> {}

Expand Down
1 change: 1 addition & 0 deletions starlark/src/tests/derive/freeze/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions starlark/src/tests/derive/freeze/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use starlark::values::Freeze;

use crate as starlark;
use crate::values::FreezeResult;
use crate::values::Freezer;
use crate::values::FrozenHeap;

Expand Down
2 changes: 2 additions & 0 deletions starlark/src/tests/derive/freeze/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion starlark/src/tests/derive/freeze/validator_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,7 +29,7 @@ struct FreezeSentinel {
impl Freeze for FreezeSentinel {
type Frozen = Self;

fn freeze(self, _: &Freezer) -> anyhow::Result<Self> {
fn freeze(self, _: &Freezer) -> FreezeResult<Self> {
assert!(!self.frozen);
Ok(Self { frozen: true })
}
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/tests/freeze_access_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +31,7 @@ struct Test<V> {
impl<'v> Freeze for Test<Value<'v>> {
type Frozen = Test<FrozenValue>;

fn freeze(self, freezer: &Freezer) -> anyhow::Result<Self::Frozen> {
fn freeze(self, freezer: &Freezer) -> FreezeResult<Self::Frozen> {
let test = Test {
field: self.field.freeze(freezer)?,
};
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/tests/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion starlark/src/tests/uncategorized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -736,7 +737,7 @@ fn test_label_assign() {

impl<'v> Freeze for Wrapper<'v> {
type Frozen = FrozenWrapper;
fn freeze(self, _freezer: &Freezer) -> anyhow::Result<Self::Frozen> {
fn freeze(self, _freezer: &Freezer) -> FreezeResult<Self::Frozen> {
Ok(FrozenWrapper)
}
}
Expand Down
1 change: 1 addition & 0 deletions starlark/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 7dd526a

Please sign in to comment.