Skip to content

functions -e ought to not allow autoloading #213

Closed

Description

@ridiculousfish

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.

Activity

  1. ridiculousfish commented on Oct 12, 2013

    @ridiculousfish
    MemberAuthor

    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.

  2. terlar commented on Oct 31, 2013

    @terlar
    Contributor

    For reference a way where functions -e still doesn't work: #1033 (comment)

  3. aldanor commented on Feb 20, 2014

    @aldanor

    Hi, any updates about this?

  4. ridiculousfish commented on Feb 20, 2014

    @ridiculousfish
    MemberAuthor

    I haven't gotten to it. Feel free to take it on if you like :)

  5. modified the milestones: , next-major on Apr 1, 2014
  6. added a commit that references this issue on Mar 11, 2015
    6dbc880
  7. ridiculousfish commented on Apr 6, 2015

    @ridiculousfish
    MemberAuthor

    Very nice fix. Merged with rebase as 73f344f. Thanks!!

  8. RomanHargrave commented on Apr 8, 2015

    @RomanHargrave
    Contributor

    @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.

  9. snnw commented on Apr 8, 2015

    @snnw
    Contributor

    @RomanHargrave Thanks for the heads-up. Confirmed on my machine. I'll try to see what's going on..

  10. snnw commented on Apr 8, 2015

    @snnw
    Contributor

    @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?

  11. ridiculousfish commented on Apr 8, 2015

    @ridiculousfish
    MemberAuthor

    Nice analysis.

  12. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions