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

Function metadata call #5226

Open
wdanilo opened this issue Feb 5, 2023 · 7 comments
Open

Function metadata call #5226

wdanilo opened this issue Feb 5, 2023 · 7 comments
Assignees
Labels
-compiler -libs Libraries: New libraries to be implemented l-parameter-metadata p-low Low priority x-new-feature Type: new feature request

Comments

@wdanilo
Copy link
Member

wdanilo commented Feb 5, 2023

This task is automatically imported from the old Task Issue Board and it was originally created by James Dunkerley.
Original issue is here.


It would be useful to be able to acquire the metadata about a function's parameters.

Ideally would like to be able to get:

  • list of the parameter names.
  • the type of the argument.
  • if the parameter has a default.

This would help us answer the metadata for widget.
Could also use to provide a visualization for a function without all the defaults.

@jdunkerley jdunkerley removed this from Issues Board Feb 6, 2023
@JaroslavTulach JaroslavTulach self-assigned this Dec 5, 2024
@github-project-automation github-project-automation bot moved this to ❓New in Issues Board Dec 5, 2024
@JaroslavTulach JaroslavTulach moved this from ❓New to ⚙️ Design in Issues Board Jan 9, 2025
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jan 9, 2025

First of all we should polish content of Meta.enso by creating Meta_Helpers.enso and moving all builtins there: #12031

@farmaazon
Copy link
Contributor

I wonder if this task is still needed (it's very old) - the current implementation rely on Suggestion Database and seems working enough. @Frizi can you confirm?

@enso-bot
Copy link

enso-bot bot commented Jan 14, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-01-13):

Progress: .

GitHub
Pull Request Description Let's reduce the amount of code inside of Meta.enso in preparation of #5226. Important Notes Turning Meta.is_a from a builtin into regular method had its issues - solve...

@JaroslavTulach JaroslavTulach moved this from ⚙️ Design to 🔧 Implementation in Issues Board Jan 14, 2025
@JaroslavTulach
Copy link
Member

JaroslavTulach commented Jan 14, 2025

Very important issue related to Meta.meta is the meta representation of no argument constructors. The following program:

from Standard.Base import all

type X
    W
    V a b c


main =
    run
    
run =
    w = X.W...
    w1 = X.W
    ac = Meta.is_atom_constructor w...
    at = Meta.is_atom w ...

    [ac, at, Meta.meta w, Meta.meta w1]

shall print [True, True, (Constructor.Value W), (Atom.Value W)]. It does, with following patch:

diff --git distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
index 79f6c30639..834ad909ee 100644
--- distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
+++ distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
@@ -299,13 +299,14 @@ atom_with_hole factory = @Tail_Call Meta_Helpers.atom_with_hole_builtin factory
    Arguments:
    - value: The runtime entity to get the meta representation of.
 meta : Any -> Atom | Constructor | Primitive | Polyglot | Unresolved_Symbol | Error
-meta value = if Meta_Helpers.is_atom_builtin value then Atom.Value value else
-    if Meta_Helpers.is_atom_constructor_builtin value then Constructor.Value value else
-        if Meta_Helpers.is_polyglot_builtin value then Polyglot.Value value else
-            if Meta_Helpers.is_unresolved_symbol_builtin value then Unresolved_Symbol.Value value else
-                if Meta_Helpers.is_error_builtin value then Error.Value value.catch else
-                    if Meta_Helpers.is_type_builtin value then Type.Value value.catch else
-                        Primitive.Value value
+meta ~value = 
+    if Meta_Helpers.is_atom_constructor_builtin value... then Constructor.Value value... else
+        if Meta_Helpers.is_atom_builtin value... then Atom.Value value else
+            if Meta_Helpers.is_polyglot_builtin value then Polyglot.Value value else
+                if Meta_Helpers.is_unresolved_symbol_builtin value then Unresolved_Symbol.Value value else
+                    if Meta_Helpers.is_error_builtin value then Error.Value value.catch else
+                        if Meta_Helpers.is_type_builtin value then Type.Value value.catch else
+                            Primitive.Value value
 
 ## PRIVATE
    ADVANCED
@@ -379,7 +380,7 @@ type Language
    Arguments:
    - value: The value to check.
 is_atom_constructor : Any -> Boolean
-is_atom_constructor value = @Tail_Call Meta_Helpers.is_atom_constructor_builtin value
+is_atom_constructor ~value = @Tail_Call Meta_Helpers.is_atom_constructor_builtin value
 
 ## PRIVATE
 
diff --git engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java
index 46abd9e29f..c930b91660 100644
--- engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java
+++ engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/meta/IsAtomConstructorNode.java
@@ -3,6 +3,10 @@ package org.enso.interpreter.node.expression.builtin.meta;
 import com.oracle.truffle.api.nodes.Node;
 import org.enso.interpreter.dsl.AcceptsError;
 import org.enso.interpreter.dsl.BuiltinMethod;
+import org.enso.interpreter.dsl.Suspend;
+import org.enso.interpreter.node.MethodRootNode;
+import org.enso.interpreter.runtime.callable.function.Function;
+import org.enso.interpreter.runtime.data.atom.AtomConstructor;
 import org.enso.interpreter.runtime.type.TypesGen;
 
 @BuiltinMethod(
@@ -11,7 +15,18 @@ import org.enso.interpreter.runtime.type.TypesGen;
     description = "Checks if the argument is a constructor.",
     autoRegister = false)
 public class IsAtomConstructorNode extends Node {
-  boolean execute(@AcceptsError Object value) {
-    return TypesGen.isAtomConstructor(value);
+  boolean execute(@Suspend @AcceptsError Object value) {
+    if (TypesGen.isAtomConstructor(value)) {
+      return true;
+    }
+    if (value instanceof Function fn) {
+      if (AtomConstructor.accessorFor(fn) != null) {
+        return true;
+      }
+      if (MethodRootNode.constructorFor(fn) != null) {
+        return true;
+      }
+    }
+    return false;
   }
 }
diff --git engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/QualifiedAccessorNode.java engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/QualifiedAccessorNode.java
index 2be3a62f49..8844ff5a34 100644
--- engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/QualifiedAccessorNode.java
+++ engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/QualifiedAccessorNode.java
@@ -54,7 +54,7 @@ final class QualifiedAccessorNode extends EnsoRootNode {
       } else if (atomConstructor == falseCtor) {
         return false;
       } else {
-        return atomConstructor.newInstance();
+        return atomConstructor.getConstructorFunction();
       }
     } else {
       return atomConstructor;

time to productize that code!

@enso-bot
Copy link

enso-bot bot commented Jan 15, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-01-14):

Progress: .

@enso-bot
Copy link

enso-bot bot commented Jan 16, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-01-15):

Progress: .

GitHub
Join the world's most widely adopted, AI-powered developer platform where millions of developers, businesses, and the largest open source community build software that advances humanity.

@enso-bot
Copy link

enso-bot bot commented Jan 17, 2025

Jaroslav Tulach reports a new STANDUP for yesterday (2025-01-16):

Progress: .

Discord
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-compiler -libs Libraries: New libraries to be implemented l-parameter-metadata p-low Low priority x-new-feature Type: new feature request
Projects
Status: 🔧 Implementation
Development

No branches or pull requests

3 participants