Skip to content

Commit

Permalink
rename :nonoverlayed to :native_executable
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Aug 30, 2023
1 parent 0034727 commit b0eaabc
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion base/boot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ macro _foldable_meta()
#=:notaskstate=#false,
#=:inaccessiblememonly=#false,
#=:noub=#true,
#=:nonoverlayed=#false))
#=:native_executable=#false))
end

const NTuple{N,T} = Tuple{Vararg{T,N}}
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,10 @@ function add_call_backedges!(interp::AbstractInterpreter, @nospecialize(rettype)
# don't bother to add backedges when both type and effects information are already
# maximized to the top since a new method couldn't refine or widen them anyway
if rettype === Any
# ignore the `:nonoverlayed` property if `interp` doesn't use overlayed method table
# ignore the `:native_executable` property if `interp` doesn't use overlayed method table
# since it will never be tainted anyway
if !isoverlayed(method_table(interp))
all_effects = Effects(all_effects; nonoverlayed=false)
all_effects = Effects(all_effects; native_executable=false)
end
if (# ignore the `:noinbounds` property if `:consistent`-cy is tainted already
(sv isa InferenceState && sv.ipo_effects.consistent === ALWAYS_FALSE) ||
Expand Down Expand Up @@ -854,7 +854,7 @@ function concrete_eval_eligible(interp::AbstractInterpreter,
mi = result.edge
if mi !== nothing && is_foldable(effects)
if f !== nothing && is_all_const_arg(arginfo, #=start=#2)
if is_nonoverlayed(interp) || is_nonoverlayed(effects)
if is_native_executable(interp) || is_native_executable(effects)
return :concrete_eval
end
# disable concrete-evaluation if this function call is tainted by some overlayed
Expand Down
28 changes: 15 additions & 13 deletions base/compiler/effects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ following meanings:
Note that undefined behavior may technically cause the method to violate any other effect
assertions (such as `:consistent` or `:effect_free`) as well, but we do not model this,
and they assume the absence of undefined behavior.
- `nonoverlayed::Bool`: indicates that any methods that may be called within this method
are not defined in an [overlayed method table](@ref OverlayMethodTable).
- `native_executable::Bool`: indicates whether this method can be executed using Julia's
native compiler and runtime. Note that in particular this is generally not the case when
any methods defined in an [`OverlayMethodTable`](OverlayMethodTable) can be called.
- `noinbounds::Bool`: If set, indicates that this method does not read the parent's `:inbounds`
state. In particular, it does not have any reached `:boundscheck` exprs, not propagates inbounds
to any children that do.
Expand Down Expand Up @@ -91,7 +92,8 @@ The output represents the state of different effect properties in the following
- `+i` (green): `true`
- `-i` (red): `false`
Additionally, if the `nonoverlayed` property is false, a red prime symbol (′) is displayed after the tuple.
Additionally, if the `native_executable` property is `false`,
a red prime symbol (′) is displayed after the tuple.
"""
struct Effects
consistent::UInt8
Expand All @@ -101,7 +103,7 @@ struct Effects
notaskstate::Bool
inaccessiblememonly::UInt8
noub::Bool
nonoverlayed::Bool
native_executable::Bool
noinbounds::Bool
function Effects(
consistent::UInt8,
Expand All @@ -111,7 +113,7 @@ struct Effects
notaskstate::Bool,
inaccessiblememonly::UInt8,
noub::Bool,
nonoverlayed::Bool,
native_executable::Bool,
noinbounds::Bool)
return new(
consistent,
Expand All @@ -121,7 +123,7 @@ struct Effects
notaskstate,
inaccessiblememonly,
noub,
nonoverlayed,
native_executable,
noinbounds)
end
end
Expand Down Expand Up @@ -152,7 +154,7 @@ function Effects(effects::Effects = _EFFECTS_UNKNOWN;
notaskstate::Bool = effects.notaskstate,
inaccessiblememonly::UInt8 = effects.inaccessiblememonly,
noub::Bool = effects.noub,
nonoverlayed::Bool = effects.nonoverlayed,
native_executable::Bool = effects.native_executable,
noinbounds::Bool = effects.noinbounds)
return Effects(
consistent,
Expand All @@ -162,7 +164,7 @@ function Effects(effects::Effects = _EFFECTS_UNKNOWN;
notaskstate,
inaccessiblememonly,
noub,
nonoverlayed,
native_executable,
noinbounds)
end

Expand All @@ -175,7 +177,7 @@ function merge_effects(old::Effects, new::Effects)
merge_effectbits(old.notaskstate, new.notaskstate),
merge_effectbits(old.inaccessiblememonly, new.inaccessiblememonly),
merge_effectbits(old.noub, new.noub),
merge_effectbits(old.nonoverlayed, new.nonoverlayed),
merge_effectbits(old.native_executable, new.native_executable),
merge_effectbits(old.noinbounds, new.noinbounds))
end

Expand All @@ -194,7 +196,7 @@ is_terminates(effects::Effects) = effects.terminates
is_notaskstate(effects::Effects) = effects.notaskstate
is_inaccessiblememonly(effects::Effects) = effects.inaccessiblememonly === ALWAYS_TRUE
is_noub(effects::Effects) = effects.noub
is_nonoverlayed(effects::Effects) = effects.nonoverlayed
is_native_executable(effects::Effects) = effects.native_executable

# implies `is_notaskstate` & `is_inaccessiblememonly`, but not explicitly checked here
is_foldable(effects::Effects) =
Expand Down Expand Up @@ -232,7 +234,7 @@ function encode_effects(e::Effects)
((e.notaskstate % UInt32) << 7) |
((e.inaccessiblememonly % UInt32) << 8) |
((e.noub % UInt32) << 10) |
((e.nonoverlayed % UInt32) << 11) |
((e.native_executable % UInt32) << 11) |
((e.noinbounds % UInt32) << 12)
end

Expand All @@ -258,7 +260,7 @@ struct EffectsOverride
notaskstate::Bool
inaccessiblememonly::Bool
noub::Bool
nonoverlayed::Bool
native_executable::Bool
end

function encode_effects_override(eo::EffectsOverride)
Expand All @@ -271,7 +273,7 @@ function encode_effects_override(eo::EffectsOverride)
eo.notaskstate && (e |= (1 << 5) % UInt32)
eo.inaccessiblememonly && (e |= (1 << 6) % UInt32)
eo.noub && (e |= (1 << 7) % UInt32)
eo.nonoverlayed && (e |= (1 << 8) % UInt32)
eo.native_executable && (e |= (1 << 8) % UInt32)
return e
end

Expand Down
7 changes: 4 additions & 3 deletions base/compiler/inferencestate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ mutable struct InferenceState
end

if def isa Method
ipo_effects = Effects(ipo_effects; nonoverlayed=is_nonoverlayed(def))
ipo_effects = Effects(ipo_effects; native_executable=is_native_executable(def))
end

restrict_abstract_call_sites = isa(def, Module)
Expand All @@ -318,8 +318,9 @@ mutable struct InferenceState
end
end

is_nonoverlayed(m::Method) = !isdefined(m, :external_mt)
is_nonoverlayed(interp::AbstractInterpreter) = !isoverlayed(method_table(interp))
is_native_executable(m::Method) = !isdefined(m, :external_mt)
is_native_executable(interp::AbstractInterpreter) = !isoverlayed(method_table(interp))

isoverlayed(::MethodTableView) = error("unsatisfied MethodTableView interface")
isoverlayed(::InternalMethodTable) = false
isoverlayed(::OverlayMethodTable) = true
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/irinterp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function concrete_eval_invoke(interp::AbstractInterpreter,
argtypes === nothing && return Pair{Any,Bool}(Bottom, false)
effects = decode_effects(code.ipo_purity_bits)
if (is_foldable(effects) && is_all_const_arg(argtypes, #=start=#1) &&
(is_nonoverlayed(interp) || is_nonoverlayed(effects)))
(is_native_executable(interp) || is_native_executable(effects)))
args = collect_const_args(argtypes, #=start=#1)
value = let world = get_world_counter(interp)
try
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ function Base.show(io::IO, e::Effects)
print(io, ',')
printstyled(io, effectbits_letter(e, :noinbounds, 'i'); color=effectbits_color(e, :noinbounds))
print(io, ')')
e.nonoverlayed || printstyled(io, ''; color=:red)
e.native_executable || printstyled(io, ''; color=:red)
end

@specialize
4 changes: 2 additions & 2 deletions base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ function adjust_effects(sv::InferenceState)
if is_effect_overridden(override, :noub)
ipo_effects = Effects(ipo_effects; noub=true)
end
if is_effect_overridden(override, :nonoverlayed)
ipo_effects = Effects(ipo_effects; nonoverlayed=true)
if is_effect_overridden(override, :native_executable)
ipo_effects = Effects(ipo_effects; native_executable=true)
end
end

Expand Down
10 changes: 5 additions & 5 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ macro _total_meta()
#=:notaskstate=#true,
#=:inaccessiblememonly=#true,
#=:noub=#true,
#=:nonoverlayed=#false))
#=:native_executable=#false))
end
# can be used in place of `@assume_effects :foldable` (supposed to be used for bootstrapping)
macro _foldable_meta()
Expand All @@ -223,7 +223,7 @@ macro _foldable_meta()
#=:notaskstate=#false,
#=:inaccessiblememonly=#true,
#=:noub=#true,
#=:nonoverlayed=#false))
#=:native_executable=#false))
end
# can be used in place of `@assume_effects :nothrow` (supposed to be used for bootstrapping)
macro _nothrow_meta()
Expand All @@ -236,7 +236,7 @@ macro _nothrow_meta()
#=:notaskstate=#false,
#=:inaccessiblememonly=#false,
#=:noub=#false,
#=:nonoverlayed=#false))
#=:native_executable=#false))
end
# can be used in place of `@assume_effects :terminates_locally` (supposed to be used for bootstrapping)
macro _terminates_locally_meta()
Expand All @@ -249,7 +249,7 @@ macro _terminates_locally_meta()
#=:notaskstate=#false,
#=:inaccessiblememonly=#false,
#=:noub=#false,
#=:nonoverlayed=#false))
#=:native_executable=#false))
end
# can be used in place of `@assume_effects :effect_free :terminates_locally` (supposed to be used for bootstrapping)
macro _effect_free_terminates_locally_meta()
Expand All @@ -262,7 +262,7 @@ macro _effect_free_terminates_locally_meta()
#=:notaskstate=#false,
#=:inaccessiblememonly=#false,
#=:noub=#false,
#=:nonoverlayed=#false))
#=:native_executable=#false))
end

# another version of inlining that propagates an inbounds context
Expand Down
24 changes: 18 additions & 6 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ The following `setting`s are supported.
- `:notaskstate`
- `:inaccessiblememonly`
- `:noub`
- `:native_executable`
- `:foldable`
- `:removable`
- `:total`
Expand Down Expand Up @@ -641,6 +642,17 @@ The `:noub` setting asserts that the method will not execute any undefined behav
any other effect assertions (such as `:consistent` or `:effect_free`) as well, but we do
not model this, and they assume the absence of undefined behavior.
---
## `:native_executable`
The `:native_executable` setting asserts that this method can be executed using Julia's
native compiler and runtime. Currently this particularly implies that any methods defined
in an [`OverlayMethodTable`](@ref Core.Compiler.OverlayMethodTable) (including this method
in question) are never be called during executing the method. However, it is worth noting
that it is safe to annotate [`@overlay`](@ref Base.Experimental.@overlay) method as
`:native_executable` when the overlay-ed method has the same semantics as the original
method and its result can safely be replaced with the result of the original method.
---
## `:foldable`
Expand Down Expand Up @@ -715,7 +727,7 @@ macro assume_effects(args...)
idx = length(args)
end
(consistent, effect_free, nothrow, terminates_globally, terminates_locally,
notaskstate, inaccessiblememonly, noub, nonoverlayed) =
notaskstate, inaccessiblememonly, noub, native_executable) =
(false, false, false, false, false, false, false, false, false, false)
for org_setting in args[1:idx]
(setting, val) = compute_assumed_setting(org_setting)
Expand All @@ -735,8 +747,8 @@ macro assume_effects(args...)
inaccessiblememonly = val
elseif setting === :noub
noub = val
elseif setting === :nonoverlayed
nonoverlayed = val
elseif setting === :native_executable
native_executable = val
elseif setting === :foldable
consistent = effect_free = terminates_globally = noub = val
elseif setting === :removable
Expand All @@ -750,17 +762,17 @@ macro assume_effects(args...)
if is_function_def(inner)
return esc(pushmeta!(ex, :purity,
consistent, effect_free, nothrow, terminates_globally, terminates_locally,
notaskstate, inaccessiblememonly, noub, nonoverlayed))
notaskstate, inaccessiblememonly, noub, native_executable))
elseif isexpr(ex, :macrocall) && ex.args[1] === Symbol("@ccall")
ex.args[1] = GlobalRef(Base, Symbol("@ccall_effects"))
insert!(ex.args, 3, Core.Compiler.encode_effects_override(Core.Compiler.EffectsOverride(
consistent, effect_free, nothrow, terminates_globally, terminates_locally,
notaskstate, inaccessiblememonly, noub, nonoverlayed)))
notaskstate, inaccessiblememonly, noub, native_executable)))
return esc(ex)
else # anonymous function case
return Expr(:meta, Expr(:purity,
consistent, effect_free, nothrow, terminates_globally, terminates_locally,
notaskstate, inaccessiblememonly, noub, nonoverlayed))
notaskstate, inaccessiblememonly, noub, native_executable))
end
end

Expand Down
6 changes: 3 additions & 3 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ typedef union __jl_purity_overrides_t {
uint8_t ipo_notaskstate : 1;
uint8_t ipo_inaccessiblememonly : 1;
uint8_t ipo_noub : 1;
uint8_t ipo_nonoverlayed : 1;
uint8_t ipo_native_executable : 1;
} overrides;
uint32_t bits;
} _jl_purity_overrides_t;
Expand Down Expand Up @@ -435,7 +435,7 @@ typedef struct _jl_code_instance_t {
// uint8_t ipo_terminates : 1;
// uint8_t ipo_notaskstate : 2;
// uint8_t ipo_inaccessiblememonly : 2;
// uint8_t ipo_nonoverlayed : 1;
// uint8_t ipo_native_executable : 1;
// uint8_t ipo_noinbounds : 1;
_Atomic(uint32_t) purity_bits;
// purity_flags:
Expand All @@ -445,7 +445,7 @@ typedef struct _jl_code_instance_t {
// uint8_t ipo_terminates : 1;
// uint8_t ipo_notaskstate : 2;
// uint8_t ipo_inaccessiblememonly : 2;
// uint8_t ipo_nonoverlayed : 1;
// uint8_t ipo_native_executable : 1;
// uint8_t ipo_noinbounds : 1;
jl_value_t *argescapes; // escape information of call arguments

Expand Down
2 changes: 1 addition & 1 deletion src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir)
li->purity.overrides.ipo_notaskstate = jl_unbox_bool(jl_exprarg(ma, 5));
li->purity.overrides.ipo_inaccessiblememonly = jl_unbox_bool(jl_exprarg(ma, 6));
li->purity.overrides.ipo_noub = jl_unbox_bool(jl_exprarg(ma, 7));
li->purity.overrides.ipo_nonoverlayed = jl_unbox_bool(jl_exprarg(ma, 8));
li->purity.overrides.ipo_native_executable = jl_unbox_bool(jl_exprarg(ma, 8));
}
}
else
Expand Down
Loading

0 comments on commit b0eaabc

Please sign in to comment.