Skip to content

gb_sets and gb_trees: Add checks to from_ordset and from_orddict#10910

Merged
bjorng merged 1 commit intoerlang:masterfrom
Maria-12648430:gb_sets_gb_trees_check
Mar 27, 2026
Merged

gb_sets and gb_trees: Add checks to from_ordset and from_orddict#10910
bjorng merged 1 commit intoerlang:masterfrom
Maria-12648430:gb_sets_gb_trees_check

Conversation

@Maria-12648430
Copy link
Copy Markdown
Contributor

@Maria-12648430 Maria-12648430 commented Mar 24, 2026

I recently had the pleasure to debug some code where, ultimately, an unordered list and/or with duplicates, was given to gb_sets:from_ordset/1. The implementation does not complain, but silently turns the list into an invalid gb_set, resulting in misbehaviors like elements that are in the set not being found, and elements that have been deleted from the set still being reported as being in the set. Adding or deleting elements from the set may also result in elements appearing and disappearing. And so on 🤷‍♀️

This is a mistake easily made. Until recently, the documentation kinda encouraged the use of from_ordset in multiple places, with the assumption that the list given to it is sorted and free of duplicates only mentioned in the prose of from_ordset. It is also a mistake very hard to find once made, more so when you're not the person who wrote that code, and the person who did left years ago. (😡)

Anyway. This PR adds checks to the functions which turn lists-that-may-be-ordsets-or-not. Internal uses bypass the check in order to not impose a penalty when not necessary.

This also applies to gb_trees:from_orddict/1, which is likewise changed by this PR.

On the way, we also added gb_trees:from_list/1, and removed the one remaining old-style catch in sets_SUITE.

There are no tests yet, we would like to hear if this addition is really wanted or not before putting more work into it 😉

This change may break some existing code, but if so, IMO for the better, as it would clearly be a bug.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

CT Test Results

    2 files    100 suites   1h 3m 58s ⏱️
2 288 tests 2 237 ✅ 51 💤 0 ❌
2 707 runs  2 651 ✅ 56 💤 0 ❌

Results for commit 9e122bb.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@Maria-12648430 Maria-12648430 force-pushed the gb_sets_gb_trees_check branch 3 times, most recently from 0ead779 to 9c8f5b6 Compare March 24, 2026 17:23
@bjorng bjorng self-assigned this Mar 25, 2026
@bjorng bjorng added the team:VM Assigned to OTP team VM label Mar 25, 2026
Copy link
Copy Markdown
Contributor

@bjorng bjorng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your pull request. It's looks good to me (except for one implementation detail), but we will have to discuss it in the OTP team.

Comment thread lib/stdlib/src/gb_sets.erl Outdated
@Maria-12648430
Copy link
Copy Markdown
Contributor Author

Thanks for your pull request. It's looks good to me (except for one implementation detail), but we will have to discuss it in the OTP team.

Sure, no problem.

As it turns out, this change has already unearthed a bug in qlc_SUITE, btw.

@Maria-12648430 Maria-12648430 force-pushed the gb_sets_gb_trees_check branch 2 times, most recently from 74ff048 to 9e122bb Compare March 25, 2026 14:55
@bjorng bjorng added the testing currently being tested, tag is used by OTP internal CI label Mar 26, 2026
@bjorng bjorng force-pushed the gb_sets_gb_trees_check branch from 9e122bb to c4d20b5 Compare March 27, 2026 13:06
bjorng
bjorng previously approved these changes Mar 27, 2026
Co-authored-by: Jan Uhlig <juhlig@hnc-agency.org>
@bjorng bjorng force-pushed the gb_sets_gb_trees_check branch from c4d20b5 to 71b86fb Compare March 27, 2026 13:23
@bjorng bjorng merged commit af2eb01 into erlang:master Mar 27, 2026
25 checks passed
@bjorng
Copy link
Copy Markdown
Contributor

bjorng commented Mar 27, 2026

Thanks for your pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team:VM Assigned to OTP team VM testing currently being tested, tag is used by OTP internal CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants