Skip to content

Commit

Permalink
refactor vector
Browse files Browse the repository at this point in the history
  • Loading branch information
rahxephon89 committed Jul 9, 2024
1 parent 2e2b36a commit b4af060
Showing 1 changed file with 31 additions and 72 deletions.
103 changes: 31 additions & 72 deletions third_party/move/move-model/src/builder/exp_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3326,12 +3326,19 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo
} else {
expected_type.clone()
};
let _vec_exp_e = self.translate_exp_in_context(
vec_exp,
&Type::Vector(Box::new(inner_ty.clone())),
let ref_vec_exp_e = &sp(
vec_exp.loc,
EA::Exp_::Borrow(mutable, Box::new(vec_exp.clone())),
);
let vec_exp_e = self.translate_exp_in_context(
ref_vec_exp_e,
&Type::Reference(
ReferenceKind::from_is_mut(mutable),
Box::new(Type::Vector(Box::new(inner_ty.clone()))),
),
context,
);
let _idx_exp_e =
let idx_exp_e =
self.translate_exp_in_context(idx_exp, &Type::Primitive(PrimitiveType::U64), context);
if self.had_errors {
return self.new_error_exp();
Expand All @@ -3342,78 +3349,30 @@ impl<'env, 'translator, 'module_translator> ExpTranslator<'env, 'translator, 'mo
"vector::borrow"
};
// TODO: comment out because of #13888
// for m in self.env().get_modules() {
// if m.is_std_vector() {
// let mid = m.get_id();
// for f in m.get_functions() {
// if f.get_full_name_str() == target_str {
// let fid = f.get_id();
// let instantiated_inner = self.subs.specialize(&inner_ty);
// let node_id = self.env().new_node(
// loc.clone(),
// Type::Reference(
// ReferenceKind::from_is_mut(mutable),
// Box::new(instantiated_inner.clone()),
// ),
// );
// self.set_node_instantiation(node_id, vec![inner_ty.clone()]);
// let ref_type = Type::Reference(
// ReferenceKind::from_is_mut(mutable),
// Box::new(self.get_node_type(vec_exp_e.node_id())),
// );
// let ref_id = self.env().new_node(loc.clone(), ref_type);
// let exp = ExpData::Call(
// ref_id,
// Operation::Borrow(ReferenceKind::from_is_mut(mutable)),
// vec![vec_exp_e.clone().into_exp()],
// );
// let _call =
// ExpData::Call(node_id, Operation::MoveFunction(mid, fid), vec![
// exp.into_exp(),
// idx_exp_e.clone().into_exp(),
// ]);
// // return call;
// }
// }
// }
// }
let mut symbol_opt = None;
let mut module_opt = None;
for (name, mid) in &self.parent.parent.module_table {
let name_str = name.name().display(self.symbol_pool()).to_string();
if name_str == "vector" || name.addr().is_one() {
let module_env = self.parent.parent.env.get_module(*mid);
for fenv in module_env.get_functions() {
if fenv.get_full_name_str() == target_str {
let symbol = fenv.get_name();
symbol_opt = Some(symbol);
module_opt = Some(name.clone());
break;
for m in self.env().get_modules() {
if m.is_std_vector() {
let mid = m.get_id();
for f in m.get_functions() {
if f.get_full_name_str() == target_str {
let fid = f.get_id();
let instantiated_inner = self.subs.specialize(&inner_ty);
let node_id = self.env().new_node(
loc.clone(),
Type::Reference(
ReferenceKind::from_is_mut(mutable),
Box::new(instantiated_inner.clone()),
),
);
self.set_node_instantiation(node_id, vec![inner_ty.clone()]);
let call = ExpData::Call(node_id, Operation::MoveFunction(mid, fid), vec![
vec_exp_e.into_exp(),
idx_exp_e.clone().into_exp(),
]);
return call;
}
}
break;
}
}
if let (Some(symbol), Some(module_name)) = (symbol_opt, module_opt) {
let name_loc = &self.to_loc(&vec_exp.loc);
return self.translate_call(
loc,
name_loc,
CallKind::Regular,
&Some(module_name.clone()),
symbol,
&None,
&[
&sp(
vec_exp.loc,
EA::Exp_::Borrow(mutable, Box::new(vec_exp.clone())),
),
idx_exp,
],
expected_type,
context,
);
}
ExpData::Invalid(self.env().new_node_id())
}

Expand Down

0 comments on commit b4af060

Please sign in to comment.