Trait functions implementation in MIR

Hello, I'm working on the MIR level and wanted to get an identifier for trait functions implementation (i.e. std::ops::FromResidual::from_residual), it seems that the def id points to the definition of the function in the trait definition, not on the actual implementation. Is there a way to point to the actual implementation before monomorphization and codegen?

I tried to use Instance, but the functions I need to analyze are part of a library with a generic parameter and some of the resolutions break.

Instance is the way. You can't get the implementation of a trait method without knowing the Self type which is part of the Substs list which contains all generic arguments. What are you exactly trying to do?

I'm building a static analysis tool to analyze Substrate pallets and I'm currently focusing on this function and I would need some more type information to be more precise in the analysis of nested calls. So let's say the entrypoint for the analysis is the add_registrar function, which is generic on T like the whole library, how should I initialize the first Instance? I followed this thread but I guess I'm doing something wrong.

If the entrypoint doesn't have generics you can use Instance::mono(tcx, def_id).

Edit: right, it does have a generic parameter. Are you trying to verify that function for any pallet or just for specific ones?

The generic parameter T here will in fact be a Runtime, which will also set all the types in the Config trait, here is an example. So the Identity pallet, where add_registrar is implemented can be used on different runtimes and the goal would be to abstract away the actual runtime and use symbols if needed. By the way how does the compiler handles monomorphization passes on such libraries that have unresolved generics?

It delays codegen until you actually use it, at which point the concrete type is known.