Skip to content

Commit

Permalink
infer_effects: add optimize::Bool optional argument (#54241)
Browse files Browse the repository at this point in the history
`optimize=false` would be useful for testing effects refinements with
post-optimization analysis.
  • Loading branch information
aviatesk committed Apr 28, 2024
1 parent 9f37ba8 commit 6023ad6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2100,6 +2100,7 @@ end
"""
Base.infer_effects(
f, types=default_tt(f);
optimize::Bool=true,
world::UInt=get_world_counter(),
interp::Core.Compiler.AbstractInterpreter=Core.Compiler.NativeInterpreter(world)) -> effects::Effects
Expand All @@ -2108,6 +2109,7 @@ Returns the possible computation effects of the function call specified by `f` a
# Arguments
- `f`: The function to analyze.
- `types` (optional): The argument types of the function. Defaults to the default tuple type of `f`.
- `optimize` (optional): Whether to run additional effects refinements based on post-optimization analysis.
- `world` (optional): The world counter to use for the analysis. Defaults to the current world counter.
- `interp` (optional): The abstract interpreter to use for the analysis. Defaults to a new `Core.Compiler.NativeInterpreter` with the specified `world`.
Expand Down Expand Up @@ -2155,6 +2157,7 @@ signature, the `:nothrow` bit gets tainted.
- [`Base.@assume_effects`](@ref): A macro for making assumptions about the effects of a method.
"""
function infer_effects(@nospecialize(f), @nospecialize(types=default_tt(f));
optimize::Bool=true,
world::UInt=get_world_counter(),
interp::Core.Compiler.AbstractInterpreter=Core.Compiler.NativeInterpreter(world))
check_generated_context(world)
Expand All @@ -2171,7 +2174,7 @@ function infer_effects(@nospecialize(f), @nospecialize(types=default_tt(f));
end
for match in matches.matches
match = match::Core.MethodMatch
frame = Core.Compiler.typeinf_frame(interp, match, #=run_optimizer=#true)
frame = Core.Compiler.typeinf_frame(interp, match, #=run_optimizer=#optimize)
frame === nothing && return Core.Compiler.Effects()
effects = Core.Compiler.merge_effects(effects, frame.result.ipo_effects)
end
Expand Down
2 changes: 2 additions & 0 deletions test/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1096,12 +1096,14 @@ function f2_optrefine()
end
return true
end
@test !Core.Compiler.is_nothrow(Base.infer_effects(f2_optrefine; optimize=false))
@test Core.Compiler.is_nothrow(Base.infer_effects(f2_optrefine))

function f3_optrefine(x)
@fastmath sqrt(x)
return x
end
@test !Core.Compiler.is_consistent(Base.infer_effects(f2_optrefine; optimize=false))
@test Core.Compiler.is_consistent(Base.infer_effects(f3_optrefine, (Float64,)))

# Check that :consistent is properly modeled for throwing statements
Expand Down

2 comments on commit 6023ad6

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.