Skip to content

Commit

Permalink
Merge branch 'master' into assert-eq-builtin
Browse files Browse the repository at this point in the history
* master:
  fix(ssa): Do not optimize for allocates in constant folding (#2466)
  • Loading branch information
TomAFrench committed Aug 28, 2023
2 parents 78a57fc + 9e272f3 commit 1c7883d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 3 additions & 1 deletion crates/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ impl Context {

// If the instruction doesn't have side-effects, cache the results so we can reuse them if
// the same instruction appears again later in the block.
if !instruction.has_side_effects(&function.dfg) {
if !instruction.has_side_effects(&function.dfg)
&& !matches!(instruction, Instruction::Allocate)
{
instruction_result_cache.insert(instruction, new_results.clone());
}
for (old_result, new_result) in old_results.iter().zip(new_results) {
Expand Down
3 changes: 2 additions & 1 deletion crates/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ impl<'a> Resolver<'a> {
// expect() here is valid, because the only places we don't have a span are omitted types
// e.g. a function without return type implicitly has a spanless UnresolvedType::Unit return type
// To get an invalid env type, the user must explicitly specify the type, which will have a span
let env_span = env.span.expect("Unexpected missing span for closure environment type");
let env_span =
env.span.expect("Unexpected missing span for closure environment type");

let env = Box::new(self.resolve_type_inner(*env, new_variables));

Expand Down
22 changes: 9 additions & 13 deletions crates/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ use crate::{
BinaryOp, BinaryOpKind, BlockExpression, ConstrainStatement, Distinctness, FunctionDefinition,
FunctionReturnType, Ident, IfExpression, InfixExpression, LValue, Lambda, Literal,
NoirFunction, NoirStruct, NoirTrait, NoirTypeAlias, Path, PathKind, Pattern, Recoverable,
TraitConstraint, TraitImpl, TraitImplItem, TraitItem, TypeImpl, UnaryOp,
UnresolvedTypeExpression, UseTree, UseTreeKind, Visibility, TraitBound,
TraitBound, TraitConstraint, TraitImpl, TraitImplItem, TraitItem, TypeImpl, UnaryOp,
UnresolvedTypeExpression, UseTree, UseTreeKind, Visibility,
};

use chumsky::prelude::*;
Expand Down Expand Up @@ -527,19 +527,17 @@ fn trait_implementation_body() -> impl NoirParser<Vec<TraitImplItem>> {
}

fn where_clause() -> impl NoirParser<Vec<TraitConstraint>> {

struct MultiTraitConstraint {
typ: UnresolvedType,
trait_bounds: Vec<TraitBound>,
}

let constraints = parse_type()
.then_ignore(just(Token::Colon))
.then(trait_bounds())
.validate(|(typ, trait_bounds), span, emit| {
let constraints = parse_type().then_ignore(just(Token::Colon)).then(trait_bounds()).validate(
|(typ, trait_bounds), span, emit| {
emit(ParserError::with_reason(ParserErrorReason::ExperimentalFeature("Traits"), span));
MultiTraitConstraint { typ, trait_bounds }
});
},
);

keyword(Keyword::Where)
.ignore_then(constraints.separated_by(just(Token::Comma)))
Expand All @@ -549,18 +547,16 @@ fn where_clause() -> impl NoirParser<Vec<TraitConstraint>> {
let mut result: Vec<TraitConstraint> = Vec::new();
for constraint in x {
for bound in constraint.trait_bounds {
result.push(TraitConstraint { typ:constraint.typ.clone(), trait_bound:bound } );
result
.push(TraitConstraint { typ: constraint.typ.clone(), trait_bound: bound });
}
}
result
})
}

fn trait_bounds() -> impl NoirParser<Vec<TraitBound>> {
trait_bound()
.separated_by(just(Token::Plus))
.at_least(1)
.allow_trailing()
trait_bound().separated_by(just(Token::Plus)).at_least(1).allow_trailing()
}

fn trait_bound() -> impl NoirParser<TraitBound> {
Expand Down

0 comments on commit 1c7883d

Please sign in to comment.