-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Free memory before calling linker #66707
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
Changes from 1 commit
266ede1
5098ba6
27513a2
becfe5c
18bb912
ea1b803
7d01b6c
8ffc944
9d5f721
68b1ac9
144d1c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,6 @@ pub struct Queries<'comp> { | |
prepare_outputs: Query<OutputFilenames>, | ||
global_ctxt: Query<BoxedGlobalCtxt>, | ||
ongoing_codegen: Query<Box<dyn Any>>, | ||
link: Query<()>, | ||
} | ||
|
||
impl<'comp> Queries<'comp> { | ||
|
@@ -98,7 +97,6 @@ impl<'comp> Queries<'comp> { | |
prepare_outputs: Default::default(), | ||
global_ctxt: Default::default(), | ||
ongoing_codegen: Default::default(), | ||
link: Default::default(), | ||
} | ||
} | ||
|
||
|
@@ -278,35 +276,54 @@ impl<'comp> Queries<'comp> { | |
}) | ||
} | ||
|
||
pub fn link(&self) -> Result<&Query<()>> { | ||
self.link.compute(|| { | ||
let sess = self.session(); | ||
pub fn linker(self) -> Result<Linker> { | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let dep_graph = self.dep_graph()?; | ||
let prepare_outputs = self.prepare_outputs()?; | ||
let ongoing_codegen = self.ongoing_codegen()?; | ||
|
||
let ongoing_codegen = self.ongoing_codegen()?.take(); | ||
let sess = self.session().clone(); | ||
let codegen_backend = self.codegen_backend().clone(); | ||
|
||
self.codegen_backend().join_codegen_and_link( | ||
ongoing_codegen, | ||
sess, | ||
&*self.dep_graph()?.peek(), | ||
&*self.prepare_outputs()?.peek(), | ||
).map_err(|_| ErrorReported)?; | ||
|
||
Ok(()) | ||
Ok(Linker { | ||
sess, | ||
dep_graph: dep_graph.take(), | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
prepare_outputs: prepare_outputs.take(), | ||
ongoing_codegen: ongoing_codegen.take(), | ||
codegen_backend, | ||
}) | ||
} | ||
} | ||
|
||
pub struct Linker { | ||
sess: Lrc<Session>, | ||
dep_graph: DepGraph, | ||
prepare_outputs: OutputFilenames, | ||
ongoing_codegen: Box<dyn Any>, | ||
codegen_backend: Lrc<Box<dyn CodegenBackend>>, | ||
} | ||
|
||
impl Linker { | ||
pub fn link(self) -> Result<()> { | ||
self.codegen_backend.join_codegen_and_link( | ||
self.ongoing_codegen, | ||
&self.sess, | ||
&self.dep_graph, | ||
&self.prepare_outputs, | ||
).map_err(|_| ErrorReported) | ||
} | ||
} | ||
|
||
impl Compiler { | ||
// This method is different to all the other methods in `Compiler` because | ||
// it lacks a `Queries` entry. It's also not currently used. It does serve | ||
// as an example of how `Compiler` can be used, with additional steps added | ||
// between some passes. And see `rustc_driver::run_compiler` for a more | ||
// complex example. | ||
pub fn enter<'c, F, T>(&'c self, f: F) -> Result<T> | ||
where F: for<'q> FnOnce(&'q Queries<'c>) -> Result<T> | ||
where F: FnOnce(Queries<'c>) -> Result<T> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This closure should take |
||
{ | ||
let queries = Queries::new(&self); | ||
f(&queries) | ||
f(queries) | ||
} | ||
|
||
// This method is different to all the other methods in `Compiler` because | ||
|
@@ -315,13 +332,13 @@ impl Compiler { | |
// between some passes. And see `rustc_driver::run_compiler` for a more | ||
// complex example. | ||
pub fn compile(&self) -> Result<()> { | ||
self.enter(|queries| { | ||
let linker = self.enter(|queries| { | ||
queries.prepare_outputs()?; | ||
|
||
if self.session().opts.output_types.contains_key(&OutputType::DepInfo) | ||
&& self.session().opts.output_types.len() == 1 | ||
{ | ||
return Ok(()) | ||
return Ok(None) | ||
} | ||
|
||
queries.global_ctxt()?; | ||
|
@@ -334,7 +351,14 @@ impl Compiler { | |
// Drop GlobalCtxt after starting codegen to free memory. | ||
mem::drop(queries.global_ctxt()?.take()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can also be dropped. |
||
|
||
queries.link().map(|_| ()) | ||
}) | ||
let linker = queries.linker()?; | ||
Ok(Some(linker)) | ||
})?; | ||
|
||
if let Some(linker) = linker { | ||
linker.link()? | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.