发明名称 System and method for inferring immutability of program variables
摘要 In accordance with various embodiments, systems and methods are provided which facilitate inferring immutability of variables. A compiler analyzes local variables within source code to determine whether they are immutable. In particular embodiments the compiler examines locations where each variable is assigned to determine whether the variable was definitely unassigned before the assignment. Because the compiler can infer whether a local variable is immutable, it is possible for the programmer to avoid using a keyword to expressly declare the local variable as immutable. Inferring immutability of variables, thus, maintains correctness of the compiled code while reducing the burden on the programmer.
申请公布号 US9542166(B2) 申请公布日期 2017.01.10
申请号 US201213677000 申请日期 2012.11.14
申请人 ORACLE INTERNATIONAL CORPORATION 发明人 Goetz Brian;Buckley Alexander;Smith Daniel;Cimadamore Maurizio
分类号 G06F9/45;G06F11/36;G06F9/44 主分类号 G06F9/45
代理机构 Tucker Ellis LLP 代理人 Tucker Ellis LLP
主权项 1. A computer-implemented method for compiling source code using a compiler operating on one or more microprocessor, the method comprising: receiving said source code wherein said source code includes a plurality of local variables wherein each of said plurality of local variables is expressed in said source code without the use of a keyword which expressly declares said each of said plurality of local variables as being immutable; identifying with the compiler each of said plurality of local variables in said source code; for each local variable of the plurality of said plurality of local variables: identifying one or more locations in the source code where said each local variable is assigned;if said local variable has an initializer, inferring that said local variable is immutable if said local variable never occurs as an operand of a pre-increment, pre-decrement, post-increment, or post-decrement operator in said source code and never occurs as a left-hand operator of an assignment operator in said source code; andif said local variable has no initializer, inferring that said local variable is immutable if said local variable never occurs as an operand of a pre-increment, pre-decrement, post-increment, or post-decrement operator in said source code, and at any location is said source code where said local variable occurs as a left-hand operator of an assignment operator said local variable is definitely unassigned before being assigned; and compiling said source code with the compiler to generate bytecode, wherein the compiler treats, during compilation, all of said plurality of local variables inferred as immutable in the same manner as a local variable expressly declared to be immutable.
地址 Redwood Shores CA US