-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Abstract Interpretation to search for overridden property names #49199
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,7 @@ function complete_symbol(sym::String, @nospecialize(ffunc), context_module::Modu | |
lookup_module = true | ||
t = Union{} | ||
val = nothing | ||
ex = :() | ||
if something(findlast(in(non_identifier_chars), sym), 0) < something(findlast(isequal('.'), sym), 0) | ||
# Find module | ||
lookup_name, name = rsplit(sym, ".", limit=2) | ||
|
@@ -213,8 +214,27 @@ function complete_symbol(sym::String, @nospecialize(ffunc), context_module::Modu | |
end | ||
end | ||
end | ||
|
||
# Also, try abstract-interpreting propertynames | ||
thunk = context_module.eval(:(() -> propertynames($(ex)))) | ||
inf_params = Core.Compiler.InferenceParams(; assume_bindings_static=true) | ||
frame = Core.Compiler.typeinf_frame( | ||
Core.Compiler.NativeInterpreter(;inf_params), | ||
first(methods(thunk)), | ||
Tuple{typeof(thunk)}, | ||
Core.svec(), | ||
true, | ||
) | ||
Comment on lines
+219
to
+227
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are some ways available to perform inference on a toplevel expression directly rather than wrapping it in a temporary function and performing inference on it. |
||
if frame !== nothing && Core.Compiler.is_inferred(frame) && isa(frame.result.result, Core.Compiler.Const) | ||
for field in frame.result.result.val | ||
s = string(field) | ||
if startswith(s, name) | ||
push!(suggestions, FieldCompletion(t, field)) | ||
end | ||
end | ||
end | ||
end | ||
suggestions | ||
return suggestions | ||
end | ||
|
||
const sorted_keywords = [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this lead to duplicate suggestions for, e.g., concrete types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably do this inference within
get_type
above.