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: iterative unification #6540

Closed
wants to merge 13 commits into from
Closed

fix: iterative unification #6540

wants to merge 13 commits into from

Conversation

guipublic
Copy link
Contributor

@guipublic guipublic commented Nov 18, 2024

Description

Problem*

Resolves #6457

Summary*

Makes iterative version of:

  • type unification
  • type conversion (hir to ast)
  • type check (in monomorphization)

Additional Context

In the issue, the problem was due to unification during elaboration and check type during monomorphisation. So type conversion was not failing.
Convert and check type are made iterative only for type variables because the issue is happening with them.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

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

@guipublic guipublic marked this pull request as ready for review November 19, 2024 09:34
@guipublic guipublic requested a review from vezenovm November 19, 2024 09:34
Copy link
Contributor

@vezenovm vezenovm left a comment

Choose a reason for hiding this comment

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

Looks good to me, seems like we have one last failing test with the inliner though. Wondering if we should just move to iterative unification for all the types? Perhaps this is better for a followup though.

compiler/noirc_evaluator/src/ssa/opt/databus.rs Outdated Show resolved Hide resolved
compiler/noirc_evaluator/src/ssa/opt/databus.rs Outdated Show resolved Hide resolved
@vezenovm
Copy link
Contributor

It looks good to me, we just need to figure out that last arithmetic generics failure.

@guipublic
Copy link
Contributor Author

It looks good to me, we just need to figure out that last arithmetic generics failure.

It was due to the changes for constant terms during unification. I tried to fix this but it was still failing so I end up using the previous recursive code for this case.

@TomAFrench
Copy link
Member

Is there a good testcase we can add that would break the old type unification code?

@jfecher
Copy link
Contributor

jfecher commented Nov 19, 2024

#6457

How long is this expected to take now? I ran it for 2:12 before halting it because it was taking too long - it didn't finish monomorphization by that point. Comparing to master, master lasts 1:12 for me before stack overflowing

@jfecher
Copy link
Contributor

jfecher commented Nov 19, 2024

This should be unneeded after #6558 - we should be avoiding building up these large type variable chains to begin with now. Sorry for not mentioning this sooner - #6558 was something I just found today while reviewing this PR and trying out a follow_bindings call before unification

@guipublic
Copy link
Contributor Author

How long is this expected to take now? I ran it for 2:12 before halting it because it was taking too long - it didn't finish monomorphization by that point. Comparing to master, master lasts 1:12 for me before stack overflowing

For me on the mainframe it run successfully in around 4 minutes (in debug mode)

@guipublic
Copy link
Contributor Author

This should be unneeded after #6558 - we should be avoiding building up these large type variable chains to begin with now. Sorry for not mentioning this sooner - #6558 was something I just found today while reviewing this PR and trying out a follow_bindings call before unification

I agree it is better to avoir the large binding chain in the first place, but having iterative version is still an improvement over the recursive one.

@jfecher
Copy link
Contributor

jfecher commented Nov 20, 2024

I don't think the iterative version is an improvement since we shouldn't have types large enough for a stack overflow now, and the iterative version is longer, more difficult to follow, and clones types on each intermediate step.

Copy link
Contributor

github-actions bot commented Dec 2, 2024

Peak Memory Sample

Program Peak Memory
keccak256 84.01M
workspace 121.98M
regression_4709 348.12M

@guipublic
Copy link
Contributor Author

At least we can see that the additional cloning does not impact the peak memory.

@TomAFrench
Copy link
Member

I'm inclined to close this if we're making this step harder to follow and adding more cloning.

@TomAFrench TomAFrench closed this Dec 9, 2024
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.

Thousands of hard-coded constants slows down execution time by 7x.
4 participants