{"action":"opened","issue":{"url":"https://api.github.com/repos/scalaz/scalaz/issues/1172","repository_url":"https://api.github.com/repos/scalaz/scalaz","labels_url":"https://api.github.com/repos/scalaz/scalaz/issues/1172/labels{/name}","comments_url":"https://api.github.com/repos/scalaz/scalaz/issues/1172/comments","events_url":"https://api.github.com/repos/scalaz/scalaz/issues/1172/events","html_url":"https://github.com/scalaz/scalaz/issues/1172","id":157334053,"number":1172,"title":"Remove or replace the TODO comment from EphemeralSream.weakMemo()","user":{"login":"dmitryleskov","id":1212272,"avatar_url":"https://avatars.githubusercontent.com/u/1212272?v=3","gravatar_id":"","url":"https://api.github.com/users/dmitryleskov","html_url":"https://github.com/dmitryleskov","followers_url":"https://api.github.com/users/dmitryleskov/followers","following_url":"https://api.github.com/users/dmitryleskov/following{/other_user}","gists_url":"https://api.github.com/users/dmitryleskov/gists{/gist_id}","starred_url":"https://api.github.com/users/dmitryleskov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmitryleskov/subscriptions","organizations_url":"https://api.github.com/users/dmitryleskov/orgs","repos_url":"https://api.github.com/users/dmitryleskov/repos","events_url":"https://api.github.com/users/dmitryleskov/events{/privacy}","received_events_url":"https://api.github.com/users/dmitryleskov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-28T11:19:23Z","updated_at":"2016-05-28T11:19:23Z","closed_at":null,"body":"There is a TODO comment in `EphemeralSream.weakMemo()` saying\r\n\r\n```scala\r\n    // TODO I don't think this annotation does anything, as `v` isn't a class member.\r\n    @volatile var v: Option[WeakReference[V]] = None\r\n    () => {\r\n    ...\r\n```\r\nMy understanding is that returned from that method is a closure, of which `v` is a free variable, so under the hood `v` gets wrapped in a `scala.runtime.VolatileObjectRef` and passed to the constructor of a `scala.runtime.AbstractFunction0` *subclass*, an instance of which represents the given closure. Absent the annotation, it would be `ObjectRef` wrapping that variable, and the difference is indeed the `volatile` attribute on the respective field (`scala.runtime.*Ref` classes are written in Java).\r\n\r\nA smaller example illustrating the difference:\r\n\r\n```scala\r\nclass Volatile {\r\n  def f: () => String = {\r\n    var nv: String = \"Non-volatile\"\r\n    @volatile var v: String = \"Volatile\"\r\n    () => {\r\n      nv = \"Foo\"\r\n      v = \"Bar\"\r\n      v\r\n    }\r\n  }\r\n}\r\n```\r\ncomplies and decompiles to:\r\n```java\r\nimport scala.*;\r\nimport scala.runtime.*;\r\n\r\npublic final class Volatile$$anonfun$f$1 extends AbstractFunction0 implements Serializable {\r\n   public static final long serialVersionUID = 0L;\r\n   private final ObjectRef nv$1;\r\n   private final VolatileObjectRef v$1;\r\n\r\n   public final String apply() {\r\n      this.nv$1.elem = \"Foo\";\r\n      this.v$1.elem = \"Bar\";\r\n      return (String)this.v$1.elem;\r\n   }\r\n\r\n   public Volatile$$anonfun$f$1(Volatile $outer, ObjectRef nv$1, VolatileObjectRef v$1) {\r\n      this.nv$1 = nv$1;\r\n      this.v$1 = v$1;\r\n   }\r\n}\r\n```\r\nSo I believe the comment can be removed (or perhaps replaced with one explaining the need for the `@volatile` annotation).\r\n\r\nFixing #1103 would probably invalidate this issue.\r\n"}}
{"actor":{"display_login":"dmitryleskov"}}