Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion stdlib/REPL/src/REPLCompletions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -213,8 +214,26 @@ function complete_symbol(sym::String, @nospecialize(ffunc), context_module::Modu
end
end
end

# Also, try abstract-interpreting propertynames
Copy link
Member

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?

Copy link
Member

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.

thunk = context_module.eval(:(() -> propertynames($(ex))))
code_info, rett = Core.Compiler.typeinf_code(
Core.Compiler.NativeInterpreter(),
Copy link
Member

Choose a reason for hiding this comment

The 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 assume_bindings_static turned on.

Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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 Const lattice element out of inference and look at that instead.

s = string(field)
if startswith(s, name)
push!(suggestions, FieldCompletion(t, field))
end
end
end
end
suggestions
return suggestions
end

const sorted_keywords = [
Expand Down