Skip to content

Emit local module like lazy val#5428

Closed
retronym wants to merge 1 commit intoscala:2.12.0from
retronym:ticket/SD-235
Closed

Emit local module like lazy val#5428
retronym wants to merge 1 commit intoscala:2.12.0from
retronym:ticket/SD-235

Conversation

@retronym
Copy link
Member

@retronym retronym commented Sep 28, 2016

The motivation is to use the new fine-grained lock scoping that
local lazies have since #5294.

Fixes scala/scala-dev#235

Co-Authored-By: Jason Zaugg jzaugg@gmail.com

Review by @adriaanm

TODO:

  • the outer pointer for the object after this PR is null:
    (C$O$2$)O$lzy$1.initialize((Object)new C$O$2$(null)); versus x$1.elem = new C$O$2$(this);
  • the name for the local variable changed O$module -> O$lzy

The motivation is to use the new fine-grained lock scoping that
local lazies have since scala#5294.

Fixes scala/scala-dev#235

Co-Authored-By: Jason Zaugg <jzaugg@gmail.com>
@retronym
Copy link
Member Author

class C { 
  def foo = {
    object O
    def oh = O 
  }
}
//2.11.8
public class C {
    private O.2. O$1$lzycompute(VolatileObjectRef x$1) {
        C c = this;
        synchronized (c) {
            if (x$1.elem == null) {
                public class C$O$2$ {
                    public C$O$2$(C $outer) {
                    }
                }
                x$1.elem = new C$O$2$(this);
            }
            return (C$O$2$)x$1.elem;
        }
    }

    public void foo() {
        VolatileObjectRef O$module = VolatileObjectRef.zero();
    }

    private final O.2. O$1(VolatileObjectRef O$module$1) {
        return O$module$1.elem == null ? this.O$1$lzycompute(O$module$1) : (O.2.)O$module$1.elem;
    }

    private final O.2. oh$1(VolatileObjectRef O$module$1) {
        return this.O$1(O$module$1);
    }
}
// This PR
public class C {
    public void foo() {
        LazyRef O$lzy = new LazyRef();
    }

    private static final /* synthetic */ O.2. O$lzycompute$1(LazyRef O$lzy$1) {
        C$O$2$ var2_2;
        LazyRef lazyRef = O$lzy$1;
        synchronized (lazyRef) {
            public class C$O$2$ {
                public C$O$2$(C $outer) {
                }
            }
            var2_2 = O$lzy$1.initialized() ? (C$O$2$)O$lzy$1.value() : (C$O$2$)O$lzy$1.initialize((Object)new C$O$2$(null));
        }
        return var2_2;
    }

    private final O.2. O$1(LazyRef O$lzy$1) {
        return O$lzy$1.initialized() ? (O.2.)O$lzy$1.value() : C.O$lzycompute$1(O$lzy$1);
    }

    private final O.2. oh$1(LazyRef O$lzy$1) {
        return this.O$1(O$lzy$1);
    }
}

@scala-jenkins scala-jenkins added this to the 2.12.0-RC2 milestone Sep 28, 2016
@adriaanm
Copy link
Contributor

Resubmitting since I can push to this PR.

@adriaanm adriaanm closed this Sep 28, 2016
@adriaanm adriaanm mentioned this pull request Sep 28, 2016
2 tasks
@SethTisue SethTisue removed this from the 2.12.0-RC2 milestone Oct 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants