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: Stop cloning FuncMeta #3968

Merged
merged 3 commits into from
Jan 8, 2024
Merged

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Jan 5, 2024

Description

Problem*

Resolves

Summary*

This PR frees us from the tyranny of cloning FuncMeta every time we want to access them via NodeInterner::func_meta. Now we will be graced with a very slight, likely imperceptible performance increase.

Additional Context

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [Exceptional Case] 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.

@TomAFrench
Copy link
Member

Will look at this on Monday.

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

@TomAFrench TomAFrench added this pull request to the merge queue Jan 8, 2024
Merged via the queue into master with commit 45f6400 Jan 8, 2024
30 checks passed
@TomAFrench TomAFrench deleted the jf/stop-cloning-function-meta branch January 8, 2024 09:41
TomAFrench added a commit that referenced this pull request Jan 8, 2024
* master:
  chore: Stop cloning `FuncMeta` (#3968)
  feat: add MVP `nargo export` command (#3870)
  chore: clippy and general cleanup of debugger (#3957)
  chore: updating the noirjs tutorial to match stable + some other improvements (#3929)
  chore: add `insert_range_check` method to `FunctionBuilder` (#3959)
  chore: remove usage of term "preprocessed" in favour of "artifact" (#3939)
TomAFrench added a commit that referenced this pull request Jan 8, 2024
* master:
  chore: Stop cloning `FuncMeta` (#3968)
github-merge-queue bot pushed a commit that referenced this pull request Jan 8, 2024
…to generic impls (#3967)

# Description

## Problem\*

Resolves #3964

## Summary\*

The core problem in #3964 stems from a trait method's generics being
different from the corresponding impl's generics. So when the former was
instantiated, and later tried to apply to the latter during
monomorphization after an impl was selected, the latter would be
unchanged. This was fixed by remembering the `TraitMethodId` during
monomorphization and calling `try_unify` between the trait method's type
and the impl method's type before monomorphizing the impl function. This
gives type bindings to translate between the two.

## Additional Context

- In creating the above type bindings, we need to bind to the original
type variables on the trait without instantiating them. This meant any
further impl searches would see that trait as having its monomorphized
type, rather than its generic type. This would break impl search since
that trait/impl would no longer apply to all the types it used to. I've
fixed this by allowing `Type::substitute` to substitute to already-bound
type variables so that when the impl search later occurs and the type is
instantiated, the instantiation automatically sheds the bindings after
its (currently bound) type variables are swapped to fresh type
variables.

Allowing substitution on already bound type variables is a bit
concerning though. It's unclear if this could cause unsoundness later
on. ~~I'll open an issue to limit the scope of this by only allowing it
during `instantiate` calls instead of all `substitute` calls.~~ I've
just implemented the change directly in this PR instead. I split
`substitute` into `substitute` and `force_substitute`.

- There's also a mostly unrelated change in this PR. `function_meta` now
returns a reference instead of cloning the entire `FunctionMeta` which
was quite wasteful. I'll work on breaking this out into a separate PR.
(Edit: #3968)

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
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