@@ -121,8 +121,8 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState;
121
121
end
122
122
inferred_result = nothing
123
123
relocatability = 0x1
124
- const_flag = is_result_constabi_eligible (result)
125
- if ! can_discard_trees || (is_cached (caller) && ! const_flag )
124
+ (; rettype, exctype, rettype_const, const_flags) = ResultForCache (result)
125
+ if ! can_discard_trees || (is_cached (caller) && iszero (const_flags & 0x1 ) )
126
126
inferred_result = transform_result_for_cache (interp, result)
127
127
# TODO : do we want to augment edges here with any :invoke targets that we got from inlining (such that we didn't have a direct edge to it already)?
128
128
relocatability = 0x0
@@ -145,9 +145,13 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState;
145
145
if ! @isdefined di
146
146
di = DebugInfo (result. linfo)
147
147
end
148
- ccall (:jl_update_codeinst , Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, UInt8, Any, Any),
149
- ci, inferred_result, const_flag, first (result. valid_worlds), last (result. valid_worlds), encode_effects (result. ipo_effects),
150
- result. analysis_results, relocatability, di, edges)
148
+ min_world, max_world = first (result. valid_worlds), last (result. valid_worlds)
149
+ ipo_effects = encode_effects (result. ipo_effects)
150
+ ccall (:jl_update_codeinst , Cvoid, (
151
+ Any, Any, Any, Any, Any, Int32, UInt, UInt,
152
+ UInt32, Any, UInt8, Any, Any),
153
+ ci, inferred_result, rettype, exctype, rettype_const, const_flags, min_world, max_world,
154
+ ipo_effects, result. analysis_results, relocatability, di, edges)
151
155
engine_reject (interp, ci)
152
156
end
153
157
return nothing
@@ -451,38 +455,15 @@ function finishinfer!(me::InferenceState, interp::AbstractInterpreter)
451
455
452
456
# finish populating inference results into the CodeInstance if possible, and maybe cache that globally for use elsewhere
453
457
if isdefined (result, :ci )
454
- result_type = result. result
455
- result_type isa LimitedAccuracy && (result_type = result_type. typ)
456
- @assert ! (result_type === nothing )
457
- if isa (result_type, Const)
458
- rettype_const = result_type. val
459
- const_flags = is_result_constabi_eligible (result) ? 0x3 : 0x2
460
- elseif isa (result_type, PartialOpaque)
461
- rettype_const = result_type
462
- const_flags = 0x2
463
- elseif isconstType (result_type)
464
- rettype_const = result_type. parameters[1 ]
465
- const_flags = 0x2
466
- elseif isa (result_type, PartialStruct)
467
- rettype_const = result_type. fields
468
- const_flags = 0x2
469
- elseif isa (result_type, InterConditional)
470
- rettype_const = result_type
471
- const_flags = 0x2
472
- elseif isa (result_type, InterMustAlias)
473
- rettype_const = result_type
474
- const_flags = 0x2
475
- else
476
- rettype_const = nothing
477
- const_flags = 0x0
478
- end
479
- relocatability = 0x0
458
+ (; rettype, exctype, rettype_const, const_flags) = ResultForCache (result)
480
459
di = nothing
481
460
edges = empty_edges # `edges` will be updated within `finish!`
482
461
ci = result. ci
483
- ccall (:jl_fill_codeinst , Cvoid, (Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
484
- ci, widenconst (result_type), widenconst (result. exc_result), rettype_const, const_flags,
485
- first (result. valid_worlds), last (result. valid_worlds),
462
+ min_world, max_world = first (result. valid_worlds), last (result. valid_worlds)
463
+ ccall (:jl_fill_codeinst , Cvoid, (
464
+ Any, Any, Any, Any, Int32, UInt, UInt,
465
+ UInt32, Any, Any, Any),
466
+ ci, rettype, exctype, rettype_const, const_flags, min_world, max_world,
486
467
encode_effects (result. ipo_effects), result. analysis_results, di, edges)
487
468
if is_cached (me)
488
469
cached_result = cache_result! (me. interp, result, ci)
@@ -494,6 +475,46 @@ function finishinfer!(me::InferenceState, interp::AbstractInterpreter)
494
475
nothing
495
476
end
496
477
478
+ struct ResultForCache
479
+ rettype
480
+ exctype
481
+ rettype_const
482
+ const_flags:: UInt8
483
+ ResultForCache (rettype, exctype, rettype_const, const_flags:: UInt8 ) = (
484
+ @nospecialize rettype exctype rettype_const;
485
+ new (rettype, exctype, rettype_const, const_flags))
486
+ end
487
+ @inline function ResultForCache (result:: InferenceResult )
488
+ result_type = result. result
489
+ result_type isa LimitedAccuracy && (result_type = result_type. typ)
490
+ @assert ! (result_type === nothing )
491
+ rettype = widenconst (result_type)
492
+ exctype = widenconst (result. exc_result)
493
+ if isa (result_type, Const)
494
+ rettype_const = result_type. val
495
+ const_flags = is_result_constabi_eligible (result) ? 0x3 : 0x2
496
+ elseif isa (result_type, PartialOpaque)
497
+ rettype_const = result_type
498
+ const_flags = 0x2
499
+ elseif isconstType (result_type)
500
+ rettype_const = result_type. parameters[1 ]
501
+ const_flags = 0x2
502
+ elseif isa (result_type, PartialStruct)
503
+ rettype_const = result_type. fields
504
+ const_flags = 0x2
505
+ elseif isa (result_type, InterConditional)
506
+ rettype_const = result_type
507
+ const_flags = 0x2
508
+ elseif isa (result_type, InterMustAlias)
509
+ rettype_const = result_type
510
+ const_flags = 0x2
511
+ else
512
+ rettype_const = nothing
513
+ const_flags = 0x0
514
+ end
515
+ return ResultForCache (rettype, exctype, rettype_const, const_flags)
516
+ end
517
+
497
518
# record the backedges
498
519
function store_backedges (caller:: CodeInstance , edges:: SimpleVector )
499
520
isa (caller. def. def, Method) || return # don't add backedges to toplevel method instance
@@ -1000,7 +1021,7 @@ function typeinf_ircode(interp::AbstractInterpreter, mi::MethodInstance,
1000
1021
end
1001
1022
(; result) = frame
1002
1023
opt = OptimizationState (frame, interp)
1003
- ir = run_passes_ipo_safe (opt . src , opt, optimize_until)
1024
+ ir = run_passes_ipo_safe (interp , opt, result; optimize_until)
1004
1025
rt = widenconst (ignorelimited (result. result))
1005
1026
return ir, rt
1006
1027
end
@@ -1025,6 +1046,7 @@ function typeinf_frame(interp::AbstractInterpreter, mi::MethodInstance, run_opti
1025
1046
opt = OptimizationState (frame, interp)
1026
1047
optimize (interp, opt, frame. result)
1027
1048
src = ir_to_codeinf! (opt)
1049
+ src. rettype = widenconst (result. result)
1028
1050
end
1029
1051
result. src = frame. src = src
1030
1052
end
0 commit comments