-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
trying reuse filetests #211
Conversation
This PR aims only integrate some code to filetest infrastructure, reuse .clif files parsing, and just to compile some clif to zkasm and print it to stdout. No new checks performed. It would be followed up by next set of PRs:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use existing arithmetic.clif
or is there some reason it wouldn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arithmetic.clif
panics for now, and changes to fix it worth separate PR
|
||
// just wrap to make CI green until executor is not ready | ||
// TODO: replace by actual execution and results checking | ||
let _ = panic::catch_unwind(AssertUnwindSafe(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use panic::catch_unwind
rather sparingly as it increases the chance of catching and ignoring the wrong types of errors. Instead, we should rely on std::result
and check that we get the appropriate error code.
In this case, though, I think we can simplify things by removing the todo!
statement from the end of execute
and then we don't need the catch_unwind
at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From once side yes, it will simplify, from the other side, this annoying catch_unwind
and todo!
explicitly marks that this parts are not ready and should be rewritten
Ok(()) | ||
} | ||
|
||
fn generate_zkasm(_func_store: &FunctionStore, func: &Function) -> Vec<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not great that we duplicate the code from https://github.com/near/wasmtime/blob/main/cranelift/filetests/src/test_zkasm.rs. We need to move the shared bits into a separate module.
For example, we can start by creating a module in cranelift/filetests/src/zkasm_codegen.rs
and moving the necessary functions from https://github.com/near/wasmtime/blob/main/cranelift/filetests/src/test_zkasm.rs for this PR. Later, we can move all relevant functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will remove test_zkasm.rs
once test_run_zkasm.rs
will be ready. And than do some refactoring, such as creating zkasm_codegen.rs
if it will be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that code duplication like this should be avoided. This code might be touched for upcoming refactorings or zkASM instrumentation. Keeping duplicate code in sync is tedious and if it gets out of sync that might lead to issues which are hard to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm definitely agree that we don't want have a code duplication. But, one more problem, it's not pure duplication, this functions are rewrited a bit for test_run_zkasm.rs
. And, until filetest infra is not ready we want to keep both versions -- one to keep existing test infra alive, the second one -- to make iterative progress to the new test infra.
As alternative, I can suggest to create some filtest-dev
branch. Code still will be reviewed before go to that branch, but we can make some exceptions for such problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully, #216 can be a good start for the refactoring to avoid duplication.
But, one more problem, it's not pure duplication, this functions are rewrited a bit for test_run_zkasm.rs
Can you please document the necessary changes so that it is easier to reconcile these two functions in the future?
Btw does anybody knows what this failed windows tests telling? I see |
This file was added in #213 - have you rebased on the latest main branch? |
Last commit changed structure of |
_: &'a Flags, | ||
_: Option<&'a dyn TargetIsa>, | ||
) -> anyhow::Result<()> { | ||
let mut zkasm_functions: Vec<Vec<String>> = Default::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Given that we have a simple Vec
type on the left, we could use a more specific Vec::new()
instead of Default::default()
:
- This will avoid bringing in additional dependency on
Default
- The resulting code will be simpler (shorter; don't have to know what is the
Default::default()
forVec
)
let mut zkasm_functions: Vec<Vec<String>> = Default::default(); | ||
let mut invocations: Vec<Vec<String>> = Default::default(); | ||
for (func, details) in &testfile.functions { | ||
let zkasm_function = zkasm_codegen::compile_clif_function(func); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I don't think zkasm_function
temporary variable adds any more clarity to the code, consider inlining it:
zkasm_functions.push(zkasm_codegen::compile_clif_function(func));
RunCommand::Print(_) => { | ||
unreachable!() | ||
} | ||
RunCommand::Run(invoce, compare, expected) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Counterintuitive, but a verb from "invocation" is "invoke".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, I was thinking for a moment that "invoke" looks much better, thanks!
unreachable!() | ||
} | ||
RunCommand::Run(invoce, compare, expected) => { | ||
let invocation = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto: this temporary is not adding much value
let isa = isa_builder | ||
.finish(settings::Flags::new(flag_builder)) | ||
.unwrap(); | ||
let mut comp_ctx = cranelift_codegen::Context::for_function(func.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "comp_ctx" -> "context" to follow the same convention as generate_zkasm
above?
// now it works for one very basic case | ||
pub fn build_test_zkasm(functions: Vec<Vec<String>>, invocations: Vec<Vec<String>>) -> String { | ||
// TODO: use generate_preambule to get preambule | ||
let preambule = "start:\n zkPC + 2 => RR\n :JMP(main)\n :JMP(finalizeExecution)"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits:
- "preambule" -> "preamble"
- Let's make it more readable by splitting across multiple lines:
let preamble = "\
start:
zkPC + 2 => RR
:JMP(main)
:JMP(finalizeExecution)";
]; | ||
for invoce in invocations { | ||
// TODO: remove this .clone() | ||
main.append(&mut invoce.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use Vec::extend
for this with something like
main.extend(invocations.iter().cloned())
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main.extend()
expects Vec<String>
while invocations
is Vec<Vec<String>>
. And I'm not sure but I guess this .cloned()
performs same amount of copying as .clone()
, isn't it?
But
for invocation in invocations {
main.extend(invocation);
}
works.
} | ||
main.push(" SP - 1 => SP".to_string()); | ||
main.push(" :JMP(RR)".to_string()); | ||
let mut postabmule = generate_postamble(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "postabmule" -> "postamble"
if let Some(command) = parse_run_command(comment.text, &func.signature)? { | ||
match command { | ||
RunCommand::Print(_) => { | ||
unreachable!() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a todo!()
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't know really now. I didn't see any Print
command yet. And if we will somehow adopt cranelift tests to zkasm (for example remove test interpret
from the header) removing print commands is normal strategy imo. But maybe todo!()
is really better here
; run: %add_i64(0, 0) == 0 | ||
; run: %add_i64(0, 1) == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these call %sub_i64
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks (= But this file is not supposed to really test something, it is more for me to debug the filetest
// TODO: this function should be much rewrited, | ||
// now it works for one very basic case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could describe the one case it works for and outline how it needs to be rewritten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It must be rewritten before we will migrate to this infra (optimistically before end of Feb), and I think nobody except me will do this, so this comment is just a signal for reviewers to not ask replace this assembling to something better, because I will do it in next PRs
// TODO: this function should be much rewrited, | ||
// now it works for one very basic case | ||
pub fn build_test_zkasm(functions: Vec<Vec<String>>, invocations: Vec<Vec<String>>) -> String { | ||
// TODO: use generate_preambule to get preambule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: use generate_preambule to get preambule | |
// TODO: use generate_preamble to get preamble |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Thanks! I bet merging this PR is not blocking me and we can wait windows tests fix |
@Akashin, now CI is green and all review notes marked as outdated. Should we merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's ship this!
Just small attempt to reuse some infra from filetests, for example
.clif
runtests parsing. Not ready to use