@@ -495,12 +495,6 @@ function CC.getindex(wvc::WorldView{CodeCache}, mi::MethodInstance)
495
495
end
496
496
497
497
function CC. setindex! (wvc:: WorldView{CodeCache} , ci:: CodeInstance , mi:: MethodInstance )
498
- src = if ci. inferred isa Vector{UInt8}
499
- ccall (:jl_uncompress_ir , Any, (Any, Ptr{Cvoid}, Any),
500
- mi. def, C_NULL , ci. inferred)
501
- else
502
- ci. inferred
503
- end
504
498
CC. setindex! (wvc. cache, ci, mi)
505
499
end
506
500
@@ -509,25 +503,42 @@ end # HAS_INTEGRATED_CACHE
509
503
# # codegen/inference integration
510
504
511
505
function ci_cache_populate (interp, cache, mi, min_world, max_world)
512
- src = CC. typeinf_ext_toplevel (interp, mi)
513
-
514
- # inference populates the cache, so we don't need to jl_get_method_inferred
515
- wvc = WorldView (cache, min_world, max_world)
516
- @assert CC. haskey (wvc, mi)
517
-
518
- # if src is rettyp_const, the codeinfo won't cache ci.inferred
519
- # (because it is normally not supposed to be used ever again).
520
- # to avoid the need to re-infer, set that field here.
521
- ci = CC. getindex (wvc, mi)
522
- if ci != = nothing && ci. inferred === nothing
523
- @static if VERSION >= v " 1.9.0-DEV.1115"
524
- @atomic ci. inferred = src
525
- else
526
- ci. inferred = src
506
+ if VERSION >= v " 1.12.0-DEV.15"
507
+ inferred_ci = CC. typeinf_ext_toplevel (interp, mi, CC. SOURCE_MODE_FORCE_SOURCE) # or SOURCE_MODE_FORCE_SOURCE_UNCACHED?
508
+
509
+ # inference should have populated our cache
510
+ wvc = WorldView (cache, min_world, max_world)
511
+ @assert CC. haskey (wvc, mi)
512
+ ci = CC. getindex (wvc, mi)
513
+
514
+ # if ci is rettype_const, the inference result won't have been cached
515
+ # (because it is normally not supposed to be used ever again).
516
+ # to avoid the need to re-infer, set that field here.
517
+ if ci. inferred === nothing
518
+ CC. setindex! (wvc, inferred_ci, mi)
519
+ ci = CC. getindex (wvc, mi)
520
+ end
521
+ else
522
+ src = CC. typeinf_ext_toplevel (interp, mi)
523
+
524
+ # inference should have populated our cache
525
+ wvc = WorldView (cache, min_world, max_world)
526
+ @assert CC. haskey (wvc, mi)
527
+ ci = CC. getindex (wvc, mi)
528
+
529
+ # if ci is rettype_const, the inference result won't have been cached
530
+ # (because it is normally not supposed to be used ever again).
531
+ # to avoid the need to re-infer, set that field here.
532
+ if ci. inferred === nothing
533
+ @static if VERSION >= v " 1.9.0-DEV.1115"
534
+ @atomic ci. inferred = src
535
+ else
536
+ ci. inferred = src
537
+ end
527
538
end
528
539
end
529
540
530
- return ci
541
+ return ci:: CodeInstance
531
542
end
532
543
533
544
function ci_cache_lookup (cache, mi, min_world, max_world)
@@ -581,6 +592,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
581
592
cache = CC. code_cache (interp)
582
593
if ci_cache_lookup (cache, job. source, job. world, job. world) === nothing
583
594
ci_cache_populate (interp, cache, job. source, job. world, job. world)
595
+ @assert ci_cache_lookup (cache, job. source, job. world, job. world) != = nothing
584
596
end
585
597
586
598
# create a callback to look-up function in our cache,
@@ -698,9 +710,10 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
698
710
ccall (:jl_get_function_id , Nothing,
699
711
(Ptr{Cvoid}, Any, Ptr{Int32}, Ptr{Int32}),
700
712
native_code, ci, llvm_func_idx, llvm_specfunc_idx)
713
+ @assert llvm_func_idx[] != - 1 || llvm_specfunc_idx[] != - 1 " Static compilation failed"
701
714
702
715
# get the function
703
- llvm_func = if llvm_func_idx[] >= 1
716
+ llvm_func = if llvm_func_idx[] >= 1
704
717
llvm_func_ref = ccall (:jl_get_llvm_function , LLVM. API. LLVMValueRef,
705
718
(Ptr{Cvoid}, UInt32), native_code, llvm_func_idx[]- 1 )
706
719
@assert llvm_func_ref != C_NULL
@@ -709,7 +722,7 @@ function compile_method_instance(@nospecialize(job::CompilerJob))
709
722
nothing
710
723
end
711
724
712
- llvm_specfunc = if llvm_specfunc_idx[] >= 1
725
+ llvm_specfunc = if llvm_specfunc_idx[] >= 1
713
726
llvm_specfunc_ref = ccall (:jl_get_llvm_function , LLVM. API. LLVMValueRef,
714
727
(Ptr{Cvoid}, UInt32), native_code, llvm_specfunc_idx[]- 1 )
715
728
@assert llvm_specfunc_ref != C_NULL
0 commit comments