Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: operator overloading & static trait method references resolving …
…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.
- Loading branch information