{"action":"created","issue":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/555","repository_url":"https://api.github.com/repos/ocaml/ocaml","labels_url":"https://api.github.com/repos/ocaml/ocaml/issues/555/labels{/name}","comments_url":"https://api.github.com/repos/ocaml/ocaml/issues/555/comments","events_url":"https://api.github.com/repos/ocaml/ocaml/issues/555/events","html_url":"https://github.com/ocaml/ocaml/pull/555","id":149434784,"number":555,"title":"Ensure that register typing constraints are respected at join points","user":{"login":"mshinwell","id":1315488,"avatar_url":"https://avatars.githubusercontent.com/u/1315488?v=3","gravatar_id":"","url":"https://api.github.com/users/mshinwell","html_url":"https://github.com/mshinwell","followers_url":"https://api.github.com/users/mshinwell/followers","following_url":"https://api.github.com/users/mshinwell/following{/other_user}","gists_url":"https://api.github.com/users/mshinwell/gists{/gist_id}","starred_url":"https://api.github.com/users/mshinwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshinwell/subscriptions","organizations_url":"https://api.github.com/users/mshinwell/orgs","repos_url":"https://api.github.com/users/mshinwell/repos","events_url":"https://api.github.com/users/mshinwell/events{/privacy}","received_events_url":"https://api.github.com/users/mshinwell/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ocaml/ocaml/labels/consider-for-release","name":"consider-for-release","color":"d93f0b"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/ocaml/ocaml/milestones/1","html_url":"https://github.com/ocaml/ocaml/milestones/4.03.0","labels_url":"https://api.github.com/repos/ocaml/ocaml/milestones/1/labels","id":1464887,"number":1,"title":"4.03.0","description":"","creator":{"login":"damiendoligez","id":19104,"avatar_url":"https://avatars.githubusercontent.com/u/19104?v=3","gravatar_id":"","url":"https://api.github.com/users/damiendoligez","html_url":"https://github.com/damiendoligez","followers_url":"https://api.github.com/users/damiendoligez/followers","following_url":"https://api.github.com/users/damiendoligez/following{/other_user}","gists_url":"https://api.github.com/users/damiendoligez/gists{/gist_id}","starred_url":"https://api.github.com/users/damiendoligez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damiendoligez/subscriptions","organizations_url":"https://api.github.com/users/damiendoligez/orgs","repos_url":"https://api.github.com/users/damiendoligez/repos","events_url":"https://api.github.com/users/damiendoligez/events{/privacy}","received_events_url":"https://api.github.com/users/damiendoligez/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":82,"state":"open","created_at":"2015-12-17T12:42:44Z","updated_at":"2016-04-20T09:26:44Z","due_on":"2016-02-07T23:00:00Z","closed_at":null},"comments":17,"created_at":"2016-04-19T11:45:31Z","updated_at":"2016-04-20T17:11:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ocaml/ocaml/pulls/555","html_url":"https://github.com/ocaml/ocaml/pull/555","diff_url":"https://github.com/ocaml/ocaml/pull/555.diff","patch_url":"https://github.com/ocaml/ocaml/pull/555.patch"},"body":"It has been known for some time that great care has to be taken when using Obj.magic to ensure that, at join points in the control flow graph, a register \"known to hold only immediates\" does not end up being used to hold a value that might be a pointer.  If this happens, it will not be registered as a GC root, which can cause it to become invalid.  (The typical fix is something like using None instead of \"unit\".)\r\n\r\nAfter having fixed a piece of code having that problem this morning it became apparent that the following function, which does not use Obj.magic, suffers from the same problem:\r\n\r\n```\r\ntype 'a typ = Int : int typ | Ptr : int list typ\r\n\r\nlet f (type a) (t : a typ) (p : int list) : a =\r\n  match t with\r\n  | Int -> 100\r\n  | Ptr -> p\r\n```\r\n\r\nIf the function \"f\" is inlined into another function then the situation above can arise, as exhibited in the test case on this pull request, which segfaults.\r\n\r\nThe only reasonable solution it would appear at present is to ensure that at join points we respect the register typing.  This may produce slightly worse code in some cases.  For such cases the correct solution to solve this problem is probably the propagation of more information about what values might be held in which identifiers right through from the type checker.\r\n\r\nI think this is probably serious enough to warrant putting in 4.03."},"comment":{"url":"https://api.github.com/repos/ocaml/ocaml/issues/comments/212518681","html_url":"https://github.com/ocaml/ocaml/pull/555#issuecomment-212518681","issue_url":"https://api.github.com/repos/ocaml/ocaml/issues/555","id":212518681,"user":{"login":"mshinwell","id":1315488,"avatar_url":"https://avatars.githubusercontent.com/u/1315488?v=3","gravatar_id":"","url":"https://api.github.com/users/mshinwell","html_url":"https://github.com/mshinwell","followers_url":"https://api.github.com/users/mshinwell/followers","following_url":"https://api.github.com/users/mshinwell/following{/other_user}","gists_url":"https://api.github.com/users/mshinwell/gists{/gist_id}","starred_url":"https://api.github.com/users/mshinwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mshinwell/subscriptions","organizations_url":"https://api.github.com/users/mshinwell/orgs","repos_url":"https://api.github.com/users/mshinwell/repos","events_url":"https://api.github.com/users/mshinwell/events{/privacy}","received_events_url":"https://api.github.com/users/mshinwell/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T17:11:02Z","updated_at":"2016-04-20T17:11:02Z","body":"Patch updated following @xavierleroy 's comment"}}