Hi Julianners,
I saw many attempt on type table block.
opened 08:37AM - 24 Apr 15 UTC
speculative
Given the importance of type stability, I would like to propose a new language c… onstruct that would allow semi-static checking of type stable blocks. In the module I am developing, I am frequently using this type of construct
``` julia
function f(a)
# Type stability
@stabilize m::Matrix{Float64} = a.m
# Compute things with m
end
...
```
I know there are:
1. The possibility to use a function - but this can be cumbersome when there are many types, and in makes the code harder to read (at least for me)
2. Tools like Lint or TypeCheck, and the macro `@code_warntype` that are useful to see/check whether the written code is type stable
but I would really like to have something that prevents code from being instable, e.g. using a "stable block" (I check and this gives a syntax error with julia 0.[34]):
``` julia
function f(a)
# Type stability
@stabilize m::Matrix{Float64} = a.m
stable begin
# Compute things - compilation error (or warning) if there is some type instability within the code
end
end
...
```
Another syntactic possibility would be to use pragmas #7449 (if they make it in the language).
@code_warntype
to trace them.
But in the end I don’t find what is the way to force type stability over a specific block. I want the code to stop or do a warn message any time it uses Any or Any like types.
I want to make sure we don’t waste resources. Do you know something that forbid type instability?
Best!
2 Likes
jw3126
August 29, 2022, 2:41pm
2
JET.@test_opt can test that a function call is never hits dynamic dispatch, which is very close to what you are asking for.
3 Likes