-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Pulse erlang comparisons between {atom, any} and any
Summary: When comparing two values `x` and `y`, when `x` is an integer and `y` can have any type (usually an unknown value, such as a function parameter), the Pulse erlang model splits cases on `y` being an integer or not, and then uses an integer and incompartible comparison on the according cases. Atoms didn't implement this, but instead of just being considered as unsupported, the code used to consider that `(x : Atom)` and `(y: Any)` were incompatible. This leads to `x == y` being interpreted as always `false`, which is neither sound (should be unconstrained) or complete (should be bottom/unreachable) when `y` can be anything. We fix this by precisely supporting `Atom` vs. `Any` comparisons the same way we do for integers. We incidentally fix `Any` vs unsupported types (such as lists) comparisons by having them unsupported instead of assuming the types are distinct. `Any` vs `Any` is also concerned by this incidental fix. Remark: this does transform some false negative tests into false positive, which at first sight would seem to be inconsistent with Pulse goals. This is because equality on unsupported types returns an unconstrained value instead of stopping the execution, which could be considered as another change (the reason for this being that stopping the execution would lead to too many false negatives with the current any-type-splitting logic). Also note that the behaviour, although less precise, is more consistent: tests that check if the result of an unsupported call is `true` or `false` should behave the same, which wasn't the case before. Reviewed By: rgrig Differential Revision: D49831551 fbshipit-source-id: 67043bd897f62691b1fa1fe0ad029d004560e9c2
- Loading branch information
1 parent
d35f9f0
commit ecd21cf
Showing
8 changed files
with
96 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ../../../.. | ||
|
||
INFER_OPTIONS = --topl-only --topl-properties property.topl --enable-issue-type TOPL_ERROR_LATENT --project-root $(TESTS_DIR) | ||
INFERPRINT_OPTIONS = --issues-tests | ||
|
||
SOURCES = $(wildcard *.erl) | ||
|
||
include $(TESTS_DIR)/erlc.make | ||
|
||
infer-out/report.json: $(MAKEFILE_LIST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
codetoanalyze/erlang/topl/track-xid/topl_track_xid.erl, direct/1, 0, TOPL_ERROR, no_bucket, ERROR, [call to src/2,call to tgt/2] | ||
codetoanalyze/erlang/topl/track-xid/topl_track_xid.erl, tuple/1, 0, TOPL_ERROR_LATENT, no_bucket, ERROR, [call to src/2,call to tgt/2] | ||
codetoanalyze/erlang/topl/track-xid/topl_track_xid.erl, map/1, 0, TOPL_ERROR_LATENT, no_bucket, ERROR, [call to src/2,call to tgt/2] |
4 changes: 4 additions & 0 deletions
4
infer/tests/codetoanalyze/erlang/topl/track-xid/property.topl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
property Xid | ||
start->start: * | ||
start->track: "b:src/2"(V, X, R) when X:Cons.strval == "xid" => r := V | ||
track->error: "b:tgt/2"(V, X, R) when X:Cons.strval == "xid" && r == V |
16 changes: 16 additions & 0 deletions
16
infer/tests/codetoanalyze/erlang/topl/track-xid/topl_track_xid.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-module(topl_track_xid). | ||
-export([direct/1, tuple/1, map/1]). | ||
|
||
direct(X) -> | ||
b:src(X, "xid"), | ||
b:tgt(X, "xid"). | ||
|
||
tuple(X) -> | ||
{Y} = X, | ||
b:src(Y, "xid"), | ||
b:tgt(Y, "xid"). | ||
|
||
map(X) -> | ||
#{y:=Y} = X, | ||
b:src(Y, "xid"), | ||
b:tgt(Y, "xid"). |