diff options
author | Aria Shrimpton <me@aria.rip> | 2024-02-19 21:27:32 +0000 |
---|---|---|
committer | Aria Shrimpton <me@aria.rip> | 2024-02-19 21:28:03 +0000 |
commit | d0a3f00a1c4116433343d11b63872888b0c2aaf6 (patch) | |
tree | ac8872190153395de76fe185048bdb237f17e0e6 | |
parent | 1edff7368236365c8db83e87c2110c42292b2907 (diff) |
also benchmark n splits
-rw-r--r-- | src/crates/cli/src/select.rs | 34 | ||||
-rw-r--r-- | src/crates/primrose/src/codegen.rs | 28 |
2 files changed, 35 insertions, 27 deletions
diff --git a/src/crates/cli/src/select.rs b/src/crates/cli/src/select.rs index fc3b812..6887e9a 100644 --- a/src/crates/cli/src/select.rs +++ b/src/crates/cli/src/select.rs @@ -2,8 +2,9 @@ use std::collections::HashMap; use anyhow::Result; use argh::FromArgs; +use cargo_metadata::camino::Utf8PathBuf; use log::info; -use primrose::{tools::nary_cartesian_product, ContainerSelection}; +use primrose::{tools::nary_cartesian_product, ConTypeName, ContainerSelection}; use tabled::{builder::Builder, settings::Style}; use crate::State; @@ -28,20 +29,9 @@ impl State { builder.set_header(["name", "implementation", "estimated cost", "file"]); for (f, ctn, candidates) in costs.iter() { for (candidate, cost) in candidates.iter() { - let name = match candidate { - ContainerSelection::Singular(x) => x.to_string(), - ContainerSelection::Split { - before, - threshold, - after, - } => { - format!("{} until n={}, then {}", before, threshold, after) - } - _ => unreachable!(), - }; builder.push_record([ ctn.as_str(), - name.as_str(), + candidate.to_string().as_str(), cost.to_string().as_str(), f.as_str(), ]); @@ -55,12 +45,10 @@ impl State { } // 'brute force' and time all possibilities - let candidates = self - .inner - .project_candidate_list(proj)? - .into_iter() - .map(|(f, ctn, v)| ((f, ctn), v)) - .collect(); + let candidates = costs + .iter() + .map(|(f, ctn, cs)| ((f, ctn), cs.into_iter().map(|(i, _)| i.clone()).collect())) + .collect::<HashMap<(&Utf8PathBuf, &ConTypeName), Vec<ContainerSelection>>>(); let possible_assignments = nary_cartesian_product(&candidates); let mut assignments_results = HashMap::new(); @@ -72,13 +60,7 @@ impl State { proj, &assignment .iter() - .map(|((f, ctn), i)| { - ( - f.clone(), - ctn.clone(), - ContainerSelection::Singular(i.to_string()), - ) - }) + .map(|((f, ctn), sel)| ((*f).clone(), (*ctn).clone(), (*sel).clone())) .collect(), )?, ); diff --git a/src/crates/primrose/src/codegen.rs b/src/crates/primrose/src/codegen.rs index e7766bf..7dd2b6c 100644 --- a/src/crates/primrose/src/codegen.rs +++ b/src/crates/primrose/src/codegen.rs @@ -1,5 +1,7 @@ //! Generating rust code from results of +use std::fmt::Display; + use crate::{ description::{InforMap, Tag}, parser::Block, @@ -12,7 +14,7 @@ const CODEGENEND: &str = "/*ENDCODEGEN*/\n"; const TRAITCRATE: &str = "primrose_library::traits::"; /// A selected concrete type that we can use -#[derive(Clone, Debug)] +#[derive(Clone)] pub enum ContainerSelection { Singular(ImplName), Profile(ImplName, usize), @@ -23,6 +25,30 @@ pub enum ContainerSelection { }, } +impl std::fmt::Debug for ContainerSelection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self) + } +} + +impl Display for ContainerSelection { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ContainerSelection::Singular(x) => write!(f, "{}", x), + ContainerSelection::Split { + before, + threshold, + after, + } => { + write!(f, "{} until n={}, then {}", before, threshold, after) + } + ContainerSelection::Profile(inner, idx) => { + write!(f, "profiled: index = {} inner = {}", idx, inner) + } + } + } +} + impl ContainerSelector { /// Generate replacement code for the whole file, with the given `(tag_id, selection)` pairs. /// This will generate invalid code if any selection is invalid, or panic if any `tag_id` is invalid. |