How to recognize variables that do not affect program output?

Sometimes the value of a variable available in the program control flow cannot affect its output. For instance:

global var_1
global var_2

start program hello(var_3, var_4)
    if (var_2 < 0) then
        save-log-to-disk (var_1, var_3, var_4)
    end-if
    return ("Hello " + var_3 + ", my name is " + var_1)
end program

Here, only var_1 and var_3 have any effect on the output, while var_2 and var_4 are used only for side effects. Do variables like var_1 and var_3 have a name in data flow theory / compiler theory? What methods of static analysis of the data stream can be used to detect them?

References to academic literature on this subject will be especially appreciated.

+4
source share
3 answers

, , , : P (x), x - . P (x) x, .. P (0) = P (1) = P (2) =...?

: M(), ?

, (Turing-complete) , " ":

M(), :

P(x):
    if x == 0:
       return 0
    Run M() for x steps
    if M() has terminated then:
        return 1
    else:
        return 0

:

P(0) = P(1) = P(2) = ... 
=> 
M() does not terminate.

M() does terminate 
=> P(x) = 1 for a sufficiently large x   
=> P(x) != P(0) = 0

, ; " " ( , ;-) , . , , , . (, , ), .

+1

Pachelbel , . , , - .

- . - ( ) , .

() ( , ) (var2), "" . , , .

, , , , " ". ( ) , . Grammatech C ++.

; . .

- , . , , ; .

" " , , , . ( " " ). , , , . ( " " , :)

", ", , - , . ( " " ).

, ; , , . , -, . YMMV.

: http://en.wikipedia.org/wiki/Data-flow_analysis . , . . : (http://en.wikipedia.org/wiki/Program_slicing)

, langauge. , , .

+1

: , , LHS . . . , .

OP, , . , : . . , .

RHS , . , , , .

, . , , , , .

IMHO - , , , (, ). , , , , , , , . , , : , , .
0

Source: https://habr.com/ru/post/1544329/


All Articles