Change Annotations.SetPreserve return type
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
Custom steps can annotate types with `TypePreserve` via the Annotations API. This can cause the linker to produce warnings IL2001 and/or IL2002 whenever the user tries to preserve methods/fields on a type that doesn't have any, putting the linker in a spot where it might produce warnings that don't give any clear indication on what's wrong and how to fix it:
```C#
// Could produce various: IL2001: Type blah has no fields to preserve
// and the best thing the user could do would be to unconditionally suppress
// the warnings -- not good.
void Test()
{
foreach (var type in Assembly.GetExecutingAssembly().GetTypes()) {
var typeDef = type.AsTypeDefinition();
Annotations.SetPreserve(typeDef, TypePreserve.Fields);
}
}
```
We could change the linker to stop producing these warnings inside `ApplyPreserveInfo` and change `SetPreserve` return type to `bool`, returning false whenever there's nothing to preserve on the passed type:
https://github.com/mono/linker/blob/30f2498c2a3de1f7e236d5793f5f1aca6e5ba456/src/linker/Linker/Annotations.cs#L317
So that custom step writers can decide what should be done in the cases where IL2001/2002 would be produced.
/cc @sbomer
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.