{"action":"created","comment":{"url":"https://api.github.com/repos/tweag/linear-base/pulls/comments/158496935","pull_request_review_id":85320390,"id":158496935,"diff_hunk":"@@ -0,0 +1,117 @@\n+{-# LANGUAGE GADTs #-}\n+{-# LANGUAGE NoImplicitPrelude #-}\n+{-# LANGUAGE ScopedTypeVariables #-}\n+\n+-- | This module introduces primitives to /safely/ store data off-heap. The\n+-- benefit of off-heap data is that it does not add to the GC pressure, and help\n+-- ensure predictable latency (/e.g./ in distributed applications). The cost is\n+-- that memory management is much more explicit: the programmer has to allocate\n+-- and free memory manually. Safety (in particular that every pointer is freed)\n+-- is enforced by linear types, which constrain usage, in particular\n+-- sharing. Off-heap data types also have less convenient syntax since they are\n+-- not directly supported by the compiler.\n+--\n+-- This module focuses on /pure/ off-heap data. That is data types like standard\n+-- Haskell. The only difference is that their lifetime is not managed by the\n+-- GC. Despite calling @malloc@ and @free@ under the hood, the entire API is\n+-- pure, and does not make calls in IO.\n+--\n+-- The allocation API is organised around a notion of memory 'Pool'. From the API\n+-- point of view, a pool serves as a source of linearity. That is: it ensures\n+-- that the allocation primitive need not take a continuation to delimit its\n+-- lifetime. Besides convenience, it avoids needlessly preventing functions from\n+-- being tail-recursive.\n+--\n+-- Pools play another role: resilience to exceptions. If an exception is raised,\n+-- all the data in the pool is deallocated. It does not, however, impose a stack\n+-- discipline: data in pools is normally freed by the destruction primitives of ,\n+-- only in case of exception are the pool deallocated in a stack-like\n+-- manner. Moreover, pool A can have data pointing to pool B, while at the same\n+-- time, pool B having data pointing to pool A.\n+--\n+-- Functions in this module are meant to be qualified.\n+\n+-- TODO: add link to an example in module header\n+-- TODO: change some words into link to the relevant API entry in the above description.\n+\n+module Data.OffHeap\n+  ( Pool\n+  , withPool\n+  , Box\n+  , alloc\n+  , deconstruct\n+  ) where\n+\n+import Foreign.Marshal.Alloc\n+import Foreign.Ptr\n+import Foreign.Storable\n+import Prelude.Linear\n+import System.IO.Unsafe\n+import qualified Unsafe.Linear as Unsafe\n+\n+-- TODO: ignoring exceptions for the moment. So that I can get some tests to\n+-- work first.\n+\n+-- TODO: Briefly explain the Dupable-reader style of API, below, and fix\n+-- details.\n+\n+-- | A 'Pool' can be 'consume'-ed. This is a no-op: it does not deallocate the\n+-- data in that pool. It cannot as there may still be accessible data in the\n+-- pool. It simply makes it impossible to add new data to the pool. It is\n+-- actually necessary to so consume a pool allocated with 'withPool' in order to\n+-- write a well-typed scope @Pool ->. Unrestricted b@.\n+data Pool = Pool\n+\n+-- TODO: document individual functions\n+\n+withPool :: (Pool ->. Unrestricted b) ->. Unrestricted b\n+withPool scope = scope Pool\n+\n+instance Consumable Pool where\n+  consume Pool = ()\n+\n+instance Dupable Pool where\n+  dup Pool = (Pool, Pool)\n+\n+-- XXX: this indirection is possibly not necessary. It's here because the inner\n+-- Ptr must be unrestricted (in order to implement deconstruct at the moment).\n+data Box a where","path":"src/Data/OffHeap.hs","position":78,"original_position":78,"commit_id":"5077a2a12aade5926adf1bd6eb0b5d81bafbbca2","original_commit_id":"5077a2a12aade5926adf1bd6eb0b5d81bafbbca2","user":{"login":"aspiwack","id":1413217,"avatar_url":"https://avatars1.githubusercontent.com/u/1413217?v=4","gravatar_id":"","url":"https://api.github.com/users/aspiwack","html_url":"https://github.com/aspiwack","followers_url":"https://api.github.com/users/aspiwack/followers","following_url":"https://api.github.com/users/aspiwack/following{/other_user}","gists_url":"https://api.github.com/users/aspiwack/gists{/gist_id}","starred_url":"https://api.github.com/users/aspiwack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspiwack/subscriptions","organizations_url":"https://api.github.com/users/aspiwack/orgs","repos_url":"https://api.github.com/users/aspiwack/repos","events_url":"https://api.github.com/users/aspiwack/events{/privacy}","received_events_url":"https://api.github.com/users/aspiwack/received_events","type":"User","site_admin":false},"body":"It's an abstraction barrier around `Ptr`. It differs from `Ptr` in that it is pure. Also it will hold some more data for exception tolerance.","created_at":"2017-12-22T14:02:40Z","updated_at":"2017-12-22T14:02:40Z","html_url":"https://github.com/tweag/linear-base/pull/8#discussion_r158496935","pull_request_url":"https://api.github.com/repos/tweag/linear-base/pulls/8","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/tweag/linear-base/pulls/comments/158496935"},"html":{"href":"https://github.com/tweag/linear-base/pull/8#discussion_r158496935"},"pull_request":{"href":"https://api.github.com/repos/tweag/linear-base/pulls/8"}},"in_reply_to_id":158495067},"pull_request":{"url":"https://api.github.com/repos/tweag/linear-base/pulls/8","id":159453989,"html_url":"https://github.com/tweag/linear-base/pull/8","diff_url":"https://github.com/tweag/linear-base/pull/8.diff","patch_url":"https://github.com/tweag/linear-base/pull/8.patch","issue_url":"https://api.github.com/repos/tweag/linear-base/issues/8","number":8,"state":"open","locked":false,"title":"First prototype of off-heap data management","user":{"login":"aspiwack","id":1413217,"avatar_url":"https://avatars1.githubusercontent.com/u/1413217?v=4","gravatar_id":"","url":"https://api.github.com/users/aspiwack","html_url":"https://github.com/aspiwack","followers_url":"https://api.github.com/users/aspiwack/followers","following_url":"https://api.github.com/users/aspiwack/following{/other_user}","gists_url":"https://api.github.com/users/aspiwack/gists{/gist_id}","starred_url":"https://api.github.com/users/aspiwack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspiwack/subscriptions","organizations_url":"https://api.github.com/users/aspiwack/orgs","repos_url":"https://api.github.com/users/aspiwack/repos","events_url":"https://api.github.com/users/aspiwack/events{/privacy}","received_events_url":"https://api.github.com/users/aspiwack/received_events","type":"User","site_admin":false},"body":"Depends on #7 .\r\n\r\nThis only ships a few tests. I will need to spend a bit of time devising a functor/monad hierarchy before I can write more. Otherwise managing the `Pool` is a pain.\r\n\r\nThere is no exception management yet. Though the path is explained. I'd rather get a few more tests and example before this.\r\n\r\nSo it's atomic enough, if not definitive. More soon.","created_at":"2017-12-20T16:02:30Z","updated_at":"2017-12-22T14:02:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dd65cead9dcfc4f76d42dc00057829dd687c6d7e","assignee":{"login":"aspiwack","id":1413217,"avatar_url":"https://avatars1.githubusercontent.com/u/1413217?v=4","gravatar_id":"","url":"https://api.github.com/users/aspiwack","html_url":"https://github.com/aspiwack","followers_url":"https://api.github.com/users/aspiwack/followers","following_url":"https://api.github.com/users/aspiwack/following{/other_user}","gists_url":"https://api.github.com/users/aspiwack/gists{/gist_id}","starred_url":"https://api.github.com/users/aspiwack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspiwack/subscriptions","organizations_url":"https://api.github.com/users/aspiwack/orgs","repos_url":"https://api.github.com/users/aspiwack/repos","events_url":"https://api.github.com/users/aspiwack/events{/privacy}","received_events_url":"https://api.github.com/users/aspiwack/received_events","type":"User","site_admin":false},"assignees":[{"login":"aspiwack","id":1413217,"avatar_url":"https://avatars1.githubusercontent.com/u/1413217?v=4","gravatar_id":"","url":"https://api.github.com/users/aspiwack","html_url":"https://github.com/aspiwack","followers_url":"https://api.github.com/users/aspiwack/followers","following_url":"https://api.github.com/users/aspiwack/following{/other_user}","gists_url":"https://api.github.com/users/aspiwack/gists{/gist_id}","starred_url":"https://api.github.com/users/aspiwack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspiwack/subscriptions","organizations_url":"https://api.github.com/users/aspiwack/orgs","repos_url":"https://api.github.com/users/aspiwack/repos","events_url":"https://api.github.com/users/aspiwack/events{/privacy}","received_events_url":"https://api.github.com/users/aspiwack/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/tweag/linear-base/pulls/8/commits","review_comments_url":"https://api.github.com/repos/tweag/linear-base/pulls/8/comments","review_comment_url":"https://api.github.com/repos/tweag/linear-base/pulls/comments{/number}","comments_url":"https://api.github.com/repos/tweag/linear-base/issues/8/comments","statuses_url":"https://api.github.com/repos/tweag/linear-base/statuses/5077a2a12aade5926adf1bd6eb0b5d81bafbbca2","head":{"label":"tweag:off-heap","ref":"off-heap","sha":"5077a2a12aade5926adf1bd6eb0b5d81bafbbca2","user":{"login":"tweag","id":6057932,"avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"repo":{"id":111791393,"name":"linear-base","full_name":"tweag/linear-base","owner":{"login":"tweag","id":6057932,"avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tweag/linear-base","description":"Prototype basic libraries for Haskell with linear types","fork":false,"url":"https://api.github.com/repos/tweag/linear-base","forks_url":"https://api.github.com/repos/tweag/linear-base/forks","keys_url":"https://api.github.com/repos/tweag/linear-base/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tweag/linear-base/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tweag/linear-base/teams","hooks_url":"https://api.github.com/repos/tweag/linear-base/hooks","issue_events_url":"https://api.github.com/repos/tweag/linear-base/issues/events{/number}","events_url":"https://api.github.com/repos/tweag/linear-base/events","assignees_url":"https://api.github.com/repos/tweag/linear-base/assignees{/user}","branches_url":"https://api.github.com/repos/tweag/linear-base/branches{/branch}","tags_url":"https://api.github.com/repos/tweag/linear-base/tags","blobs_url":"https://api.github.com/repos/tweag/linear-base/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tweag/linear-base/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tweag/linear-base/git/refs{/sha}","trees_url":"https://api.github.com/repos/tweag/linear-base/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tweag/linear-base/statuses/{sha}","languages_url":"https://api.github.com/repos/tweag/linear-base/languages","stargazers_url":"https://api.github.com/repos/tweag/linear-base/stargazers","contributors_url":"https://api.github.com/repos/tweag/linear-base/contributors","subscribers_url":"https://api.github.com/repos/tweag/linear-base/subscribers","subscription_url":"https://api.github.com/repos/tweag/linear-base/subscription","commits_url":"https://api.github.com/repos/tweag/linear-base/commits{/sha}","git_commits_url":"https://api.github.com/repos/tweag/linear-base/git/commits{/sha}","comments_url":"https://api.github.com/repos/tweag/linear-base/comments{/number}","issue_comment_url":"https://api.github.com/repos/tweag/linear-base/issues/comments{/number}","contents_url":"https://api.github.com/repos/tweag/linear-base/contents/{+path}","compare_url":"https://api.github.com/repos/tweag/linear-base/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tweag/linear-base/merges","archive_url":"https://api.github.com/repos/tweag/linear-base/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tweag/linear-base/downloads","issues_url":"https://api.github.com/repos/tweag/linear-base/issues{/number}","pulls_url":"https://api.github.com/repos/tweag/linear-base/pulls{/number}","milestones_url":"https://api.github.com/repos/tweag/linear-base/milestones{/number}","notifications_url":"https://api.github.com/repos/tweag/linear-base/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tweag/linear-base/labels{/name}","releases_url":"https://api.github.com/repos/tweag/linear-base/releases{/id}","deployments_url":"https://api.github.com/repos/tweag/linear-base/deployments","created_at":"2017-11-23T09:46:09Z","updated_at":"2017-11-27T18:34:22Z","pushed_at":"2017-12-22T12:50:44Z","git_url":"git://github.com/tweag/linear-base.git","ssh_url":"git@github.com:tweag/linear-base.git","clone_url":"https://github.com/tweag/linear-base.git","svn_url":"https://github.com/tweag/linear-base","homepage":null,"size":69,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":2,"open_issues":2,"watchers":2,"default_branch":"master"}},"base":{"label":"tweag:master","ref":"master","sha":"007b884ebb0e3182ea73e450683f9660b7a92f40","user":{"login":"tweag","id":6057932,"avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"repo":{"id":111791393,"name":"linear-base","full_name":"tweag/linear-base","owner":{"login":"tweag","id":6057932,"avatar_url":"https://avatars3.githubusercontent.com/u/6057932?v=4","gravatar_id":"","url":"https://api.github.com/users/tweag","html_url":"https://github.com/tweag","followers_url":"https://api.github.com/users/tweag/followers","following_url":"https://api.github.com/users/tweag/following{/other_user}","gists_url":"https://api.github.com/users/tweag/gists{/gist_id}","starred_url":"https://api.github.com/users/tweag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tweag/subscriptions","organizations_url":"https://api.github.com/users/tweag/orgs","repos_url":"https://api.github.com/users/tweag/repos","events_url":"https://api.github.com/users/tweag/events{/privacy}","received_events_url":"https://api.github.com/users/tweag/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/tweag/linear-base","description":"Prototype basic libraries for Haskell with linear types","fork":false,"url":"https://api.github.com/repos/tweag/linear-base","forks_url":"https://api.github.com/repos/tweag/linear-base/forks","keys_url":"https://api.github.com/repos/tweag/linear-base/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tweag/linear-base/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tweag/linear-base/teams","hooks_url":"https://api.github.com/repos/tweag/linear-base/hooks","issue_events_url":"https://api.github.com/repos/tweag/linear-base/issues/events{/number}","events_url":"https://api.github.com/repos/tweag/linear-base/events","assignees_url":"https://api.github.com/repos/tweag/linear-base/assignees{/user}","branches_url":"https://api.github.com/repos/tweag/linear-base/branches{/branch}","tags_url":"https://api.github.com/repos/tweag/linear-base/tags","blobs_url":"https://api.github.com/repos/tweag/linear-base/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tweag/linear-base/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tweag/linear-base/git/refs{/sha}","trees_url":"https://api.github.com/repos/tweag/linear-base/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tweag/linear-base/statuses/{sha}","languages_url":"https://api.github.com/repos/tweag/linear-base/languages","stargazers_url":"https://api.github.com/repos/tweag/linear-base/stargazers","contributors_url":"https://api.github.com/repos/tweag/linear-base/contributors","subscribers_url":"https://api.github.com/repos/tweag/linear-base/subscribers","subscription_url":"https://api.github.com/repos/tweag/linear-base/subscription","commits_url":"https://api.github.com/repos/tweag/linear-base/commits{/sha}","git_commits_url":"https://api.github.com/repos/tweag/linear-base/git/commits{/sha}","comments_url":"https://api.github.com/repos/tweag/linear-base/comments{/number}","issue_comment_url":"https://api.github.com/repos/tweag/linear-base/issues/comments{/number}","contents_url":"https://api.github.com/repos/tweag/linear-base/contents/{+path}","compare_url":"https://api.github.com/repos/tweag/linear-base/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tweag/linear-base/merges","archive_url":"https://api.github.com/repos/tweag/linear-base/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tweag/linear-base/downloads","issues_url":"https://api.github.com/repos/tweag/linear-base/issues{/number}","pulls_url":"https://api.github.com/repos/tweag/linear-base/pulls{/number}","milestones_url":"https://api.github.com/repos/tweag/linear-base/milestones{/number}","notifications_url":"https://api.github.com/repos/tweag/linear-base/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tweag/linear-base/labels{/name}","releases_url":"https://api.github.com/repos/tweag/linear-base/releases{/id}","deployments_url":"https://api.github.com/repos/tweag/linear-base/deployments","created_at":"2017-11-23T09:46:09Z","updated_at":"2017-11-27T18:34:22Z","pushed_at":"2017-12-22T12:50:44Z","git_url":"git://github.com/tweag/linear-base.git","ssh_url":"git@github.com:tweag/linear-base.git","clone_url":"https://github.com/tweag/linear-base.git","svn_url":"https://github.com/tweag/linear-base","homepage":null,"size":69,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":2,"open_issues":2,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/tweag/linear-base/pulls/8"},"html":{"href":"https://github.com/tweag/linear-base/pull/8"},"issue":{"href":"https://api.github.com/repos/tweag/linear-base/issues/8"},"comments":{"href":"https://api.github.com/repos/tweag/linear-base/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/tweag/linear-base/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/tweag/linear-base/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/tweag/linear-base/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/tweag/linear-base/statuses/5077a2a12aade5926adf1bd6eb0b5d81bafbbca2"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"aspiwack"}}