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 effects modeling for return_type #45299

Merged
merged 2 commits into from
May 16, 2022
Merged

Fix effects modeling for return_type #45299

merged 2 commits into from
May 16, 2022

Conversation

Keno
Copy link
Member

@Keno Keno commented May 12, 2022

Effects modeling was bad in both directions (not precise in some cases, incorrect in others). This pair of commits refactors the code to make the effects modeling precise and then uses it in the optimizer to address the correctness issues.

@Keno Keno force-pushed the kf/rt_effect_free branch 2 times, most recently from f51974c to b8eb426 Compare May 13, 2022 00:37
elseif f === Tuple && la == 2
tristate_merge!(sv, EFFECTS_UNKNOWN) # TODO
aty = argtypes[2]
ty = isvarargtype(aty) ? unwrapva(aty) : widenconst(aty)
if !isconcretetype(ty)
return CallMeta(Tuple, false)
return CallMeta(Tuple, EFFECTS_UNKNOWN, false)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Now we can remove the tristate_merge!(sv, EFFECTS_UNKNOWN) # TODO at L1640.

base/compiler/tfuncs.jl Show resolved Hide resolved
end
end
end
end
end
return CallMeta(Type, false)
return CallMeta(Type, EFFECTS_THROWS, false)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Should we call it EFFECTS_UNKNOWN here, since we don't know the method being called at all?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

(specifically, it might be one that specifies the world age, and thus possibly needs to happen specifically later)

Copy link
Member Author

Choose a reason for hiding this comment

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

(specifically, it might be one that specifies the world age, and thus possibly needs to happen specifically later)

I'm not sure I'm following. Are you concerned that the version that takes a world age would get called with a future world-age (or possibly from pre-compilation), which would cause consistency to be tainted as well? Surely it should always at least terminate and be effect free for our purposes.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I was mostly more considering that people could add other methods to it, hypothetically, and perhaps those wouldn't have the same effects limits. It is not a significant concern however.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps, but by the same argument, someone could overwrite the method we're modeling above. I think going into Core.Compiler and extending and overriding methods is just caveat emptor.

@@ -1749,15 +1739,13 @@ function abstract_call(interp::AbstractInterpreter, arginfo::ArgInfo,
tristate_merge!(sv, Effects()) # TODO
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
tristate_merge!(sv, Effects()) # TODO

I think this TODO is completed by abstract_call_opaque_closure's effects tracking above

Copy link
Member Author

Choose a reason for hiding this comment

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

Not quite, because we don't account for the type constraints on the opaque closure type, which implicitly get evaluated on the call and return. I can probably just go ahead and fix that while I'm at it though.

Keno added 2 commits May 15, 2022 21:57
In addition to the TODO placeholder that was taininting all effects
for `return_type`, we were also accidentally picking up the effects
of the function we were analyzing. This mostly didn't show up as
an issue, because we were treating return_type as pure in optimization,
but it could prevent deletion of unused functions by incorrectly
tainting the effects.
Inlining had a special case for return_type that was not taking
into account whether or not return_type was being called correctly.
Since we already have the correct modeling in inference, remove
the special case from inlining and simply have inference forward
its conclusions.
@Keno Keno merged commit 37dd084 into master May 16, 2022
@Keno Keno deleted the kf/rt_effect_free branch May 16, 2022 04:56
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Jun 16, 2022
JuliaLang/julia#45299 improved the effect inference on
`Core.Compiler.return_type` callsite.
This commit make our effect rendering consistent with it.
aviatesk added a commit to JuliaDebug/Cthulhu.jl that referenced this pull request Jun 16, 2022
JuliaLang/julia#45299 improved the effect inference on
`Core.Compiler.return_type` callsite.
This commit make our effect rendering consistent with it.
@aviatesk aviatesk mentioned this pull request Jul 21, 2022
32 tasks
aviatesk pushed a commit that referenced this pull request Jul 26, 2022
Fix effects modeling for return_type
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.

4 participants