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 justActive condition #1936

Merged
merged 1 commit into from
Oct 22, 2024
Merged

Fix justActive condition #1936

merged 1 commit into from
Oct 22, 2024

Conversation

danielwe
Copy link
Contributor

@danielwe danielwe commented Oct 3, 2024

Closes #1935

Let me know if there's a better/more correct solution

@@ -467,7 +467,7 @@ end

subT = fieldtype(T, f)

if justActive && !allocatedinline(subT)
if justActive && ismutabletype(subT)
Copy link
Member

Choose a reason for hiding this comment

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

So I understand the failure but I’m confused why this would resolve it.

@vchuravy do you have cycles to review as well

Copy link
Contributor Author

@danielwe danielwe Oct 4, 2024

Choose a reason for hiding this comment

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

As mentioned in #1935 (comment), the problem is that a struct that contains non-isbits fields and can be incompletely initialized will not be allocated inline, even if it is immutable. As such, it's an error to conclude anything about activity from allocatedinline. A type can have immutable semantics and thus contain active values even if it is not allocated inline.

A mutable type, however, is of either duplicated or const type, hence it's safe to take this early return path. (Judging by #1926 this is true even if the mutable type has differentiable const fields.)

Copy link
Contributor Author

@danielwe danielwe Oct 4, 2024

Choose a reason for hiding this comment

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

I suppose since a non-inlined value necessarily has a memory address, an alternative would be to disregard the purported immutability and let make_zero! zero out the relevant fields anyway. However, the ccall(:jl_set_nth_field, ...) solution from #1926 doesn't work on these types, so it would have to be done with raw pointer twiddling.

But this doesn't sound appealing to me for several reasons, the most important of which is that you can now get a DupState type by nesting an immutable ActiveState type inside an immutable container (provided the justActive = false case is changed to be consistent with this choice). See Tuple{Incomplete} from the test case for an example; in other words, this would require a user to annotate an Incomplete argument as Active or MixedDuplicated, but a Tuple{Incomplete} argument as Duplicated. This would be non-intuitive, hard to reason about, and probably even harder to explain to users. Better to respect that Incomplete is immutable as declared. That leaves us with the above conclusion: you can't use allocatedinline to conclude about activity state.

This was referenced Oct 11, 2024
@wsmoses wsmoses merged commit 6c23ee7 into EnzymeAD:main Oct 22, 2024
11 of 24 checks passed
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.

active_reg_inner with justActive = true incorrect with immutable types that can be incompletely initialized
2 participants