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

Revert "[compiler v2] Fix bugs around compilation of vector code" #9643

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 2 additions & 40 deletions third_party/move/move-compiler-v2/src/bytecode_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ impl<'env> Generator<'env> {
// Dispatcher

impl<'env> Generator<'env> {
/// Generate code, for the given expression, and store the result in the given temporary.
fn gen(&mut self, targets: Vec<TempIndex>, exp: &Exp) {
match exp.as_ref() {
ExpData::Invalid(id) => self.internal_error(*id, "invalid expression"),
Expand Down Expand Up @@ -719,25 +720,7 @@ impl<'env> Generator<'env> {
.env()
.get_node_instantiation_opt(id)
.unwrap_or_default();
// Function calls can have implicit conversion of &mut to &, need to compute implicit
// conversions.
let param_types: Vec<Type> = self
.env()
.get_function(fun)
.get_parameters()
.into_iter()
.map(|Parameter(_, ty)| ty.instantiate(&type_args))
.collect();
if args.len() != param_types.len() {
self.internal_error(id, "inconsistent type arity");
return;
}
let args = args
.iter()
.zip(param_types.into_iter())
.map(|(e, t)| self.maybe_convert(e, &t))
.collect::<Vec<_>>();
let args = self.gen_arg_list(&args);
let args = self.gen_arg_list(args);
self.emit_with(id, |attr| {
Bytecode::Call(
attr,
Expand All @@ -749,27 +732,6 @@ impl<'env> Generator<'env> {
})
}

/// Convert the expression so it matches the expected type. This is currently only needed
/// for `&mut` to `&` conversion, in which case we need to to introduce a Freeze operation.
fn maybe_convert(&self, exp: &Exp, expected_ty: &Type) -> Exp {
let id = exp.node_id();
let exp_ty = self.env().get_node_type(id);
if let (
Type::Reference(ReferenceKind::Mutable, _),
Type::Reference(ReferenceKind::Immutable, et),
) = (exp_ty, expected_ty)
{
let freeze_id = self
.env()
.new_node(self.env().get_node_loc(id), expected_ty.clone());
self.env()
.set_node_instantiation(freeze_id, vec![et.as_ref().clone()]);
ExpData::Call(freeze_id, Operation::Freeze, vec![exp.clone()]).into_exp()
} else {
exp.clone()
}
}

fn gen_arg_list(&mut self, exps: &[Exp]) -> Vec<TempIndex> {
exps.iter().map(|exp| self.gen_arg(exp)).collect()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,7 @@ impl<'a> FunctionGenerator<'a> {
) {
let fun_ctx = ctx.fun_ctx;
self.abstract_push_args(ctx, source);
if let Some(opcode) = ctx.fun_ctx.module.get_well_known_function_code(
&ctx.fun_ctx.loc,
id,
Some(
self.gen
.signature(&ctx.fun_ctx.module, &ctx.fun_ctx.loc, inst.to_vec()),
),
) {
self.emit(opcode)
} else if inst.is_empty() {
if inst.is_empty() {
let idx = self.gen.function_index(
&fun_ctx.module,
&fun_ctx.loc,
Expand All @@ -532,7 +523,7 @@ impl<'a> FunctionGenerator<'a> {
let idx = self.gen.function_instantiation_index(
&fun_ctx.module,
&fun_ctx.loc,
&fun_ctx.module.env.get_function(id),
fun_ctx.fun.func_env,
inst.to_vec(),
);
self.emit(FF::Bytecode::CallGeneric(idx))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use move_binary_format::{
};
use move_core_types::{account_address::AccountAddress, identifier::Identifier};
use move_model::{
ast::Address,
model::{
FieldEnv, FunId, FunctionEnv, GlobalEnv, Loc, ModuleEnv, ModuleId, Parameter, QualifiedId,
StructEnv, StructId, TypeParameter, TypeParameterKind,
Expand Down Expand Up @@ -624,41 +623,4 @@ impl<'env> ModuleContext<'env> {
value as FF::TableIndex
}
}

/// Get the file format opcode for a well-known function. This applies currently to a set
/// vector functions which have builtin opcodes. Gets passed an optional type instantiation
/// in form of a signature.
pub fn get_well_known_function_code(
&self,
loc: &Loc,
qid: QualifiedId<FunId>,
inst_sign: Option<FF::SignatureIndex>,
) -> Option<FF::Bytecode> {
let fun = self.env.get_function(qid);
let mod_name = fun.module_env.get_name();
if mod_name.addr() != &Address::Numerical(AccountAddress::ONE) {
return None;
}
let pool = self.env.symbol_pool();
if pool.string(mod_name.name()).as_str() == "vector" {
if let Some(inst) = inst_sign {
match pool.string(fun.get_name()).as_str() {
"empty" => Some(FF::Bytecode::VecPack(inst, 0)),
"length" => Some(FF::Bytecode::VecLen(inst)),
"borrow" => Some(FF::Bytecode::VecImmBorrow(inst)),
"borrow_mut" => Some(FF::Bytecode::VecMutBorrow(inst)),
"push_back" => Some(FF::Bytecode::VecPushBack(inst)),
"pop_back" => Some(FF::Bytecode::VecPopBack(inst)),
"destroy_empty" => Some(FF::Bytecode::VecUnpack(inst, 0)),
"swap" => Some(FF::Bytecode::VecSwap(inst)),
_ => None,
}
} else {
self.internal_error(loc, "expected type instantiation for vector operation");
None
}
} else {
None
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ impl FunctionTargetProcessor for LiveVarAnalysisProcessor {
mut data: FunctionData,
_scc_opt: Option<&[FunctionEnv]>,
) -> FunctionData {
if fun_env.is_native() {
return data;
}
// Call the existing live-var analysis from the move-prover.
let target = FunctionTarget::new(fun_env, &data);
let offset_to_live_refs = livevar_analysis::LiveVarAnnotation::from_map(
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading