better indexing for heterogeneous arrays
- Dominant language
- Swift
- Stars
- 118
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
We have many operations that "map" a heterogeneous array through a function that transforms elements. (See https://github.com/borglab/SwiftFusion/issues/114 for some examples).
The heterogeneous arrays have a `var storage: [ObjectIdentifier: Something]` field that stores their elements. There are two ways that the map operations could produce the `storage` for the resulting heterogeneous arrays:
1. Transform the `Something`s, but leave the `ObjectIdentifier`s unchanged (even if the transform changes the type of the elements).
2. Transform the `Something`s, and also transform the `ObjectIdentifier` to the identifier of the transformed element type.
Option 1 has the drawback that the resulting `ObjectIdentifier` no longer matches the element type and therefore the subscript using `TypedID`, which assumes that the `ObjectIdentifier` matches the element type, can't index into the result heterogeneous array. Option 2 has the drawback that `ObjectIdentifier`s can collide if the transform function maps distinct types to the same type.
We actually currently use both options in different places, depending on what we need. In [the place where we use option 2](https://github.com/borglab/SwiftFusion/blob/37139c5baa12656dd4440696985d4d591ac6e36f/Sources/SwiftFusion/Inference/VariableAssignments.swift#L104), we don't handle collisions so we should really fix it soon (none of the use cases that we have implemented so far cause collisions).
The correct solution is probably to use option 1 but add additional data to `TypedID` so that we can subscript into the resulting arrays using `TypedID`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.