Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsound record contract deduplication #2042

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Sep 16, 2024

Closes #2041.

As hinted in the original issue, the culprit is indeed the contract deduplication optimization, and more specifically the contract equality checker. The checker only looks at the fields' values to establish equality without looking at the metadata, which is obviously wrong, as it would equate most contracts with the same structures such as {foo | Number} and {foo | String}, since the distinction is in the metadata.

This commit fixes the issue by comparing the field metadata as well.

Contract equality code used to flat out ignore all of the metadata of a
fields, including contract annotations, which is obviously entirely
wrong. This means that `{foo | String}` and `{foo | Number}` was deemed
equal and deduplicated as the same contract.

This commit fixes the issue by comparing the metadata as well. Contract
labels are a subtle matter, and they are the only part that is ignored
by the contract equality code.
@yannham
Copy link
Member Author

yannham commented Sep 16, 2024

TODO:

  • add regression test
  • check the impact on the performance on the private benchmark

@yannham yannham requested a review from jneem September 16, 2024 12:38
@github-actions github-actions bot temporarily deployed to pull request September 16, 2024 12:39 Inactive
core/src/typecheck/eq.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request September 16, 2024 13:21 Inactive
Copy link
Contributor

github-actions bot commented Sep 16, 2024

🐰 Bencher Report

Branch2042/merge
Testbedubuntu-latest

⚠️ WARNING: The following Measure does not have a Threshold. Without a Threshold, no Alerts will ever be generated!

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds CLI flag.

Click to view all benchmark results
BenchmarkLatencynanoseconds (ns)
fibonacci 10📈 view plot
⚠️ NO THRESHOLD
498,230.00
pidigits 100📈 view plot
⚠️ NO THRESHOLD
3,281,100.00
product 30📈 view plot
⚠️ NO THRESHOLD
820,750.00
scalar 10📈 view plot
⚠️ NO THRESHOLD
1,495,100.00
sum 30📈 view plot
⚠️ NO THRESHOLD
824,090.00
🐰 View full continuous benchmarking report in Bencher

@github-actions github-actions bot temporarily deployed to pull request September 16, 2024 14:25 Inactive
@yannham yannham added this pull request to the merge queue Sep 16, 2024
Merged via the queue into master with commit 4a4825e Sep 16, 2024
7 checks passed
@yannham yannham deleted the fix/contract-dedup-record-unsound branch September 16, 2024 16:14
yannham added a commit that referenced this pull request Sep 17, 2024
* Fix contract equality unsound on records

Contract equality code used to flat out ignore all of the metadata of a
fields, including contract annotations, which is obviously entirely
wrong. This means that `{foo | String}` and `{foo | Number}` was deemed
equal and deduplicated as the same contract.

This commit fixes the issue by comparing the metadata as well. Contract
labels are a subtle matter, and they are the only part that is ignored
by the contract equality code.

* Add comparison of label's type_environment for safety

* Update core/src/typecheck/eq.rs

Co-authored-by: jneem <[email protected]>

* Add integration test for contract dedup unsoundness

---------

Co-authored-by: jneem <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple contracts on a record not working as intended
2 participants