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(ssa): codegen missing check for unary minus #2413

Merged
merged 4 commits into from
Aug 25, 2023

Conversation

alexvitkov
Copy link
Contributor

Description

Problem*

Resolves #2412

Summary*

For normal binary expression we call FunctionContext::insert_binary which inserts a binary instruction and checks if truncation is needed.

However, for unary minus we directly call into the FunctionBuilder which skips this check -- this PR replaces that function call with a call to FunctionContext::insert_binary.

The location argument in FunctionContext::insert_binary is also made optional since ast::Unary doesn't have a location and it would be a bit of a pain to add it, because in mono we sometimes generate unary expressions on the fly.

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.

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

It looks like the only place we generae Unary expressions outside of monomorphizing Prefix expressions is when evaluating zeroed_value_of_type. Can you add a span to that call instead so we don't have to have an optional span here?

@alexvitkov
Copy link
Contributor Author

I've added location to ast::Unary. We also generate implicit references/dereferences during type-checking, which also needed locations in the node_interner, or else we'd crash when trying to access the location when creating the corresponding ast::Unary

1b47c85

Copy link
Contributor

@jfecher jfecher left a comment

Choose a reason for hiding this comment

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

Thank you!

@jfecher jfecher added this pull request to the merge queue Aug 25, 2023
Merged via the queue into noir-lang:master with commit 1435a86 Aug 25, 2023
16 checks passed
TomAFrench added a commit that referenced this pull request Aug 25, 2023
* master:
  fix: Implement new mem2reg pass (#2420)
  feat(nargo): Support optional directory in git dependencies (#2436)
  fix(acir_gen): Pass accurate contents to slice inputs for bb func calls (#2435)
  fix(ssa): codegen missing check for unary minus (#2413)
  fix(lsp): Remove duplicated creation of lenses (#2433)
  feat: Add `test(should_fail)` attribute for tests that are meant to fail (#2418)
  chore: improve error message for InternalError (#2429)
  chore: Add stdlib to every crate as it is added to graph (#2392)
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.

2 participants