[purity] Add model for Object.clone()

Summary: `Object.clone` modeled as pure until the analysis can distinguish returning a fresh object vs. having no side-effects.

Reviewed By: skcho

Differential Revision: D20439998

fbshipit-source-id: 421054cfb
master
Ezgi Çiçek 5 years ago committed by Facebook GitHub Bot
parent baaf81b554
commit 2bd39abefc

@ -119,6 +119,7 @@ module ProcName = struct
; +PatternMatch.implements_lang "StringBuilder" &:: "<init>" <>--> PurityDomain.pure
; +PatternMatch.implements_lang "StringBuilder" &:: "append" <>--> modifies_first
; +PatternMatch.implements_lang "StringBuilder" &:: "length" <>--> PurityDomain.pure
; +PatternMatch.implements_lang "Object" &:: "clone" <>--> PurityDomain.pure
; +PatternMatch.implements_lang "Object" &:: "equals" <>--> PurityDomain.pure
; +PatternMatch.implements_lang "Object" &:: "toString" <>--> PurityDomain.pure
; +PatternMatch.implements_lang "Object" &:: "getClass" <>--> PurityDomain.pure

@ -4,6 +4,8 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import java.util.ArrayList;
class PurityModeled {
double math_random_impure() {
@ -15,4 +17,19 @@ class PurityModeled {
// copies an array from the specified source array
System.arraycopy(src, 0, dst, 0, 1);
}
enum Color {
RED,
GREEN,
BLUE; // values() calls clone
}
public void enum_iter_pure() {
for (Color c : Color.values()) {}
}
void clone_pure(ArrayList<String> list) {
ArrayList<String> cloned = (ArrayList<String>) list.clone();
cloned.add(""); // no change the list
}
}

@ -4,7 +4,11 @@ codetoanalyze/java/purity/Localities.java, Localities.call_impure_with_fresh_arg
codetoanalyze/java/purity/Localities.java, Localities.length_pure(java.util.ArrayList):int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int Localities.length_pure(ArrayList)]
codetoanalyze/java/purity/Localities.java, Localities.mkHC_pure(Localities$Counter):Localities$HasCounter, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function Localities$HasCounter Localities.mkHC_pure(Localities$Counter)]
codetoanalyze/java/purity/Localities.java, Localities.setFreshArrayEntry_pure(int,int):int[], 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int[] Localities.setFreshArrayEntry_pure(int,int)]
codetoanalyze/java/purity/PurityModeled.java, PurityModeled$Color.valueOf(java.lang.String):PurityModeled$Color, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function PurityModeled$Color PurityModeled$Color.valueOf(String)]
codetoanalyze/java/purity/PurityModeled.java, PurityModeled$Color.values():PurityModeled$Color[], 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function PurityModeled$Color[] PurityModeled$Color.values()]
codetoanalyze/java/purity/PurityModeled.java, PurityModeled.arraycopy_pure(int[]):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void PurityModeled.arraycopy_pure(int[])]
codetoanalyze/java/purity/PurityModeled.java, PurityModeled.clone_pure(java.util.ArrayList):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void PurityModeled.clone_pure(ArrayList)]
codetoanalyze/java/purity/PurityModeled.java, PurityModeled.enum_iter_pure():void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void PurityModeled.enum_iter_pure()]
codetoanalyze/java/purity/Test.java, Test.call_pure_pure(int):void, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function void Test.call_pure_pure(int)]
codetoanalyze/java/purity/Test.java, Test.emptyList_impure_FP():java.util.ArrayList, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function ArrayList Test.emptyList_impure_FP()]
codetoanalyze/java/purity/Test.java, Test.local_alloc_pure(int,int):int, 0, PURE_FUNCTION, no_bucket, ERROR, [Side-effect free function int Test.local_alloc_pure(int,int)]

Loading…
Cancel
Save