You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you use functions -e to erase an autoloader function, it just gets autoloader again immediately. We should be smart about this and set a tombstone function to block it.
I'd like to discuss this a bit more. The way autoloading functions work is that a class autoload_t keeps track of the files it has loaded (e.g. math.fish), and their last-modified time (stat.st_mtime). The fix above erases the function from the function list, but not the autoload data. So it puts us in a sort of fragile state: the autoload machinery thinks the function has been loaded, while the function list has no entry for the function because it has been erased. If the autoload machinery decides to autoload the function again, for whatever reason, the function will come back. This may happen (for example) if the modification date on the file changes, or for random other reasons.
This is why erasing autoloaded functions is deliberately blocked: it's not reliable, since the function may or may not come back at some point.
Now if you define your own function, e.g. by sourcing a file directly or typing function blah blah..., it adds an entry to the function list along with a flag that indicates that this function was not autoloaded. Then we deliberately avoid autoloading that function again:
if (iter != loaded_functions.end() && !iter->second.is_autoload)
{
/* We have a non-autoload version already */
return 0;
}
That ensures autoloaded functions don't trump explicitly defined ones. If you define fish_prompt e.g. in config.fish, it won't later autoload the one in your functions directory and overwrite it.
So a robust fix for erasing autoloaded functions would work similarly. When a function is erased, we need to record that fact (what I called a "tombstone function") so that we don't later try to autoload it. I won't back the above changes out, but we need to implement the tombstone functionality before we ship a release with this change.
@ridiculousfish@snnw It looks like 73f344f or similar somehow borked autoloading hidden functions. I say this because it is the only major modification to either function.cpp or builtins.cpp between effected revisions. This is causing issues with the oh-my-fish startup script. In short, OMF uses a few _functions defined in $oh_my_fish_path/functions/_$name.fish during the plugin loading process. As of e421c12, they were being discovered correctly, however, as of 8742867 they are being ignored by the autoloader, thereby creating a waterfall of errors that exceeds my scrollback.
@ridiculousfish
This is what happens:
If fish_function_path has changed, then autoload_t::load evicts all its nodes, tombstoning any autoloaded functions, which then never get autoloaded again, resulting in oh-my-fish missing a few functions. I think we shouldn't tombstone functions in this case.
@RomanHargrave
A PR with a quick fix (with limited testing), which fixes this for me, is incoming. Can you please test?
Activity
ridiculousfish commentedon Oct 12, 2013
I'd like to discuss this a bit more. The way autoloading functions work is that a class
autoload_tkeeps track of the files it has loaded (e.g. math.fish), and their last-modified time (stat.st_mtime). The fix above erases the function from the function list, but not the autoload data. So it puts us in a sort of fragile state: the autoload machinery thinks the function has been loaded, while the function list has no entry for the function because it has been erased. If the autoload machinery decides to autoload the function again, for whatever reason, the function will come back. This may happen (for example) if the modification date on the file changes, or for random other reasons.This is why erasing autoloaded functions is deliberately blocked: it's not reliable, since the function may or may not come back at some point.
Now if you define your own function, e.g. by sourcing a file directly or typing
function blah blah..., it adds an entry to the function list along with a flag that indicates that this function was not autoloaded. Then we deliberately avoid autoloading that function again:That ensures autoloaded functions don't trump explicitly defined ones. If you define
fish_prompte.g. in config.fish, it won't later autoload the one in your functions directory and overwrite it.So a robust fix for erasing autoloaded functions would work similarly. When a function is erased, we need to record that fact (what I called a "tombstone function") so that we don't later try to autoload it. I won't back the above changes out, but we need to implement the tombstone functionality before we ship a release with this change.
terlar commentedon Oct 31, 2013
For reference a way where
functions -estill doesn't work: #1033 (comment)aldanor commentedon Feb 20, 2014
Hi, any updates about this?
ridiculousfish commentedon Feb 20, 2014
I haven't gotten to it. Feel free to take it on if you like :)
Revert 1349d12 and properly fix fish-shell#213
ridiculousfish commentedon Apr 6, 2015
Very nice fix. Merged with rebase as 73f344f. Thanks!!
RomanHargrave commentedon Apr 8, 2015
@ridiculousfish @snnw It looks like
73f344for similar somehow borked autoloading hidden functions. I say this because it is the only major modification to eitherfunction.cpporbuiltins.cppbetween effected revisions. This is causing issues with the oh-my-fish startup script. In short, OMF uses a few_functionsdefined in$oh_my_fish_path/functions/_$name.fishduring the plugin loading process. As ofe421c12, they were being discovered correctly, however, as of8742867they are being ignored by the autoloader, thereby creating a waterfall of errors that exceeds my scrollback.snnw commentedon Apr 8, 2015
@RomanHargrave Thanks for the heads-up. Confirmed on my machine. I'll try to see what's going on..
Tombstone only when explicitly removing a function.
snnw commentedon Apr 8, 2015
@ridiculousfish
This is what happens:
If
fish_function_pathhas changed, thenautoload_t::loadevicts all its nodes, tombstoning any autoloaded functions, which then never get autoloaded again, resulting in oh-my-fish missing a few functions. I think we shouldn't tombstone functions in this case.@RomanHargrave
A PR with a quick fix (with limited testing), which fixes this for me, is incoming. Can you please test?
ridiculousfish commentedon Apr 8, 2015
Nice analysis.
Tombstone only when explicitly removing a function.
Tombstone only when explicitly removing a function.