Skip to content

Pure brillig functions which return their own arguments should be simplified out #11404

@TomAFrench

Description

@TomAFrench

Consider the program

fn main(b: Field) -> pub Field {
    unsafe {
        identity(b)
    }
}

unconstrained fn identity(b: Field) -> Field {
    b
}

This compiles down to the SSA

acir(inline) predicate_pure fn main f0 {
  b0(v0: Field):
    v2 = call f1(v0) -> Field
    return v2
}
brillig(inline) predicate_pure fn identity f1 {
  b0(v0: Field):
    return v0
}

We should be able to determine that f1 is pure and we can write some/all of its outputs directly in terms of its inputs. We can then replace any references to the outputs with the associated input and simplify the function signature (or remove the function call) accordingly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions