{"action":"opened","issue":{"url":"https://api.github.com/repos/Whiley/WhileyCompiler/issues/555","labels_url":"https://api.github.com/repos/Whiley/WhileyCompiler/issues/555/labels{/name}","comments_url":"https://api.github.com/repos/Whiley/WhileyCompiler/issues/555/comments","events_url":"https://api.github.com/repos/Whiley/WhileyCompiler/issues/555/events","html_url":"https://github.com/Whiley/WhileyCompiler/issues/555","id":124412970,"number":555,"title":"Tagged Unions on the JVM","user":{"login":"DavePearce","id":484459,"avatar_url":"https://avatars.githubusercontent.com/u/484459?v=3","gravatar_id":"","url":"https://api.github.com/users/DavePearce","html_url":"https://github.com/DavePearce","followers_url":"https://api.github.com/users/DavePearce/followers","following_url":"https://api.github.com/users/DavePearce/following{/other_user}","gists_url":"https://api.github.com/users/DavePearce/gists{/gist_id}","starred_url":"https://api.github.com/users/DavePearce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavePearce/subscriptions","organizations_url":"https://api.github.com/users/DavePearce/orgs","repos_url":"https://api.github.com/users/DavePearce/repos","events_url":"https://api.github.com/users/DavePearce/events{/privacy}","received_events_url":"https://api.github.com/users/DavePearce/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Whiley/WhileyCompiler/labels/Feature","name":"Feature","color":"009800"},{"url":"https://api.github.com/repos/Whiley/WhileyCompiler/labels/Useful","name":"Useful","color":"DDDDDD"},{"url":"https://api.github.com/repos/Whiley/WhileyCompiler/labels/WYJC","name":"WYJC","color":"000000"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/Whiley/WhileyCompiler/milestones/2","html_url":"https://github.com/Whiley/WhileyCompiler/milestones/ChangeList%20Post%20v0.4.0","labels_url":"https://api.github.com/repos/Whiley/WhileyCompiler/milestones/2/labels","id":37574,"number":2,"title":"ChangeList Post v0.4.0","description":"This is a dumping ground for all changes that will note make the v0.4.0 release.","creator":{"login":"DavePearce","id":484459,"avatar_url":"https://avatars.githubusercontent.com/u/484459?v=3","gravatar_id":"","url":"https://api.github.com/users/DavePearce","html_url":"https://github.com/DavePearce","followers_url":"https://api.github.com/users/DavePearce/followers","following_url":"https://api.github.com/users/DavePearce/following{/other_user}","gists_url":"https://api.github.com/users/DavePearce/gists{/gist_id}","starred_url":"https://api.github.com/users/DavePearce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DavePearce/subscriptions","organizations_url":"https://api.github.com/users/DavePearce/orgs","repos_url":"https://api.github.com/users/DavePearce/repos","events_url":"https://api.github.com/users/DavePearce/events{/privacy}","received_events_url":"https://api.github.com/users/DavePearce/received_events","type":"User","site_admin":false},"open_issues":43,"closed_issues":39,"state":"open","created_at":"2011-09-14T20:39:00Z","updated_at":"2015-12-30T23:20:30Z","due_on":null,"closed_at":null},"comments":0,"created_at":"2015-12-30T23:20:30Z","updated_at":"2015-12-30T23:20:30Z","closed_at":null,"body":"(follows from #552 and #86)\r\n\r\nThe way that runtime type testing is implemented on the JVM is both inefficient and, essentially, flawed.  We want runtime type testing to have the minimum additional overhead possible.  In particular:\r\n\r\n1. **When no union types are present, no additional overhead is incurred**.  For example, no additional storage space is allocated for representing runtime types, etc.\r\n\r\n2. **The overhead incurred is proportional to the number of distinct type classes.**  For example, if have only the union type <code>null | int</code> then exactly 1 bit of information is required to encode this.  In reality, we might use a larger data type (e.g. a <code>byte</code>, <code>short</code>, etc) but it will remain proportional to the minimum required.  Overhead here is measured in terms of time and space.\r\n\r\nThe current JVM implementation is inefficient because it requires, for example, checking all elements of an array to distinguish the types <code>int[]</code> and <code>bool[]</code>, when in fact a single bit which can be checked in constant time is all that is required.\r\n\r\nThe current JVM implementation is also flawed because it does not properly handled function references (see #552).  At the moment, the JVM implementation is built around the notion that the value being tested represents a \"tree\", whilst the type tested against can be cyclic.  With function / method references we lose this property.  This is because we cannot inspect the function to see what it does (like for other data types) and, hence, we must rely on the declared type (which maybe acyclic)."}}