{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/12010","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/12010/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/12010/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/12010/events","html_url":"https://github.com/JuliaLang/julia/issues/12010","id":93019989,"number":12010,"title":"make const a toplevel expr or error","user":{"login":"vtjnash","id":330950,"avatar_url":"https://avatars.githubusercontent.com/u/330950?v=3","gravatar_id":"","url":"https://api.github.com/users/vtjnash","html_url":"https://github.com/vtjnash","followers_url":"https://api.github.com/users/vtjnash/followers","following_url":"https://api.github.com/users/vtjnash/following{/other_user}","gists_url":"https://api.github.com/users/vtjnash/gists{/gist_id}","starred_url":"https://api.github.com/users/vtjnash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtjnash/subscriptions","organizations_url":"https://api.github.com/users/vtjnash/orgs","repos_url":"https://api.github.com/users/vtjnash/repos","events_url":"https://api.github.com/users/vtjnash/events{/privacy}","received_events_url":"https://api.github.com/users/vtjnash/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/priority","name":"priority","color":"7b07ce"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-07-04T15:12:26Z","updated_at":"2015-07-04T15:52:30Z","closed_at":null,"body":"`const` can cause serious, subtle bugs when combined with precompilation. it is valid to use from the `:toplevel` scope, but it can cause problems if used at runtime (and it's already ignored when specified at the local scope. this could be fixed by warning for and ignoring the const declaration outside of the toplevel scope. or this could be fixed by internally distinguishing between `const` (as it is currently defined) and a new `assigned once` attribute (that provides none of the inference speed benefits of const, but just doesn't allow reassignment).\r\n\r\nthe following is fine:\r\n```julia\r\nmodule Fine\r\nconst binding = value\r\nend\r\n```\r\n\r\nthe following can confuse precompilation (and isn't great for type inference either):\r\n```\r\nmodule Bad\r\n__init__() = (global const binding = value)\r\nend\r\n```\r\n\r\nthe following currently is ignored by parsing, so is neither bad nor good:\r\n```julia\r\nmodule Either\r\nf() = (const localb = localv)\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/118525467","html_url":"https://github.com/JuliaLang/julia/issues/12010#issuecomment-118525467","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/12010","id":118525467,"user":{"login":"vtjnash","id":330950,"avatar_url":"https://avatars.githubusercontent.com/u/330950?v=3","gravatar_id":"","url":"https://api.github.com/users/vtjnash","html_url":"https://github.com/vtjnash","followers_url":"https://api.github.com/users/vtjnash/followers","following_url":"https://api.github.com/users/vtjnash/following{/other_user}","gists_url":"https://api.github.com/users/vtjnash/gists{/gist_id}","starred_url":"https://api.github.com/users/vtjnash/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtjnash/subscriptions","organizations_url":"https://api.github.com/users/vtjnash/orgs","repos_url":"https://api.github.com/users/vtjnash/repos","events_url":"https://api.github.com/users/vtjnash/events{/privacy}","received_events_url":"https://api.github.com/users/vtjnash/received_events","type":"User","site_admin":false},"created_at":"2015-07-04T15:52:30Z","updated_at":"2015-07-04T15:52:30Z","body":"> Sorry I forgot to mention that this should also be combined with letting typeinf/precompile look into functions (especially __init__) to see that the const global will be assigned at runtime.\r\n\r\n@carnaval is that something typeinference could handle?\r\n\r\n> I think I get it now. Presumably \"only\" affects functions that get JITted before the cache is written?\r\n\r\nJIT isn't really the right term, since this is AOT compiling. But since this is AOT, it's generally beneficial to do as much work as possible to build a good / complete cache."}}