-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Then, what's the status of Code Contracts usage in .NET Core? #23869
Comments
@LYP951018 what is included in CoreFX? Can you share a link/reference? |
Seems to be usable. Please provide additional details / repro if you think it is not completely true. |
Code Contracts in .NET Framework provides API surface only, but requires the use of a rewriter. For example, see http://referencesource.microsoft.com/#mscorlib/system/diagnostics/contracts/contracts.cs,388 The current tools (including the rewriter) provided by the Microsoft Research Code Contracts project does not work with .NET Core and the new project system. The project is abandoned and all but officially discontinued. In this context, the OP's question, which I'm curious to know as well, is twofold:
As far as I know, neither of the last two points are true. |
CC @weshaggard as I recall this issue was triggered before. |
@karelz No, it's not usable. Without |
So that a) code that's written with the APIs can still compile, b) use of the APIs that don't require CONTRACT_FULL (like Contract.Assert) still work, and c) the APIs can be used with the tooling in the future if/when it becomes available.
Because it simply wasn't removed when it was brought over from the original .NET Framework code. New usage hasn't been added, and lots of usage has been replaced (e.g. replacing Contract.Assert with Debug.Assert), but we've yet to do a full sweep to clean out the old usage. You can see @danmosemsft recently did a sweep in the coreclr repo (dotnet/coreclr#14136), and I imagine he's eyeing corefx next. Such work is tracked by https://github.com/dotnet/corefx/issues/15443. |
"Still compile" is really bad. Imagine someone didn't know
When? It seems that the Code Contracts repo has been abandoned, and the forum is almost dead. Will it become avaliable? And, I found little document about the implementation/source code of Code Contracts. That means porting by community is... hard, even impossible. |
It's probably too late to remove them now that it's in .NET Standard, but perhaps it could be obsoleted to prevent compatibility assumptions like the OP made? Code Contracts is also an extraordinarily complex academic project, so there's no hope for "the community" picking up the pieces and giving the project new life. It's almost certain that no third party tooling will ever use |
That's a valid concern with the design of the Contracts library in general, but that has nothing to do with corefx; it's always been like that. |
If the APIs are useless today, we should obsolete them in https://github.com/dotnet/platform-compat ... we can even obsolete them on specific platforms if needed. |
I'm really going to miss code contracts, I would like to see them in .NET core. Very helpful tool. |
It's not an "extraordinarily complex academic project". The reason it never got mainstream support funding, in my understanding, is that it's not able to handle threading. Likewise, Pex and Moles couldn't handle concurrency checks either.
Could you elaborate? |
I'm gonna have to ask for proof on that. From what I can tell, as a complete outsider:
I've tried to make fixes to the project, but I've only been able to scratch the surface. It's horribly complicated - perhaps by necessity, given what it's trying to achieve - but the point still stands.
Contracts had enough of a push within Microsoft to get the .NET Framework team to add The Contract team appear to have done some premature abstraction here - creating a generic solution when there is only one implementation is usually a bad idea and will require reworking the abstraction. (You can tell that the APIs were targeted at Code Contracts specifically because they're in System.Diagnostics.Contracts and require the Those APIs, Rewriting IL is almost certainly setting you up for failure. You need to keep up with not only the capabilities of .NET, but the different manners in which various compilers emit different IL to do the same thing. Code Contracts has not, and so there is code today that is perfectly valid C# 5.0 syntax that the rewriter and/or static checker totally crap themselves on. If you were going to start a new project today that does this, you're in for one big long-term headache. The only other option is to hook into the compiler itself. Roslyn does not have any support for code generators or code rewriters (this is something often discussed on dotnet/csharplang), but it does have support for running third-party code to produce errors and warnings. This suits the static checker much better - Roslyn has syntax, semantic model, and flow analysis. C# 8.0 will (hopefully) introduce nullable reference types, which will make heavy use of flow analysis. So, if all you're getting out of Code Contracts is For anything else, if you can express it in attributes and annotate your code, a Roslyn Analyser can do that too for other things (e.g. Ergo, it's almost certain that no third party tooling will ever use Assume, Requires, Ensures, Ensures<> or Invariant. Most of Contract's static analysis is better served by Roslyn Analysers anyway, or C#8's Nullable Reference Types. |
Related: dotnet/csharplang#105. Anyway, what's the current alternative to CC as of Q2 2020? |
Related: microsoft/CodeContracts#231
If the contracts feature is not usable, why included in corefx?
The text was updated successfully, but these errors were encountered: