Skip to content
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

[compiler-v2] v2 uses more stack space #14243

Open
wrwg opened this issue Aug 10, 2024 · 0 comments
Open

[compiler-v2] v2 uses more stack space #14243

wrwg opened this issue Aug 10, 2024 · 0 comments
Assignees
Labels
bug Something isn't working compiler-v2-stable compiler-v2 stale-exempt Prevents issues from being automatically marked and closed as stale

Comments

@wrwg
Copy link
Contributor

wrwg commented Aug 10, 2024

Given the following source:

//# print-bytecode --input=module
module 0xc0ffee::m {
   fun id_mut<T>(r: &mut T): &mut T {
        r
    }

    fun t0() {
        let x = &mut 0;
        let y = id_mut(x);
        *y;
        *x;
    }
}

... v1 creates bytecode which pops the unused *y immediately from the stack:

// Move bytecode v6
module c0ffee.m {


id_mut<Ty0>(Arg0: &mut Ty0): &mut Ty0 /* def_idx: 0 */ {
B0:
	0: MoveLoc[0](Arg0: &mut Ty0)
	1: Ret
}
t0() /* def_idx: 1 */ {
L0:	loc0: u64
L1:	loc1: &mut u64
B0:
	0: LdU64(0)
	1: StLoc[0](loc0: u64)
	2: MutBorrowLoc[0](loc0: u64)
	3: StLoc[1](loc1: &mut u64)
	4: CopyLoc[1](loc1: &mut u64)
	5: Call id_mut<u64>(&mut u64): &mut u64
	6: ReadRef
	7: Pop
	8: MoveLoc[1](loc1: &mut u64)
	9: ReadRef
	10: Pop
	11: Ret
}
}

But v2 waits with the pop until the end:

// Move bytecode v7
module c0ffee.m {


id_mut<Ty0>(Arg0: &mut Ty0): &mut Ty0 /* def_idx: 0 */ {
B0:
	0: MoveLoc[0](Arg0: &mut Ty0)
	1: Ret
}
t0() /* def_idx: 1 */ {
L0:	loc0: u64
L1:	loc1: &mut u64
L2:	loc2: &mut u64
B0:
	0: LdU64(0)
	1: StLoc[0](loc0: u64)
	2: MutBorrowLoc[0](loc0: u64)
	3: StLoc[1](loc1: &mut u64)
	4: CopyLoc[1](loc1: &mut u64)
	5: Call id_mut<u64>(&mut u64): &mut u64
	6: ReadRef
	7: MoveLoc[1](loc1: &mut u64)
	8: ReadRef
	9: Pop
	10: Pop
	11: Ret
}
}

Need to investigate whether this is a sign of a deeper issue in stack size usage in real world code.

@wrwg wrwg added the bug Something isn't working label Aug 10, 2024
@sausagee sausagee added stale-exempt Prevents issues from being automatically marked and closed as stale compiler-v2 labels Aug 22, 2024
@brmataptos brmataptos moved this from 🆕 New to Assigned in Move Language and Runtime Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler-v2-stable compiler-v2 stale-exempt Prevents issues from being automatically marked and closed as stale
Projects
Status: Assigned
Development

No branches or pull requests

4 participants