{"action":"created","issue":{"url":"https://api.github.com/repos/chapel-lang/chapel/issues/10181","repository_url":"https://api.github.com/repos/chapel-lang/chapel","labels_url":"https://api.github.com/repos/chapel-lang/chapel/issues/10181/labels{/name}","comments_url":"https://api.github.com/repos/chapel-lang/chapel/issues/10181/comments","events_url":"https://api.github.com/repos/chapel-lang/chapel/issues/10181/events","html_url":"https://github.com/chapel-lang/chapel/issues/10181","id":338977228,"node_id":"MDU6SXNzdWUzMzg5NzcyMjg=","number":10181,"title":"Subclassing Layouts and Distributions","user":{"login":"ben-albrecht","id":3595449,"node_id":"MDQ6VXNlcjM1OTU0NDk=","avatar_url":"https://avatars1.githubusercontent.com/u/3595449?v=4","gravatar_id":"","url":"https://api.github.com/users/ben-albrecht","html_url":"https://github.com/ben-albrecht","followers_url":"https://api.github.com/users/ben-albrecht/followers","following_url":"https://api.github.com/users/ben-albrecht/following{/other_user}","gists_url":"https://api.github.com/users/ben-albrecht/gists{/gist_id}","starred_url":"https://api.github.com/users/ben-albrecht/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ben-albrecht/subscriptions","organizations_url":"https://api.github.com/users/ben-albrecht/orgs","repos_url":"https://api.github.com/users/ben-albrecht/repos","events_url":"https://api.github.com/users/ben-albrecht/events{/privacy}","received_events_url":"https://api.github.com/users/ben-albrecht/received_events","type":"User","site_admin":false},"labels":[{"id":496591534,"node_id":"MDU6TGFiZWw0OTY1OTE1MzQ=","url":"https://api.github.com/repos/chapel-lang/chapel/labels/area:%20Modules","name":"area: Modules","color":"d4c5f9","default":false},{"id":112762321,"node_id":"MDU6TGFiZWwxMTI3NjIzMjE=","url":"https://api.github.com/repos/chapel-lang/chapel/labels/type:%20Design","name":"type: Design","color":"e99695","default":false},{"id":520459015,"node_id":"MDU6TGFiZWw1MjA0NTkwMTU=","url":"https://api.github.com/repos/chapel-lang/chapel/labels/user%20issue","name":"user issue","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-07-06T15:16:44Z","updated_at":"2018-07-06T16:16:52Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Subclassing layouts and distributions seems to be more difficult than it should be.\r\n\r\nConsider the exercise: What code is required to make an unchanged subclass of the `Block` distribution?\r\n\r\nI had hoped it would be as simple as:\r\n\r\n```chpl\r\nuse BlockDist;\r\n\r\nclass MyBlock: Block {\r\n\r\n}\r\n```\r\n\r\nUnfortunately, the compiler requires us to write our own initializer:\r\n\r\n```\r\nerror: Cannot create default constructor on type 'MyBlock', which inherits from a type that defines an initializer\r\n```\r\n\r\nAlright, so maybe we need to copy the initializer over from `Block`:\r\n\r\n```chpl\r\nuse BlockDist;\r\n\r\nclass MyBlock: Block {\r\n\r\n  proc init(boundingBox: domain,\r\n            targetLocales: [] locale = Locales,\r\n            dataParTasksPerLocale=getDataParTasksPerLocale(),\r\n            dataParIgnoreRunningTasks=getDataParIgnoreRunningTasks(),\r\n            dataParMinGranularity=getDataParMinGranularity(),\r\n            param rank = boundingBox.rank,\r\n            type idxType = boundingBox.idxType,\r\n            type sparseLayoutType = unmanaged DefaultDist)\r\n  {\r\n    super.init(boundingBox, targetLocales, dataParTasksPerLocale,\r\n               dataParIgnoreRunningTasks, dataParMinGranularity,\r\n               rank, idxType, sparseLayoutType);\r\n  }\r\n}\r\n\r\nvar D = {1..4, 1..4};\r\nvar myBlockD = D dmapped MyBlock(boundingBox=D);\r\nvar A: [myBlockD] int;\r\n```\r\n\r\nThis results in a backend compiler error:\r\n\r\n```\r\nIn file included from /var/folders/gl/n_gvpvk56gq21_7_zqbhcgvh000h70/T//chpl-user-12099.deleteme/_main.c:26:\r\n/var/folders/gl/n_gvpvk56gq21_7_zqbhcgvh000h70/T//chpl-user-12099.deleteme/ChapelArray.c:1075:11: error: assigning to 'chpl___RuntimeTypeInfo'\r\n      (aka 'struct chpl_chpl___RuntimeTypeInfo_s') from incompatible type 'chpl___RuntimeTypeInfo2' (aka 'struct chpl_chpl___RuntimeTypeInfo2_s')\r\ncall_tmp2 = chpl__buildDomainRuntimeType(d, _ln, _fn);\r\n          ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n1 error generated.\r\nmake: *** [/var/folders/gl/n_gvpvk56gq21_7_zqbhcgvh000h70/T//chpl-user-12099.deleteme/inherit.tmp] Error 1\r\nerror: compiling generated source\r\n```\r\n\r\nThat error should probably be understood better, but it's a dead end for now.\r\n\r\nIf you're a Chapel compiler developer, you may be aware of a useful `pragma` to get around writing your own initializer:\r\n\r\n```chpl\r\nuse BlockDist;\r\n\r\npragma \"use default init\"\r\nclass MyBlock: Block {\r\n\r\n}\r\n\r\nvar D = {1..4, 1..4};\r\nvar myBlockD = D dmapped MyBlock(boundingBox=D);\r\nvar A: [myBlockD] int;\r\n```\r\n\r\nUnfortunately, this provides an initializer that expect no args, which is not too useful:\r\n\r\n```\r\nerror: unresolved call 'MyBlock.init(boundingBox=domain(2,int(64),false))'\r\ninherit.chpl:9: note: candidates are: MyBlock.init()\r\n```\r\n\r\nI am not sure how to proceed from here. It would be helpful to find a work-around in the short-term, but I think subclassing distributions and layouts should be easier in the long-term.\r\n\r\nSeparately, I am not sure how to handle the inheritance of the composite pattern used in distributions, i.e. will the user need to subclass all 6 classes (shown below) in order to make a simple modification to an existing distribution? I imagine it would depend on where they are making modifications.\r\n\r\n```chpl\r\n// The Block distribution is defined with six classes:\r\n//\r\n//   Block       : distribution class\r\n//   BlockDom    : domain class\r\n//   BlockArr    : array class\r\n//   LocBlock    : local distribution class (per-locale instances)\r\n//   LocBlockDom : local domain class (per-locale instances)\r\n//   LocBlockArr : local array class (per-locale instances)\r\n//\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/chapel-lang/chapel/issues/comments/403080141","html_url":"https://github.com/chapel-lang/chapel/issues/10181#issuecomment-403080141","issue_url":"https://api.github.com/repos/chapel-lang/chapel/issues/10181","id":403080141,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMzA4MDE0MQ==","user":{"login":"lydia-duncan","id":2454710,"node_id":"MDQ6VXNlcjI0NTQ3MTA=","avatar_url":"https://avatars2.githubusercontent.com/u/2454710?v=4","gravatar_id":"","url":"https://api.github.com/users/lydia-duncan","html_url":"https://github.com/lydia-duncan","followers_url":"https://api.github.com/users/lydia-duncan/followers","following_url":"https://api.github.com/users/lydia-duncan/following{/other_user}","gists_url":"https://api.github.com/users/lydia-duncan/gists{/gist_id}","starred_url":"https://api.github.com/users/lydia-duncan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lydia-duncan/subscriptions","organizations_url":"https://api.github.com/users/lydia-duncan/orgs","repos_url":"https://api.github.com/users/lydia-duncan/repos","events_url":"https://api.github.com/users/lydia-duncan/events{/privacy}","received_events_url":"https://api.github.com/users/lydia-duncan/received_events","type":"User","site_admin":false},"created_at":"2018-07-06T16:16:52Z","updated_at":"2018-07-06T16:16:52Z","author_association":"MEMBER","body":"Better to just have the user start writing it themselves, instead of thinking one is fine and having it disappear on them when the explicit replacement for the other one gets written."}}
{"actor":{"display_login":"lydia-duncan"}}