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

Annotate Node fields as const #80

Open
tpgillam opened this issue Aug 18, 2022 · 0 comments
Open

Annotate Node fields as const #80

tpgillam opened this issue Aug 18, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@tpgillam
Copy link
Owner

Make use of the new functionality in Julia 1.8 introduced here: JuliaLang/julia#43305

Should hopefully be able to annotate both members of Node, since the structure itself is only mutable to allow finalizers to run.
Two things to consider:

  1. How to do this in a way that doesn't break compatibility with Julia 1.6?
  2. If both fields are marked as const, will this break finalizers for the object?
  3. We should test that the fields actually cannot be mutated.

TimeDag.jl/src/core.jl

Lines 14 to 25 in 2216089

!!! warning
Note that a `Node` is only declared mutable so that we can attach finalizers to
instances. This is required for the [`WeakIdentityMap`](@ref) to work.
Nodes should NEVER actually be mutated!
Due to subgraph elimination, nodes that are equivalent should always be identical objects.
We therefore leave `hash` & `==` defined in terms of the `objectid`.
"""
mutable struct Node{T}
parents::NTuple{N,Node} where {N}
op::NodeOp{T}
end

1 — if no neater solution is available, should just be able to do a switch based on the VERSION >= v"1.8", so as to switch between two different struct definitions.
2 — the tests should catch this if it breaks.

@tpgillam tpgillam added the enhancement New feature or request label Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant