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

Fixes method Eq not found when used with where clause. #3348

Merged
merged 2 commits into from
Nov 22, 2022

Conversation

esdrubal
Copy link
Contributor

The problem was that although two TypeInfo::UnknownGeneric were unified they were not regarded as equals by are_equal_minus_dynamic_types.

Solution was to change how TypeInfo::UnknownGeneric are compared in are_equal_minus_dynamic_types. Which can now check if two TypeInfo::UnknownGeneric were previously unified. This was accomplished by adding two methods to the type engine insert_unified_type and get_unified_types.

Closes #3324

@mohammadfawaz mohammadfawaz requested a review from a team November 11, 2022 15:00
@mohammadfawaz mohammadfawaz added bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Nov 11, 2022
@emilyaherbert
Copy link
Contributor

@esdrubal does this fix #3326?

@emilyaherbert emilyaherbert self-requested a review November 17, 2022 16:28
@esdrubal
Copy link
Contributor Author

esdrubal commented Nov 17, 2022

@esdrubal does this fix #3326?

No it does not fix #3326. But #3391 does.

emilyaherbert
emilyaherbert previously approved these changes Nov 22, 2022
Copy link
Contributor

@emilyaherbert emilyaherbert left a comment

Choose a reason for hiding this comment

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

Apologies for the super delayed review---I was OOO for some time for being sick.

This looks good, thanks!

@emilyaherbert emilyaherbert requested review from Centril and a team and removed request for Centril November 22, 2022 18:09
mohammadfawaz
mohammadfawaz previously approved these changes Nov 22, 2022
@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Nov 22, 2022

Oh, conflicts 😐

The problem was that although two `TypeInfo::UnknownGeneric` were
unified they were not regarded as equals by `are_equal_minus_dynamic_types`.

Solution was to change how `TypeInfo::UnknownGeneric` are compared in
`are_equal_minus_dynamic_types`. Which can now check if two
`TypeInfo::UnknownGeneric` were previously unified. This was
accomplished by adding two methods to the type engine `insert_unified_type` and
`get_unified_types`.

Closes FuelLabs#3324
Adds a comment as requested in review.

Adds more insert_unified_type to unify and unify_right which
covers one case that does not currently pass in CI until FuelLabs#3391 is merged.
@esdrubal
Copy link
Contributor Author

Conflicts resolved.

@tritao tritao enabled auto-merge (squash) November 22, 2022 21:14
@tritao tritao merged commit f581909 into FuelLabs:master Nov 22, 2022
sdankel pushed a commit that referenced this pull request Dec 14, 2022
The problem was that although two `TypeInfo::UnknownGeneric` were
unified they were not regarded as equals by
`are_equal_minus_dynamic_types`.

Solution was to change how `TypeInfo::UnknownGeneric` are compared in
`are_equal_minus_dynamic_types`. Which can now check if two
`TypeInfo::UnknownGeneric` were previously unified. This was
accomplished by adding two methods to the type engine
`insert_unified_type` and `get_unified_types`.

Closes #3324
emilyaherbert added a commit that referenced this pull request Jan 23, 2023
This PR fixes #3864 by changing the way that trait impls are re-exported
to the greater namespace. Previously they we reexported somewhat at
random, with one place being at function declaration sites. They _were
not_ reexported at function call sites and method call sites. This PR
changes this so to standardize the re-export locations to include
function call sites and method call sites and to exclude function
declaration sites.

This PR serves as an alternate fix to #3324, as the bug with this issue
involved re-exporting traits. Take this Sway example:

```rust
script;

use core::ops::*;

impl<T> Option<T> {
    pub fn ok_or<E>(self, err: E) -> Result<T, E> {
        match self {
            Option::Some(v) => Result::Ok(v),
            Option::None => Result::Err(err),
        }
    }
}

fn test_ok_or<T, E>(val: T, default: E) where T: Eq {
    match Option::Some(val).ok_or(default) {
        Result::Ok(inner) => assert(inner == val),
        Result::Err(_) => revert(0),
    }
}

fn main() {}
```

This PR better serves to re-export the trait constraint `T: Eq` to the
usable namespace inside of the function body for `ok_or`. So, this PR
also removes the `unify_map` abstraction which was added to the
`TypeEngine` in #3348.

Closes #3864

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
sdankel pushed a commit that referenced this pull request Jan 25, 2023
This PR fixes #3864 by changing the way that trait impls are re-exported
to the greater namespace. Previously they we reexported somewhat at
random, with one place being at function declaration sites. They _were
not_ reexported at function call sites and method call sites. This PR
changes this so to standardize the re-export locations to include
function call sites and method call sites and to exclude function
declaration sites.

This PR serves as an alternate fix to #3324, as the bug with this issue
involved re-exporting traits. Take this Sway example:

```rust
script;

use core::ops::*;

impl<T> Option<T> {
    pub fn ok_or<E>(self, err: E) -> Result<T, E> {
        match self {
            Option::Some(v) => Result::Ok(v),
            Option::None => Result::Err(err),
        }
    }
}

fn test_ok_or<T, E>(val: T, default: E) where T: Eq {
    match Option::Some(val).ok_or(default) {
        Result::Ok(inner) => assert(inner == val),
        Result::Err(_) => revert(0),
    }
}

fn main() {}
```

This PR better serves to re-export the trait constraint `T: Eq` to the
usable namespace inside of the function body for `ok_or`. So, this PR
also removes the `unify_map` abstraction which was added to the
`TypeEngine` in #3348.

Closes #3864

Co-authored-by: emilyaherbert <emily.herbert@fuel.sh>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trait constraints issue in the Eq trait while testing ok_or
5 participants