-
-
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 1 commit
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,26 @@ function complete_symbol(sym::String, @nospecialize(ffunc), context_module::Modu | |
end | ||
end | ||
end | ||
|
||
# Also, try abstract-interpreting propertynames | ||
thunk = context_module.eval(:(() -> propertynames($(ex)))) | ||
code_info, rett = Core.Compiler.typeinf_code( | ||
Core.Compiler.NativeInterpreter(), | ||
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. For this to be meaningfully powerful, i think you probably need an interpreter with 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. We should separate the cache for this inference that is much aggressive than the ordinary inference. |
||
first(methods(thunk)), | ||
Tuple{typeof(thunk)}, | ||
Core.svec(), | ||
true, | ||
) | ||
if rett <: Tuple && hasproperty(rett, :parameters) && all(rett.parameters .<: Symbol) | ||
for field in code_info.code[end].val | ||
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. This assumes that the code constant folds, which is not a valid assumption. You need to get the non-wiedened |
||
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.