[immutability] Add support for modifications to Litho's Immutable Maps

Reviewed By: skcho

Differential Revision: D27008496

fbshipit-source-id: b4f4198b6
master
Ezgi Çiçek 4 years ago committed by Facebook GitHub Bot
parent 583a011666
commit bf0fa55a45

@ -196,6 +196,7 @@ COST_TESTS += java_fb-performance
DIRECT_TESTS += \
java_fb-config-impact \
java_fb-gk-interaction \
java_fb-immutability \
java_fb-performance
endif

@ -129,7 +129,7 @@ let get_modified_params pname post_stack pre_heap post formals =
BaseMemory.Edges.fold edges_pre ~init:acc ~f:(fun acc (access, (addr, _)) ->
add_to_modified pname ~pvar ~access ~addr pre_heap post acc )
| None ->
debug "The address is not materialized in in pre-heap." ;
debug "The address %a is not materialized in pre-heap.\n" AbstractValue.pp addr ;
acc )
| _ ->
acc )

@ -50,21 +50,30 @@ let pure =
; exited= Exited.bottom }
let implements_immutable_map tenv = function
| Typ.JavaClass java_class_name ->
JavaClassName.to_string java_class_name
|> PatternMatch.Java.implements_xmob_utils "ImmutableIntHashMap" tenv
| _ ->
false
let filter_modifies_immutable tenv ~f =
ModifiedVarMap.filter (fun _pvar ModifiedAccess.{ordered_access_list} ->
List.exists ordered_access_list ~f:(fun access ->
match access with
| HilExp.Access.FieldAccess fname ->
let class_name = Fieldname.get_class_name fname in
Tenv.lookup tenv class_name
|> Option.exists ~f:(fun mstruct ->
f mstruct
|> List.exists ~f:(fun (fieldname, _typ, annot) ->
String.equal
(Fieldname.get_field_name fieldname)
(Fieldname.get_field_name fname)
&& Annotations.ia_has_annotation_with annot (fun annot ->
Annotations.annot_ends_with annot Annotations.immutable ) ) )
implements_immutable_map tenv class_name
|| Tenv.lookup tenv class_name
|> Option.exists ~f:(fun mstruct ->
f mstruct
|> List.exists ~f:(fun (fieldname, _typ, annot) ->
String.equal
(Fieldname.get_field_name fieldname)
(Fieldname.get_field_name fname)
&& Annotations.ia_has_annotation_with annot (fun annot ->
Annotations.annot_ends_with annot Annotations.immutable ) ) )
| _ ->
false ) )

@ -0,0 +1 @@
{"pulse-model-return-first-arg": ".*ImmutableIntHashMap.duplicate\\(\\)\\|.*IntHashMap.moveToImmutable\\(\\)"}

@ -0,0 +1,15 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
TESTS_DIR = ../../..
ANALYZER = checkers
INFER_OPTIONS = --impurity-only --report-immutable-modifications --disable-issue-type IMPURE_FUNCTION \
--disable-issue-type NULLPTR_DEREFERENCE --report-force-relative-path
INFERPRINT_OPTIONS = --issues-tests
SOURCES = $(wildcard *.java)
include $(TESTS_DIR)/javac.make
Loading…
Cancel
Save