Skip to content

Commit 47a08bb

Browse files
committed
add gc_safe to :foreigncall expr
1 parent c95daff commit 47a08bb

File tree

18 files changed

+77
-63
lines changed

18 files changed

+77
-63
lines changed

base/boot.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ AbstractArray{T}(A::AbstractArray{S,N}) where {T,S,N} = AbstractArray{T,N}(A)
507507
## Helper for proper GC rooting without unsafe_convert
508508
eval(Core, quote
509509
_Symbol(ptr::Ptr{UInt8}, sz::Int, root::Any) = $(Expr(:foreigncall, QuoteNode(:jl_symbol_n),
510-
Ref{Symbol}, svec(Ptr{UInt8}, Int), 0, QuoteNode(:ccall), :ptr, :sz, :root))
510+
Ref{Symbol}, svec(Ptr{UInt8}, Int), 0, false, QuoteNode(:ccall), :ptr, :sz, :root))
511511
end)
512512

513513
function Symbol(s::String)

base/compiler/abstractinterpretation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ function abstract_eval_foreigncall(interp::AbstractInterpreter, e::Expr, vtypes:
25882588
effects = foreigncall_effects(e) do @nospecialize x
25892589
abstract_eval_value(interp, x, vtypes, sv)
25902590
end
2591-
cconv = e.args[5]
2591+
cconv = e.args[6]
25922592
if isa(cconv, QuoteNode) && (v = cconv.value; isa(v, Tuple{Symbol, UInt8}))
25932593
override = decode_effects_override(v[2])
25942594
effects = Effects(effects;

base/compiler/ssair/EscapeAnalysis/EscapeAnalysis.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,18 @@ function compute_frameinfo(ir::IRCode)
745745
ndims = alloc_array_ndims(nn)
746746
ndims === nothing && @goto next_stmt
747747
if ndims 0
748-
length(args) ndims+6 || @goto next_stmt
748+
length(args) ndims+7 || @goto next_stmt
749749
dims = Int[]
750750
for i in 1:ndims
751-
dim = argextype(args[i+6], ir)
751+
dim = argextype(args[i+7], ir)
752752
isa(dim, Const) || @goto next_stmt
753753
dim = dim.val
754754
isa(dim, Int) || @goto next_stmt
755755
push!(dims, dim)
756756
end
757757
else
758-
length(args) 7 || @goto next_stmt
759-
dims = argextype(args[7], ir)
758+
length(args) 8 || @goto next_stmt
759+
dims = argextype(args[8], ir)
760760
if isa(dims, Const)
761761
dims = dims.val
762762
isa(dims, Tuple{Vararg{Int}}) || @goto next_stmt
@@ -1153,7 +1153,7 @@ end
11531153
# TODO: we can apply a similar strategy like builtin calls to specialize some foreigncalls
11541154
function escape_foreigncall!(astate::AnalysisState, pc::Int, args::Vector{Any})
11551155
nargs = length(args)
1156-
if nargs < 6
1156+
if nargs < 7
11571157
# invalid foreigncall, just escape everything
11581158
add_conservative_changes!(astate, pc, args)
11591159
return
@@ -1196,7 +1196,7 @@ function escape_foreigncall!(astate::AnalysisState, pc::Int, args::Vector{Any})
11961196
add_escape_change!(astate, args[5+i], arg_info)
11971197
add_liveness_change!(astate, args[5+i], pc)
11981198
end
1199-
for i = (5+nargs):length(args)
1199+
for i = (6+nargs):length(args)
12001200
arg = args[i]
12011201
add_escape_change!(astate, arg, ⊥)
12021202
add_liveness_change!(astate, arg, pc)

base/compiler/ssair/inlining.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ function late_inline_special_case!(
18021802
return SomeCase(typevar_call)
18031803
elseif f === UnionAll && length(argtypes) == 3 && (optimizer_lattice(state.interp), argtypes[2], TypeVar)
18041804
unionall_call = Expr(:foreigncall, QuoteNode(:jl_type_unionall), Any, svec(Any, Any),
1805-
0, QuoteNode(:ccall), stmt.args[2], stmt.args[3])
1805+
0, false, QuoteNode(:ccall), stmt.args[2], stmt.args[3])
18061806
return SomeCase(unionall_call)
18071807
elseif is_return_type(f)
18081808
if isconstType(type)

base/compiler/ssair/passes.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
10411041
nccallargs = length(stmt.args[3]::SimpleVector)
10421042
preserved = Int[]
10431043
new_preserves = Any[]
1044-
for pidx in (6+nccallargs):length(stmt.args)
1044+
for pidx in (7+nccallargs):length(stmt.args)
10451045
preserved_arg = stmt.args[pidx]
10461046
isa(preserved_arg, SSAValue) || continue
10471047
let intermediaries = SPCSet()
@@ -1613,10 +1613,10 @@ end
16131613
function form_new_preserves(origex::Expr, intermediates::Vector{Int}, new_preserves::Vector{Any})
16141614
newex = Expr(:foreigncall)
16151615
nccallargs = length(origex.args[3]::SimpleVector)
1616-
for i in 1:(6+nccallargs-1)
1616+
for i in 1:(7+nccallargs-1)
16171617
push!(newex.args, origex.args[i])
16181618
end
1619-
for i in (6+nccallargs):length(origex.args)
1619+
for i in (7+nccallargs):length(origex.args)
16201620
x = origex.args[i]
16211621
# don't need to preserve intermediaries
16221622
if isa(x, SSAValue) && x.id in intermediates

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,7 @@ end
29052905
# N.B. the `abstract_eval` callback below allows us to use these queries
29062906
# both during abstract interpret and optimization
29072907

2908-
const FOREIGNCALL_ARG_START = 6
2908+
const FOREIGNCALL_ARG_START = 7
29092909

29102910
function foreigncall_effects(@specialize(abstract_eval), e::Expr)
29112911
args = e.args

base/compiler/validation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const VALID_EXPR_HEADS = IdDict{Symbol,UnitRange{Int}}(
2323
:copyast => 1:1,
2424
:meta => 0:typemax(Int),
2525
:global => 1:1,
26-
:foreigncall => 5:typemax(Int), # name, RT, AT, nreq, (cconv, effects), args..., roots...
26+
:foreigncall => 6:typemax(Int), # name, RT, AT, nreq, gc_safe, (cconv, effects), args..., roots...
2727
:cfunction => 5:5,
2828
:isdefined => 1:1,
2929
:code_coverage_effect => 0:0,

base/meta.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ function _partially_inline!(@nospecialize(x), slot_replacements::Vector{Any},
403403
elseif i == 4
404404
@assert isa(x.args[4], Int)
405405
elseif i == 5
406-
@assert isa((x.args[5]::QuoteNode).value, Union{Symbol, Tuple{Symbol, UInt8}})
406+
@assert isa(x.ars[5], Bool)
407+
elseif i == 6
408+
@assert isa((x.args[6]::QuoteNode).value, Union{Symbol, Tuple{Symbol, UInt8}})
407409
else
408410
x.args[i] = _partially_inline!(x.args[i], slot_replacements,
409411
type_signature, static_param_values,

base/strings/string.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ end
8787

8888
# This is @assume_effects :effect_free :nothrow :terminates_globally @ccall jl_alloc_string(n::Csize_t)::Ref{String},
8989
# but the macro is not available at this time in bootstrap, so we write it manually.
90-
@eval _string_n(n::Integer) = $(Expr(:foreigncall, QuoteNode(:jl_alloc_string), Ref{String}, Expr(:call, Expr(:core, :svec), :Csize_t), 1, QuoteNode((:ccall,0xe)), :(convert(Csize_t, n))))
90+
@eval _string_n(n::Integer) = $(Expr(:foreigncall, QuoteNode(:jl_alloc_string), Ref{String}, Expr(:call, Expr(:core, :svec), :Csize_t), 1, false, QuoteNode((:ccall,0xe)), :(convert(Csize_t, n))))
9191

9292
"""
9393
String(s::AbstractString)

doc/src/devdocs/ast.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,19 @@ These symbols appear in the `head` field of [`Expr`](@ref)s in lowered form.
498498

499499
The number of required arguments for a varargs function definition.
500500

501-
* `args[5]::QuoteNode{Symbol}` : calling convention
501+
* `args[5]::Bool` : gc_safe
502+
503+
If this foreigncall is safe to execute concurrently to GC.
504+
505+
* `args[6]::QuoteNode{Symbol}` : calling convention
502506

503507
The calling convention for the call.
504508

505-
* `args[6:5+length(args[3])]` : arguments
509+
* `args[7:6+length(args[3])]` : arguments
506510

507511
The values for all the arguments (with types of each given in args[3]).
508512

509-
* `args[6+length(args[3])+1:end]` : gc-roots
513+
* `args[7+length(args[3])+1:end]` : gc-roots
510514

511515
The additional objects that may need to be gc-rooted for the duration of the call.
512516
See [Working with LLVM](@ref Working-with-LLVM) for where these are derived from and how they get handled.

0 commit comments

Comments
 (0)