Skip to content

Commit 771071c

Browse files
JakobDegenfacebook-github-bot
authored andcommitted
module: Remove a duplicate field from UnboundValue
Summary: This is already stored in the `NativeMethod` This adds a pointer indirection to this call, but not a virtual call, so it should be fine. In any case, it'll be gone again next diff Reviewed By: Nero5023 Differential Revision: D73726007 fbshipit-source-id: dbba4073bc01626d6afceed61c6831c129cd5216
1 parent d1ef4b5 commit 771071c

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

starlark/src/environment/methods.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use crate::values::FrozenHeap;
3030
use crate::values::FrozenHeapRef;
3131
use crate::values::FrozenRef;
3232
use crate::values::FrozenValue;
33-
use crate::values::FrozenValueTyped;
3433
use crate::values::Heap;
3534
use crate::values::Value;
3635
use crate::values::function::NativeAttribute;
@@ -75,7 +74,7 @@ impl Methods {
7574
pub(crate) fn get_ty(&self, name: &str) -> Option<Ty> {
7675
match self.members.get_str(name)? {
7776
UnboundValue::Attr(attr) => Some(attr.typ.dupe()),
78-
UnboundValue::Method(method, _) => Some(method.ty.dupe()),
77+
UnboundValue::Method(method) => Some(method.ty.dupe()),
7978
}
8079
}
8180

@@ -220,17 +219,13 @@ impl MethodsBuilder {
220219
);
221220
self.members.insert(
222221
name,
223-
UnboundValue::Method(
224-
FrozenValueTyped::new(self.heap.alloc(NativeMethod {
225-
function,
226-
name: name.to_owned(),
227-
speculative_exec_safe: components.speculative_exec_safe,
228-
docs: components.into_docs(None),
229-
ty,
230-
}))
231-
.unwrap(),
222+
UnboundValue::Method(self.heap.alloc_simple_typed(NativeMethod {
232223
function,
233-
),
224+
name: name.to_owned(),
225+
speculative_exec_safe: components.speculative_exec_safe,
226+
docs: components.into_docs(None),
227+
ty,
228+
})),
234229
);
235230
}
236231

starlark/src/eval/compiler/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ impl ExprCompiled {
873873
let v = get_attr_hashed_raw(left.to_value(), attr, ctx.heap()).ok()?;
874874
match v {
875875
MemberOrValue::Member(m) => match m {
876-
UnboundValue::Method(m, _) => Some(
876+
UnboundValue::Method(m) => Some(
877877
ctx.frozen_heap()
878878
.alloc_simple(BoundMethodGen::new(left, *m)),
879879
),

starlark/src/values/types/unbound.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,13 @@ use crate::values::Value;
3232
use crate::values::ValueLike;
3333
use crate::values::function::BoundMethodGen;
3434
use crate::values::function::NativeAttribute;
35-
use crate::values::function::NativeMeth;
3635
use crate::values::function::NativeMethod;
3736

3837
/// A value or an unbound method or unbound attribute.
3938
#[derive(Clone)]
4039
pub(crate) enum UnboundValue {
4140
/// A method with `this` unbound.
42-
Method(
43-
FrozenValueTyped<'static, NativeMethod>,
44-
FrozenRef<'static, dyn NativeMeth>,
45-
),
41+
Method(FrozenValueTyped<'static, NativeMethod>),
4642
/// An attribute with `this` unbound.
4743
Attr(FrozenValueTyped<'static, NativeAttribute>),
4844
}
@@ -57,7 +53,7 @@ impl UnboundValue {
5753
#[inline]
5854
pub(crate) fn to_frozen_value(&self) -> FrozenValue {
5955
match self {
60-
UnboundValue::Method(m, _) => m.to_frozen_value(),
56+
UnboundValue::Method(m) => m.to_frozen_value(),
6157
UnboundValue::Attr(a) => a.to_frozen_value(),
6258
}
6359
}
@@ -66,7 +62,7 @@ impl UnboundValue {
6662
#[inline]
6763
pub(crate) fn bind<'v>(&self, this: Value<'v>, heap: &'v Heap) -> crate::Result<Value<'v>> {
6864
match self {
69-
UnboundValue::Method(m, _) => {
65+
UnboundValue::Method(m) => {
7066
Ok(heap.alloc_complex(BoundMethodGen::new(this.to_value(), *m)))
7167
}
7268
UnboundValue::Attr(a) => a.invoke(this, heap),
@@ -85,7 +81,7 @@ impl UnboundValue {
8581
self.to_frozen_value().to_value(),
8682
Some(span),
8783
|eval| match self {
88-
UnboundValue::Method(_, m) => m.invoke(eval, this, args),
84+
UnboundValue::Method(m) => m.function.invoke(eval, this, args),
8985
UnboundValue::Attr(a) => a.invoke(this, eval.heap()),
9086
},
9187
)

0 commit comments

Comments
 (0)