Skip to content

Instantly share code, notes, and snippets.

@Innf107
Created December 14, 2025 23:04
Show Gist options
  • Select an option

  • Save Innf107/e69a78dd232a3116ad991ac470270c24 to your computer and use it in GitHub Desktop.

Select an option

Save Innf107/e69a78dd232a3116ad991ac470270c24 to your computer and use it in GitHub Desktop.
#!/usr/bin/env polaris
options {
"--string-as-vec" as stringAsVec : "Set String's representation to Vec (this is kind of an implementation detail so it feels a bit cheaty but it is true in rust)"
}
module List = import("@std/list.pls")
let instantiationLines = lines(!bash "-c" 'readelf -sW target/debug/ddc | grep access_scoped | rustfilt | grep -Po "(?<=DerivedIngredient<).*(?=>::access_scoped)" | grep -v "DB,K,V" | sort | uniq')
let rawInstantiations = List.map(\line -> split(",", line), instantiationLines)
let rejoinInstantiations(list) = match list {
[] -> []
[x] -> [x]
(inst1 :: inst2 :: rest) ->
if List.length(regexpMatch("\\(", inst1)) == List.length(regexpMatch("\\)", inst1))
&& List.length(regexpMatch("\\<", inst1)) == List.length(regexpMatch("\\>", inst1)) then {
inst1 :: rejoinInstantiations(inst2 :: rest)
} else {
rejoinInstantiations(("${inst1},${inst2}") :: rest)
}
}
let instantiations = List.map(rejoinInstantiations, rawInstantiations)
let unlines(list) = match list {
[] -> ""
[x] -> x
(x :: xs) -> "${x}\n${unlines(xs)}"
}
let nub(list) = match(list) {
[] -> []
x :: xs -> {
let tail = nub(xs)
if List.contains(x, tail) then
tail
else
x :: tail
}
}
let findMap(f, list) = match(list) {
[] -> Nothing
(x :: xs) -> match f(x) {
Nothing -> findMap(f, xs)
Just(y) -> Just(y)
}
}
let types = nub(List.concatMap(\x -> x, instantiations))
let rawRepresentations = [
("ddc::db::StaticFile", "String * Vec"),
("alloc::vec::Vec<alloc::string::String>", "Vec"),
("()", "()"),
("ddc::db::Database", "() + Arc"),
("alloc::vec::Vec<(alloc::string::String,alloc::string::String)>", "Vec"),
("core::option::Option<ddc::db::CssOutput>", "() + (String * String)"),
("core::option::Option<ddc::queries::CompiledCss>", "String"),
("ddc::db::AllRenderedHtml", "HashMap"),
("core::option::Option<facet_value::value::Value>", "() + Value"),
("ddc::db::DataFile", "String * String"),
("ddc::types::SassContent", "String"),
("ddc::db::SassFile", "String * String"),
("ddc::db::SiteOutput", "Vec * Vec"),
("ddc::db::SiteTree", "BTreeMap<String, Section> * BTreeMap<String, Page>"),
("ddc::db::ParsedData", "ParsedData"),
("ddc::db::SourceFile", "String * String * i64"),
("alloc::vec::Vec<u8>", "Vec"),
("core::option::Option<alloc::vec::Vec<u8>>", "() + Vec"),
("core::option::Option<ddc::db::ProcessedImages>", "() + (u32 * u32 * String * Vec * Vec)"),
("core::option::Option<ddc::image::ImageMetadata>", "u32 * u32 * String * Vec"),
("ddc::cas::InputHash", "[u8;32]"),
("(ddc::db::StaticFile,ddc::db::CharSet)", "String * Vec"),
("ddc::db::StaticFileOutput", "String * Vec"),
("ddc::types::TemplateContent", "String"),
("ddc::db::TemplateFile", "String * String"),
("ddc::queries::DataValuePath", "Vec"),
("ddc::queries::LocalFontAnalysis", "HashMap * Vec"),
("core::option::Option<alloc::string::String>", "() + String"),
("ddc::types::Route", "String"),
("ddc::db::RenderedHtml", "String"),
("ddc::db::DatabaseSnapshot", "DatabaseSnapshot"), # I couldn't find this one. Pretty sure it's auto-generated
("std::collections::hash::map::HashMap<alloc::string::String,alloc::string::String>", "HashMap"),
("std::collections::hash::map::HashMap<alloc::string::String,ddc::db::DataFile>", "HashMap"),
("std::collections::hash::map::HashMap<alloc::string::String,alloc::vec::Vec<u8>>", "HashMap"),
("std::collections::hash::map::HashMap<alloc::string::String,ddc::db::TemplateFile>", "HashMap")
]
let representations =
if stringAsVec then
List.map(\(typeName, rep) -> (typeName, regexpReplace("String", "Vec", rep)), rawRepresentations)
else
rawRepresentations
let replaceWithRepresentation(typeName) = {
match findMap(\(key, value) -> if key == typeName then Just(value) else Nothing, representations) {
Nothing -> fail("No recorded representation for '${typeName}'")
Just(representation) -> representation
}
}
let withReplacedRepresentations = [List.map(replaceWithRepresentation, instantiation) | let instantiation <- instantiations]
List.for(nub(withReplacedRepresentations), print)
# List.for(representations, \(_, rep) -> print(rep))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment