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

refactor: avoid dynamic dispatch for non-folding operations #770

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions src/extension/const_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ impl Debug for Box<dyn ConstFold> {
}
}

impl Default for Box<dyn ConstFold> {
fn default() -> Self {
Box::new(|&_: &_| None)
}
}

/// Blanket implementation for functions that only require the constants to
/// evaluate - type arguments are not relevant.
impl<T> ConstFold for T
Expand Down
6 changes: 3 additions & 3 deletions src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub struct OpDef {

/// Operations can optionally implement [`ConstFold`] to implement constant folding.
#[serde(skip)]
constant_folder: Box<dyn ConstFold>,
constant_folder: Option<Box<dyn ConstFold>>,
}

impl OpDef {
Expand Down Expand Up @@ -421,7 +421,7 @@ impl OpDef {
/// Set the constant folding function for this Op, which can evaluate it
/// given constant inputs.
pub fn set_constant_folder(&mut self, fold: impl ConstFold + 'static) {
self.constant_folder = Box::new(fold)
self.constant_folder = Some(Box::new(fold))
}

/// Evaluate an instance of this [`OpDef`] defined by the `type_args`, given
Expand All @@ -431,7 +431,7 @@ impl OpDef {
type_args: &[TypeArg],
consts: &[(crate::IncomingPort, crate::ops::Const)],
) -> ConstFoldResult {
self.constant_folder.fold(type_args, consts)
(self.constant_folder.as_ref())?.fold(type_args, consts)
}
}

Expand Down