Skip to content

Commit

Permalink
Improving: syntax sugar remover, underscored substitution and tags pr…
Browse files Browse the repository at this point in the history
…opagation intermediate signals
  • Loading branch information
clararod9 committed Feb 7, 2023
1 parent 1dadb4a commit c7432b4
Show file tree
Hide file tree
Showing 20 changed files with 737 additions and 355 deletions.
8 changes: 7 additions & 1 deletion compiler/src/hir/component_preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ fn rm_statement(stmt: &mut Statement) {
rm_init(stmt);
} else if stmt.is_substitution(){
rm_substitution(stmt);
} else if stmt.is_underscore_substitution(){
rm_underscore_substitution(stmt);
}
else{
}

fn rm_underscore_substitution(stmt: &mut Statement){
use Statement::{Block, UnderscoreSubstitution};
if let UnderscoreSubstitution { meta, .. } = stmt{
*stmt = Block{ meta: meta.clone(), stmts: Vec::new() };
}
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/src/hir/merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ fn produce_vcf_stmt(stmt: &Statement, state: &mut State, environment: &mut E) {
produce_vcf_while(stmt, state, environment);
} else if stmt.is_if_then_else() {
produce_vcf_conditional(stmt, state, environment);
} else if stmt.is_underscore_substitution() {
//No code should be produced for an instruction of the form _ <== exp;
} else {
unreachable!();
}
Expand Down Expand Up @@ -359,6 +361,8 @@ fn link_stmt(stmt: &mut Statement, state: &State, env: &mut E) {
link_declaration(stmt, state, env);
} else if stmt.is_substitution() {
link_substitution(stmt, state, env);
} else if stmt.is_underscore_substitution() {
//No code should be produced for an instruction of the form _ <== exp;
} else {
unreachable!();
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/hir/sugar_cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn extend_statement(stmt: &mut Statement, state: &mut State, context: &Context)
extend_log_call(stmt, state, context)
} else if stmt.is_assert() {
extend_assert(stmt, state, context)
} else {
} else{
unreachable!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/hir/type_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn infer_type_stmt(stmt: &Statement, state: &State, context: &mut SearchInfo) ->
Option::None
} else if stmt.is_assert() {
Option::None
} else {
} else{
unreachable!()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,18 @@ impl ComponentRepresentation {

for (symbol, route) in node.outputs() {
component.outputs.insert(symbol.clone(), SignalSlice::new_with_route(route, &true));

let tags_output = node.signal_to_tags.get(symbol);
if tags_output.is_some(){
component.outputs_tags.insert(symbol.to_string(), tags_output.unwrap().clone());
let component_tags_output = component.outputs_tags.get_mut(symbol);
if tags_output.is_some() && component_tags_output.is_some(){
let result_tags_output = tags_output.unwrap();
let result_component_tags_output = component_tags_output.unwrap();
for (tag, value) in result_tags_output{
// only update the output tag in case it contains the tag in the definition
if result_component_tags_output.contains_key(tag){
result_component_tags_output.insert(tag.clone(), value.clone());
}
}
}
}
component.node_pointer = Option::Some(node_pointer);
Expand Down
28 changes: 25 additions & 3 deletions constraint_generation/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,30 @@ fn execute_statement(
&runtime.call_trace,
)?
}
UnderscoreSubstitution{ meta, rhe, op} =>{
let f_result = execute_expression(rhe, program_archive, runtime, flag_verbose)?;
let arithmetic_slice = safe_unwrap_to_arithmetic_slice(f_result, line!());
if *op == AssignOp::AssignConstraintSignal{
for i in 0..AExpressionSlice::get_number_of_cells(&arithmetic_slice){
let _value_cell = treat_result_with_memory_error(
AExpressionSlice::access_value_by_index(&arithmetic_slice, i),
meta,
&mut runtime.runtime_errors,
&runtime.call_trace,
)?;
//let constraint_expression = AExpr::transform_expression_to_constraint_form(
// value_cell,
// runtime.constants.get_p(),
//).unwrap();
//if let Option::Some(node) = actual_node {
//for signal in constraint_expression.take_signals(){
// node.add_underscored_signal(signal);
//}
//}
}
}
Option::None
}
};
Result::Ok(res)
}
Expand Down Expand Up @@ -960,16 +984,14 @@ fn perform_assign(
}
}
}
/* else { // it is a tag that does not belong to the value
else { // it is a tag that does not belong to the signal
reference_to_tags.insert(tag.clone(), value.clone());
if let Option::Some(node) = actual_node{
node.add_tag_signal(symbol, &tag, value.clone());
} else{
unreachable!();
}
}
*/
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions constraint_generation/src/execution_data/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ pub fn apply_computed(stmt: &mut Statement, analysis: &Analysis) {
*arg = computed_or_original(analysis, arg);
apply_computed_expr(arg, analysis);
}
UnderscoreSubstitution { rhe, .. } => {
*rhe = computed_or_original(analysis, rhe);
apply_computed_expr(rhe, analysis);
},
}
}

Expand Down
6 changes: 3 additions & 3 deletions constraint_list/src/constraint_simplification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ pub fn simplification(smp: &mut Simplifier) -> (ConstraintStorage, SignalMap) {
let mut deleted = HashSet::new();
let mut lconst = LinkedList::new();
let mut no_rounds = smp.no_rounds;
let remove_unused = apply_linear;
let remove_unused = true;

let relevant_signals = {
// println!("Creating first relevant set");
Expand Down Expand Up @@ -529,7 +529,7 @@ pub fn simplification(smp: &mut Simplifier) -> (ConstraintStorage, SignalMap) {
relevant
};

let linear_substitutions = if remove_unused {
let linear_substitutions = if apply_linear {
let now = SystemTime::now();
let (subs, mut cons) = linear_simplification(
&mut substitution_log,
Expand Down Expand Up @@ -585,7 +585,7 @@ pub fn simplification(smp: &mut Simplifier) -> (ConstraintStorage, SignalMap) {
let mut round_id = 0;
let _ = round_id;
let mut linear = with_linear;
let mut apply_round = remove_unused && no_rounds > 0 && !linear.is_empty();
let mut apply_round = no_rounds > 0 && !linear.is_empty();
let mut non_linear_map = if apply_round || remove_unused {
// println!("Building non-linear map");
let now = SystemTime::now();
Expand Down
4 changes: 2 additions & 2 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ pub fn run_parser(
let lib = program_archive.get_file_library().clone();
let program_archive_result = apply_syntactic_sugar( &mut program_archive);
match program_archive_result {
Result::Err(v) => {Result::Err((lib,vec![v]))}
Result::Ok(()) => {Ok((program_archive, warnings))}
Result::Err(v) => Result::Err((lib,vec![v])),
Result::Ok(_) => Ok((program_archive, warnings)),
}
}
}
Expand Down
Loading

0 comments on commit c7432b4

Please sign in to comment.