Skip to content

Conversation

@axic
Copy link
Member

@axic axic commented Jan 14, 2019

Implements #48.

@axic axic requested a review from jakelang January 14, 2019 01:58
use parity_wasm::elements::*;

/// Enum on which ModuleTranslator is implemented.
pub enum DropSection<'a> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably will rewrite to have this as DropSectionKind and DropSection as a vector of DropSectionKind. In that case the entire code can be rewritten somewhat, potentially with a single loop, though one must be careful when removing sections with a lower index.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this rewrite I could also introduce with_preset with ewasm which removes the namessection and all custom sections with names debug.


let sections = module.sections_mut();
if index > sections.len() {
return Err(ModuleError::Custom("Not found.".to_string()));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this should be considered an error or marked as Ok(false).

Potentially we need a flag in the translator configuration saying whether fields not found is an error or not and behave accordingly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is no case where Ok(false) is returned and false indicates no mutation, it probably makes sense that this should be OK. Although a flag would make it more versatile.

impl<'a> DropSection<'a> {
fn find_index(&self, module: &Module) -> Result<usize, String> {
Ok(match &self {
DropSection::NamesSection => names_section_index_for(module)?,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was named _for because it had a section enum as a parameter to be generic. If we keep these helpers, they need better naming.

@jakelang jakelang added the wip label Jan 15, 2019
pub enum DropSection<'a> {
NamesSection,
/// Name of the custom section.
CustomSectionByName(&'a String),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps another mode for DropSection would be identifying data sections that are used for rust debugging and panic messages.
Identifying these is not exactly straightforward, but one option is just using a plain regex lookup for things like libcore in the data sections. Not sure what the risk of false positives for this would be.

@axic
Copy link
Member Author

axic commented Apr 11, 2019

@jakelang where do we stand with this?

@axic axic force-pushed the dropsection branch 3 times, most recently from 0c62c18 to da86747 Compare June 4, 2019 12:20
@jakelang jakelang added enhancement New feature or request ready Ready for review and merge and removed wip labels Jun 4, 2019
@jakelang jakelang merged commit 8681504 into master Jun 20, 2019
@jakelang jakelang deleted the dropsection branch June 20, 2019 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready Ready for review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants