{"action":"created","comment":{"url":"https://api.github.com/repos/numba/numba/pulls/comments/39768977","id":39768977,"diff_hunk":"@@ -0,0 +1,222 @@\n+===================\n+NBEP 2: JIT Classes\n+===================\n+\n+:Author: Siu Kwan Lam\n+:Date: Sept 2015\n+:Status: Draft\n+\n+Introduction\n+============\n+\n+Numba does not yet support user-defined classes.\n+Classes provide useful abstraction and promote modularity when used\n+right.  In the simplest sense, a class specifies the set of data and\n+operations as attributes and methods, respectively.\n+A class instance is an instantiation of that class.\n+This proposal will focus on supporting this simple usecase of classes--with\n+just attributes and methods.  Other features, such as class methods, static\n+methods, and inheritance are deferred to another proposal, but we believe\n+these features can be easily implemented given the foundation described here.\n+\n+\n+Proposal: jit-classes\n+=====================\n+\n+A JIT-classes is more restricted than a Python class.\n+We will focus on the following operations on a class and its instance:\n+\n+* Instantiation: create an instance of a class using the class object as the\n+  constructor: ``cls(*args, **kwargs)``\n+* Destruction: remove resources allocated during instantiation and release\n+  all references to other objects.\n+* Attribute access: loading and storing attributes using ``instance.attr``\n+  syntax.\n+* Method access: loading methods using ``instance.method`` syntax.\n+\n+With these operations, a class object (not the instance) does not need to be\n+materialize. Using the class object as a constructor is fully resolved (a\n+runtime implementation is picked) during the typing phase in the compiler.\n+This means **a class object will not be first class**.  On the other hand,\n+implementating a first-class class object will require an\n+\"interface\" type, or the type of class.\n+\n+The instantiation of a class will allocate resources for storing the data\n+attributes.  This is described in the \"Storage model\" section.  Methods are\n+never stored in the instance.  They are information attached to the class.\n+Since a class object only exists in the type domain, the methods will also be\n+fully resolved at the typing phase.  Again, numba do not have first-class\n+function value and each function type maps uniquely to each function\n+implementation (this needs to be changed to support function value as argument).\n+\n+A class instance can contain other NRT reference-counted object as attributes.\n+To properly clean up an instance, a desctruction is called when the reference\n+count of the instance is dropped to zero.  This is described in the\n+\"Reference count and descructor\" section.\n+\n+Storage model\n+~~~~~~~~~~~~~\n+\n+For compatibility with C, attributes are stored in a simple plain-old-data\n+structure.  Each attribute are stored in a user-defined order in a padded\n+(for proper alignment), contiguous memory region. An instance that contains\n+three fields of int32, float32, complex64 will be compatible with the following\n+C structure::\n+\n+    struct {\n+        int32     field0;\n+        float32   field1;\n+        complex64 field2;\n+    };\n+\n+This will also be comptabile with an aligned numpy structure dtype.\n+\n+\n+Methods\n+~~~~~~~\n+\n+Methods are regular function that can be bounded to an instance.\n+They can be compiled as regular function by numba.\n+The operation ``getattr(instance, name)`` (getting an attribute ``name`` from\n+``instance``) performs the bounding if the attribute is a method.","path":"docs/source/proposals/jit-classes.rst","position":81,"original_position":81,"commit_id":"e3af140cb5412c461957442044d27482db8e379e","original_commit_id":"e3af140cb5412c461957442044d27482db8e379e","user":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"body":"This will be runtime since it is binding the instance (only exist at runtime) to the method.","created_at":"2015-09-17T16:46:50Z","updated_at":"2015-09-17T16:46:50Z","html_url":"https://github.com/numba/numba/pull/1433#discussion_r39768977","pull_request_url":"https://api.github.com/repos/numba/numba/pulls/1433","_links":{"self":{"href":"https://api.github.com/repos/numba/numba/pulls/comments/39768977"},"html":{"href":"https://github.com/numba/numba/pull/1433#discussion_r39768977"},"pull_request":{"href":"https://api.github.com/repos/numba/numba/pulls/1433"}}},"pull_request":{"url":"https://api.github.com/repos/numba/numba/pulls/1433","id":45200316,"html_url":"https://github.com/numba/numba/pull/1433","diff_url":"https://github.com/numba/numba/pull/1433.diff","patch_url":"https://github.com/numba/numba/pull/1433.patch","issue_url":"https://api.github.com/repos/numba/numba/issues/1433","number":1433,"state":"open","locked":false,"title":"NBEP: JIT classes","user":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"body":"Proposal for JIT classes; and, a immutable version I called JIT struct.\r\n\r\nPoC: https://github.com/sklam/numba/tree/experiment/jitclasses\r\n","created_at":"2015-09-16T17:27:39Z","updated_at":"2015-09-17T16:46:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1139a343ce27c87790ff0bd6f31fffc8833c8503","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/numba/numba/pulls/1433/commits","review_comments_url":"https://api.github.com/repos/numba/numba/pulls/1433/comments","review_comment_url":"https://api.github.com/repos/numba/numba/pulls/comments{/number}","comments_url":"https://api.github.com/repos/numba/numba/issues/1433/comments","statuses_url":"https://api.github.com/repos/numba/numba/statuses/e3af140cb5412c461957442044d27482db8e379e","head":{"label":"sklam:nbep/jit-classes","ref":"nbep/jit-classes","sha":"e3af140cb5412c461957442044d27482db8e379e","user":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"repo":{"id":4992750,"name":"numba","full_name":"sklam/numba","owner":{"login":"sklam","id":1929845,"avatar_url":"https://avatars.githubusercontent.com/u/1929845?v=3","gravatar_id":"","url":"https://api.github.com/users/sklam","html_url":"https://github.com/sklam","followers_url":"https://api.github.com/users/sklam/followers","following_url":"https://api.github.com/users/sklam/following{/other_user}","gists_url":"https://api.github.com/users/sklam/gists{/gist_id}","starred_url":"https://api.github.com/users/sklam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sklam/subscriptions","organizations_url":"https://api.github.com/users/sklam/orgs","repos_url":"https://api.github.com/users/sklam/repos","events_url":"https://api.github.com/users/sklam/events{/privacy}","received_events_url":"https://api.github.com/users/sklam/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sklam/numba","description":"NumPy aware dynamic Python compiler using LLVM","fork":true,"url":"https://api.github.com/repos/sklam/numba","forks_url":"https://api.github.com/repos/sklam/numba/forks","keys_url":"https://api.github.com/repos/sklam/numba/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sklam/numba/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sklam/numba/teams","hooks_url":"https://api.github.com/repos/sklam/numba/hooks","issue_events_url":"https://api.github.com/repos/sklam/numba/issues/events{/number}","events_url":"https://api.github.com/repos/sklam/numba/events","assignees_url":"https://api.github.com/repos/sklam/numba/assignees{/user}","branches_url":"https://api.github.com/repos/sklam/numba/branches{/branch}","tags_url":"https://api.github.com/repos/sklam/numba/tags","blobs_url":"https://api.github.com/repos/sklam/numba/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sklam/numba/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sklam/numba/git/refs{/sha}","trees_url":"https://api.github.com/repos/sklam/numba/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sklam/numba/statuses/{sha}","languages_url":"https://api.github.com/repos/sklam/numba/languages","stargazers_url":"https://api.github.com/repos/sklam/numba/stargazers","contributors_url":"https://api.github.com/repos/sklam/numba/contributors","subscribers_url":"https://api.github.com/repos/sklam/numba/subscribers","subscription_url":"https://api.github.com/repos/sklam/numba/subscription","commits_url":"https://api.github.com/repos/sklam/numba/commits{/sha}","git_commits_url":"https://api.github.com/repos/sklam/numba/git/commits{/sha}","comments_url":"https://api.github.com/repos/sklam/numba/comments{/number}","issue_comment_url":"https://api.github.com/repos/sklam/numba/issues/comments{/number}","contents_url":"https://api.github.com/repos/sklam/numba/contents/{+path}","compare_url":"https://api.github.com/repos/sklam/numba/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sklam/numba/merges","archive_url":"https://api.github.com/repos/sklam/numba/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sklam/numba/downloads","issues_url":"https://api.github.com/repos/sklam/numba/issues{/number}","pulls_url":"https://api.github.com/repos/sklam/numba/pulls{/number}","milestones_url":"https://api.github.com/repos/sklam/numba/milestones{/number}","notifications_url":"https://api.github.com/repos/sklam/numba/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sklam/numba/labels{/name}","releases_url":"https://api.github.com/repos/sklam/numba/releases{/id}","created_at":"2012-07-11T17:49:38Z","updated_at":"2015-04-21T17:10:09Z","pushed_at":"2015-09-16T18:15:28Z","git_url":"git://github.com/sklam/numba.git","ssh_url":"git@github.com:sklam/numba.git","clone_url":"https://github.com/sklam/numba.git","svn_url":"https://github.com/sklam/numba","homepage":"","size":26436,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"numba:master","ref":"master","sha":"ac9929dbcd58311f164fdebe962295ea980483f6","user":{"login":"numba","id":1628082,"avatar_url":"https://avatars.githubusercontent.com/u/1628082?v=3","gravatar_id":"","url":"https://api.github.com/users/numba","html_url":"https://github.com/numba","followers_url":"https://api.github.com/users/numba/followers","following_url":"https://api.github.com/users/numba/following{/other_user}","gists_url":"https://api.github.com/users/numba/gists{/gist_id}","starred_url":"https://api.github.com/users/numba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numba/subscriptions","organizations_url":"https://api.github.com/users/numba/orgs","repos_url":"https://api.github.com/users/numba/repos","events_url":"https://api.github.com/users/numba/events{/privacy}","received_events_url":"https://api.github.com/users/numba/received_events","type":"Organization","site_admin":false},"repo":{"id":3659275,"name":"numba","full_name":"numba/numba","owner":{"login":"numba","id":1628082,"avatar_url":"https://avatars.githubusercontent.com/u/1628082?v=3","gravatar_id":"","url":"https://api.github.com/users/numba","html_url":"https://github.com/numba","followers_url":"https://api.github.com/users/numba/followers","following_url":"https://api.github.com/users/numba/following{/other_user}","gists_url":"https://api.github.com/users/numba/gists{/gist_id}","starred_url":"https://api.github.com/users/numba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/numba/subscriptions","organizations_url":"https://api.github.com/users/numba/orgs","repos_url":"https://api.github.com/users/numba/repos","events_url":"https://api.github.com/users/numba/events{/privacy}","received_events_url":"https://api.github.com/users/numba/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/numba/numba","description":"NumPy aware dynamic Python compiler using LLVM","fork":false,"url":"https://api.github.com/repos/numba/numba","forks_url":"https://api.github.com/repos/numba/numba/forks","keys_url":"https://api.github.com/repos/numba/numba/keys{/key_id}","collaborators_url":"https://api.github.com/repos/numba/numba/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/numba/numba/teams","hooks_url":"https://api.github.com/repos/numba/numba/hooks","issue_events_url":"https://api.github.com/repos/numba/numba/issues/events{/number}","events_url":"https://api.github.com/repos/numba/numba/events","assignees_url":"https://api.github.com/repos/numba/numba/assignees{/user}","branches_url":"https://api.github.com/repos/numba/numba/branches{/branch}","tags_url":"https://api.github.com/repos/numba/numba/tags","blobs_url":"https://api.github.com/repos/numba/numba/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/numba/numba/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/numba/numba/git/refs{/sha}","trees_url":"https://api.github.com/repos/numba/numba/git/trees{/sha}","statuses_url":"https://api.github.com/repos/numba/numba/statuses/{sha}","languages_url":"https://api.github.com/repos/numba/numba/languages","stargazers_url":"https://api.github.com/repos/numba/numba/stargazers","contributors_url":"https://api.github.com/repos/numba/numba/contributors","subscribers_url":"https://api.github.com/repos/numba/numba/subscribers","subscription_url":"https://api.github.com/repos/numba/numba/subscription","commits_url":"https://api.github.com/repos/numba/numba/commits{/sha}","git_commits_url":"https://api.github.com/repos/numba/numba/git/commits{/sha}","comments_url":"https://api.github.com/repos/numba/numba/comments{/number}","issue_comment_url":"https://api.github.com/repos/numba/numba/issues/comments{/number}","contents_url":"https://api.github.com/repos/numba/numba/contents/{+path}","compare_url":"https://api.github.com/repos/numba/numba/compare/{base}...{head}","merges_url":"https://api.github.com/repos/numba/numba/merges","archive_url":"https://api.github.com/repos/numba/numba/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/numba/numba/downloads","issues_url":"https://api.github.com/repos/numba/numba/issues{/number}","pulls_url":"https://api.github.com/repos/numba/numba/pulls{/number}","milestones_url":"https://api.github.com/repos/numba/numba/milestones{/number}","notifications_url":"https://api.github.com/repos/numba/numba/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/numba/numba/labels{/name}","releases_url":"https://api.github.com/repos/numba/numba/releases{/id}","created_at":"2012-03-08T11:12:43Z","updated_at":"2015-09-16T02:15:04Z","pushed_at":"2015-09-17T11:34:47Z","git_url":"git://github.com/numba/numba.git","ssh_url":"git@github.com:numba/numba.git","clone_url":"https://github.com/numba/numba.git","svn_url":"https://github.com/numba/numba","homepage":"http://numba.pydata.org/","size":36106,"stargazers_count":1555,"watchers_count":1555,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":165,"mirror_url":null,"open_issues_count":190,"forks":165,"open_issues":190,"watchers":1555,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/numba/numba/pulls/1433"},"html":{"href":"https://github.com/numba/numba/pull/1433"},"issue":{"href":"https://api.github.com/repos/numba/numba/issues/1433"},"comments":{"href":"https://api.github.com/repos/numba/numba/issues/1433/comments"},"review_comments":{"href":"https://api.github.com/repos/numba/numba/pulls/1433/comments"},"review_comment":{"href":"https://api.github.com/repos/numba/numba/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/numba/numba/pulls/1433/commits"},"statuses":{"href":"https://api.github.com/repos/numba/numba/statuses/e3af140cb5412c461957442044d27482db8e379e"}}}}