Inferencing types of variables in a dynamically typed language
OwnerJames G. Peterson, Weng-Kiang Tjiang +1inventors
InventorsJames G. Peterson, Weng-Kiang Tjiang, John R. Allen
Life of this patent
Estimating the term…
Abstract
A computer is programmed to identify types of variables, in a computer program which includes a number of variables that are used without any explicit indication of their type, by repeatedly performing at least propagation of types from variables' definitions to variables' uses and removal of unreachable code. Repetition of type propagation from definitions to uses and removal of unreachable code is one aspect of the invention. The repetition can be terminated differently in different embodiments. In many embodiments, the repetition is performed until no unreachable code is found.
Claims20
A method of identifying types of variables in computer programs, the method being performed in a computer, the method comprising:
- receiving a computer program comprising a plurality of variables used without explicit indication of a type of each variable in the plurality of variables;
- initializing the type of said each variable to unknown;
- automatically changing an initial representation of the computer program while preserving semantics of the computer program, by repeated use of a plurality of program transformations;
- wherein a changed representation of the computer program is obtained on completion of said automatically changing;
- automatically associating a first type with a first variable in the plurality of variables, wherein said first type is obtained by type propagation of a second type from a definition of a second variable to a use of said second variable in an expression in said changed representation, wherein said expression is included in a statement in said computer program, said statement comprising said first variable and said second variable;
- automatically checking if the computer program comprises unreachable code and eliminating said unreachable code if found;
- in response to said eliminating, repeating each of:
- said initializing, said automatically changing, said automatically associating, and said automatically checking;
- wherein a different type is associated with the first variable in a final representation of the computer program obtained after completion of said repeating.
A method of identifying types of variables in computer programs, the method being performed in a computer, the method comprising:
- receiving a computer program comprising a plurality of variables used without explicit indication of a type of each variable in the plurality of variables;
- initializing the type of said each variable to unknown;
- automatically changing an initial representation of the computer program while preserving semantics of the computer program, by repeated use of a plurality of program transformations;
- wherein a changed representation of the computer program is obtained on completion of said automatically changing;
- automatically associating multiple types with a first variable in the plurality of variables, wherein said multiple types are obtained by type propagation of a second type from a definition of a second variable to a use of said second variable in an expression in said changed representation, wherein said expression is included in a statement in said computer program, said statement comprising said first variable and said second variable;
- repeating said initializing and said automatically changing;
- and
- automatically associating a single type with said variable by type propagation based on a representation obtained from repetition of said automatically changing.
A method of identifying types of variables in computer programs, the method being performed in a computer, the method comprising:
- receiving a computer program comprising a plurality of variables used without explicit indication of a type of each variable in the plurality of variables;
- initializing the type of said each variable to unknown;
- automatically changing an initial representation of the computer program while preserving semantics of the computer program, by repeated use of a plurality of program transformations;
- wherein a changed representation of the computer program is obtained on completion of said automatically changing;
- automatically associating a first type with a variable in the plurality of variables, wherein said first type is obtained by type propagation of a second type from a definition of a second variable to a use of said second variable in an expression in said changed representation, wherein said expression is included in a statement in said computer program, said statement comprising said first variable and said second variable;
- repeating said initializing and said automatically changing;
- and
- automatically associating a second type with said variable by type propagation based on a representation obtained from repetition of said automatically changing.
Dependencies are inferred from the claim text.