Skip to content

Commit 7309756

Browse files
authored
minor fix on getfield_nothrow (#52083)
- fixed index of `order` when there are 5 arguments - add type check for `boundscheck` argument
1 parent 1b967b8 commit 7309756

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

base/compiler/tfuncs.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -929,29 +929,31 @@ function getfield_boundscheck((; fargs, argtypes)::ArgInfo) # Symbol
929929
elseif length(argtypes) == 4
930930
fargs !== nothing && (farg = fargs[4])
931931
boundscheck = argtypes[4]
932-
isvarargtype(boundscheck) && return :unknown
932+
isvarargtype(boundscheck) && return :unsafe
933933
if widenconst(boundscheck) === Symbol
934934
return :on
935935
end
936936
elseif length(argtypes) == 5
937937
fargs !== nothing && (farg = fargs[5])
938938
boundscheck = argtypes[5]
939939
else
940-
return :unknown
940+
return :unsafe
941941
end
942-
isvarargtype(boundscheck) && return :unknown
942+
isvarargtype(boundscheck) && return :unsafe
943943
boundscheck = widenconditional(boundscheck)
944944
if widenconst(boundscheck) === Bool
945945
if isa(boundscheck, Const)
946946
return boundscheck.val::Bool ? :on : :off
947947
elseif farg !== nothing && isexpr(farg, :boundscheck)
948948
return :boundscheck
949949
end
950+
return :unknown
950951
end
951-
return :unknown
952+
return :unsafe
952953
end
953954

954955
function getfield_nothrow(𝕃::AbstractLattice, arginfo::ArgInfo, boundscheck::Symbol=getfield_boundscheck(arginfo))
956+
boundscheck === :unsafe && return false
955957
(;argtypes) = arginfo
956958
ordering = Const(:not_atomic)
957959
if length(argtypes) == 4
@@ -960,7 +962,7 @@ function getfield_nothrow(𝕃::AbstractLattice, arginfo::ArgInfo, boundscheck::
960962
ordering = argtypes[4]
961963
end
962964
elseif length(argtypes) == 5
963-
ordering = argtypes[5]
965+
ordering = argtypes[4]
964966
elseif length(argtypes) != 3
965967
return false
966968
end

test/compiler/effects.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,25 @@ end |> Core.Compiler.is_nothrow
497497
getfield(t, i, false) # invalid name type
498498
end |> !Core.Compiler.is_nothrow
499499

500+
@test Base.infer_effects((Some{Any},)) do some
501+
getfield(some, 1, :not_atomic)
502+
end |> Core.Compiler.is_nothrow
503+
@test Base.infer_effects((Some{Any},)) do some
504+
getfield(some, 1, :invalid_atomic_spec)
505+
end |> !Core.Compiler.is_nothrow
506+
@test Base.infer_effects((Some{Any},Bool)) do some, boundscheck
507+
getfield(some, 1, boundscheck)
508+
end |> Core.Compiler.is_nothrow
509+
@test Base.infer_effects((Some{Any},Bool)) do some, boundscheck
510+
getfield(some, 1, :not_atomic, boundscheck)
511+
end |> Core.Compiler.is_nothrow
512+
@test Base.infer_effects((Some{Any},Bool)) do some, boundscheck
513+
getfield(some, 1, :invalid_atomic_spec, boundscheck)
514+
end |> !Core.Compiler.is_nothrow
515+
@test Base.infer_effects((Some{Any},Any)) do some, boundscheck
516+
getfield(some, 1, :not_atomic, boundscheck)
517+
end |> !Core.Compiler.is_nothrow
518+
500519
@test Core.Compiler.is_consistent(Base.infer_effects(setindex!, (Base.RefValue{Int}, Int)))
501520

502521
# :inaccessiblememonly effect

0 commit comments

Comments
 (0)