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

[Feature] [Compiler-V2] += and the like #14583

Merged
merged 60 commits into from
Oct 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
a72ea5e
impl += for *(lhs()) += rhs()
Aug 28, 2024
95065d2
impl += for other cases
Aug 30, 2024
9a34d50
refactor
Sep 11, 2024
e3a6025
format
Sep 11, 2024
43c48b5
refactor
Sep 11, 2024
5871826
optimize
Sep 11, 2024
74a0d26
add tests
Sep 12, 2024
d73c78e
update tests
Sep 13, 2024
cd35b48
rename tmp
Sep 13, 2024
3ecf1c8
add tests
Sep 13, 2024
fdaafba
add todo
Sep 17, 2024
61e8eb6
change loc
Sep 17, 2024
7d2634f
remove unused var
Sep 17, 2024
2cd83e0
update test
Sep 17, 2024
37bb3dc
gate feature
Sep 17, 2024
c55a859
update tests
Sep 17, 2024
058ba91
add transactional tests
Sep 17, 2024
7506cea
format
Sep 17, 2024
a8af4f8
add tests
Sep 17, 2024
27a241d
add tests
Sep 17, 2024
7a304c0
move the transformation to expansion phase
Sep 18, 2024
26e968a
refactor
Sep 19, 2024
53db6fb
support more ops
Sep 19, 2024
fdd59c1
format
Sep 19, 2024
851c5b0
add test
Sep 19, 2024
1abb954
update tests
Sep 19, 2024
456ae7f
remove test dir
Sep 19, 2024
71c2b76
rename testdir
Sep 19, 2024
ec0a170
update tests
Sep 19, 2024
2b18d99
add tests
Sep 20, 2024
cc937be
remove commented function
Sep 20, 2024
ebda849
remove comments
Sep 24, 2024
5b43ad0
update tests
Sep 24, 2024
96b070e
update tests
Sep 24, 2024
6ad78f0
update tests
Sep 24, 2024
bd630d9
typo
Sep 24, 2024
50bc663
refactor
Sep 24, 2024
74d9fcd
add tests
Sep 26, 2024
17e2b59
bug fix: eval order of op =
Oct 1, 2024
aa0ba02
bug fix cont: eval order op =
Oct 1, 2024
2acb1f1
comment
Oct 1, 2024
4175c65
refactor
Oct 1, 2024
06f2f8d
update tests
Oct 1, 2024
d8f09ed
update test
Oct 1, 2024
76bb472
update tests
Oct 1, 2024
d646650
update tests
Oct 1, 2024
8fed2c2
remove comment
Oct 1, 2024
7229ba2
update comments
Oct 1, 2024
4d1ee61
comment
Oct 1, 2024
b7b7899
comment
Oct 1, 2024
2804253
refactor
Oct 1, 2024
0134630
refactor
Oct 1, 2024
e8ea100
refactor
Oct 1, 2024
f06491a
comment
Oct 1, 2024
4640d14
refactor
Oct 1, 2024
4379af0
add tests
Oct 2, 2024
44175bf
add tests
Oct 2, 2024
5f398a4
lint
Oct 2, 2024
44f851c
lint
Oct 2, 2024
2cebd2a
bug fix
Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bug fix cont: eval order op =
Zekun Wang committed Oct 2, 2024
commit aa0ba0250f1f3ddec6d1222030fc74fe54eecbb9
82 changes: 53 additions & 29 deletions third_party/move/move-compiler/src/expansion/translate.rs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may want another variant of LValue for vector indexing.

Original file line number Diff line number Diff line change
@@ -2711,33 +2711,45 @@ fn exp_(context: &mut Context, sp!(loc, pe_): P::Exp) -> E::Exp {
match op_opt {
// *e1 += e2
// =>
// { let t = e1; *t = *t + e2 }
// { let t2 = e2; let t1 = e1; *t1 = *t1 + t2 }
Some(op) => {
let inner_loc = el.loc;
fEst1ck marked this conversation as resolved.
Show resolved Hide resolved
// t
let tmp_symbol = Symbol::from("$t");
// t1
let tmp_symbol = Symbol::from("$t1");
let tmp_name = sp(inner_loc, tmp_symbol);
let mod_acc = ModuleAccess_::Name(tmp_name);
let tmp_ = EE::Name(sp(inner_loc, mod_acc.clone()), None);
let tmp = sp(inner_loc, tmp_);
// let t = e1;
let lval_ = LValue_::Var(sp(inner_loc, mod_acc), None);
let mod_acc1 = ModuleAccess_::Name(tmp_name);
let tmp_ = EE::Name(sp(inner_loc, mod_acc1.clone()), None);
let tmp1 = sp(inner_loc, tmp_);
// t2
let tmp_symbol = Symbol::from("$t2");
let tmp_name = sp(inner_loc, tmp_symbol);
let mod_acc2 = ModuleAccess_::Name(tmp_name);
let tmp_ = EE::Name(sp(inner_loc, mod_acc2.clone()), None);
let tmp2 = sp(inner_loc, tmp_);
// let t2 = e2;
let lval_ = LValue_::Var(sp(inner_loc, mod_acc2), None);
let lval = sp(inner_loc, lval_);
let lvals = sp(inner_loc, vec![lval]);
let bind_ = SequenceItem_::Bind(lvals, *er);
let bind2 = sp(inner_loc, bind_);
// let t1 = e1;
let lval_ = LValue_::Var(sp(inner_loc, mod_acc1), None);
let lval = sp(inner_loc, lval_);
let lvals = sp(inner_loc, vec![lval]);
let bind_ = SequenceItem_::Bind(lvals, match &el.value {
EE::Index(..) => sp(inner_loc, EE::Borrow(true, el)),
_ => *el,
});
let bind = sp(inner_loc, bind_);
// *t
let deref_tmp = sp(loc, EE::Dereference(Box::new(tmp.clone())));
// *t + e2
let rhs_expanded = sp(loc, EE::BinopExp(Box::new(deref_tmp), op, er));
// *t = *t + e2
let assign = sp(loc, EE::Mutate(Box::new(tmp), Box::new(rhs_expanded)));
// { let t = e1; *t = *t + e2 }
let bind1 = sp(inner_loc, bind_);
// *t1
let deref_tmp1 = sp(loc, EE::Dereference(Box::new(tmp1.clone())));
// *t1 + t2
let rhs_expanded = sp(loc, EE::BinopExp(Box::new(deref_tmp1), op, Box::new(tmp2)));
// *t1 = *t1 + t2
let assign = sp(loc, EE::Mutate(Box::new(tmp1), Box::new(rhs_expanded)));
// { let t2 = e2; let t1 = e1; *t1 = *t1 + t2 }
let sequence =
VecDeque::from([bind, sp(loc, SequenceItem_::Seq(assign))]);
VecDeque::from([bind2, bind1, sp(loc, SequenceItem_::Seq(assign))]);
EE::Block(sequence)
},
None => EE::Mutate(el, er),
@@ -2746,15 +2758,27 @@ fn exp_(context: &mut Context, sp!(loc, pe_): P::Exp) -> E::Exp {
Some(LValue::FieldMutate(edotted)) => match op_opt {
// e1.f += e2
// =>
// { let t = &mut e1.f; *t = *t + e2 }
// { let t2 = e2; let t1 = &mut e1.f; *t1 = *t1 + t2 }
Some(op) => {
let lhs_loc = edotted.loc;
// t
// t2
let tmp_symbol = Symbol::from("$t2");
let tmp_name = sp(lhs_loc, tmp_symbol);
let mod_acc2 = ModuleAccess_::Name(tmp_name);
let tmp_ = EE::Name(sp(lhs_loc, mod_acc2.clone()), None);
let tmp2 = sp(lhs_loc, tmp_);
// let t2 = e2;
let lval_ = LValue_::Var(sp(lhs_loc, mod_acc2), None);
let lval = sp(lhs_loc, lval_);
let lvals = sp(lhs_loc, vec![lval]);
let bind_ = SequenceItem_::Bind(lvals, *er);
let bind2 = sp(lhs_loc, bind_);
// t1
let tmp_symbol = Symbol::from("$t");
let tmp_name = sp(lhs_loc, tmp_symbol);
let mod_acc = ModuleAccess_::Name(tmp_name);
let tmp_ = EE::Name(sp(lhs_loc, mod_acc.clone()), None);
let tmp = sp(lhs_loc, tmp_);
let tmp1 = sp(lhs_loc, tmp_);
// e1.f
let e = sp(edotted.loc, EE::ExpDotted(edotted));
// &mut e1.f
@@ -2764,15 +2788,15 @@ fn exp_(context: &mut Context, sp!(loc, pe_): P::Exp) -> E::Exp {
let lval = sp(lhs_loc, lval_);
let lvals = sp(lhs_loc, vec![lval]);
let bind_ = SequenceItem_::Bind(lvals, e_mut);
let bind = sp(lhs_loc, bind_);
// *t
let deref_tmp = sp(loc, EE::Dereference(Box::new(tmp.clone())));
// *t + e2
let rhs_expanded = sp(loc, EE::BinopExp(Box::new(deref_tmp), op, er));
// *t = *t + e2
let assign = sp(loc, EE::Mutate(Box::new(tmp), Box::new(rhs_expanded)));
// { let t = *e1; *t = *t + e2 }
let sequence = VecDeque::from([bind, sp(loc, SequenceItem_::Seq(assign))]);
let bind1 = sp(lhs_loc, bind_);
// *t1
let deref_tmp1 = sp(loc, EE::Dereference(Box::new(tmp1.clone())));
// *t1 + t2
let rhs_expanded = sp(loc, EE::BinopExp(Box::new(deref_tmp1), op, Box::new(tmp2)));
// *t1 = *t1 + t2
let assign = sp(loc, EE::Mutate(Box::new(tmp1), Box::new(rhs_expanded)));
// { let t2 = e2; let t1 = &mut e1.f; *t1 = *t1 + t2 }
let sequence = VecDeque::from([bind2, bind1, sp(loc, SequenceItem_::Seq(assign))]);
EE::Block(sequence)
},
None => EE::FieldMutate(edotted, er),