Skip to content

Commit ac352a0

Browse files
committed
fixup! s/Lambda/NativeCode/g
1 parent e85ab94 commit ac352a0

23 files changed

+531
-486
lines changed

base/boot.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ Symbol(s::Symbol) = s
442442

443443
# module providing the IR object model
444444
module IR
445-
export CodeInfo, MethodInstance, Lambda, GotoNode,
445+
export CodeInfo, MethodInstance, NativeCode, GotoNode,
446446
NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot,
447447
PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode
448448

449-
import Core: CodeInfo, MethodInstance, GotoNode,
449+
import Core: CodeInfo, MethodInstance, NativeCode, GotoNode,
450450
NewvarNode, SSAValue, Slot, SlotNumber, TypedSlot,
451451
PiNode, PhiNode, PhiCNode, UpsilonNode, LineInfoNode
452452

base/compiler/compiler.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ getfield(getfield(Main, :Core), :eval)(getfield(Main, :Core), :(baremodule Compi
55
using Core.Intrinsics, Core.IR
66

77
import Core: print, println, show, write, unsafe_write, stdout, stderr,
8-
_apply, svec, apply_type, Builtin, IntrinsicFunction, MethodInstance, Lambda
8+
_apply, svec, apply_type, Builtin, IntrinsicFunction, MethodInstance, NativeCode
99

1010
const getproperty = getfield
1111
const setproperty! = setfield!

base/compiler/optimize.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function add_backedge!(li::MethodInstance, caller::OptimizationState)
116116
nothing
117117
end
118118

119-
function add_backedge!(li::Lambda, caller::OptimizationState)
119+
function add_backedge!(li::NativeCode, caller::OptimizationState)
120120
update_valid_age!(min_world(li), max_world(li), caller)
121121
add_backedge!(li.def, caller)
122122
nothing

base/compiler/ssair/inlining.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ function find_inferred(mi::MethodInstance, @nospecialize(atypes), sv::Optimizati
12251225
end
12261226

12271227
linfo = inf_for_methodinstance(mi, sv.params.world)
1228-
if linfo isa Lambda
1228+
if linfo isa NativeCode
12291229
if invoke_api(linfo) == 2
12301230
# in this case function can be inlined to a constant
12311231
return svec(true, quoted(linfo.rettype_const))

base/compiler/typeinfer.jl

+15-13
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function cache_result(result::InferenceResult, min_valid::UInt, max_valid::UInt)
9292
# check if the existing linfo metadata is also sufficient to describe the current inference result
9393
# to decide if it is worth caching this
9494
already_inferred = !result.linfo.inInference
95-
if inf_for_methodinstance(result.linfo, min_valid, max_valid) isa Lambda
95+
if inf_for_methodinstance(result.linfo, min_valid, max_valid) isa NativeCode
9696
already_inferred = true
9797
end
9898

@@ -132,7 +132,7 @@ function cache_result(result::InferenceResult, min_valid::UInt, max_valid::UInt)
132132
if !isa(inferred_result, Union{CodeInfo, Vector{UInt8}})
133133
inferred_result = nothing
134134
end
135-
ccall(:jl_set_method_inferred, Ref{Lambda}, (Any, Any, Any, Any, Int32, UInt, UInt),
135+
ccall(:jl_set_method_inferred, Ref{NativeCode}, (Any, Any, Any, Any, Int32, UInt, UInt),
136136
result.linfo, widenconst(result.result), rettype_const, inferred_result,
137137
const_flags, min_valid, max_valid)
138138
end
@@ -451,7 +451,7 @@ end
451451
function typeinf_edge(method::Method, @nospecialize(atypes), sparams::SimpleVector, caller::InferenceState)
452452
mi = specialize_method(method, atypes, sparams)::MethodInstance
453453
code = inf_for_methodinstance(mi, caller.params.world)
454-
if code isa Lambda # return existing rettype if the code is already inferred
454+
if code isa NativeCode # return existing rettype if the code is already inferred
455455
update_valid_age!(min_world(code), max_world(code), caller)
456456
if isdefined(code, :rettype_const)
457457
return Const(code.rettype_const), mi
@@ -522,10 +522,11 @@ function typeinf_ext(mi::MethodInstance, params::Params)
522522
for i = 1:2 # test-and-lock-and-test
523523
i == 2 && ccall(:jl_typeinf_begin, Cvoid, ())
524524
code = inf_for_methodinstance(mi, params.world)
525-
if code isa Lambda
525+
if code isa NativeCode
526526
# see if this code already exists in the cache
527527
inf = code.inferred
528528
if invoke_api(code) == 2
529+
i == 2 && ccall(:jl_typeinf_end, Cvoid, ())
529530
tree = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
530531
tree.code = Any[ Expr(:return, quoted(code.rettype_const)) ]
531532
nargs = Int(method.nargs)
@@ -542,20 +543,21 @@ function typeinf_ext(mi::MethodInstance, params::Params)
542543
tree.rettype = typeof(code.rettype_const)
543544
tree.min_world = code.min_world
544545
tree.max_world = code.max_world
545-
i == 2 && ccall(:jl_typeinf_end, Cvoid, ())
546546
return tree
547547
elseif isa(inf, CodeInfo)
548548
i == 2 && ccall(:jl_typeinf_end, Cvoid, ())
549-
inf.min_world = code.min_world
550-
inf.min_world = code.min_world
551-
inf.rettype = code.rettype
549+
if !(inf.min_world == code.min_world &&
550+
inf.max_world == code.max_world &&
551+
inf.rettype === code.rettype)
552+
inf = copy(inf)
553+
inf.min_world = code.min_world
554+
inf.max_world = code.max_world
555+
inf.rettype = code.rettype
556+
end
552557
return inf
553558
elseif isa(inf, Vector{UInt8})
554-
inf = _uncompressed_ast(code, inf)
555559
i == 2 && ccall(:jl_typeinf_end, Cvoid, ())
556-
inf.min_world = code.min_world
557-
inf.min_world = code.min_world
558-
inf.rettype = code.rettype
560+
inf = _uncompressed_ast(code, inf)
559561
return inf
560562
end
561563
end
@@ -578,7 +580,7 @@ function typeinf_type(method::Method, @nospecialize(atypes), sparams::SimpleVect
578580
for i = 1:2 # test-and-lock-and-test
579581
i == 2 && ccall(:jl_typeinf_begin, Cvoid, ())
580582
code = inf_for_methodinstance(mi, params.world)
581-
if code isa Lambda
583+
if code isa NativeCode
582584
# see if this rettype already exists in the cache
583585
i == 2 && ccall(:jl_typeinf_end, Cvoid, ())
584586
return code.rettype

base/compiler/utilities.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ end
8181
# MethodInstance/CodeInfo #
8282
###########################
8383

84-
function invoke_api(li::Lambda)
84+
function invoke_api(li::NativeCode)
8585
return ccall(:jl_invoke_api, Cint, (Any,), li)
8686
end
8787

@@ -119,7 +119,7 @@ end
119119
function inf_for_methodinstance(mi::MethodInstance, min_world::UInt, max_world::UInt=min_world)
120120
inf = ccall(:jl_is_rettype_inferred, Ptr{Nothing}, (Any, UInt, UInt), mi, min_world, max_world)
121121
inf == C_NULL && return nothing
122-
return unsafe_pointer_to_objref(inf)::Lambda
122+
return unsafe_pointer_to_objref(inf)::NativeCode
123123
end
124124

125125

base/reflection.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ uncompressed_ast(m::Method) = isdefined(m, :source) ? _uncompressed_ast(m, m.sou
903903
error("Code for this Method is not available.")
904904
_uncompressed_ast(m::Method, s::CodeInfo) = copy(s)
905905
_uncompressed_ast(m::Method, s::Array{UInt8,1}) = ccall(:jl_uncompress_ast, Any, (Any, Ptr{Cvoid}, Any), m, C_NULL, s)::CodeInfo
906-
_uncompressed_ast(m::Core.Lambda, s::Array{UInt8,1}) = ccall(:jl_uncompress_ast, Any, (Any, Ptr{Cvoid}, Any), li.def.def::Method, li, s)::CodeInfo
906+
_uncompressed_ast(m::Core.NativeCode, s::Array{UInt8,1}) = ccall(:jl_uncompress_ast, Any, (Any, Ptr{Cvoid}, Any), li.def.def::Method, li, s)::CodeInfo
907907

908908
function method_instances(@nospecialize(f), @nospecialize(t), world::UInt = typemax(UInt))
909909
tt = signature_type(f, t)
@@ -1309,8 +1309,8 @@ has_bottom_parameter(t::Union) = has_bottom_parameter(t.a) & has_bottom_paramete
13091309
has_bottom_parameter(t::TypeVar) = t.ub == Bottom || has_bottom_parameter(t.ub)
13101310
has_bottom_parameter(::Any) = false
13111311

1312-
min_world(m::Core.Lambda) = reinterpret(UInt, m.min_world)
1313-
max_world(m::Core.Lambda) = reinterpret(UInt, m.max_world)
1312+
min_world(m::Core.NativeCode) = reinterpret(UInt, m.min_world)
1313+
max_world(m::Core.NativeCode) = reinterpret(UInt, m.max_world)
13141314
min_world(m::Core.CodeInfo) = reinterpret(UInt, m.min_world)
13151315
max_world(m::Core.CodeInfo) = reinterpret(UInt, m.max_world)
13161316
get_world_counter() = ccall(:jl_get_world_counter, UInt, ())

doc/src/devdocs/ast.md

+61-15
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ types exist in lowered form:
260260

261261
* `CodeInfo`
262262

263-
Wraps the IR of a method. Its `code` field is an array of expressions to execute.
263+
Wraps the IR of a group of statements. Its `code` field is an array of expressions to execute.
264264

265265
* `GotoNode`
266266

@@ -489,7 +489,11 @@ A unique'd container describing the shared metadata for a single method.
489489

490490
* `source`
491491

492-
The original source code (usually compressed).
492+
The original source code (if available, usually compressed).
493+
494+
* `generator`
495+
496+
A callable object which can be executed to get specialized source for a specific method signature.
493497

494498
* `roots`
495499

@@ -500,9 +504,9 @@ A unique'd container describing the shared metadata for a single method.
500504

501505
Descriptive bit-fields for the source code of this Method.
502506

503-
* `min_world` / `max_world`
507+
* `primary_world`
504508

505-
The range of world ages for which this method is visible to dispatch.
509+
The world age that "owns" this Method.
506510

507511

508512
### MethodInstance
@@ -527,16 +531,38 @@ for important details on how to modify these fields safely.
527531
runtime `MethodInstance` from the `MethodTable` cache, this will always be defined and
528532
indexable.
529533

530-
* `rettype`
534+
* `uninferred`
535+
536+
The uncompressed source code for a toplevel thunk. Additionally, for a generated function,
537+
this is one of many places that the source code might be found.
538+
539+
* `backedges`
540+
541+
We store the reverse-list of cache dependencies for efficient tracking of incremental reanalysis/recompilation work that may be needed after a new method definitions.
542+
This works by keeping a list of the other `MethodInstance` that have been inferred or optimized to contain a possible call to this `MethodInstance`.
543+
Those optimization results might be stored somewhere in the `cache`, or it might have been the result of something we didn't want to cache, such as constant propagation.
544+
Thus we merge all of those backedges to various cache entries here (there's almost always only the one applicable cache entry with a sentinal value for max_world anyways).
545+
546+
* `cache`
547+
548+
Cache of `NativeCode` objects that share this template instantiation.
549+
550+
### MethodInstance
551+
552+
* `def`
553+
554+
The `MethodInstance` that this cache entry is derived from.
555+
556+
557+
* `rettype`/`rettype_const`
531558

532559
The inferred return type for the `specFunctionObject` field, which (in most cases) is
533560
also the computed return type for the function in general.
534561

535562
* `inferred`
536563

537-
May contain a cache of the inferred source for this function, or other information about
538-
the inference result such as a constant return value may be put here (if `jlcall_api ==
539-
2`), or it could be set to `nothing` to just indicate `rettype` is inferred.
564+
May contain a cache of the inferred source for this function,
565+
or it could be set to `nothing` to just indicate `rettype` is inferred.
540566

541567
* `ftpr`
542568

@@ -548,30 +574,32 @@ for important details on how to modify these fields safely.
548574

549575
* 0 - Not compiled yet
550576
* 1 - JL_CALLABLE `jl_value_t *(*)(jl_function_t *f, jl_value_t *args[nargs], uint32_t nargs)`
551-
* 2 - Constant (value stored in `inferred`)
577+
* 2 - Constant (value stored in `rettype_const`)
552578
* 3 - With Static-parameters forwarded `jl_value_t *(*)(jl_svec_t *sparams, jl_function_t *f, jl_value_t *args[nargs], uint32_t nargs)`
553579
* 4 - Run in interpreter `jl_value_t *(*)(jl_method_instance_t *meth, jl_function_t *f, jl_value_t *args[nargs], uint32_t nargs)`
554580

555581
* `min_world` / `max_world`
556582

557583
The range of world ages for which this method instance is valid to be called.
584+
If max_world is the special token value `-1`, the value is not yet known.
585+
It may continue to be used until we encounter a backedge that requires us to reconsider.
558586

559587

560588
### CodeInfo
561589

562-
A temporary container for holding lowered source code.
590+
A (usually temporary) container for holding lowered source code.
563591

564592
* `code`
565593

566594
An `Any` array of statements
567595

568596
* `slotnames`
569597

570-
An array of symbols giving the name of each slot (argument or local variable).
598+
An array of symbols giving names for each slot (argument or local variable).
571599

572600
* `slottypes`
573601

574-
An array of types for the slots.
602+
An array of types for the slots (e.g. variables).
575603

576604
* `slotflags`
577605

@@ -587,7 +615,17 @@ A temporary container for holding lowered source code.
587615
Either an array or an `Int`.
588616

589617
If an `Int`, it gives the number of compiler-inserted temporary locations in the
590-
function. If an array, specifies a type for each location.
618+
function (the length of `code` array). If an array, specifies a type for each location.
619+
620+
* `ssaflags`
621+
622+
Statement-level flags for each expression in the function. Many of these are reserved, but not yet implemented:
623+
624+
* 0 = inbounds
625+
* 1,2 = <reserved> inlinehint,always-inline,noinline
626+
* 3 = <reserved> strict-ieee (strictfp)
627+
* 4-6 = <unused>
628+
* 7 = <reserved> has out-of-band info
591629

592630
* `linetable`
593631

@@ -598,6 +636,14 @@ A temporary container for holding lowered source code.
598636
An array of integer indices into the `linetable`, giving the location associated
599637
with each statement.
600638

639+
* `parent`
640+
641+
The `MethodInstance` that "owns" this object (if applicable).
642+
643+
* `min_world`/`max_world`
644+
645+
The range of world ages for which this code was valid at the time when it had been inferred.
646+
601647
Boolean properties:
602648

603649
* `inferred`
@@ -606,11 +652,11 @@ Boolean properties:
606652

607653
* `inlineable`
608654

609-
Whether this should be inlined.
655+
Whether this should be eligable for inlining.
610656

611657
* `propagate_inbounds`
612658

613-
Whether this should should propagate `@inbounds` when inlined for the purpose of eliding
659+
Whether this should should propagate `@inbounds` when inlined, for the purpose of eliding
614660
`@boundscheck` blocks.
615661

616662
* `pure`

src/builtins.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ void jl_init_primitives(void) JL_GC_DISABLED
12561256
add_builtin("Module", (jl_value_t*)jl_module_type);
12571257
add_builtin("MethodTable", (jl_value_t*)jl_methtable_type);
12581258
add_builtin("Method", (jl_value_t*)jl_method_type);
1259-
add_builtin("Lambda", (jl_value_t*)jl_lambda_type);
1259+
add_builtin("NativeCode", (jl_value_t*)jl_nativecode_type);
12601260
add_builtin("TypeMapEntry", (jl_value_t*)jl_typemap_entry_type);
12611261
add_builtin("TypeMapLevel", (jl_value_t*)jl_typemap_level_type);
12621262
add_builtin("Symbol", (jl_value_t*)jl_sym_type);

0 commit comments

Comments
 (0)