3 ms·
When I was working with Julia I wanted it to just throw an error whenever a top level program was compiled to unstable types. I didn’t find a way to do it thoug
by xiphias2 5y ago
When I was working with Julia I wanted it to just throw an error whenever a top level program was compiled to unstable types. I didn’t find a way to do it though :(
- ulysses4ever 5y agoI absolutely agree that providing a tool to _assert_ stability (just like usual @assert) would be great. We thought about it when writing the paper but never got to device anything like that. For smooth integration, that would probably require hacking on Julia itself.
- adgjlsfhk1 5y agoJulia has the `@infered` macro in `Test` that throws an error if your code isn't type stable.
- leephillips 5y agoDo you know about the code_warntype macro and function?
- kwertzzz 5y agoThe code_warntype macro is helpful, but to prevent a future inadvertently introduced type stability, a failing test would be much better. Test.@inferred is not quite what is needed: function foo(x) s = 0 # better use a zero of the same type than x # s = zero(x) for y in x s += y end return s end Test.@inferred Float64 foo(12.1) This test succeeds even if code is type-unstable
- fault1 5y agoOne problem is Julia is just ahead of time compiled, so you need something like JET to iteratively run stability analysis via abstract interpretation if you intend to run it for a top level program: https://aviatesk.github.io/JET.jl/dev/optanalysis/ https://aviatesk.github.io/JET.jl/dev/optanalysis/ It recently got support on vscode. What was available in Julia before (things like @code_typed) are only applicable locally, so there is only limited benefit. Because linters have dramatically improved in recent years, it feels like Julia was lagging behind until recently. Actually thinking about it, Julia could use something like refinement types ala Liquidhaskell: http://ucsd-progsys.github.io/liquidhaskell-tutorial/Tutorial_01_Introduction.html http://ucsd-progsys.github.io/liquidhaskell-tutorial/Tutoria...