-
Notifications
You must be signed in to change notification settings - Fork 4
Cache the results of the monomorphisation call resolver #79
Changes from all commits
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 |
---|---|---|
|
@@ -285,6 +285,13 @@ pub fn collect_crate_mono_items( | |
tcx: TyCtxt<'_>, | ||
mode: MonoItemCollectionMode, | ||
) -> (FxHashSet<MonoItem<'_>>, InliningMap<'_>) { | ||
// Initialise Yorick call resolution map. | ||
{ | ||
let mut resolutions = tcx.call_resolution_map.borrow_mut(); | ||
assert!(resolutions.is_none()); // Should only be initialised once. | ||
*resolutions = Some(FxHashMap::default()); | ||
} | ||
|
||
let _prof_timer = tcx.prof.generic_activity("monomorphization_collector"); | ||
|
||
let roots = time(tcx.sess, "collecting roots", || { | ||
|
@@ -727,6 +734,10 @@ fn visit_fn_use<'tcx>( | |
ty::Instance::resolve_for_fn_ptr | ||
}; | ||
let instance = resolver(tcx, ty::ParamEnv::reveal_all(), def_id, substs).unwrap(); | ||
|
||
let mut resolutions = tcx.call_resolution_map.borrow_mut(); | ||
resolutions.as_mut().unwrap().insert((def_id, substs), instance); | ||
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 is not correct. Doing a cast to an fnptr can give a different result than a direct call, while both defid and substs are the same. 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. Would it be correct if the hashmap were keyed 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. Yes, but only when you don't codegen generic functions. When codegenning generic functions, you will really need to monomorphize the substs and then use 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. Yes, that's what I feared. We may have to make some fairly substantial changes to our system in light of this. Thanks again for this discussion. By the way, between us we could probably implement a missing part of the rustc guide here:
And the link to So it seems that the type parameters become "promoted constants" during monomorphisation. (I also think the main MIR data type is now 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.
What do you mean?
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.
The wording in the compiler guide talks in these terms, which surprised me a little:
It's talking about making a generic type parameter into a concrete one, I think? Through the act of promotion. 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. It is actually talking about turning fn abc() {
let a: &'static u8 = 1 + 2;
} into fn abc() {
static PROMOTED0: u8 = 1 + 2;
let a: &'static u8 = &PROMOTED0;
} 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. Oh, I see. We could probably improve the wording there too. |
||
|
||
visit_instance_use(tcx, instance, is_direct_call, output); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not true. The backend can call
Instance::resolve*
.