Skip to content

Commit

Permalink
impl common traits for StarlarkCallableChecked
Browse files Browse the repository at this point in the history
Reviewed By: perehonchuk

Differential Revision: D63677028

fbshipit-source-id: 23171d3bbcd17106c68e25f7ea4296c9189cb014
  • Loading branch information
stepancheg authored and facebook-github-bot committed Oct 1, 2024
1 parent 6619188 commit 85fcfab
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions starlark/src/values/typing/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,59 @@ impl<P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> FrozenStarlarkCallable<P
/// Unpacking with this type is expensive:
/// usually it is OK to use it for code executed once at top-level scope (like `rule()`),
/// but not for code executed many times (like `partial()`).
#[derive(Allocative)]
#[allocative(bound = "")]
pub struct StarlarkCallableChecked<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr>(
pub Value<'v>,
PhantomData<AtomicPtr<(P, R)>>,
);

impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> Clone
for StarlarkCallableChecked<'v, P, R>
{
fn clone(&self) -> Self {
*self
}
}

impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> Copy
for StarlarkCallableChecked<'v, P, R>
{
}

impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> Dupe
for StarlarkCallableChecked<'v, P, R>
{
}

impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> Debug
for StarlarkCallableChecked<'v, P, R>
{
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_tuple("StarlarkCallableChecked")
.field(&self.0)
.finish()
}
}

unsafe impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> Trace<'v>
for StarlarkCallableChecked<'v, P, R>
{
fn trace(&mut self, tracer: &Tracer<'v>) {
let StarlarkCallableChecked(value, phantom) = self;
value.trace(tracer);
phantom.trace(tracer);
}
}

impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> AllocValue<'v>
for StarlarkCallableChecked<'v, P, R>
{
fn alloc_value(self, _heap: &'v Heap) -> Value<'v> {
self.0
}
}

impl<'v, P: StarlarkCallableParamSpec, R: StarlarkTypeRepr> StarlarkCallableChecked<'v, P, R> {
/// Convert to [`StarlarkCallable`].
pub fn to_unchecked(self) -> StarlarkCallable<'v, P, R> {
Expand Down

0 comments on commit 85fcfab

Please sign in to comment.