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

Consolidate multiple optimization levels down to one #1754

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

gbrail
Copy link
Collaborator

@gbrail gbrail commented Dec 11, 2024

Instead of 10+ optimization, levels, reduce them to one -- "interpreted mode" and compiled mode. This includes:

  • Adding an "interpreted mode" flag to Context
  • Deprecate "optimization level" flags in Context
  • Add an "-int" flag to the shell to support the new level
  • Keep old "-opt" shell flag, but take it out of documentation
  • Reduce many tests that ran in three optimization levels to just run twice

Remove them from main code and replace with "interpreted mode" flag.
Disable deprecation warnings in tests because we still want to test the
old stuff for now at least.
@@ -80,8 +80,7 @@ public String[] processOptions(String args[]) {
continue;
}
if ((arg.equals("-opt") || arg.equals("-O")) && ++i < args.length) {
int optLevel = Integer.parseInt(args[i]);
compilerEnv.setOptimizationLevel(optLevel);
// This no longer has an effect, but parse it for backward compatibility
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we can add a version hint to the comment, i fear when reading this later someone likes to know the version that introduces this change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Check out new comments, thanks!

@@ -551,7 +551,7 @@ static void processFileSecure(Context cx, Scriptable scope, String path, Object
Object source = readFileOrUrl(path, !isClass);

byte[] digest = getDigest(source);
String key = path + "_" + cx.getOptimizationLevel();
String key = path + "_" + (cx.isInterpretedMode() ? "int" : "comp");
Copy link
Collaborator

Choose a reason for hiding this comment

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

'int' might be confusing, is there any good reason for this shortening?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really -- AFAIK this is just used as a cache key but there's no reason why not to make it longer. (Previously it was just an integer.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Checkout the latest patch, it supports both "-int" and "-interpreted"

@@ -34,7 +34,7 @@ msg.shell.usage =\
\ -w Enable warnings.\n\
\ -version 100|110|120|130|140|150|160|170|180|200\n\
\ Set a specific language version.\n\
\ -opt [-1|0-9] Set optimization level.\n\
\ -int Run in interpreted mode.\n\
Copy link
Collaborator

Choose a reason for hiding this comment

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

'int' is confusing

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, although don't you think that '-interpreted' is too long? And '-I' is too much like the "-I" argument in a C compiler.

What if we support both "-int" and "-interpreted" command-line flags?

Copy link
Collaborator

Choose a reason for hiding this comment

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

although don't you think that '-interpreted' is too long?

sometimes, but i learned the hard way that is easier for me to type this many chars while writing the code & doc the spending the the answering all the questions ;-D


return null;
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this is removed?

Copy link
Collaborator Author

@gbrail gbrail Dec 13, 2024

Choose a reason for hiding this comment

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

This function, and "getTestOptLevels", is no longer used. There's also a duplicate-ish version of this class in the "tests" module where this might be used more.

@rbri
Copy link
Collaborator

rbri commented Dec 12, 2024

Another great step on our journey to modernize this

* Add proper deprecation warnings
* Rename old "doctests" files to make them clearer
@gbrail gbrail marked this pull request as ready for review December 13, 2024 07:04
@rbri
Copy link
Collaborator

rbri commented Dec 16, 2024

@gbrail i just notice that we have the Utils class more or less twice

  • rhino/src/test/java/org/mozilla/javascript/tests/Utils.java
  • tests/src/test/java/org/mozilla/javascript/tests/Utils.java

I think we have to merge it into one - but i'm to far away from gradle modules to understand how we can make the one from the rhino module available in the test module also.

Maybe you can have a look at this (please)

@gbrail
Copy link
Collaborator Author

gbrail commented Dec 17, 2024

I'd like to address the "Utils" class in a different PR, but we can try some things. However, I think that we might need a new "test-utils" module to contain that if we want to do it the cleanest possible way.

@gbrail gbrail merged commit 8f8c3dc into mozilla:master Dec 17, 2024
3 checks passed
@gbrail gbrail deleted the greg-one-opt branch December 17, 2024 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants