### Setting DispatchDoctor Mode via Preferences.jl Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/README.md Shows how to programmatically configure the `dispatch_doctor_mode` preference for a specific package using `Preferences.set_preferences!`. This allows users or test suites to override the package's default mode, for example, enabling error checking during testing. ```Julia using Preferences: set_preferences! set_preferences!("MyPackage", "dispatch_doctor_mode" => "error") ``` -------------------------------- ### Documenting register_macro! Utility (Julia) Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/docs/src/reference.md Documents the `register_macro!` utility function. This function allows users to customize how `@stable` interacts with other macros or declare macros incompatible with `@stable`. ```Julia @docs register_macro! ``` -------------------------------- ### Documenting @stable and @unstable Macros (Julia) Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/docs/src/reference.md Documents the `@stable` and `@unstable` macros from the DispatchDoctor.jl package. These macros are used for controlling stability checks. ```Julia @docs @stable @unstable ``` -------------------------------- ### Configuring Default Mode for DispatchDoctor in a Julia Package Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/README.md Demonstrates how to wrap the main code of a Julia package within a `@stable` block with `default_mode="disable"`. This sets the default behavior of DispatchDoctor to be a no-op, allowing users to opt-in to checks via Preferences.jl. ```Julia module MyPackage using DispatchDoctor @stable default_mode="disable" begin # Entire package code end end ``` -------------------------------- ### Documenting allow_unstable Utility (Julia) Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/docs/src/reference.md Documents the `allow_unstable` utility function. This function is used to temporarily disable the `@stable` check for a specific function call. ```Julia @docs allow_unstable ``` -------------------------------- ### Applying @stable to a Function (Julia) Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/README.md Demonstrates how to use the `@stable` macro to wrap a single Julia function. This macro adds runtime checks to ensure the function's return value is type stable, throwing an error if instability is detected. ```julia using DispatchDoctor: @stable @stable function relu(x) if x > 0 return x else return 0.0 end end ``` -------------------------------- ### Applying @stable to a Code Block (Julia) Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/README.md Shows how to apply the `@stable` macro to a `begin...end` block, module, or anonymous function. This applies the type stability check to all definitions within the block, including nested modules and included files. It also introduces the `@unstable` macro to selectively disable checks within a `@stable` block. ```julia @stable begin f() = rand(Bool) ? 0 : 1.0 f(x) = x module A # Will apply to code inside modules: g(; a, b) = a + b # Will recursively apply to included files: include("myfile.jl") module B # as well as nested submodules! # `@unstable` inverts `@stable`: using DispatchDoctor: @unstable @unstable h() = rand(Bool) ? 0 : 1.0 # This can also apply to code blocks: @unstable begin h(x::Int) = rand(Bool) ? 0 : 1.0 # ^ And target specific methods end end end end ``` -------------------------------- ### Documenting DispatchDoctor.type_instability Internal (Julia) Source: https://github.com/milescranmer/dispatchdoctor.jl/blob/main/docs/src/reference.md Documents the `DispatchDoctor.type_instability` internal function or type. This is part of the internal implementation of the DispatchDoctor.jl package, likely related to detecting or reporting type instability. ```Julia @docs DispatchDoctor.type_instability ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.