Skip to content

disallow mutation of BinaryHeap fields - #995

Draft
nsajko wants to merge 1 commit into
JuliaCollections:masterfrom
nsajko:mutable-struct-BinaryHeap
Draft

nsajko wants to merge 1 commit into
JuliaCollections:masterfrom
nsajko:mutable-struct-BinaryHeap

Conversation

@nsajko

@nsajko nsajko commented Oct 6, 2026

Copy link
Copy Markdown
Member

I see no reason to allow mutating the fields. The implementation does not require it, and I think the fields are not a public interface.

Making the fields const allows the Julia compiler/optimizer more freedom when reasoning about code that involves BinaryHeap values.

NB: for the case when the subtype of Ordering is zero bytes wide, it would make more sense to just change mutable struct into struct. While the order is often of singleton type, that is not always the case. Thus this change is conservative, going for the straight improvement while avoiding a trade off. If necessary, it is possible to change to just struct BinaryHeap after this change is merged.

Cross-reference issue #988.

Corresponding PR to the BinaryHeaps package:

I see no reason to allow mutating the fields. The implementation does
not require it, and I think the fields are not a public interface.

Making the fields `const` allows the Julia compiler/optimizer more
freedom when reasoning about code that involves `BinaryHeap` values.

NB: for the case when the subtype of `Ordering` is zero bytes wide, it
would make more sense to just change `mutable struct` into `struct`.
While the order is often of singleton type, that is not always the case.
Thus this change is conservative, going for the straight improvement
while avoiding a trade off. If necessary, it is possible to change to
just `struct BinaryHeap`  after this change is merged.

Cross-reference issue JuliaCollections#988.

Corresponding PR to the BinaryHeaps package:

* SciML/BinaryHeaps.jl#27
@nsajko

nsajko commented Oct 6, 2026

Copy link
Copy Markdown
Member Author

const for a field of a mutable struct requires Julia v1.8 or above. Related PR to drop pre-LTS versions of Julia: #990.

This branch has not been deployed

No deployments
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.

1 participant