@@ -118,10 +118,9 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState)
118
118
# we can now widen our applicability in the global cache too
119
119
store_backedges (ci, edges)
120
120
end
121
- inferred_result = nothing
122
- uncompressed = inferred_result
123
- const_flag = is_result_constabi_eligible (result)
124
- discard_src = caller. cache_mode === CACHE_MODE_NULL || const_flag
121
+ uncompressed = inferred_result = nothing
122
+ (; rettype, exctype, rettype_const, const_flags) = ResultForCache (result)
123
+ discard_src = caller. cache_mode === CACHE_MODE_NULL || is_result_constabi_eligible (result)
125
124
if ! discard_src
126
125
inferred_result = transform_result_for_cache (interp, result)
127
126
# 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)?
@@ -143,9 +142,13 @@ function finish!(interp::AbstractInterpreter, caller::InferenceState)
143
142
if ! @isdefined di
144
143
di = DebugInfo (result. linfo)
145
144
end
146
- ccall (:jl_update_codeinst , Cvoid, (Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
147
- ci, inferred_result, const_flag, first (result. valid_worlds), last (result. valid_worlds), encode_effects (result. ipo_effects),
148
- result. analysis_results, di, edges)
145
+ min_world, max_world = first (result. valid_worlds), last (result. valid_worlds)
146
+ ipo_effects = encode_effects (result. ipo_effects)
147
+ ccall (:jl_update_codeinst , Cvoid, (
148
+ Any, Any, Any, Any, Any, Int32, UInt, UInt,
149
+ UInt32, Any, Any, Any),
150
+ ci, inferred_result, rettype, exctype, rettype_const, const_flags, min_world, max_world,
151
+ ipo_effects, result. analysis_results, di, edges)
149
152
engine_reject (interp, ci)
150
153
if ! discard_src && isdefined (interp, :codegen ) && uncompressed isa CodeInfo
151
154
# record that the caller could use this result to generate code when required, if desired, to avoid repeating n^2 work
@@ -488,37 +491,15 @@ function finishinfer!(me::InferenceState, interp::AbstractInterpreter)
488
491
489
492
# finish populating inference results into the CodeInstance if possible, and maybe cache that globally for use elsewhere
490
493
if isdefined (result, :ci )
491
- result_type = result. result
492
- result_type isa LimitedAccuracy && (result_type = result_type. typ)
493
- @assert ! (result_type === nothing )
494
- if isa (result_type, Const)
495
- rettype_const = result_type. val
496
- const_flags = is_result_constabi_eligible (result) ? 0x3 : 0x2
497
- elseif isa (result_type, PartialOpaque)
498
- rettype_const = result_type
499
- const_flags = 0x2
500
- elseif isconstType (result_type)
501
- rettype_const = result_type. parameters[1 ]
502
- const_flags = 0x2
503
- elseif isa (result_type, PartialStruct)
504
- rettype_const = result_type. fields
505
- const_flags = 0x2
506
- elseif isa (result_type, InterConditional)
507
- rettype_const = result_type
508
- const_flags = 0x2
509
- elseif isa (result_type, InterMustAlias)
510
- rettype_const = result_type
511
- const_flags = 0x2
512
- else
513
- rettype_const = nothing
514
- const_flags = 0x0
515
- end
494
+ (; rettype, exctype, rettype_const, const_flags) = ResultForCache (result)
516
495
di = nothing
517
496
edges = empty_edges # `edges` will be updated within `finish!`
518
497
ci = result. ci
519
- ccall (:jl_fill_codeinst , Cvoid, (Any, Any, Any, Any, Int32, UInt, UInt, UInt32, Any, Any, Any),
520
- ci, widenconst (result_type), widenconst (result. exc_result), rettype_const, const_flags,
521
- first (result. valid_worlds), last (result. valid_worlds),
498
+ min_world, max_world = first (result. valid_worlds), last (result. valid_worlds)
499
+ ccall (:jl_fill_codeinst , Cvoid, (
500
+ Any, Any, Any, Any, Int32, UInt, UInt,
501
+ UInt32, Any, Any, Any),
502
+ ci, rettype, exctype, rettype_const, const_flags, min_world, max_world,
522
503
encode_effects (result. ipo_effects), result. analysis_results, di, edges)
523
504
if is_cached (me) # CACHE_MODE_GLOBAL
524
505
cached_result = cache_result! (me. interp, result, ci)
@@ -530,6 +511,46 @@ function finishinfer!(me::InferenceState, interp::AbstractInterpreter)
530
511
nothing
531
512
end
532
513
514
+ struct ResultForCache
515
+ rettype
516
+ exctype
517
+ rettype_const
518
+ const_flags:: UInt8
519
+ ResultForCache (rettype, exctype, rettype_const, const_flags:: UInt8 ) = (
520
+ @nospecialize rettype exctype rettype_const;
521
+ new (rettype, exctype, rettype_const, const_flags))
522
+ end
523
+ @inline function ResultForCache (result:: InferenceResult )
524
+ result_type = result. result
525
+ result_type isa LimitedAccuracy && (result_type = result_type. typ)
526
+ @assert ! (result_type === nothing )
527
+ rettype = widenconst (result_type)
528
+ exctype = widenconst (result. exc_result)
529
+ if isa (result_type, Const)
530
+ rettype_const = result_type. val
531
+ const_flags = is_result_constabi_eligible (result) ? 0x3 : 0x2
532
+ elseif isa (result_type, PartialOpaque)
533
+ rettype_const = result_type
534
+ const_flags = 0x2
535
+ elseif isconstType (result_type)
536
+ rettype_const = result_type. parameters[1 ]
537
+ const_flags = 0x2
538
+ elseif isa (result_type, PartialStruct)
539
+ rettype_const = result_type. fields
540
+ const_flags = 0x2
541
+ elseif isa (result_type, InterConditional)
542
+ rettype_const = result_type
543
+ const_flags = 0x2
544
+ elseif isa (result_type, InterMustAlias)
545
+ rettype_const = result_type
546
+ const_flags = 0x2
547
+ else
548
+ rettype_const = nothing
549
+ const_flags = 0x0
550
+ end
551
+ return ResultForCache (rettype, exctype, rettype_const, const_flags)
552
+ end
553
+
533
554
# record the backedges
534
555
function store_backedges (caller:: CodeInstance , edges:: SimpleVector )
535
556
isa (caller. def. def, Method) || return # don't add backedges to toplevel method instance
@@ -1025,7 +1046,7 @@ function typeinf_ircode(interp::AbstractInterpreter, mi::MethodInstance,
1025
1046
end
1026
1047
(; result) = frame
1027
1048
opt = OptimizationState (frame, interp)
1028
- ir = run_passes_ipo_safe (opt . src , opt, optimize_until)
1049
+ ir = run_passes_ipo_safe (interp , opt, result; optimize_until)
1029
1050
rt = widenconst (ignorelimited (result. result))
1030
1051
return ir, rt
1031
1052
end
@@ -1050,6 +1071,7 @@ function typeinf_frame(interp::AbstractInterpreter, mi::MethodInstance, run_opti
1050
1071
opt = OptimizationState (frame, interp)
1051
1072
optimize (interp, opt, frame. result)
1052
1073
src = ir_to_codeinf! (opt)
1074
+ src. rettype = widenconst (result. result)
1053
1075
end
1054
1076
result. src = frame. src = src
1055
1077
end
0 commit comments