Would it be possible to have a compiler that predicts all possible errors associated with a particular situation?

By virtue of the "specific situation" I mean that he uses some data to which he will have access, for example, the current database setting, the version of some OS, etc.

Imagine if the compiler checks the database that you are currently using in your application and invoke a warning that says 'to let you know that the current data in your database will never invoke an expression you wrote ' or things like if it becomes null, which you will actually be screwed into ). It might take a while, but if he had something (such as a current database) he could check something, not just "every opportunity."

Do you think this is possible / valuable? Does it exist somewhere?

It would be great to have a quantum compiler that detects every possibility and automatically comes up with exception handling, etc.

+2


source to share


6 answers


This is theoretically possible, but unlikely. Basically, you are doing static analysis to use some ancillary data to test some requirements. This is generally possible, but static analyzes generally suffer from some degree of imprecision. For example, if I have a block of code:

If(getResultFromDB() == someResult) {
do this;
} else {
do that;
}

      

You would essentially like the analysis to complain to you if you write code in the first if block, because the database can never return someResult. This is theoretically possible, I mean you just have to examine all possible return values โ€‹โ€‹for the getResultFromDB () function for a given database, and then complete the response.



The problem is that this number can be absolutely massive. And this is generally a problem with static analyzes, in order to get accurate results, we need to consider ALL possible execution paths, input data, contexts, etc. In practice, this is simply not feasible, so static analysis will usually make concessions when it shrinks the size of its current feature set.

Edit: If you are interested in advanced static analysis in general, here's an interesting analysis that I read, did the other day. It tries to find possible XSS attacks in the PHP source code. To find database-related XSS attacks, they actually mimic the effects of queries against the database as an abstract database. http://www.cs.washington.edu/homes/mernst/pubs/create-attacks-tr054.pdf

0


source


I can't guarantee it, but it seems to be isomorphic to Halting's problem, which is not known to be possible.



+5


source


As James suspects, this is isomorphic to Halting's problem and therefore impossible to do.

In fact, this problem can be trivially reduced to compiling Perl (since Perl requires situational knowledge). There is a simple, elegant proof that Perl cannot compile.

Thus, we have at least one counter example (Perl), where the static compiler cannot check the correctness of programs, which contradicts the hypothesis. QED

+3


source


It doesn't exist anywhere that I know of (yet). However, I really like the idea of โ€‹โ€‹humanized error messages:

You know, if this becomes a null value you are really going to be screwed.

As for whether this is actually possible: I would say that over time anything can happen, so who really knows (and who I am to predict the future).

Is it valuable: YEAH! It would be a huge time-saver, and if she did what you said, coming up with an exception would be one of the most useful tools. EVER !!!

0


source


It sounds like you are talking about a complex form of data flow analysis . This method is used by existing compilers and is widely used by static analysis tools . There is probably no tool currently as advanced as you suggest, but that doesn't mean it can't be built given enough time and research.

0


source


While this problem cannot be fully resolved, there are some attempts to make static analysis as smart as possible, one of them - NStatic by Wesner Moise - has expectations set quite high (this could also be the reason that this tool did not ship and does not seem to soon will be sent:))

http://wesnerm.blogs.com/net_undocumented/nstatic/

0


source







All Articles