-
-
Notifications
You must be signed in to change notification settings - Fork 747
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
Scoping bug when defining a function from a previous scope #2530
Comments
As a minimal fix (which would resolve the settings app problem), I reckon if we updated the outer function's scope, that'd do it - provided this didn't tangle with the inner function |
Hmm - thanks! That's a tricky one. However the functionality exists so that people can edit a function on demand via the REPL - basically replacing its code while running it in the scope it was originally defined in. It feels like defining the same function twice in normal code is an error? Perhaps we should be using a different codepath for redefining a function in code though - as when you do
Oh, you mean https://github.com/espruino/BangleApps/blob/master/apps/recorder/settings.js ? This shouldn't be an issue at all with a normal But normally we would never fast load because |
This prevents issues with not loading settings on exit, or jumping into other apps such as the recorder, while not unloading settings. See also espruino/Espruino#2530
Yes - I imagined But yes - I believe this is a recorder specific issue, its settings app loads its app, which is fastloaded into (since both it and settings have As a fix, I think we just disable fastload for settings - I already had to put in a similar fix for DST. I'll let you decide what you think about redefining functions via code / this issue |
So are you saying this happens normally? Or only with the Because I don't think we should be going around putting hacks in all the applications to deal with the fact that Do you think we can just put exceptions into the I think it also makes sense for all the apps that have issues with But really the Perhaps Also maybe for the function replace we should just throw an exception if we try and replace a function with another function that itself has a scope defined? Because that's almost certainly an error? |
No, just with fastload - I'd expect fastload to not need an exception for settings though. @thyttan @halemmerich, what would you say if we altered fastload to only allow fastloading out of an app if the app had set a This would cover settings and other cases where apps are unaware of fastload, at the possible pessimisation of apps that might just work with it. Alternatively we add an exception to fastload for the settings app (and possibly others as we find them). @gfwilliams yes, r.e. the function replacing, I think we should throw an exception or fully replace the previous function, to avoid the existing behaviour which takes a bit of tracking down (but we preserve |
I thought this was already part of the logic?
But I'll leave the technicalities to @halemmerich since he's the brains on this. ;) |
I think this is the issue - The thing is any app can call It's a very easy change to make and can be done to any app once it's been checked that the app can totally unload itself (as is loading into an app with widgets), and then it'll run fast for everyone. So Personally I think it shouldn't exist. If we took all the time we spent tracking down fastload related issues, and instead spent it just changing |
I'm somewhat sympathetic towards this stance. But one thing that I think is not straight forward is, with fastload utils you have it sit in the middle and check weather the next app uses widgets and in that case it allows a fastload (if the current app has a remove handler). So you have for every app going out from the launcher the best possible loading speed. Maybe that logic could be put into And also there's the App history feature in fastload utils that I'm personally quite fond of 😛 |
Maybe one could argue all apps should just load widgets and if not wanted just hide them? Then it would maybe be OK to hardcode |
Thanks - yes, that's a good point. So the way I see it right now:
Do you think that's about right? So, we could disable fastload (by default, maybe via an option?) for anything that's not a clock or a launcher? OR, we currently have this magic 'launch cache' code that's duplicated in every main launcher: https://github.com/espruino/BangleApps/blob/master/apps/launch/app.js#L23-L39 And that's felt like a bad idea for a while (especially as they all use the same cache file!) - so how about we make a module for it, and also include the I feel like that'd be a good solution which is safe(ish) and works for everyone? The other benefit is of course the issue with For the small percentage of apps that do load other apps (and where speed is an issue) they could be modified manually to do |
Just to add I guess |
Yes, if the next app uses widgets.
Yes, but doesn't this solve itself by apps other than clocks and launchers not having a remove handler set? (bar e.g.
As I said abouve I think this is already, virtually at least, the case? But maybe it's a good idea for further flexibility. I don't get an immediate feeling either way.
Yes, without thinking about it very much that feels like a great idea to me!
Yes, I agree it's a shame to slow down non-fastloadable apps even further.
This sounds like a good idea to me and I'd probably like to do that for e.g.
OK - I always assumed the the full bootcycle was needed to rewrite the settings. But thinking about it that's probably not the case? |
I don't think fastload cares? It doesn't check
Pretty sure not - this whole issue wouldn't be a problem if it did.
Cool, yes. I think if you did it now, you'd at minimum get a fast swap to the clock from spotrem, and then maybe later even a fastload without the
Hmm - good point. How often do you go into settings and then not change anything? I guess maybe that means it's not so important to make fast loadable. |
I see your point now - yes. But that sounds to me like it's a bug rather then the supposed behaviour of Maybe we give it a day or two and give @halemmerich a chance to weigh in? |
It has been a few more days, but I had a look at fastboot. The idea was to only fastload into incompatible apps, never fastload out of them. That would be as @gfwilliams correctly said completely bonkers. I did not yet have a look at why settings could fastload the recorder app, but it absolutely should not. I do not see settings set It actually does not fastload on my watch when going from settings to the recorder app. |
Minimal repro:
I believe this bug is the combination of two problems:
This is visible, for example, when the settings app loads the recorder app - both scripts reference a
settings
variable, and both define ashowMainMenu
function. The recorder app'sshowMainMenu
then inherits the settings app'ssettings
, causing bugs/exceptions.Further details on why I believe the hoisting (of the assignment) shouldn't happen:
as it's equivalent to:
The text was updated successfully, but these errors were encountered: