# Vague proposal: Extending coherence with workspaces

**URL:** <https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216>\
**Category:** language design\
**Created:** [March 4, 2016, 1:16am UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216 "2016-03-04T01:16:45Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [March 10, 2016, 9:54pm UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216/21 "2016-03-10T21:54:43Z")

</div>

> [@Thiez](#):
>
> Exactly, Sequence is simply a special case of Map, from indices to items. Or a Map is simply a Sequence of key-value tuples. Depending on how you look at it, they're really the same thing.

This not correct (at least without something approaching dependent types) because maps do not guarantee that if `n` is a key, `pred(n)` is also a key, and there is no way to express a refinement of the map interface which provides this guarantee. Iteration introduces some order, it might even be a non-arbitrary order (BTreeMap is an ordered map, by the way), but it does not mean that the keys in the map are all of the values in the range `0..len`.

These are fundamentally different interfaces. It does not mean anything to 'push' to a map, and you can not insert at arbitrary indices greater than the length of a sequence.

> [@Thiez](#):
>
> I get the feeling that your division between Sequence and Map is based on formats such as JSON

Serialization, especially to formats like JSON, is a very obvious use case for the ability to provide blanket impls for both sequences and maps.

---

<div class="post-metadata">

**Author:** ![Thiez](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/thiez/32/3344_2.png) [@Thiez](https://internals.rust-lang.org/u/Thiez)\
**Post date:** [March 10, 2016, 11:41pm UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216/22 "2016-03-10T23:41:27Z")

</div>

Perhaps `Sequence` does not map to `Map` as well as the other way round, so I will focus on representing `Map` and `Sequence`. When turning a `Map` into a `Sequence` there is no need to guarantee that the keys all fall in the range `0..len`. We simply assign the indices to the elements as they are yielded by iteration (e.g. with `Iterator::enumerate`) and the items in the sequence are the key-value pairs.

> [@withoutboats](#):
>
> These are fundamentally different interfaces. It does not mean anything to 'push' to a map, and you can not insert at arbitrary indices greater than the length of a sequence.

Now we can `push` to a `Map` simply by `push`'ing the new key-value pair. To find something in our `Map` we simply look at the item in the `Sequence` with a matching key and the highest index.

At the end of the day I don't think there is much point in being extremely strict with invariants for maps and sequences when serialization is involved, because anyone can easily edit the serialized data and break the invariants. I doubt we'll agree on this, so perhaps it's best to agree to disagree 🙂

---

<div class="post-metadata">

**Author:** ![withoutboats](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/withoutboats/32/4560_2.png) [@withoutboats](https://internals.rust-lang.org/u/withoutboats)\
**Post date:** [March 11, 2016, 12:02am UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216/23 "2016-03-11T00:02:14Z")

</div>

The map in itself does not contain any notion of an index to its key value pairs. Iteration introduces a sequentiality to this only because iteration is performed in linear time and so events necessarily happen in sequence (parallel iterators have no such sequentiality). You can’t ‘push’ a key/value pair to a map because there’s no guarantee that key/value pair will be at the end of the map by virtue of being the most recently pushed item. Its also important that in sequences, repetition is allowed, which is not true of maps (if you try to view them as sequences of key/value pairs).

This conversation is wildly off-topic, it would be best to delay it to another time.

---

<div class="post-metadata">

**Author:** ![GolDDranks](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/golddranks/32/1158_2.png) [@GolDDranks](https://internals.rust-lang.org/u/GolDDranks)\
**Post date:** [March 24, 2016, 7:43am UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216/24 "2016-03-24T07:43:07Z")

</div>

Another proposal that should be orthogonal to the workspaces proposal but that might helps with coherence issues: Relax orphan rules for derived impls, aka “algorithmically derived opt-in blanket impls”: [https://github.com/rust-lang/rfcs/issues/1553](https://github.com/rust-lang/rfcs/issues/1553)

---

<div class="post-metadata">

**Author:** ![oli-obk](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/oli-obk/32/3168_2.png) [@oli-obk](https://internals.rust-lang.org/u/oli-obk)\
**Post date:** [November 8, 2016, 8:45am UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216/25 "2016-11-08T08:45:26Z")

</div>

to anyone interested, the "magical feature activation depending on available crates" idea is now an RFC by @withoutboats:

> <https://github.com/rust-lang/rfcs/pull/1787>

---

<div class="post-metadata">

**Author:** ![nikomatsakis](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nikomatsakis/32/5410_2.png) [@nikomatsakis](https://internals.rust-lang.org/u/nikomatsakis)\
**Post date:** [March 25, 2019, 8:25am UTC](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216/26 "2019-03-25T08:25:50Z")

</div>

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

[Previous page](https://internals.rust-lang.org/t/vague-proposal-extending-coherence-with-workspaces/3216.md?page=1)
