Skip to content

Commit

Permalink
first step for #54
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Oct 14, 2020
1 parent 0def4aa commit 08c685d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
39 changes: 22 additions & 17 deletions src/abstractinterpretation.jl
Expand Up @@ -293,24 +293,29 @@ function CC.abstract_eval_special_value(interp::JETInterpreter, @nospecialize(e)
ret = val.t
end
elseif isa(e, GlobalRef)
# report access to undefined global variable
mod, sym = e.mod, e.name
if isdefined(mod, sym)
# FIXME: this might produce wrong result if the current frame is cached and the
# global variable later be updated (both actually or abstractly, anyway);
# 1. if we have established a way to convert a already-existing global variable
# to virtual global variable we can do that here and add backedge
# 2. `NativeInterpreter` just returns `Any` for this case, so it might be okay
# if JET just follows that and give up profiling on non-constant global variables ...
val = getfield(mod, sym)
@debug "propagating non-constant global variable as constant" mod sym val
ret = Const(val)
mod, name = e.mod, e.name
if isdefined(mod, name)
# we don't track types of global variables except when we're in toplevel frame,
# and here we just annotate this as `Any`; NOTE: this is becasue:
# - we can't track side-effects of assignments of global variables that happen in
# (possibly deeply nested) callees, and it might be possible if we just ignore
# assignments happens in callees that aren't reached by type inference by
# the widening heuristics
# - consistency with Julia's native type inference
# - it's hard to track side effects for cached frames

# TODO: add report pass here (for performance linting)
else
add_remark!(interp, sv, GlobalUndefVarErrorReport(interp, sv, mod, sym))
# `ret` here should be annotated as `Any` by `NativeInterpreter`, but we want to
# be more conservative and change it to `Bottom` and suppress any further abstract
# interpretation with this
ret = Bottom
# report access to undefined global variable
add_remark!(interp, sv, GlobalUndefVarErrorReport(interp, sv, mod, name))

# `ret` at this point should be annotated as `Any` by `NativeInterpreter`, and
# we just pass it as is to collect as much error points as possible within this
# frame
# IDEA: we can change it to `Bottom` to suppress any further abstract interpretation
# with this variable, and the later analysis after the update on this (currently)
# undefined variable just works because we will invalidate the cache for this frame
# anyway
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/tfuncs.jl
Expand Up @@ -16,12 +16,12 @@ function CC.builtin_tfunction(interp::JETInterpreter, @nospecialize(f), argtypes
if isa(name, Symbol)
if isa(obj, Const) && (obj, Module)
mod = obj.val
if !isdefined(mod, name)
# `ret` here should be annotated as `Any` by `getfield_tfunc`, but
# we want to be more conservative and change it to `Bottom` and
# suppress any further abstract interpretation with this
if isdefined(mod, name)
# TODO: add report pass here (for performance linting)
else
# report access to undefined global variable
add_remark!(interp, sv, GlobalUndefVarErrorReport(interp, sv, mod, name))
return Bottom
# return Bottom
end
elseif ret === Bottom
# general case when an error is detected by the native `getfield_tfunc`
Expand Down
3 changes: 2 additions & 1 deletion src/virtualprocess.jl
Expand Up @@ -216,7 +216,7 @@ function virtual_process!(toplevelex::Expr,
# NOTE: needs to happen here since JuliaInterpreter.jl assumes there're `Symbol`s as
# `GlobalRef`s in toplevel frames
fix_global_symbols!(src, virtualmod)

# bail out if nothing to profile (just a performance optimization)
if all(is_return(last(src.code)) ? concretized[begin:end-1] : concretized)
continue
Expand Down Expand Up @@ -334,6 +334,7 @@ function select_statements(src)
# special case `include` calls
if f === :include
concretize[i] = true
continue
end

# add more statements necessary for the first time interpretation of a type definition
Expand Down

0 comments on commit 08c685d

Please sign in to comment.