Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
58c6636
initial setup
kentosugama Mar 10, 2023
551bc8c
add wasm-opt crate
kentosugama Apr 6, 2023
9e77b4b
wasm-opt scaffolding
kentosugama Apr 6, 2023
cbc47eb
remove boiler
kentosugama Apr 6, 2023
959a69d
scaffold
kentosugama Apr 6, 2023
cf8e985
extract the custom sectionsg
kentosugama Apr 6, 2023
645fc35
reinsert data sections
kentosugama Apr 6, 2023
6c41502
let user specify optimization level
kentosugama Apr 6, 2023
077559f
use proper temp file
kentosugama Apr 7, 2023
a7af326
recurse for actor classes
kentosugama Apr 7, 2023
c59205e
nicer error messages
kentosugama Apr 7, 2023
ccd1622
add some file tests
kentosugama Apr 7, 2023
65f18ca
add semantic tests
kentosugama Apr 7, 2023
2fae562
test different optimization levels
kentosugama Apr 10, 2023
a8e62ac
make test cases more complex
kentosugama Apr 10, 2023
a07a95a
test preservation of metadata sections
kentosugama Apr 10, 2023
9df6cbc
Add documentation in readme
kentosugama Apr 10, 2023
21dced7
Update README.md
kentosugama Apr 10, 2023
09d0424
move into shrink and remove test cases
kentosugama Apr 10, 2023
ec44977
merge conflict
kentosugama Apr 10, 2023
b40649c
move tests into shrink test
kentosugama Apr 10, 2023
d9229cd
change error handling to not exit
kentosugama Apr 10, 2023
deec640
remove a reparsing of module
kentosugama Apr 11, 2023
82fcb3d
update tests
kentosugama Apr 11, 2023
da85724
Bump version
kentosugama Apr 11, 2023
c163dcf
inline call to list_metadata
kentosugama Apr 11, 2023
1427f59
remove keep_name_section and rename function
kentosugama Apr 11, 2023
dd0b87c
remove redundant get
kentosugama Apr 11, 2023
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
Prev Previous commit
Next Next commit
reinsert data sections
  • Loading branch information
kentosugama committed Apr 6, 2023
commit 645fc352b250934b389ffc4036829c1616caeb86
27 changes: 20 additions & 7 deletions src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ pub fn optimize(m: &mut Module, keep_name_section: bool) {
let temp_file_name = "temp.opt.wasm";
let temp_path = PathBuf::from(temp_file_name);

// pull out the custom sections to preserve
// pull out a copy of the custom sections to preserve
let m_copy = parse_wasm(&m.emit_wasm(), keep_name_section).unwrap();
let mut metadata_sections = Vec::new();
list_metadata(m).iter().for_each(|full_name| {
list_metadata(&m_copy).iter().for_each(|full_name| {
match full_name.strip_prefix("icp:public ") {
Some(name) => metadata_sections.push(("public", name, get_metadata(m, name).unwrap())),
Some(name) => {
metadata_sections.push(("public", name, get_metadata(&m_copy, name).unwrap()))
}
None => match full_name.strip_prefix("icp:private ") {
Some(name) => {
metadata_sections.push(("private", name, get_metadata(m, name).unwrap()))
metadata_sections.push(("private", name, get_metadata(&m_copy, name).unwrap()))
}
None => unreachable!(),
},
Expand All @@ -30,8 +33,18 @@ pub fn optimize(m: &mut Module, keep_name_section: bool) {
.run(temp_file_name, temp_file_name)
.unwrap();

// FIXME re-insert the custom section before assigning back to m

// read back in from fs and assign back to m
// read optimized wasm back in from fs
*m = parse_wasm_file(temp_path, keep_name_section).unwrap();

// re-insert the custom sections
metadata_sections
.iter()
.for_each(|(visibility, name, data)| {
let visibility = match *visibility {
"public" => Kind::Public,
"private" => Kind::Private,
_ => unreachable!(),
};
add_metadata(m, visibility, name, data.to_vec());
});
}