Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes bundle-elim leaving references to deleted parameters #463

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix bundle_elim bugs
  • Loading branch information
UnsignedByte committed Oct 1, 2024
commit 94f97f24b089f6caf0242349a4b53833ec652890
16 changes: 8 additions & 8 deletions crates/filament/src/ir_passes/bundle_elim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use fil_ir::{
self as ir, Access, AddCtx, Bind, Command, Component, Connect, Ctx,
DenseIndexInfo, DisplayCtx, Expr, Foreign, Info, InvIdx, Invoke, Liveness,
MutCtx, Port, PortIdx, PortOwner, Range, Subst, Time,
MutCtx, Param, Port, PortIdx, PortOwner, Range, SparseInfoMap, Subst, Time,

Check failure on line 8 in crates/filament/src/ir_passes/bundle_elim.rs

View workflow job for this annotation

GitHub Actions / Check Formatting

unused import: `Param`

Check warning on line 8 in crates/filament/src/ir_passes/bundle_elim.rs

View workflow job for this annotation

GitHub Actions / Test Compiler

unused import: `Param`
};
use fil_utils as utils;
use itertools::Itertools;
Expand All @@ -17,7 +17,7 @@
// Eliminates bundle ports by breaking them into multiple len-1 ports, and eliminates local ports altogether.
pub struct BundleElim {
/// Mapping from component to the map from signature bundle port to generated port.
context: DenseIndexInfo<Component, HashMap<PortIdx, PortInfo>>,
context: DenseIndexInfo<Component, SparseInfoMap<Port, PortInfo>>,
/// Mapping from index into a dst port to an index of the src port.
local_map: HashMap<
(PortIdx, /*idxs=*/ Vec<usize>),
Expand Down Expand Up @@ -54,7 +54,7 @@
None => break group,
}
};
let (lens, sig_ports) = &comp_info[port];
let (lens, sig_ports) = &comp_info[*port];
ports.push(sig_ports[utils::flat_idx(idxs, lens)])
}

Expand Down Expand Up @@ -118,7 +118,7 @@

// creates a new liveness with the new start and end times and length one
let live = Liveness {
idxs: vec![idxs[0]], // this should technically be some null parameter, as it will refer to a deleted parameter now.
idxs: vec![],
lens: vec![one],
range: Range { start, end },
};
Expand All @@ -136,7 +136,7 @@
base: Foreign::new(
// maps the foreign to the corresponding single port
// this works because all signature ports are compiled first.
self.context[owner][&key].1[i],
self.context[owner][key].1[i],
owner,
),
}
Expand Down Expand Up @@ -165,7 +165,7 @@
}

/// Compiles the signature of a component and adds the new ports to the context mapping.
fn sig(&self, comp: &mut Component) -> HashMap<PortIdx, PortInfo> {
fn sig(&self, comp: &mut Component) -> SparseInfoMap<Port, PortInfo> {
// loop through signature ports and compile them
comp.ports()
.idx_iter()
Expand All @@ -181,7 +181,7 @@
&self,
idx: InvIdx,
comp: &mut Component,
) -> HashMap<PortIdx, PortInfo> {
) -> SparseInfoMap<Port, PortInfo> {
let Invoke { ports, .. } = comp.get_mut(idx);
// first take all the old ports and split them up
let mappings = std::mem::take(ports)
Expand Down Expand Up @@ -230,7 +230,7 @@
) -> Action {
let Connect { src, dst, .. } = connect;

if !self.context.get(data.idx).contains_key(&dst.port) {
if !self.context.get(data.idx).contains(dst.port) {
// we are writing to a local port here.
return Action::Change(vec![]);
}
Expand Down
17 changes: 17 additions & 0 deletions crates/ir/src/utils/sparse_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ where
pub fn iter(&self) -> impl Iterator<Item = (Key, &Info)> + '_ {
self.map.iter().map(|(idx, val)| (*idx, val))
}

/// Extend the map with the values from another map.
pub fn extend(&mut self, other: Self) {
self.map.extend(other.map);
}
}

impl<Assoc, Info, Key> Default for SparseInfoMap<Assoc, Info, Key>
Expand Down Expand Up @@ -98,6 +103,18 @@ impl<T, V, Idx: IdxLike<T>> FromIterator<(Idx, V)>
}
}

impl<Assoc, Info, Key> IntoIterator for SparseInfoMap<Assoc, Info, Key>
where
Key: IdxLike<Assoc>,
{
type Item = (Key, Info);
type IntoIter = std::collections::hash_map::IntoIter<Key, Info>;

fn into_iter(self) -> Self::IntoIter {
self.map.into_iter()
}
}

impl<T, V, Idx: IdxLike<T>> std::ops::Index<Idx> for SparseInfoMap<T, V, Idx> {
type Output = V;

Expand Down
Loading