-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
inference: fix bad effects for recursion #51092
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -432,6 +432,34 @@ function cycle_fix_limited(@nospecialize(typ), sv::InferenceState) | |||||||||||||||||
return typ | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function adjust_effects(ipo_effects::Effects, def::Method) | ||||||||||||||||||
# override the analyzed effects using manually annotated effect settings | ||||||||||||||||||
override = decode_effects_override(def.purity) | ||||||||||||||||||
if is_effect_overridden(override, :consistent) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; consistent=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :effect_free) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; effect_free=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :nothrow) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; nothrow=true) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :terminates_globally) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; terminates=true) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :notaskstate) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; notaskstate=true) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :inaccessiblememonly) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; inaccessiblememonly=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :noub) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; noub=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
return ipo_effects | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
function adjust_effects(sv::InferenceState) | ||||||||||||||||||
ipo_effects = sv.ipo_effects | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -478,28 +506,7 @@ function adjust_effects(sv::InferenceState) | |||||||||||||||||
# override the analyzed effects using manually annotated effect settings | ||||||||||||||||||
def = sv.linfo.def | ||||||||||||||||||
if isa(def, Method) | ||||||||||||||||||
override = decode_effects_override(def.purity) | ||||||||||||||||||
if is_effect_overridden(override, :consistent) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; consistent=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :effect_free) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; effect_free=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :nothrow) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; nothrow=true) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :terminates_globally) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; terminates=true) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :notaskstate) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; notaskstate=true) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :inaccessiblememonly) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; inaccessiblememonly=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
if is_effect_overridden(override, :noub) | ||||||||||||||||||
ipo_effects = Effects(ipo_effects; noub=ALWAYS_TRUE) | ||||||||||||||||||
end | ||||||||||||||||||
ipo_effects = adjust_effects(ipo_effects, def) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
return ipo_effects | ||||||||||||||||||
|
@@ -850,16 +857,18 @@ function typeinf_edge(interp::AbstractInterpreter, method::Method, @nospecialize | |||||||||||||||||
end | ||||||||||||||||||
typeinf(interp, frame) | ||||||||||||||||||
update_valid_age!(caller, frame.valid_worlds) | ||||||||||||||||||
edge = is_inferred(frame) ? mi : nothing | ||||||||||||||||||
return EdgeCallResult(frame.bestguess, edge, frame.ipo_effects) # effects are adjusted already within `finish` | ||||||||||||||||||
isinferred = is_inferred(frame) | ||||||||||||||||||
edge = isinferred ? mi : nothing | ||||||||||||||||||
effects = isinferred ? frame.ipo_effects : adjust_effects(Effects(), method) # effects are adjusted already within `finish` for ipo_effects | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I came up with this fix for
Suggested change
But I just realized this isn't correct, because we can't guarantee that any overlay methods aren't involved within a recursive call graph.. I think there are two options:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||
return EdgeCallResult(frame.bestguess, edge, effects) | ||||||||||||||||||
elseif frame === true | ||||||||||||||||||
# unresolvable cycle | ||||||||||||||||||
return EdgeCallResult(Any, nothing, Effects()) | ||||||||||||||||||
end | ||||||||||||||||||
# return the current knowledge about this cycle | ||||||||||||||||||
frame = frame::InferenceState | ||||||||||||||||||
update_valid_age!(caller, frame.valid_worlds) | ||||||||||||||||||
return EdgeCallResult(frame.bestguess, nothing, adjust_effects(frame)) | ||||||||||||||||||
return EdgeCallResult(frame.bestguess, nothing, adjust_effects(Effects(), method)) | ||||||||||||||||||
end | ||||||||||||||||||
|
||||||||||||||||||
function cached_return_type(code::CodeInstance) | ||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.