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

chore: Use --show-output flag on execution rather than compilation #2116

Merged
merged 6 commits into from
Aug 2, 2023

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Aug 1, 2023

Description

Problem*

When we moved println from being an ACIR opcode to a Brillig foreign call the --show-output logic changed as we no longer need to thread the flag down to ACIR generation. We can now provide it as an execute options to execute_circuit.

This fixes the previous logic we had where we do not print during nargo test but only print if specified with the --show-output flag.

I also adding reporting for compile errors inside of run_test. We previously were not reporting compile errors in tests and would simply fail with: Error: 1 test failed which provides no information.

I have added this test into strings:

fn failed_constraint(hex_as_field: Field) {
    std::println(hex_as_field);
    assert(hex_as_field != 0x41);
}

#[test]
fn test_failed_constraint() {
    failed_constraint(0x41);
}

which now reports this:

unning 3 test functions...
Testing test_call_main...
error: 
   ┌─ /mnt/user-data/maxim/noir/crates/nargo_cli/tests/test_data/strings/src/main.nr:52:12
   │
52 │     assert(hex_as_field != 0x41);
   │            -------------------- Failed constraint

Testing test_prints_strings...
ok
Testing test_prints_array...
ok
Error: 1 test failed

Location:
    crates/nargo_cli/src/cli/mod.rs:74:5

We should make sure to advise users in the docs to use nargo execute if they want to debug failing constraints with println statements. This is due to every input in a test being a constant rather than a witness, so we issue an error during compilation while we only print during execution (which comes after compilation).

We could consider not error'ing out on a failed constraint during test compilation, thus leaving print statements to still be executed. This should be done in a separate PR though that threads a "nargo test" compile option into the evaluator.

Summary*

Documentation

  • This PR requires documentation updates when merged.

    • I will submit a noir-lang/docs PR.
    • I will request for and support Dev Rel's help in documenting this PR.

Additional Context

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm marked this pull request as draft August 1, 2023 21:37
@vezenovm
Copy link
Contributor Author

vezenovm commented Aug 1, 2023

Converting back to a draft until I fix why the same program using nargo execute has println output while a test does not

@vezenovm vezenovm marked this pull request as ready for review August 2, 2023 14:30
@vezenovm vezenovm requested review from TomAFrench and jfecher August 2, 2023 14:30
@vezenovm
Copy link
Contributor Author

vezenovm commented Aug 2, 2023

We should make sure to advise users in the docs to use nargo execute if they want to debug failing constraints with println statements. This is due to every input in a test being a constant rather than a witness, so we issue an error during compilation while we only print during execution (which comes after compilation).

This note in the main PR description is why I requested an update to the docs

@TomAFrench
Copy link
Member

TomAFrench commented Aug 2, 2023

In order to debug failing constraints with println calls nargo execute should be used instead

I think it might be confusing to describe it as "nargo test doesn't print while nargo execute does". It's closer to "any constraints which fail at compile time prevent printing any debug info".

Perhaps we should allow debug builds of Noir code which doesn't enforce Constrain instructions at compile time?

@vezenovm
Copy link
Contributor Author

vezenovm commented Aug 2, 2023

Perhaps we should allow debug builds of Noir code which doesn't enforce Constrain instructions at compile time?

I think this might be worth it so that we don't have inconsistent functionality. I suggested this in the main PR description:

We could consider not error'ing out on a failed constraint during test compilation, thus leaving print statements to still be executed. This should be done in a separate PR though that threads a "nargo test" compile option into the evaluator.

I suggested it for a separate PR though as I thought it might warrant a discussion and I mainly wanted to fix the --show-output flag. We don't print anything on a failing test right now anyway so this PR isn't really changing functionality there.

@TomAFrench
Copy link
Member

Ah apologies, I didn't see you mentioned this in the PR description. Agree on it being OOS for this PR but could you add an issue for this?

I'm a little concerned with users reading that they should use nargo execute and then running into the same issue as they did in nargo test though.

@vezenovm
Copy link
Contributor Author

vezenovm commented Aug 2, 2023

Made an issue here: #2128

I'm a little concerned with users reading that they should use nargo execute and then running into the same issue as they did in nargo test though.

Do you mean with how we currently have it that if a user has a failing compile-time constraint they will not see prints?

@TomAFrench
Copy link
Member

Yes that's right

@TomAFrench TomAFrench changed the title chore: Use --show-output flag on execution rather than compilation chore: Use --show-output flag on execution rather than compilation Aug 2, 2023
@vezenovm
Copy link
Contributor Author

vezenovm commented Aug 2, 2023

Yeah I see. I guess we should just note in the docs then that until we have a debug mode, println will not work for failed constraints caught at compile time. I altered the comment and linked the issue. Let me know what you think @TomAFrench.

Copy link
Member

@TomAFrench TomAFrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Yeah, no issues with the PR as it stands, just want to avoid incorrect docs.

@TomAFrench TomAFrench added this pull request to the merge queue Aug 2, 2023
Merged via the queue into master with commit 27ab78f Aug 2, 2023
@TomAFrench TomAFrench deleted the mv/show-output-fix branch August 2, 2023 18:37
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
  feat!: Support workspaces and package selection on every nargo command (#1992)
  chore: Make a more clear error for slices passed to std::println (#2113)
  feat: Implement type aliases (#2112)
  feat: Add `Option<T>` to noir stdlib (#1781)
  feat: Format strings for prints  (#1952)
  feat(acir_gen): RecursiveAggregation opcode and updates to black box func call generation (#2097)
  fix: Mutating a variable no longer mutates its copy (#2057)
  fix: Implement `.len()` in Acir-Gen (#2077)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
  feat!: Support workspaces and package selection on every nargo command (#1992)
  chore: Make a more clear error for slices passed to std::println (#2113)
  feat: Implement type aliases (#2112)
  feat: Add `Option<T>` to noir stdlib (#1781)
  feat: Format strings for prints  (#1952)
  feat(acir_gen): RecursiveAggregation opcode and updates to black box func call generation (#2097)
  fix: Mutating a variable no longer mutates its copy (#2057)
  fix: Implement `.len()` in Acir-Gen (#2077)
TomAFrench added a commit that referenced this pull request Aug 2, 2023
* master:
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
  fix: Rename `Option::value` to `Option::_value` (#2127)
  feat: replace boolean `AND`s with multiplication (#1954)
  chore: create a `const` to hold the panic message (#2122)
  feat: Add support for bitshifts by distances known at runtime (#2072)
  feat: Add additional `BinaryOp` simplifications (#2124)
  fix: flattening pass no longer overwrites previously mapped condition values (#2117)
  chore(noirc_driver): Unify crate preparation (#2119)
TomAFrench added a commit that referenced this pull request Aug 3, 2023
* master:
  chore: replace usage of `Directive::Quotient` with brillig opcode  (#1766)
  chore: clippy fix (#2136)
  feat: Initial work on rewriting closures to regular functions with hi… (#1959)
  chore: Decouple acir blockid from ssa valueid (#2103)
  chore: Initialize copy array from previous values in `array_set` (#2106)
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  fix(globals): Accurately filter literals for resolving globals (#2126)
  feat: Optimize away constant calls to black box functions (#1981)
@Savio-Sou
Copy link
Collaborator

Would this be going into v0.10.0?

@TomAFrench
Copy link
Member

Yes, all PRs being merged currently will be going into the 0.10.0 release.

TomAFrench added a commit that referenced this pull request Aug 4, 2023
* master: (50 commits)
  chore: update stale comment on `create_circuit` (#2173)
  chore: Replace `resolve_path` function with a trait that impls normalize (#2157)
  chore: clippy fix (#2174)
  feat!: Allow specifying new package name with `--name` flag (#2144)
  chore!: remove unused flags on LSP command (#2170)
  chore: Hide the `show_ssa` and `show_brillig` flags (#2171)
  chore: bump `clap` to 4.3.19 (#2167)
  chore: Move the long line of `nargo info` to `long_about` (#2151)
  chore: Refactor `normalize_path` into an API on FileManager (#2156)
  fix: Implement slices of structs (#2150)
  chore: Refreshed ACIR artifacts (#2148)
  chore: Rebuild ACIR test artifacts (#2147)
  chore: remove short flags for `--show-ssa` and `--deny-warnings` (#2141)
  chore: replace usage of `Directive::Quotient` with brillig opcode  (#1766)
  chore: clippy fix (#2136)
  feat: Initial work on rewriting closures to regular functions with hi… (#1959)
  chore: Decouple acir blockid from ssa valueid (#2103)
  chore: Initialize copy array from previous values in `array_set` (#2106)
  chore: rename `ssa_refactor` module to `ssa` (#2129)
  chore: Use `--show-output` flag on execution rather than compilation  (#2116)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants