-
Notifications
You must be signed in to change notification settings - Fork 13.3k
link-dead-code limitations (bad for code coverage) #39293
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
Comments
One improvement for this that I can see would be monomorphising all of the methods and trait impls for a type when it's instantiated, rather than just the necessary methods. This would solve most of these problems, I think. |
@clarcharr I think that would be a great intermediary solution, because it would catch all the cases I currently have. Even though only doing this for methods and trait impls of instansiated types would not fix this fully, because generic functions and generic types that are never instansiated would still have this issue (but I think those are quite rare). @malbarbo I'm not sure about binary size, but because this would normally only be done for test builds I don't think it should be an issue for a first version. I have one possible optimization to avoid excessive blowing up of the binary though. There could be kept track of which methods are not monomorphised at all and only monomorphise them for one of the types that they could be monomorphised for. |
Looks like the problem here is (in general) that we don't use the OTOH, dead code doesn't really need to be tested -- so perhaps this isn't really a problem. |
You maybe be writing a library and forget to test a generic function. It is dead code in the library but a client may use the (untested) function. |
Generic functions without monomorphization don't end up in the generated binary, so they aren't included in the coverage metrics. See rust-lang/rust#39293.
Consider a cargo project (
dead
) with thissrc/lib.rs
file:Running
outputs
We can observe that that only
fun0
and<() as Trait>::fun2
is included (also checked withnm
and runningkcov
). Not includingfun1
andTrait::fun2
makes code coverage inflates (usingkcov
).I can see that
fun1
andTrait::fun2
is not included because they need to be monomorphised. One partial solution would be to monomorphise the default methods implementations for every type that implements the trait, but I think this could blow the binary size and compilation time.Would it be possible to add this symbols without monomorphisation? Or maybe creating a monomorphised version that just panics? (Could all generic paramaters be set to
!
?)The text was updated successfully, but these errors were encountered: