Skip to content

Conversation

jjfumero
Copy link
Member

@jjfumero jjfumero commented Sep 5, 2025

  • DialectSample: Example of how to extends the code reflection Op to create a new dialect.
  • DynamicFunctionBuild: Example of how to create a new function dynamically to compute the inverse of a square root. The code model is built dynamically for a new method and it is evaluated in the Interpreter.

How to run?

mvn clean package
java --enable-preview -cp target/crsamples-1.0-SNAPSHOT.jar oracle.code.samples.DialectSample
java --enable-preview -cp target/crsamples-1.0-SNAPSHOT.jar oracle.code.samples.DynamicFunctionBuild

Progress

  • Change must not contain extraneous whitespace

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/549/head:pull/549
$ git checkout pull/549

Update a local copy of the PR:
$ git checkout pull/549
$ git pull https://git.openjdk.org/babylon.git pull/549/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 549

View PR using the GUI difftool:
$ git pr show -t 549

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/549.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 5, 2025

👋 Welcome back jfumero! A progress list of the required criteria for merging this PR into code-reflection will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 5, 2025

@jjfumero This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

New Examples: Dialects and Dynamic Function Builds

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the code-reflection branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@jjfumero jjfumero marked this pull request as ready for review September 5, 2025 11:17
@jjfumero jjfumero changed the title Code Reflection sample for creating new Ops for a dialect New Examples: Dialects and Dynamic Function Builds Sep 5, 2025
@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 5, 2025
@jjfumero
Copy link
Member Author

jjfumero commented Sep 5, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 5, 2025
@openjdk
Copy link

openjdk bot commented Sep 5, 2025

@jjfumero
Your change (at version 46bf9c9) is now ready to be sponsored by a Committer.

@mlbridge
Copy link

mlbridge bot commented Sep 5, 2025

Webrevs

@jjfumero
Copy link
Member Author

jjfumero commented Sep 5, 2025

/integrate

@openjdk openjdk bot added sponsor Pull request is ready to be sponsored and removed sponsor Pull request is ready to be sponsored labels Sep 5, 2025
@openjdk
Copy link

openjdk bot commented Sep 5, 2025

@jjfumero
Your change (at version dbde9d0) is now ready to be sponsored by a Committer.


@Override
public Map<String, Object> externalize() {
return Map.of("", this.typeElement);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typeElement is already part of the operation, it's result type so this is duplicating information. Instead consider a property of addition as an example e.g., the kind of addition for integral types like signed, unsigned, or saturating.


private TypeElement typeElement;

MyAdd(String name, List<Value> operands, TypeElement typeElement) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operation name should not generally be something the user provides when constructing an operation. The name is for human readability in text, and the key that allows (re-)construction when parsing text back into code models. It's something that should be derived from other inputs and/or constant data. Further, its not something we should really use for pattern matching.

I would like to see if we could remove the name from the state of Op. OpWriter of course needs it. Maybe by default the written operation name is the operation (fully qualified) class name, and implementations can override it maybe via a separate interface. We might be able to group the name and externalization of state under one concept for reading/parsing.


@Override
public Map<String, Object> externalize() {
return Map.of("", this.typeDescriptor);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be the name of the function to invoke, which you are currently using as the operation name.

@jjfumero
Copy link
Member Author

jjfumero commented Sep 9, 2025

Thanks Paul for the feedback. I will make some modifications to adapt to these changes.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants