-
Notifications
You must be signed in to change notification settings - Fork 323
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
Meta.get_annotation and extension methods #7000
Conversation
|
||
Test.specify "verify calling everything works" <| | ||
describe_anno = Meta.get_annotation it "describe" "which" | ||
describe_anno it . should_equal 13 |
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.
This is very "verbose", @jdunkerley! One has to:
- a lambda function
@which (self -> self.a)
as annotation - gets a lambda function via
Meta.get_annotation
- needs to invoke it
I was hoping Meta.get_annotation
actually invokes the code in @which self.a
by itself internally! E.g. one could reference self
in the code after @which
and it evaluation would happen by itself too.
With the current state of affairs, there is no reason why Meta.get_annotation
shall take self
argument! It rather needs a Function
!
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.
67fb583 let's anyone "resolve" a function and then pass such function as a handle around. Then everyone can query for annotations associated with that function.
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.
Agree on the get_annotation
having to unwind to get the value is annoying.
I wrapped it in the visualization layer and haven't thought of it since!
@@ -217,6 +218,20 @@ type Polyglot | |||
lang_str = get_polyglot_language self.value | |||
if lang_str == "java" then Language.Java else Language.Unknown | |||
|
|||
type Function |
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.
There are many type
in Meta
- why don't we have a single Meta
type and many constructors Atom
, Constructor
, Primitive
, etc.? Is this just a heritage or is there a benefit of doing so?
Vote +1 for me to attempt to rewrite to single Meta
type and constructors. Vote -1 for keeping status quo as much as possible. CCing @jdunkerley, @GregoryTravis, @radeusgd
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.
I'm not strongly attached to either way, although I think the current state of things is fine.
I think the reason could have been that each 'variant' has a different set of operations available on it - an Atom
may have a fields
field, but this does not make sense for a Function
or Primitive
. Ofc we can just throw 'Illegal_State' for such wrong calls but IMO this does not look good - it's better when the API of each 'variant' is visible from its type not from for what it works and for what it throws.
On the other hand, I'd appreciate some 'common parent type' for all these, but without class hierarchies / interfaces, I don't think we can have the cake (common type) and eat it too (clear, variant-specific API). Do you think it's somehow possible?
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.
Yes, the common type is the problem. There is a really long signature and I'd love to shorten it to meta : Any -> Meta
.
an just throw 'Illegal_State' for such wrong calls
Right now we are getting No_Such_Method
errors. Rather than throwing the (or another) error, I'd just return some default, when sensible. If I rewrote to Meta
with multiple constructors.
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.
This looks like a good workaround to the issue,
So to be clear. The IDE would call: Widgets.get_widget_json value value.my_function ["arg1", "arg3"] ...
.
We will need to amend the Visualization layer and the rust code. We must include the ...
to shutdown auto evaluation of the defaulted argument.
|
||
Test.specify "verify calling everything works" <| | ||
describe_anno = Meta.get_annotation it "describe" "which" | ||
describe_anno it . should_equal 13 |
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.
Agree on the get_annotation
having to unwind to get the value is annoying.
I wrapped it in the visualization layer and haven't thought of it since!
Wouldn't it have to be
instead? I think we need to use |
I don't know how the IDE is supposed to accomplish that by using the Visualizations API. Right now it is not possible to refer to multiple existing expressions in a single visualization call. See https://github.com/orgs/enso-org/discussions/6832 for more details. Right now, the
|
…ystem of get_annotation
@@ -392,7 +392,7 @@ impl QueryData { | |||
/// Generate visualization metadata for this query. | |||
fn visualization_metadata(&self) -> Metadata { | |||
let arguments: Vec<Code> = vec![ | |||
Self::escape_visualization_argument(&self.method_name).into(), | |||
format!("(self.{}...)", &self.method_name).into(), |
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.
It is surprising to me that this could work. I assumed that the arguments passed to the visualization preprocessor were treated as expressions in method call argument position. In that case, self
would not refer to the right thing. Looks like my assumption was incorrect.
So, to be clear, is it true that the passed-in "arguments" are treated effectively as expressions within the BODY of the visualization preprocessor method?
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.
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.
While it will surely work when sketching out that query flow in the IDE itself, the question is if it will be resolved as intended through the visualization API. You would need to check the log of visualization requests and responses to be sure it behaves as expected.
The IDE is able to come up with a decent set of widgets purely based on data from suggestion database that it already has, even when the visualization query fails. So inspecting the graph visually for dropdowns is not enough to assess that it works.
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.
It doesn't work. Evaluation fails with unknown/wrong self
. Is there a way to obtain the name of the self
node? In this case operator18
? It might be available... No it doesn't seem to be readily available in EvalNode.parseExpression
as the LocalScope
is empty.
Can we at least find the type of operator18
out, @Frizi?
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.
How does the self
value get in, @4e6? There is:
ctx.executionService.callFunctionWithInstrument(
visualisation.cache,
visualisation.module,
visualisation.callback,
expressionValue +: visualisation.arguments: _*
)
in ProgramExecutionSupport.scala
and expressionValue
is self
while the rest is defined by the visualization.
The visualisation.module
is an interesting object - update: no, it is not - the last interesting module identification is in IdExecutionInstrument
just before calling onExpressionReturn
when we can get node.getRootNode().getModuleScope()
to be the ModuleScope
of the user module.
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.
To continue experiments I'd like to change the IDE to invoke the WIDGET_VISUALIZATION_METHOD
with one more argument - reference (FQN name is sufficient) to the module that is being edited. Help needed - nothing in widget.rs
file seems to have a reference to the module name as far as I can tell.
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.
Given that we already send the expression ID into the visualization, can't the used module be computed from that on the engine side?
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.
... already send the expression ID into the visualization, can't the used module be
computed from that on the engine side?
You send it to a completely different part of the engine. It needs to be available when evaluating the visualization. Engine knows nothing about Widgets.get_widget_json
- that is a contract between IDE and Standard.Visualization
- I shouldn't try to interpret the arguments to Widgets.get_widget_json
function in the engine - better if the IDE assembles them properly.
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.
However IDE cannot specify the name of the module that requests the visualization, as the IDE doesn't know it. According to @Frizi, following might help:
Interesting change: https://github.com/enso-org/enso/pull/7028/files#diff-4b79b29711f3cafb4bc4dbbd0882b63066d1de06e338bc8f86bf7c03a3e2e936R45
The project name will now actually be available in the graph.
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.
return 4; | ||
} | ||
if (TypesGen.isDataflowError(value)) { | ||
return -5; |
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.
These indices look rather magical, I think we should have some comment explaining where they come from.
Why is the dataflow index the only negative one?
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.
This is the relevant commit to read: 133ba8d
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.
I think it would be good to have some comment explaining this logic, as it's not that easy to understand it.
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.
What is the result of Meta.meta (Error.throw "Foo")
?
IIRC it used to be Error.Value
, but how I understand the current code, I'd guess it to be Primitive.Value
(for Text
). Do I understand it correctly?
@JaroslavTulach What's the status here? |
Still struggling and I will continue to struggle for the next iteration. |
Will be fixed by #7115 - no need for the changes in this PR anymore. |
Pull Request Description
Attempt to fix #6955. Writing a test to check behavior of
Meta.get_annotation
and extension methods. The idea is to deprecateMeta.get_attribute
and rather than that obtain the annotation for function itself.That however requires to pass function as a handle thru the visualizations. The problem there is that saturated functions like to turn themselves into into results and we shall prevent that. Hence 5d87c9c introduces
Meta.Function
with itsget_annotation parameter_name
method.Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
./run ide build
.