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

Traits map can grow significantly #5002

Open
anton-trunov opened this issue Aug 23, 2023 · 0 comments
Open

Traits map can grow significantly #5002

anton-trunov opened this issue Aug 23, 2023 · 0 comments
Assignees
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen

Comments

@anton-trunov
Copy link
Contributor

In the example below each d.contains(Data2 { x: 42, y: 42 }) makes the traits map grow which might slow down compilation time.
We should probably deduplicate the map entries.

contract;

trait Eq {
    fn eq(self, other: Self) -> bool;
}

impl Eq for u64 {
    fn eq(self, other: Self) -> bool {
        __eq(self, other)
    }
}

struct Data2<T, K> {
  x: T,
  y: K
}

impl<T,K> Data2<T,K> {
  fn contains(self, other: Self) -> bool where T: Eq, K: Eq  {
    true
  }
}

fn main() -> u64 {
  let d = Data2 { x: 42, y: 42 };
  d.contains(Data2 { x: 42, y: 42 });
  d.contains(Data2 { x: 42, y: 42 });
  d.contains(Data2 { x: 42, y: 42 });
/// ... and a bunch of d.contains(Data2 { x: 42, y: 42 });

  42
}
@anton-trunov anton-trunov added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Aug 23, 2023
@esdrubal esdrubal self-assigned this Aug 23, 2023
anton-trunov added a commit that referenced this issue Aug 23, 2023
The type resolution function calls this function at a later stage,
hence this one is not needed.

This makes trait map sizes smaller and saves a bunch of type ids.

Partially resolves issue #5002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

No branches or pull requests

2 participants