Skip to content

Commit 36d2e67

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Remove Deref for DictMut
Summary: `Dict` should not be a part of public API. This (and a few other things) get in the way. It should not be public API because being public prevents changes how it is implemented. Reviewed By: JakobDegen Differential Revision: D63741054 fbshipit-source-id: 90527765e409da6776a9cbf88d1fd1c3c6ec3870
1 parent 74a5dd5 commit 36d2e67

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

starlark/src/eval/compiler/stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ pub(crate) fn bit_or_assign<'v>(
585585
Ok,
586586
)?;
587587
for (k, v) in rhs.iter_hashed() {
588-
dict.insert_hashed(k, v);
588+
dict.aref.insert_hashed(k, v);
589589
}
590590
}
591591
Ok(lhs)

starlark/src/values/types/dict/methods.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn dict_methods(registry: &mut MethodsBuilder) {
5353
/// ```
5454
fn clear(this: Value) -> anyhow::Result<NoneType> {
5555
let mut this = DictMut::from_value(this)?;
56-
this.clear();
56+
this.aref.clear();
5757
Ok(NoneType)
5858
}
5959

@@ -172,7 +172,7 @@ pub(crate) fn dict_methods(registry: &mut MethodsBuilder) {
172172
#[starlark(require = pos)] default: Option<Value<'v>>,
173173
) -> starlark::Result<Value<'v>> {
174174
let mut me = DictMut::from_value(this)?;
175-
match me.remove_hashed(key.get_hashed()?) {
175+
match me.aref.remove_hashed(key.get_hashed()?) {
176176
Some(x) => Ok(x),
177177
None => match default {
178178
Some(v) => Ok(v),
@@ -266,7 +266,7 @@ pub(crate) fn dict_methods(registry: &mut MethodsBuilder) {
266266
) -> starlark::Result<Value<'v>> {
267267
let mut this = DictMut::from_value(this)?;
268268
let key = key.get_hashed()?;
269-
match this.content.entry_hashed(key) {
269+
match this.aref.content.entry_hashed(key) {
270270
starlark_map::small_map::Entry::Occupied(e) => Ok(*e.get()),
271271
starlark_map::small_map::Entry::Vacant(e) => {
272272
let default = default.unwrap_or_else(Value::new_none);
@@ -326,7 +326,7 @@ pub(crate) fn dict_methods(registry: &mut MethodsBuilder) {
326326
if let Some(pairs) = pairs {
327327
if let Some(dict) = DictRef::from_value(pairs) {
328328
for (k, v) in dict.iter_hashed() {
329-
this.insert_hashed(k, v);
329+
this.aref.insert_hashed(k, v);
330330
}
331331
} else {
332332
for v in pairs.iterate(heap)? {
@@ -337,13 +337,13 @@ pub(crate) fn dict_methods(registry: &mut MethodsBuilder) {
337337
"dict.update expect a list of pairs or a dictionary as first argument, got a list of non-pairs.",
338338
).into());
339339
};
340-
this.insert_hashed(k.get_hashed()?, v);
340+
this.aref.insert_hashed(k.get_hashed()?, v);
341341
}
342342
}
343343
}
344344

345345
for (k, v) in kwargs.iter_hashed() {
346-
this.insert_hashed(k, v);
346+
this.aref.insert_hashed(k, v);
347347
}
348348
Ok(NoneType)
349349
}

starlark/src/values/types/dict/refs.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::cell::RefCell;
2020
use std::cell::RefMut;
2121
use std::convert::Infallible;
2222
use std::ops::Deref;
23-
use std::ops::DerefMut;
2423

2524
use dupe::Dupe;
2625
use either::Either;
@@ -140,20 +139,6 @@ impl<'v> Deref for DictRef<'v> {
140139
}
141140
}
142141

143-
impl<'v> Deref for DictMut<'v> {
144-
type Target = Dict<'v>;
145-
146-
fn deref(&self) -> &Self::Target {
147-
&self.aref
148-
}
149-
}
150-
151-
impl<'v> DerefMut for DictMut<'v> {
152-
fn deref_mut(&mut self) -> &mut Self::Target {
153-
&mut self.aref
154-
}
155-
}
156-
157142
impl<'v> StarlarkTypeRepr for DictRef<'v> {
158143
type Canonical = <DictType<FrozenValue, FrozenValue> as StarlarkTypeRepr>::Canonical;
159144

0 commit comments

Comments
 (0)