Skip to content
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

First draft of an analyzer for capability APIs #111

Closed
wants to merge 1 commit into from

Conversation

terrajobst
Copy link
Contributor

@terrajobst terrajobst commented Apr 14, 2020

This design isn't ready yet. I only created the draft PR so that I can point folks to it.

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the early feedback - I found this sort of by accident. I like it! The general approach seems very flexible and could help in lot of scenarios.

Comment on lines +43 to +44
This might be useful for .NET Standard library developers and much less useful
for people building .NET Core apps. We might also want different defaults.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some capabilities will be less interesting for .NET Core apps, but some are as applicable as for .NET Standard libraries (I can still try to use Registry APIs when building app for Linux, it should warn). For that reason I think this should be on-by-default if we can make it performant enough.


This would behave the same was tagging the assemblies, modules, types, or
members with the `[RequiredXxxCapability]` but without requiring callers to
check it. It's basically a suppression for a specific capability.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it looks like suppression and behaves like suppression -> it might as well be a suppression 😄 - Why would not SuppressMessage (or the new UnconditionalSuppressMessage) work here? Maybe I don't understand the "assertion" pattern.

Comment on lines +54 to +56
This probably doesn't work in Roslyn as the diagnostic set needs to be known
statically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I agree, but it would be nice if we could make at least some with distinct IDs. If nothing else it would behave nicer in combination with suppression and warning settings in IDEs.
So for example those we define in the framework could come with distinct IDs.

return configuredPath;
}
*/s
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the code looks like:

if (Registry.IsSupported)
{ // read from registry }
else
{ throw new Exception("This feature requires registry"); }

The analyzer would probably mark this as "perfectly fine", but in reality it's as broken as before. Should we consider some kind of detection of this "Anti-pattern"?

}
```

## Q & A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we possibly fold the proposed "linker unfriendly" attribute into this as well?: dotnet/runtime#33862
It looks like a good fit.

}
```

## Q & A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the handling of issues inside dependencies (NuGets mostly)? For example with the registry APIs above:
I write an app which itself doesn't call any of the registry APIs, but it uses a NuGet which does call them. Running the analyzer on the app itself will not reveal any problems, but the app is still broken on Linux.

}
```

## Q & A
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also consider how is this related to the feature switch functionality: https://github.com/dotnet/designs/blob/master/accepted/2020/feature-switch.md

In short - linker could remove the "false" branches in lot of cases (reducing code size) - assuming this is integrated correctly.

@terrajobst
Copy link
Contributor Author

terrajobst commented Feb 24, 2021

It doesn't seem we're pursuing this for now. If scenarios require this, we might come back to it.

@terrajobst terrajobst closed this Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants