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

fix: iterative unification #6540

Closed
wants to merge 13 commits into from
46 changes: 46 additions & 0 deletions compiler/noirc_evaluator/src/ssa/opt/databus.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::ssa::ir::instruction::Instruction;



impl Ssa {
/// Map arrays with the last instruction that uses it
/// For this we simply process all the instructions in execution order
/// and update the map whenever there is a match
pub(crate) fn map_to_call_data_array(&self) -> HashMap<ValueId, InstructionId> {
let mut array_use = HashMap::default();
for func in self.functions.values() {
let mut reverse_post_order = PostOrder::with_function(func).into_vec();
reverse_post_order.reverse();
for block in reverse_post_order {
last_use(block, &func.dfg, &mut array_use);
}
}
array_use
}
//la question c comment on remplace ?
guipublic marked this conversation as resolved.
Show resolved Hide resolved
//on pourrait simplement garder une liste instruction_id -> new instruction
// et on les remplace dans la liste des instructions instructions_mut()
pub(crate) fn array_me(block_id: BasicBlockId, dfg: &mut DataFlowGraph) {
let block = &dfg[block_id];
for instruction_id in block.instructions() {
match &dfg[*instruction_id] {
Instruction::ArrayGet { array, index } => {
// Get operations to call-data parameters are replaced by a get to the call-data-bus array
if let Some(call_data) = dfg.data_bus.call_data {
let array_id = dfg.resolve(*array);
if dfg.data_bus.call_data_map.contains_key(&array_id) {
// on doit remplacer ce get par un autre, mais on doit d'abord fiare un calcul
guipublic marked this conversation as resolved.
Show resolved Hide resolved
//
dfg.make_constant(FieldElement::from(
self.data_bus.call_data_map[&array_id] as i128,
), type_of_value(index));
let new_index = self.acir_context.add_var(index, bus_index)?; //TODO add instruction
Instruction::ArrayGet { array: call_data, index: new_index };; //on veut remplacer par ca
}
}
}

}
}
}
}
5 changes: 3 additions & 2 deletions compiler/noirc_frontend/src/elaborator/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
hir::{def_collector::dc_crate::UnresolvedTrait, type_check::TypeCheckError},
hir_def::{
function::Parameters,
iterative_unification::Unifier,
traits::{ResolvedTraitBound, TraitFunction},
},
node_interner::{DependencyId, FuncId, NodeInterner, ReferenceId, TraitId},
Expand Down Expand Up @@ -347,7 +348,7 @@ fn check_function_type_matches_expected_type(

if params_a.len() == params_b.len() {
for (i, (a, b)) in params_a.iter().zip(params_b.iter()).enumerate() {
if a.try_unify(b, &mut bindings).is_err() {
if Unifier::try_unify(a, b, &mut bindings).is_err() {
errors.push(TypeCheckError::TraitMethodParameterTypeMismatch {
method_name: method_name.to_string(),
expected_typ: a.to_string(),
Expand All @@ -358,7 +359,7 @@ fn check_function_type_matches_expected_type(
}
}

if ret_b.try_unify(ret_a, &mut bindings).is_err() {
if Unifier::try_unify(ret_b, ret_a, &mut bindings).is_err() {
errors.push(TypeCheckError::TypeMismatch {
expected_typ: ret_a.to_string(),
expr_typ: ret_b.to_string(),
Expand Down
3 changes: 2 additions & 1 deletion compiler/noirc_frontend/src/elaborator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::{
HirMethodReference, HirPrefixExpression, TraitMethod,
},
function::FuncMeta,
iterative_unification::Unifier,
stmt::HirStatement,
traits::{NamedType, ResolvedTraitBound, Trait, TraitConstraint},
},
Expand Down Expand Up @@ -681,7 +682,7 @@ impl<'context> Elaborator<'context> {
make_error: impl FnOnce() -> TypeCheckError,
) {
let mut bindings = TypeBindings::new();
if actual.try_unify(expected, &mut bindings).is_err() {
if Unifier::try_unify(actual, expected, &mut bindings).is_err() {
self.errors.push((make_error().into(), file));
}
}
Expand Down
Loading
Loading