-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unsound contract equality fast check (#1703)
* Fix unsound ptr eq check in contract equality For performance reason, the contract equality checker performs a quick pointer check to see if the two terms to compare are physically equal. In this case, it used to return `true` directly, eschewing more costly recursive checks. However, this is unsound, because the same term (physically) might be in two different environments, and have two different values. This is typically the case with function application: when evaluating `f 1` and `f 2`, both terms will physically point to the body of `f`, but in a different environment. Thus, we also need to ensure that environment are equals as well in this quick check. This commit adds a fast `ptr_eq` check to the environment as well, and now checks that both terms and their respective environments are pairwise physically equals. Passing by, this commits also fix unrelated clippy warning, after the udpate to clippy 1.73. * Add regression test for #1700 * Implement env equality during typechecking * Cosmetic renaming and slight rework of comments * Fix contract test by deeply evaluating it * Remove confusing comments
- Loading branch information
Showing
5 changed files
with
51 additions
and
17 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
11 changes: 11 additions & 0 deletions
11
core/tests/integration/fail/contracts/unsound_dedup_dict_contract.ncl
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,11 @@ | ||
# test.type = 'error' | ||
# eval = 'full' | ||
# | ||
# [test.metadata] | ||
# error = 'EvalError::BlameError' | ||
|
||
# Regression test for https://github.com/tweag/nickel/issues/1700 | ||
let False = std.contract.from_predicate (fun x => false) in | ||
({ bli = {foo = 1} } | ||
| { _| {..} }) | ||
| { _| False } |