Skip to content
This repository was archived by the owner on Jan 17, 2022. It is now read-only.

Conversation

lexfrl
Copy link
Contributor

@lexfrl lexfrl commented Jul 31, 2018

Just a subtraction of build logic to a lib

@lexfrl lexfrl requested review from pepyakin and NikVolf and removed request for pepyakin and NikVolf July 31, 2018 18:15
@lexfrl
Copy link
Contributor Author

lexfrl commented Jul 31, 2018

don't quite understand a reason why

test optimizer::tests::call_indirect ... FAILED

But locally it passes. And also there is no changes in optimizer code..

@lexfrl
Copy link
Contributor Author

lexfrl commented Jul 31, 2018

so, it failing in master too https://travis-ci.org/paritytech/wasm-utils/builds/410384083

@pepyakin
Copy link
Contributor

The error seems to come from the newest parity-wasm library, in particular this change.

@lexfrl lexfrl force-pushed the move-build-to-lib branch from bea81dc to e84600d Compare August 1, 2018 10:04
matches.is_present("enforce_stack_adjustment"),
matches.value_of("shrink_stack").unwrap_or_else(|| "49152").parse()
.expect("New stack size is not valid u32"),
matches.is_present("skip_optimization")).map_err(Error::Build)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

).map_err should be on the next line


parity_wasm::serialize_to_file(
&path,
ctor_module.expect("ctor_module shouldn't be None, b/c 'constructor' argument is set to true in build")
Copy link
Contributor

Choose a reason for hiding this comment

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

b/c ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because

Copy link
Contributor

Choose a reason for hiding this comment

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

can we avoid non-obvious abbreviations?

src/build.rs Outdated
target: Target,
runtime_type: Option<&[u8]>,
runtime_version: Option<u32>,
mut public_api_entries: Vec<&str>,
Copy link
Contributor

@NikVolf NikVolf Aug 1, 2018

Choose a reason for hiding this comment

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

this is a bad choice for this argument in signature for public api

&[&str] would be ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you explain? I'd better to use [u8; 4] or u32, not &str

Copy link
Contributor

Choose a reason for hiding this comment

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

because it allows wider use of types when invoking the function

&vec!["a", "b"][..], &["a", "b"], &["a", "b"][1..], etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to use the type system soundness here. So I'd better use [u8; 4] here

Copy link
Contributor

Choose a reason for hiding this comment

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

what is [u8; 4]? how it is related to Vec<&str>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so for user it will be more descriptive API which could help to avoid the runtime error

Copy link
Contributor

Choose a reason for hiding this comment

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

how can you put a string in [u8; 4] ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cause for runtime_type we use exactly 4 bytes. Would be nice to declare it as it is 🤗

Copy link
Contributor

@NikVolf NikVolf Aug 1, 2018

Choose a reason for hiding this comment

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

the conversation is about strings for public_api_entries argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, ok 🙈

if constructor {
if !has_ctor(&ctor_module) {
Err(Error::NoCreateSymbolFound)?
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what are the identation here? some spaces + tab?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cant find any spaces in indentation in this snippet

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm.. probably github changed the way how it displays the diff

Copy link
Contributor

Choose a reason for hiding this comment

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

looks ok, sorry

}

pub fn build(
mut module: elements::Module,
Copy link
Contributor

Choose a reason for hiding this comment

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

bad identations everywhere

Copy link
Contributor Author

@lexfrl lexfrl Aug 1, 2018

Choose a reason for hiding this comment

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

I don't understand, why you think so?

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like tabs everywhere, sorry

@lexfrl lexfrl force-pushed the move-build-to-lib branch from e84600d to 03e4df3 Compare August 1, 2018 10:59
src/build.rs Outdated
mut public_api_entries: Vec<&str>,
enforce_stack_adjustment: bool,
stack_size: u32,
skip_optimization: bool) -> Result<(elements::Module, Option<elements::Module>), Error> {
Copy link
Contributor

@NikVolf NikVolf Aug 1, 2018

Choose a reason for hiding this comment

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

but this is bad should be

	skip_optimization: bool,
) -> Result<(elements::Module, Option<elements::Module>), Error> {

src/build.rs Outdated
inject_runtime_type,
PackingError,
OptimizerError
};
Copy link
Contributor

Choose a reason for hiding this comment

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

should be at the beginning of the line

src/build.rs Outdated
use parity_wasm;
use parity_wasm::elements;


Copy link
Contributor

Choose a reason for hiding this comment

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

redundant empty line

src/build.rs Outdated
}
let ctor_module =
pack_instance(
parity_wasm::serialize(module.clone()).map_err(Error::Encoding)?, ctor_module.clone())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

bad indentations

should use smth like

pack_instance(
   ... arguments
)?;

@lexfrl lexfrl force-pushed the move-build-to-lib branch 2 times, most recently from 5e4dd63 to 1694e6f Compare August 1, 2018 11:33
src/build.rs Outdated
}
let ctor_module = pack_instance(
parity_wasm::serialize(module.clone()).map_err(Error::Encoding)?,
ctor_module.clone()
Copy link
Contributor

Choose a reason for hiding this comment

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

there should be a comma after the last argument

@lexfrl lexfrl force-pushed the move-build-to-lib branch from 1694e6f to d2749e6 Compare August 1, 2018 11:35
src/build.rs Outdated
}

#[derive(Debug, Clone, Copy)]
pub enum Target {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Target is better name that SourceTarget, since SourceTarget outlines that it is the target which we take as a source to process further

Copy link
Contributor Author

@lexfrl lexfrl Aug 1, 2018

Choose a reason for hiding this comment

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

sure.
But because now it lives in build.rs, which don't care know about "files" and now it doesn't require such a context clarification, IMO

Copy link
Contributor

Choose a reason for hiding this comment

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

But the logic retained
Why not call it "source" then?


parity_wasm::serialize_to_file(
&path,
ctor_module.expect("ctor_module can't be None, because 'constructor' argument is set to true in build")
Copy link
Contributor

Choose a reason for hiding this comment

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

there should be a comma after the last argument when each is on a dedicated line

@lexfrl lexfrl force-pushed the move-build-to-lib branch from d2749e6 to 1124b50 Compare August 1, 2018 11:47
src/build.rs Outdated
pub fn build(
mut module: elements::Module,
constructor: bool,
target: SourceTarget,
Copy link
Contributor

Choose a reason for hiding this comment

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

source_target as well?

@lexfrl lexfrl force-pushed the move-build-to-lib branch from ecb5fa6 to e97ccd7 Compare August 1, 2018 12:29
src/build.rs Outdated
mut module: elements::Module,
constructor: bool,
source_target: SourceTarget,
runtime_type: Option<[u8; 4]>,
Copy link
Contributor

Choose a reason for hiding this comment

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

should it be runtime_spec: Option<([u8; 4], u32)> (or dedicated struct inside Option) instead of two parameters?

it's even parsed from cli this way - either both are present, or both are None

Copy link
Contributor Author

@lexfrl lexfrl Aug 1, 2018

Choose a reason for hiding this comment

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

make sense. I'd like also add a struct for additional params (flags)

src/build.rs Outdated
shrink_unknown_stack,
inject_runtime_type,
PackingError,
OptimizerError
Copy link
Contributor

Choose a reason for hiding this comment

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

comma

src/build.rs Outdated
public_api_entries: &[&str],
enforce_stack_adjustment: bool,
stack_size: u32,
skip_optimization: bool
Copy link
Contributor

Choose a reason for hiding this comment

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

comma

fn from(err: utils::PackingError) -> Self {
Error::Packing(err)
}
Build(BuildError)
Copy link
Contributor

Choose a reason for hiding this comment

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

comma

@lexfrl lexfrl force-pushed the move-build-to-lib branch from 326b271 to 4dcab78 Compare August 1, 2018 13:17
@lexfrl lexfrl force-pushed the move-build-to-lib branch from d6cdf08 to dc2b350 Compare August 1, 2018 13:31
@NikVolf
Copy link
Contributor

NikVolf commented Aug 1, 2018

Great job

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants