Skip to content

Commit 0e4cf64

Browse files
committed
simplify entry points to type inference
this breaks up the typeinf_edge function into its subcomponents, allowing callers to exercise only the pieces they care about rather than returning all possible values the caller might care about in a Tuple also fixes missing test-and-lock-and-set for threaded inference
1 parent a6a8946 commit 0e4cf64

File tree

4 files changed

+192
-161
lines changed

4 files changed

+192
-161
lines changed

base/REPLCompletions.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function find_start_brace(s::AbstractString; c_start='(', c_end=')')
235235
braces != 1 && return 0:-1, -1
236236
method_name_end = reverseind(r, i)
237237
startind = nextind(s, rsearch(s, non_identifier_chars, method_name_end))
238-
return startind:endof(s), method_name_end
238+
return (startind:endof(s), method_name_end)
239239
end
240240

241241
# Returns the value in a expression if sym is defined in current namespace fn.
@@ -249,18 +249,18 @@ function get_value(sym::Expr, fn)
249249
fn, found = get_value(ex, fn)
250250
!found && return (nothing, false)
251251
end
252-
fn, true
252+
return (fn, true)
253253
end
254254
get_value(sym::Symbol, fn) = isdefined(fn, sym) ? (getfield(fn, sym), true) : (nothing, false)
255255
get_value(sym::QuoteNode, fn) = isdefined(fn, sym.value) ? (getfield(fn, sym.value), true) : (nothing, false)
256-
get_value(sym, fn) = sym, true
256+
get_value(sym, fn) = (sym, true)
257257

258258
# Return the value of a getfield call expression
259259
function get_value_getfield(ex::Expr, fn)
260260
# Example :((top(getfield))(Base,:max))
261261
val, found = get_value_getfield(ex.args[2],fn) #Look up Base in Main and returns the module
262262
found || return (nothing, false)
263-
get_value_getfield(ex.args[3],val) #Look up max in Base and returns the function if found.
263+
return get_value_getfield(ex.args[3], val) #Look up max in Base and returns the function if found.
264264
end
265265
get_value_getfield(sym, fn) = get_value(sym, fn)
266266

@@ -285,9 +285,9 @@ function get_type_call(expr::Expr)
285285
length(mt) == 1 || return (Any, false)
286286
m = first(mt)
287287
# Typeinference
288-
linfo = Base.func_for_method_checked(m[3], Tuple{args...})
289-
(tree, return_type) = Core.Inference.typeinf(linfo, m[1], m[2])
290-
return return_type, true
288+
return_type = Core.Inference.typeinf_type(m[3], m[1], m[2])
289+
return_type === nothing && return (Any, false)
290+
return (return_type, true)
291291
end
292292
# Returns the return type. example: get_type(:(Base.strip("",' ')),Main) returns (String,true)
293293
function get_type(sym::Expr, fn)
@@ -305,7 +305,7 @@ function get_type(sym::Expr, fn)
305305
end
306306
return get_type_call(sym)
307307
end
308-
(Any, false)
308+
return (Any, false)
309309
end
310310
function get_type(sym, fn)
311311
val, found = get_value(sym, fn)

0 commit comments

Comments
 (0)