{"action":"created","issue":{"url":"https://api.github.com/repos/chapel-lang/chapel/issues/9946","repository_url":"https://api.github.com/repos/chapel-lang/chapel","labels_url":"https://api.github.com/repos/chapel-lang/chapel/issues/9946/labels{/name}","comments_url":"https://api.github.com/repos/chapel-lang/chapel/issues/9946/comments","events_url":"https://api.github.com/repos/chapel-lang/chapel/issues/9946/events","html_url":"https://github.com/chapel-lang/chapel/issues/9946","id":334266279,"node_id":"MDU6SXNzdWUzMzQyNjYyNzk=","number":9946,"title":"Should _defaultOf work on records once constructors are deprecated?","user":{"login":"benharsh","id":1883119,"node_id":"MDQ6VXNlcjE4ODMxMTk=","avatar_url":"https://avatars0.githubusercontent.com/u/1883119?v=4","gravatar_id":"","url":"https://api.github.com/users/benharsh","html_url":"https://github.com/benharsh","followers_url":"https://api.github.com/users/benharsh/followers","following_url":"https://api.github.com/users/benharsh/following{/other_user}","gists_url":"https://api.github.com/users/benharsh/gists{/gist_id}","starred_url":"https://api.github.com/users/benharsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benharsh/subscriptions","organizations_url":"https://api.github.com/users/benharsh/orgs","repos_url":"https://api.github.com/users/benharsh/repos","events_url":"https://api.github.com/users/benharsh/events{/privacy}","received_events_url":"https://api.github.com/users/benharsh/received_events","type":"User","site_admin":false},"labels":[{"id":499565193,"node_id":"MDU6TGFiZWw0OTk1NjUxOTM=","url":"https://api.github.com/repos/chapel-lang/chapel/labels/area:%20Language","name":"area: Language","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}],"state":"open","locked":false,"assignee":{"login":"benharsh","id":1883119,"node_id":"MDQ6VXNlcjE4ODMxMTk=","avatar_url":"https://avatars0.githubusercontent.com/u/1883119?v=4","gravatar_id":"","url":"https://api.github.com/users/benharsh","html_url":"https://github.com/benharsh","followers_url":"https://api.github.com/users/benharsh/followers","following_url":"https://api.github.com/users/benharsh/following{/other_user}","gists_url":"https://api.github.com/users/benharsh/gists{/gist_id}","starred_url":"https://api.github.com/users/benharsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benharsh/subscriptions","organizations_url":"https://api.github.com/users/benharsh/orgs","repos_url":"https://api.github.com/users/benharsh/repos","events_url":"https://api.github.com/users/benharsh/events{/privacy}","received_events_url":"https://api.github.com/users/benharsh/received_events","type":"User","site_admin":false},"assignees":[{"login":"benharsh","id":1883119,"node_id":"MDQ6VXNlcjE4ODMxMTk=","avatar_url":"https://avatars0.githubusercontent.com/u/1883119?v=4","gravatar_id":"","url":"https://api.github.com/users/benharsh","html_url":"https://github.com/benharsh","followers_url":"https://api.github.com/users/benharsh/followers","following_url":"https://api.github.com/users/benharsh/following{/other_user}","gists_url":"https://api.github.com/users/benharsh/gists{/gist_id}","starred_url":"https://api.github.com/users/benharsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benharsh/subscriptions","organizations_url":"https://api.github.com/users/benharsh/orgs","repos_url":"https://api.github.com/users/benharsh/repos","events_url":"https://api.github.com/users/benharsh/events{/privacy}","received_events_url":"https://api.github.com/users/benharsh/received_events","type":"User","site_admin":false}],"milestone":null,"comments":12,"created_at":"2018-06-20T22:03:48Z","updated_at":"2018-07-05T23:59:00Z","closed_at":null,"author_association":"MEMBER","body":"The following program does not produce the expected output under ``--force-initializers`` because _defaultOf is not invoked:\r\n```chpl\r\n// expressions/lydia/noinit/usedWithRecord.chpl\r\nrecord Foo {\r\n  var bar: int;\r\n  var baz: bool;\r\n\r\n}\r\n\r\nproc _defaultOf(type t) where t == Foo {\r\n  writeln(\"I default initialized!\");\r\n  var res:t = noinit;\r\n  // The following could be replaced with a call to the _defaultOf for those\r\n  // respective types.  But it isn't important.\r\n  res.bar = 0;\r\n  res.baz = false;\r\n  return res;\r\n}\r\n\r\nvar foo:Foo = noinit; // Should not print out the message\r\nfoo.bar = 4;\r\nfoo.baz = true;\r\nwriteln(foo);\r\nvar bar:Foo;          // Should print out the message\r\nwriteln(bar);\r\n```\r\n\r\nThe compiler currently ignores _defaultOf for concrete records. Is that what we want long-term?"},"comment":{"url":"https://api.github.com/repos/chapel-lang/chapel/issues/comments/402885182","html_url":"https://github.com/chapel-lang/chapel/issues/9946#issuecomment-402885182","issue_url":"https://api.github.com/repos/chapel-lang/chapel/issues/9946","id":402885182,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjg4NTE4Mg==","user":{"login":"LouisJenkinsCS","id":4269990,"node_id":"MDQ6VXNlcjQyNjk5OTA=","avatar_url":"https://avatars2.githubusercontent.com/u/4269990?v=4","gravatar_id":"","url":"https://api.github.com/users/LouisJenkinsCS","html_url":"https://github.com/LouisJenkinsCS","followers_url":"https://api.github.com/users/LouisJenkinsCS/followers","following_url":"https://api.github.com/users/LouisJenkinsCS/following{/other_user}","gists_url":"https://api.github.com/users/LouisJenkinsCS/gists{/gist_id}","starred_url":"https://api.github.com/users/LouisJenkinsCS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LouisJenkinsCS/subscriptions","organizations_url":"https://api.github.com/users/LouisJenkinsCS/orgs","repos_url":"https://api.github.com/users/LouisJenkinsCS/repos","events_url":"https://api.github.com/users/LouisJenkinsCS/events{/privacy}","received_events_url":"https://api.github.com/users/LouisJenkinsCS/received_events","type":"User","site_admin":false},"created_at":"2018-07-05T23:59:00Z","updated_at":"2018-07-05T23:59:00Z","author_association":"MEMBER","body":"Okay, so `_defaultOf` shouldn't be relied on right now, but I would still prefer to use a built-in construct like `noinit` over a custom method that has to be defined for any and every type. I'd rather avoid using `throws` in that I want to avoid having to force any users to wrap it in a `try` or `try!` statement, plus for performance reasons.\r\n\r\nFor example, if we have a concurrent data structure that it is impossible to know whether or not an operation will successfully complete until you attempt it, my assumption is that a tuple is better. For example, imagine if we a have tight-loop where we are attempting to dequeue from a non-blocking queue...\r\n\r\n```chpl\r\nrecord Data {\r\n   var obj : SomeObject;\r\n   proc init() { someObject = SomeObject; }\r\n   proc ~init() { delete someObject; } \r\n}\r\nvar q : Queue(Data);\r\nwhile true {\r\n   var (hasElt, elt) = q.dequeue();\r\n   if !hasElt { \r\n      chpl_task_yield();\r\n      continue;\r\n   }\r\n   process(elt);\r\n}\r\n```\r\n\r\nWhere `Queue` is a non-blocking queue, as its default behavior is to return immediately on failure rather than loop until it succeeds. We don't want to invoke the zero-argument initializer here, but lets say that we went the route of forcing the user to specify their own function to create a dummy-value of their desired type, how would they go about doing so?\r\n\r\n```chpl\r\nproc dummy(type t) where t == Data {\r\n   // Can't do this... it will still initialize it...\r\n   //var d : Data;\r\n   // Might be able to do this, maybe we can't, depends on if it is supported in future\r\n   // var d : Data = noinit;\r\n   // This will leak memory, but it will be uninitialized, I'd assume...\r\n   // var d : c_malloc(Data, 1)[0]\r\n   // ???\r\n}\r\n```\r\n\r\nFor the sake of efficiency, what can the user do to avoid the additional overhead? I am in favor of, again, letting the user 'shoot themselves in the foot' for the sake of performance."}}
{"actor":{"display_login":"LouisJenkinsCS"}}