{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/10980","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/10980/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/10980/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/10980/events","html_url":"https://github.com/JuliaLang/julia/issues/10980","id":70627618,"number":10980,"title":"Type stable block","user":{"login":"bpiwowar","id":423314,"avatar_url":"https://avatars.githubusercontent.com/u/423314?v=3","gravatar_id":"","url":"https://api.github.com/users/bpiwowar","html_url":"https://github.com/bpiwowar","followers_url":"https://api.github.com/users/bpiwowar/followers","following_url":"https://api.github.com/users/bpiwowar/following{/other_user}","gists_url":"https://api.github.com/users/bpiwowar/gists{/gist_id}","starred_url":"https://api.github.com/users/bpiwowar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bpiwowar/subscriptions","organizations_url":"https://api.github.com/users/bpiwowar/orgs","repos_url":"https://api.github.com/users/bpiwowar/repos","events_url":"https://api.github.com/users/bpiwowar/events{/privacy}","received_events_url":"https://api.github.com/users/bpiwowar/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-24T08:37:43Z","updated_at":"2015-04-24T12:44:49Z","closed_at":null,"body":"Given the importance of type stability, I would like to propose a new language construct that would allow semi-static checking of type stable blocks. In the module I am developing, I am frequently using this type of construct\r\n\r\n```julia\r\nfunction f(a)\r\n # Type stability\r\n@stabilize m::Matrix{Float64} = a.m\r\n\r\n # Compute things with m\r\n\r\nend\r\n...\r\n```\r\n\r\nI know there are:\r\n\r\n1. 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)\r\n1. Tools like Lint or TypeCheck, and the macro `@code_warntype` that are useful to see/check whether the written code is type stable\r\n\r\nbut 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]):\r\n\r\n```julia\r\nfunction f(a)\r\n # Type stability\r\n@stabilize m::Matrix{Float64} = a.m\r\n\r\n stable begin\r\n  # Compute things - compilation error (or warning) if there is some type instability within the code\r\n end\r\n\r\nend\r\n...\r\n```\r\n\r\nAnother syntactic possibility would be to use pragmas #1974 (if they make it in the language).\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/95920927","html_url":"https://github.com/JuliaLang/julia/issues/10980#issuecomment-95920927","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/10980","id":95920927,"user":{"login":"pao","id":140497,"avatar_url":"https://avatars.githubusercontent.com/u/140497?v=3","gravatar_id":"","url":"https://api.github.com/users/pao","html_url":"https://github.com/pao","followers_url":"https://api.github.com/users/pao/followers","following_url":"https://api.github.com/users/pao/following{/other_user}","gists_url":"https://api.github.com/users/pao/gists{/gist_id}","starred_url":"https://api.github.com/users/pao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pao/subscriptions","organizations_url":"https://api.github.com/users/pao/orgs","repos_url":"https://api.github.com/users/pao/repos","events_url":"https://api.github.com/users/pao/events{/privacy}","received_events_url":"https://api.github.com/users/pao/received_events","type":"User","site_admin":false},"created_at":"2015-04-24T12:44:49Z","updated_at":"2015-04-24T12:44:49Z","body":"A third--and I suspect preferred--syntactic possibility would be to add it as an annotation macro which would insert a `:meta` node in the AST, like `@inline`, `@simd`, and `@fastmath`:\r\n\r\n```Julia\r\n@error_unstable begin\r\n    ...\r\nend\r\n```\r\n\r\nThe hard part of this is the backend--detecting and acting on the type instability."}}