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

Feature request: remove dead has branches at source->source optimization step #25

Open
jm355 opened this issue Dec 19, 2024 · 4 comments

Comments

@jm355
Copy link

jm355 commented Dec 19, 2024

sdk 7 brought the ability to compile out dead branches based on has checks, however they're not enabled by default and most devices won't get this until new device configs get rolled out. Can prettier monkeyc do this at the source->source optimization step?

@markw65
Copy link
Owner

markw65 commented Dec 19, 2024

Yes - I think I need to do some of it under an option, because people have argued that they don't want Foo has :Bar to be optimized to false for a device, since it's possible that a newer version of the firmware will support that feature, and they don't want to have to keep updating their builds.

On the other hand it's always safe to optimize a condition to true, when the device is guaranteed to support it, because th .iq file won't install on devices older than the one you build against.

@jm355
Copy link
Author

jm355 commented Dec 19, 2024

It looks like it already does this for has checks for Rez, e.g. if (Rez has :Styles && Rez.Styles has :device_info && Rez.Styles.device_info has :screenWidth)

@markw65
Copy link
Owner

markw65 commented Dec 19, 2024

If you check for something that isn't defined anywhere (including in the Toybox), it will optimize the has check to false, because there's no possibility of any other result.

For things that it does find, there are two possibilities:

  • it's defined by the system, in which case whether it's actually available or not may depend on the device you're compiling for
  • it's defined by your code, in which case it definitely exists (assuming we've already dealt with exclude annotations).

I currently don't distinguish between those cases, so I never optimize has checks for things that have a definition.

My proposed change is:

  • always optimize checks of user defined symbols to true
  • always optimize checks of Toybox symbols that are available to the current device to true
  • under a new option, optimize checks of Toybox symbols that are not available to the current device to false

@jm355
Copy link
Author

jm355 commented Dec 19, 2024

Sounds good to me!

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

No branches or pull requests

2 participants