mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
fixed drop specialization assert for unreachable switch branches on unions
This commit is contained in:
parent
32e0ea38ef
commit
14a338e15b
1 changed files with 12 additions and 11 deletions
|
@ -873,7 +873,7 @@ fn specialize_union<'a, 'i>(
|
||||||
|
|
||||||
// We know the tag, we can specialize the decrement for the tag.
|
// We know the tag, we can specialize the decrement for the tag.
|
||||||
UnionFieldLayouts::Found { field_layouts, tag } => {
|
UnionFieldLayouts::Found { field_layouts, tag } => {
|
||||||
match environment.union_children.get(symbol) {
|
match environment.union_children.get(&(*symbol, tag)) {
|
||||||
None => keep_original_decrement!(),
|
None => keep_original_decrement!(),
|
||||||
Some(children) => {
|
Some(children) => {
|
||||||
// TODO perhaps this allocation can be avoided.
|
// TODO perhaps this allocation can be avoided.
|
||||||
|
@ -884,13 +884,11 @@ fn specialize_union<'a, 'i>(
|
||||||
let mut index_symbols = MutMap::default();
|
let mut index_symbols = MutMap::default();
|
||||||
|
|
||||||
for (index, _layout) in field_layouts.iter().enumerate() {
|
for (index, _layout) in field_layouts.iter().enumerate() {
|
||||||
for (child, t, _i) in children_clone
|
for (child, _i) in children_clone
|
||||||
.iter()
|
.iter()
|
||||||
.rev()
|
.rev()
|
||||||
.filter(|(_child, _t, i)| *i == index as u64)
|
.filter(|(_child, i)| *i == index as u64)
|
||||||
{
|
{
|
||||||
debug_assert_eq!(tag, *t);
|
|
||||||
|
|
||||||
let removed = incremented_children.pop(child);
|
let removed = incremented_children.pop(child);
|
||||||
index_symbols.entry(index).or_insert((*child, removed));
|
index_symbols.entry(index).or_insert((*child, removed));
|
||||||
|
|
||||||
|
@ -1392,7 +1390,7 @@ struct DropSpecializationEnvironment<'a> {
|
||||||
struct_children: MutMap<Parent, Vec<'a, (Child, Index)>>,
|
struct_children: MutMap<Parent, Vec<'a, (Child, Index)>>,
|
||||||
|
|
||||||
// Keeps track of which parent symbol is indexed by which child symbol for unions
|
// Keeps track of which parent symbol is indexed by which child symbol for unions
|
||||||
union_children: MutMap<Parent, Vec<'a, (Child, Tag, Index)>>,
|
union_children: MutMap<(Parent, Tag), Vec<'a, (Child, Index)>>,
|
||||||
|
|
||||||
// Keeps track of which parent symbol is indexed by which child symbol for boxes
|
// Keeps track of which parent symbol is indexed by which child symbol for boxes
|
||||||
box_children: MutMap<Parent, Vec<'a, Child>>,
|
box_children: MutMap<Parent, Vec<'a, Child>>,
|
||||||
|
@ -1469,9 +1467,9 @@ impl<'a> DropSpecializationEnvironment<'a> {
|
||||||
|
|
||||||
fn add_union_child(&mut self, parent: Parent, child: Child, tag: u16, index: Index) {
|
fn add_union_child(&mut self, parent: Parent, child: Child, tag: u16, index: Index) {
|
||||||
self.union_children
|
self.union_children
|
||||||
.entry(parent)
|
.entry((parent, tag))
|
||||||
.or_insert_with(|| Vec::new_in(self.arena))
|
.or_insert_with(|| Vec::new_in(self.arena))
|
||||||
.push((child, tag, index));
|
.push((child, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_list_child(&mut self, parent: Parent, child: Child, index: u64) {
|
fn add_list_child(&mut self, parent: Parent, child: Child, index: u64) {
|
||||||
|
@ -1494,9 +1492,12 @@ impl<'a> DropSpecializationEnvironment<'a> {
|
||||||
res.extend(children.iter().rev().map(|(child, _)| child));
|
res.extend(children.iter().rev().map(|(child, _)| child));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(children) = self.union_children.get(parent) {
|
let children = self
|
||||||
res.extend(children.iter().rev().map(|(child, _, _)| child));
|
.union_children
|
||||||
}
|
.iter()
|
||||||
|
.filter(|(k, _v)| k.0 == *parent)
|
||||||
|
.flat_map(|(_k, v)| v.iter().rev());
|
||||||
|
res.extend(children.map(|(child, _)| child));
|
||||||
|
|
||||||
if let Some(children) = self.box_children.get(parent) {
|
if let Some(children) = self.box_children.get(parent) {
|
||||||
res.extend(children.iter().rev());
|
res.extend(children.iter().rev());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue