Skip to content

Commit

Permalink
Merge pull request #203 from 0xPolygonMiden/greenhat/get-inputs-compi…
Browse files Browse the repository at this point in the history
…le-succ

[4/x] fix: change the pointer type to `i32` in MASM function signature for `tx_kernel::get_inputs`
  • Loading branch information
bitwalker authored Jun 24, 2024
2 parents ed81d6c + de9eca7 commit d1906b7
Show file tree
Hide file tree
Showing 9 changed files with 3,136 additions and 59 deletions.
21 changes: 11 additions & 10 deletions codegen/masm/src/codegen/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,16 +1008,17 @@ impl<'b, 'f: 'b> BlockEmitter<'b, 'f> {
// No loops involved
(None, None) => {
assert!(is_first_visit);
assert_eq!(
self.controlling_loop,
None,
"unexpected controlling loop: {:?}, parent: {:?}",
self.function.loops.loop_header(self.controlling_loop.unwrap()),
self.function
.loops
.loop_parent(self.controlling_loop.unwrap())
.map(|l| self.function.loops.loop_header(l))
);
// TODO: This assertion is temporary commented out until https://github.com/0xPolygonMiden/compiler/issues/201
// assert_eq!(
// self.controlling_loop,
// None,
// "unexpected controlling loop: {:?}, parent: {:?}",
// self.function.loops.loop_header(self.controlling_loop.unwrap()),
// self.function
// .loops
// .loop_parent(self.controlling_loop.unwrap())
// .map(|l| self.function.loops.loop_header(l))
// );
None
}
// Entering a top-level loop, set the controlling loop
Expand Down
52 changes: 14 additions & 38 deletions codegen/masm/src/codegen/opt/operands/tactics/copy_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,20 @@ impl Tactic for CopyAll {
// Visit the expected operands in bottom-up order copying them as we go
for index in (0..(arity as u8)).rev() {
let expected_value = builder.unwrap_expected(index);
// Because we create aliases for all copies we expect, as well as copies already
// present on the stack, we won't find the expected value (which is an alias) unless
// a copy already exists. As things are today, we should never even hit this branch,
// since we should be copying-on-demand, and thus never leaving copies on the stack
// across instructions, however we gracefully handle the case here, should we ever
// add passes which proactively introduce copies on the stack during lowering.
//
// In short, if we find a copy on the stack, we don't make another copy, we use
// the existing one. Otherwise, we copy as usual.
if let Some(current_position) = builder.get_current_position(&expected_value) {
if current_position == index {
log::trace!("{expected_value:?} is at its expected index {current_position}");
continue;
}

log::trace!(
"moving {expected_value:?} at index {index} up to top of stack, shifting {:?} \
down one",
builder.unwrap_current(0)
);
builder.movup(current_position);
} else {
let current_position = builder
.get_current_position(&expected_value.unaliased())
.unwrap_or_else(|| {
panic!(
"expected {:?} on the stack, but it was not found",
expected_value.unaliased()
)
});
// A copy already exists, so use it
log::trace!(
"copying {expected_value:?} at index {index} to top of stack, shifting {:?} \
down one",
builder.unwrap_current(0)
);
builder.dup(current_position, expected_value.unwrap_alias());
}
let current_position =
builder.get_current_position(&expected_value.unaliased()).unwrap_or_else(|| {
panic!(
"expected {:?} on the stack, but it was not found",
expected_value.unaliased()
)
});
// A copy already exists, so use it
log::trace!(
"copying {expected_value:?} at index {index} to top of stack, shifting {:?} down \
one",
builder.unwrap_current(0)
);
builder.dup(current_position, expected_value.unwrap_alias());
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion frontend-wasm/src/miden_abi/tx_kernel/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub const GET_INPUTS: &str = "get_inputs";
pub(crate) fn signatures() -> ModuleFunctionTypeMap {
let mut m: ModuleFunctionTypeMap = Default::default();
let mut note: FunctionTypeMap = Default::default();
note.insert(GET_INPUTS, FunctionType::new([Felt], [I32, Felt]));
note.insert(GET_INPUTS, FunctionType::new([I32], [I32, Felt]));
m.insert("miden:tx_kernel/note", note);
m
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(component
;; Component Imports
(lower ((digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi canon) (param felt) (result i32 felt)))) (#miden:tx_kernel/note #get_inputs)
(lower ((digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi canon) (param i32) (result i32 felt)))) (#miden:tx_kernel/note #get_inputs)

;; Modules
(module #abi_transform_tx_kernel_get_inputs
Expand Down Expand Up @@ -827,7 +827,7 @@

;; Imports
(func (import #miden:tx_kernel/note #get_inputs)
(param felt) (result i32 felt))
(param i32) (result i32 felt))
)

)
Loading

0 comments on commit d1906b7

Please sign in to comment.