Skip to content

Commit 6023ad6

Browse files
authored
infer_effects: add optimize::Bool optional argument (#54241)
`optimize=false` would be useful for testing effects refinements with post-optimization analysis.
1 parent 9f37ba8 commit 6023ad6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

base/reflection.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,6 +2100,7 @@ end
21002100
"""
21012101
Base.infer_effects(
21022102
f, types=default_tt(f);
2103+
optimize::Bool=true,
21032104
world::UInt=get_world_counter(),
21042105
interp::Core.Compiler.AbstractInterpreter=Core.Compiler.NativeInterpreter(world)) -> effects::Effects
21052106
@@ -2108,6 +2109,7 @@ Returns the possible computation effects of the function call specified by `f` a
21082109
# Arguments
21092110
- `f`: The function to analyze.
21102111
- `types` (optional): The argument types of the function. Defaults to the default tuple type of `f`.
2112+
- `optimize` (optional): Whether to run additional effects refinements based on post-optimization analysis.
21112113
- `world` (optional): The world counter to use for the analysis. Defaults to the current world counter.
21122114
- `interp` (optional): The abstract interpreter to use for the analysis. Defaults to a new `Core.Compiler.NativeInterpreter` with the specified `world`.
21132115
@@ -2155,6 +2157,7 @@ signature, the `:nothrow` bit gets tainted.
21552157
- [`Base.@assume_effects`](@ref): A macro for making assumptions about the effects of a method.
21562158
"""
21572159
function infer_effects(@nospecialize(f), @nospecialize(types=default_tt(f));
2160+
optimize::Bool=true,
21582161
world::UInt=get_world_counter(),
21592162
interp::Core.Compiler.AbstractInterpreter=Core.Compiler.NativeInterpreter(world))
21602163
check_generated_context(world)
@@ -2171,7 +2174,7 @@ function infer_effects(@nospecialize(f), @nospecialize(types=default_tt(f));
21712174
end
21722175
for match in matches.matches
21732176
match = match::Core.MethodMatch
2174-
frame = Core.Compiler.typeinf_frame(interp, match, #=run_optimizer=#true)
2177+
frame = Core.Compiler.typeinf_frame(interp, match, #=run_optimizer=#optimize)
21752178
frame === nothing && return Core.Compiler.Effects()
21762179
effects = Core.Compiler.merge_effects(effects, frame.result.ipo_effects)
21772180
end

test/compiler/effects.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,12 +1096,14 @@ function f2_optrefine()
10961096
end
10971097
return true
10981098
end
1099+
@test !Core.Compiler.is_nothrow(Base.infer_effects(f2_optrefine; optimize=false))
10991100
@test Core.Compiler.is_nothrow(Base.infer_effects(f2_optrefine))
11001101

11011102
function f3_optrefine(x)
11021103
@fastmath sqrt(x)
11031104
return x
11041105
end
1106+
@test !Core.Compiler.is_consistent(Base.infer_effects(f2_optrefine; optimize=false))
11051107
@test Core.Compiler.is_consistent(Base.infer_effects(f3_optrefine, (Float64,)))
11061108

11071109
# Check that :consistent is properly modeled for throwing statements

0 commit comments

Comments
 (0)