MilesCranmer / DispatchDoctor.jl

The dispatch doctor prescribes type stability
Apache License 2.0
128 stars 6 forks source link

Add preferences interface #14

Closed MilesCranmer closed 1 month ago

MilesCranmer commented 1 month ago

@mkitti what do you think?

From the new README:

You might find it useful to only enable @stable during unit-testing, to have it check every function in a library, but not throw errors for downstream users. For this, you can use the mode keyword to set the default behavior:

module MyPackage
using DispatchDoctor
@stable mode="disable" begin

# Entire package code

end
end

This sets the default, but the mode is configurable via Preferences.jl:

using MyPackage
using Preferences

set_preferences!(MyPackage, "instability_check" => "error")

which you can also set to be "warn" if you would just like warnings. You might find it useful to set this during testing.

coveralls commented 1 month ago

Coverage Status

coverage: 93.194% (-5.0%) from 98.235% when pulling 52a76511e68f3f0f2595024d0c048694b795d3eb on preferences into d78753cb743ef76a6f7e6664332c461f2f2ca75b on main.

MilesCranmer commented 1 month ago

@mkitti is there a way to check for preferences from the parent modules as well?

I ran into an issue where

module A
    @stable begin
        module B
            f() = rand(Bool) ? 1 : 1.0
        end
    end
end

the LocalPreferences.toml for A (which is a registered package) is not being propagated to B... Is that a known issue?

mkitti commented 1 month ago

Note that the macro form of @load_preference uses the package's UUID: https://github.com/JuliaPackaging/Preferences.jl/blob/209a45060b8eef13a790300189dfd30c2cb6a1e1/src/Preferences.jl#L52-L56

See get_uuid: https://github.com/JuliaPackaging/Preferences.jl/blob/209a45060b8eef13a790300189dfd30c2cb6a1e1/src/utils.jl#L36-L53

MilesCranmer commented 1 month ago

Thanks! get_uuid fixed it.

And the style of this, any final comments on it? Is this the sort of idea you had in mind?

And "instability_check" or maybe "dispatch_doctor"... Any preference?

MilesCranmer commented 1 month ago

Going to merge so people see the new syntax before too long, but happy to change things later if needed.

mkitti commented 1 month ago

Is there a preference for DispatchDoctor.jl itself that might change the default behavior?

MilesCranmer commented 1 month ago

Do you mean whether default_mode should be something other than "error"?