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 memory leak in resolve #30863

Merged
merged 1 commit into from
Jan 14, 2016
Merged

Fix memory leak in resolve #30863

merged 1 commit into from
Jan 14, 2016

Conversation

jseyfried
Copy link
Contributor

Use arena allocation instead of reference counting for Modules to fix memory leaks from Rc cycles.

A module references its module children and its import resolutions, and an import resolution references the module defining the imported name, so there is a cycle whenever a module imports something from an ancestor module.

For example,

mod foo { // `foo` references `bar`.
    fn baz() {}
    mod bar { // `bar` references the import.
        use foo::baz; // The import references `foo`.
    }
}

@alexcrichton
Copy link
Member

r? @eddyb

@eddyb
Copy link
Member

eddyb commented Jan 13, 2016

Nice catch! I thought we were using Weak properly, but parent pointers aren't the only source of cycles.

@@ -1170,7 +1167,7 @@ pub struct Resolver<'a, 'tcx: 'a> {

ast_map: &'a hir_map::Map<'tcx>,
Copy link
Member

Choose a reason for hiding this comment

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

This seems to infect everything with 'tcx but it's improper, it should be 'hir instead ('tcx is for the type context, which we do not have here).
Not really blocking this PR, just that it's the first time I notice it.

@eddyb
Copy link
Member

eddyb commented Jan 13, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Jan 13, 2016

📌 Commit a8514d3 has been approved by eddyb

Manishearth added a commit to Manishearth/rust that referenced this pull request Jan 14, 2016
Use arena allocation instead of reference counting for `Module`s to fix memory leaks from `Rc` cycles.

A module references its module children and its import resolutions, and an import resolution references the module defining the imported name, so there is a cycle whenever a module imports something from an ancestor module.

For example,
```rust
mod foo { // `foo` references `bar`.
    fn baz() {}
    mod bar { // `bar` references the import.
        use foo::baz; // The import references `foo`.
    }
}
```
bors added a commit that referenced this pull request Jan 14, 2016
@bors bors merged commit a8514d3 into rust-lang:master Jan 14, 2016
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.

4 participants