# Cargo::util::config::\* - why all the Cells?

**URL:** <https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994>\
**Category:** cargo\
**Created:** [October 1, 2017, 1:42pm UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994 "2017-10-01T13:42:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![derekdreery](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/derekdreery/32/2632_2.png) [@derekdreery](https://internals.rust-lang.org/u/derekdreery)\
**Post date:** [October 1, 2017, 1:42pm UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/1 "2017-10-01T13:42:16Z")

</div>

In `cargo::util::config::Config`, lots of fields are cells. I was wondering what the reason is for this - why can’t methods that update fields just take `&mut self`?

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [October 1, 2017, 1:46pm UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/2 "2017-10-01T13:46:12Z")

</div>

I don’t think there’s any real reason behind this except “it used to be convenient”. I think `Config::configure` is the only method that needs to mutate most of this fields, and it is only called inside `execute` at src/bin/cargo.rs:149.

It might be interesting to try to get rid of those cells and see if it works!

---

<div class="post-metadata">

**Author:** ![derekdreery](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/derekdreery/32/2632_2.png) [@derekdreery](https://internals.rust-lang.org/u/derekdreery)\
**Post date:** [October 3, 2017, 11:18am UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/3 "2017-10-03T11:18:49Z")

</div>

I’ve had more of a look, and it seems that having interior mutability here means you can pass Config around all over the place, without worrying about having more than 1 mutable reference. I think it should still not have interior mutability, as it obscures what is happening, so I’ll see if it’s fesible to change.

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [October 3, 2017, 11:20am UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/4 "2017-10-03T11:20:23Z")

</div>

Yeah, I think some of thous cells are mutated down the line somhere, but there’s a high change that `&mut` will suffice for most of them!

---

<div class="post-metadata">

**Author:** ![derekdreery](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/derekdreery/32/2632_2.png) [@derekdreery](https://internals.rust-lang.org/u/derekdreery)\
**Post date:** [October 4, 2017, 5:25pm UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/5 "2017-10-04T17:25:19Z")

</div>

I’ve successfully removed a few of the Cells and all tests pass, but now I need to decide what to do with the remaining ones, especially `LazyCell`s. Currently they are lazily initialized, which improves performance if they are never used (to initialize `rustc`, `values`, `cargo_exe`, `rustdoc` requires a filesystem call, to initialize `easy` requires loading a shared object file).

I could just load these eagerly, or load them in a worker thread, or leave them unchanged. What do you think is best?

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [October 4, 2017, 6:07pm UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/6 "2017-10-04T18:07:32Z")

</div>

I think `LazyCell` is a great abstraction, actually, because it allows to defer some work without introducing mutabilty and reference wrappers, like `Ref` of `RefCell`, so I think it’s best to leave it as is.

It would be great to switch to [https://github.com/indiv0/lazycell](https://github.com/indiv0/lazycell), but we’ll need a couple of additional APIs for that: [https://github.com/indiv0/lazycell/pulls](https://github.com/indiv0/lazycell/pulls).

---

<div class="post-metadata">

**Author:** ![derekdreery](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/derekdreery/32/2632_2.png) [@derekdreery](https://internals.rust-lang.org/u/derekdreery)\
**Post date:** [October 4, 2017, 6:18pm UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/7 "2017-10-04T18:18:40Z")

</div>

I’ve submitted a [PR](https://github.com/rust-lang/cargo/pull/4578) just for the Cells

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:29am UTC](https://internals.rust-lang.org/t/cargo-util-config-why-all-the-cells/5994/8 "2019-03-25T08:29:04Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
