Skip to content

2022 02 08 report

Artem Pelenitsyn edited this page Mar 1, 2023 · 1 revision

Report 2022-08-02

Intro

Last week I added two things to the current project:

  1. An eager version of the @stable macro to check a function definition for stability.
  2. An utility called is_stable_module that hopefully makes it easier to check more code using our approach.

Here are some details on both.

@stable eager and lazy

On last week Julia meeting, Yulia pointed out that my @stable macro is too eager: it will fail for a function calling another, not-yet-defined function. E.g.:
@stable f() = g()

@stable g() = 1

Including a file with such content will flag f as unstable because it calls unknown (at that point) function g that, therefore, can return Any.

The workaround is straightforward: put the given definition into a worklist to be processed later. The exact moment is decided by the user: they have to call check_all_stable() then. That’s is less nice, of course, but I can’t think of a better solution.

Right now, @stable works for the above example as expected (both functions are stable). The old, eager strategy is still around by the name @stable! (note the bang) in case the user knows that checking right now is okay.

Is module stable?

I added an utility to check for stability a whole module in the sense: all of function definitions in the given module are stable. It should make trying it out on real modules from real Julia packages easier. I haven’t really worked out the way the info should be collected. On small examples, just printing out about unstable functions worked reasonably well, but that’s not ideal for large code.

Here’s an example with first three functions in a module stable and the last one not.

module M
export a, b, c;
a()=1; b()=2; c=3;
d()=if rand()>0.5; 1; else ""; end
end

By default the utility checks only exported names, so only the first three functions will be checked by default. The following tests will pass:

@testset "is_stable_module" begin
    @test is_stable_module(M)
    @test ! is_stable_module(M, SearchCfg(exported_names_only=false))
end

For next week I was going to improve reporting of unstable module members and then try on real modules.