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

Let runtime library functions specify their parameter names #2285

Merged
merged 3 commits into from
May 1, 2024

Conversation

oxc
Copy link
Contributor

@oxc oxc commented Apr 28, 2024

This commit is part of #2284, but given that it affects not only the Javascript system, I've decided to pull it out into a separate PR.


In cases where a runtime library function has multiple overloads with the same arity, the parameter names cannot be nicely resolved from the implementation function, because they have different meaning depending on the selected type signature.
Instead of hardcoding this in TypescriptDefinition, let function definition include parameter names where this makes sense.

Unfortunately, this requires some extra pass-through constructors in LibraryFunction. At least one of them can resolved once we switch to JDK22 and statements before the this() call are allowed.

These parameter names will also show up in ashref/jsref, but unfortunately the reflection-based parameter names don't show up, because KoLmafia is only compiled with the required -parameters switch for tests and tsDef (see build.gradle#L285-L289). Is there a good reason not to enable this generally?

@oxc oxc requested a review from a team as a code owner April 28, 2024 18:25
@oxc
Copy link
Contributor Author

oxc commented Apr 28, 2024

Could someone please re-run the tests on windows? They pass fine here: https://github.com/oxc/kolmafia/actions/runs/8869700421/job/24350661462

@oxc
Copy link
Contributor Author

oxc commented Apr 28, 2024

For completeness sake, I want to provide an alternative suggestion: instead of mixing reflection and explicitly named parameters, we could just switch all runtime functions to include their parameter names. Let me know if I should add this to this PR.

@oxc oxc changed the title Let runtime library functions ambiguate their parameter names Let runtime library functions un-ambiguate their parameter names Apr 28, 2024
@gausie
Copy link
Contributor

gausie commented Apr 29, 2024

For completeness sake, I want to provide an alternative suggestion: instead of mixing reflection and explicitly named parameters, we could just switch all runtime functions to include their parameter names. Let me know if I should add this to this PR.

I do think your proposed alternative is probably better, but not necessary for right now if you don't feel up to it.

@midgleyc
Copy link
Member

These parameter names will also show up in ashref/jsref, but unfortunately the reflection-based parameter names don't show up, because KoLmafia is only compiled with the required -parameters switch for tests and tsDef (see build.gradle#L285-L289). Is there a good reason not to enable this generally?

My guess would be that they've just not been used until now, and enabling the flag probably increases the filesize by some amount, so it was cleaner to not do it.

I would support its addition for a nicer ashref / jsref.

@oxc
Copy link
Contributor Author

oxc commented Apr 30, 2024

They would already have shown up in ashref, but your guess might still be true from earlier times.

If nobody objects, I might still add namedParams to all functions, in a couple of days.

@gausie
Copy link
Contributor

gausie commented Apr 30, 2024 via email

In cases where a runtime library function has multiple overloads with
the same arity, the parameter names cannot be nicely resolved from the
implementation function, because they have different meaning depending
on the selected type signature.
Instead of hardcoding this in TypescriptDefinition, let function
definition include parameter names where this makes sense.

Unfortunately, this requires some extra pass-through constructors in
LibraryFunction. At least one of them can resolved once we switch to
JDK22 and statements before the this() call are allowed.
@oxc
Copy link
Contributor Author

oxc commented May 1, 2024

I've added param names for all functions. I have not provided any new names (except for the "adventure" function in the last commit for demonstration purposes).
I have removed the reflection based parameter names from the code.

@oxc oxc changed the title Let runtime library functions un-ambiguate their parameter names Let runtime library functions specify their parameter names May 1, 2024
Copy link
Contributor

@gausie gausie left a comment

Choose a reason for hiding this comment

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

Thank you, this rocks!

@gausie gausie merged commit 44dae6b into kolmafia:main May 1, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants