Skip to content

Commit 8b1c923

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Return FrozenStringValue from StarlarkValue::get_type_value
Summary: More assertions with types. Reviewed By: ndmitchell Differential Revision: D30892350 fbshipit-source-id: a434db7a8cc42780d75402cb61db1e04e723ec29
1 parent 7ff0491 commit 8b1c923

File tree

9 files changed

+29
-25
lines changed

9 files changed

+29
-25
lines changed

starlark/src/eval/fragment/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl ExprCompiledValue {
6666
Self::Value(x) => box move |_| Ok(x.to_value()),
6767
Self::Compiled(x) => x,
6868
Self::Type(x) => expr!("type", x, |_eval| {
69-
x.get_ref().get_type_value().to_value()
69+
x.get_ref().get_type_value().unpack().to_value()
7070
})
7171
.as_compiled(),
7272
}

starlark/src/eval/fragment/known.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,18 @@ impl Compiler<'_> {
8888
// In practice people only really use the empty versions as constants.
8989
match &expr.node {
9090
ExprP::Dict(xs) if xs.is_empty() => {
91-
return ExprCompiledValue::Value(Dict::get_type_value_static());
91+
return ExprCompiledValue::Value(Dict::get_type_value_static().unpack());
9292
}
9393
ExprP::List(xs) if xs.is_empty() => {
94-
return ExprCompiledValue::Value(List::get_type_value_static());
94+
return ExprCompiledValue::Value(List::get_type_value_static().unpack());
9595
}
9696
// No need to handle Tuple as it will become frozen if it has no inner-calls
9797
_ => {}
9898
}
9999
match self.expr(expr) {
100-
ExprCompiledValue::Value(x) => ExprCompiledValue::Value(x.to_value().get_type_value()),
100+
ExprCompiledValue::Value(x) => {
101+
ExprCompiledValue::Value(x.to_value().get_type_value().unpack())
102+
}
101103
x => ExprCompiledValue::Type(box x),
102104
}
103105
}

starlark/src/macros/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ macro_rules! starlark_type {
2424
fn get_type(&self) -> &'static str {
2525
$typ
2626
}
27-
fn get_type_value(&self) -> $crate::values::FrozenValue {
27+
fn get_type_value(&self) -> $crate::values::FrozenStringValue {
2828
Self::get_type_value_static()
2929
}
30-
fn get_type_value_static() -> $crate::values::FrozenValue {
30+
fn get_type_value_static() -> $crate::values::FrozenStringValue {
3131
const N: usize = $typ.len();
3232
static RES: $crate::values::ConstFrozenStringN<N> =
3333
$crate::values::ConstFrozenStringN::new($typ);
34-
RES.unpack()
34+
RES.erase()
3535
}
3636
};
3737
}

starlark/src/stdlib/funcs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ pub(crate) fn global_functions(builder: &mut GlobalsBuilder) {
913913
/// # "#);
914914
/// ```
915915
fn r#type(ref a: Value) -> Value<'v> {
916-
Ok(a.get_type_value().to_value())
916+
Ok(a.get_type_value().unpack().to_value())
917917
}
918918

919919
/// [zip](

starlark/src/values/layout/avalue.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use crate::{
2424
layout::arena::{AValueHeader, AValueRepr},
2525
none::NoneType,
2626
string::StarlarkStr,
27-
ComplexValue, Freezer, FrozenValue, Heap, SimpleValue, StarlarkValue, Tracer, Value,
27+
ComplexValue, Freezer, FrozenStringValue, FrozenValue, Heap, SimpleValue, StarlarkValue,
28+
Tracer, Value,
2829
},
2930
};
3031
use gazebo::{any::AnyLifetime, cast, coerce::Coerce};
@@ -298,10 +299,10 @@ impl<'v, Mode: 'static, T: StarlarkValue<'v>> StarlarkValue<'v> for Wrapper<Mode
298299
fn get_type(&self) -> &'static str {
299300
self.1.get_type()
300301
}
301-
fn get_type_value(&self) -> FrozenValue {
302+
fn get_type_value(&self) -> FrozenStringValue {
302303
self.1.get_type_value()
303304
}
304-
fn get_type_value_static() -> FrozenValue {
305+
fn get_type_value_static() -> FrozenStringValue {
305306
T::get_type_value_static()
306307
}
307308
fn matches_type(&self, ty: &str) -> bool {

starlark/src/values/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ impl<'v> Value<'v> {
566566
self.invoke(location, params, eval)
567567
}
568568

569-
pub fn get_type_value(self) -> FrozenValue {
569+
pub fn get_type_value(self) -> FrozenStringValue {
570570
self.get_ref().get_type_value()
571571
}
572572
}

starlark/src/values/traits.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ use crate::{
3434
environment::Globals,
3535
eval::{Arguments, Evaluator},
3636
values::{
37-
docs::DocItem, function::FUNCTION_TYPE, ControlError, Freezer, FrozenValue, Heap, Tracer,
38-
Value, ValueError,
37+
docs::DocItem, function::FUNCTION_TYPE, ControlError, Freezer, FrozenStringValue, Heap,
38+
Tracer, Value, ValueError,
3939
},
4040
};
4141
use gazebo::any::AnyLifetime;
@@ -339,20 +339,20 @@ pub trait StarlarkValue<'v>: 'v + AnyLifetime<'v> + AsStarlarkValue<'v> + Debug
339339
/// Usually implemented by the [`starlark_type!`] macro.
340340
fn get_type(&self) -> &'static str;
341341

342-
/// Like get_type, but returns a reusable [`FrozenValue`] pointer to it.
343-
/// This function deliberately doesn't take a heap, as it would not be performant
344-
/// to allocate a new value each time.
342+
/// Like [`get_type`](Self::get_type), but returns a reusable [`FrozenStringValue`]
343+
/// pointer to it. This function deliberately doesn't take a heap,
344+
/// as it would not be performant to allocate a new value each time.
345345
///
346346
/// Usually implemented by the [`starlark_type!`] macro.
347-
fn get_type_value(&self) -> FrozenValue;
347+
fn get_type_value(&self) -> FrozenStringValue;
348348

349349
/// Like [`get_type_value`](Self::get_type_value), but does not require `self`.
350350
///
351351
/// This function must return the same statically-allocated instance as
352352
/// [`get_type_value`](Self::get_type_value).
353353
///
354354
/// Usually implemented by the [`starlark_type!`] macro.
355-
fn get_type_value_static() -> FrozenValue
355+
fn get_type_value_static() -> FrozenStringValue
356356
where
357357
Self: Sized;
358358

starlark/src/values/types/dict.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::{
2424
values::{
2525
comparison::equals_small_map, error::ValueError, iter::ARefIterator,
2626
string::hash_string_value, AllocFrozenValue, AllocValue, ComplexValue, Freezer, FromValue,
27-
FrozenHeap, FrozenValue, Heap, SimpleValue, StarlarkValue, Trace, UnpackValue, Value,
28-
ValueLike,
27+
FrozenHeap, FrozenStringValue, FrozenValue, Heap, SimpleValue, StarlarkValue, Trace,
28+
UnpackValue, Value, ValueLike,
2929
},
3030
};
3131
use gazebo::{
@@ -150,7 +150,7 @@ impl<'v> Dict<'v> {
150150
/// The result of calling `type()` on dictionaries.
151151
pub const TYPE: &'static str = "dict";
152152

153-
pub fn get_type_value_static() -> FrozenValue {
153+
pub fn get_type_value_static() -> FrozenStringValue {
154154
DictGen::<FrozenDict>::get_type_value_static()
155155
}
156156

starlark/src/values/types/list.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use crate::{
2525
error::ValueError,
2626
index::{apply_slice, convert_index},
2727
iter::ARefIterator,
28-
AllocFrozenValue, AllocValue, ComplexValue, Freezer, FromValue, FrozenHeap, FrozenValue,
29-
Heap, SimpleValue, StarlarkValue, UnpackValue, Value, ValueLike,
28+
AllocFrozenValue, AllocValue, ComplexValue, Freezer, FromValue, FrozenHeap,
29+
FrozenStringValue, FrozenValue, Heap, SimpleValue, StarlarkValue, UnpackValue, Value,
30+
ValueLike,
3031
},
3132
};
3233
use gazebo::{
@@ -183,7 +184,7 @@ impl<'v> List<'v> {
183184
/// The result of calling `type()` on lists.
184185
pub const TYPE: &'static str = "list";
185186

186-
pub fn get_type_value_static() -> FrozenValue {
187+
pub fn get_type_value_static() -> FrozenStringValue {
187188
ListGen::<FrozenList>::get_type_value_static()
188189
}
189190

0 commit comments

Comments
 (0)