Skip to content

Review/fields lazies #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/compiler/scala/tools/nsc/transform/Fields.scala
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
val refClass = lazyHolders.getOrElse(lazyValType.typeSymbol, LazyRefClass)
val refTpe = if (refClass != LazyRefClass) refClass.tpe else appliedType(refClass.typeConstructor, List(lazyValType))

val flags = (lazyVal.flags & FieldFlags | ARTIFACT | MUTABLE) & ~(IMPLICIT | STABLE) // TODO: why include MUTABLE???
val flags = (lazyVal.flags & FieldFlags | ARTIFACT) & ~(IMPLICIT | STABLE)
val name = lazyVal.name.toTermName.append(nme.LAZY_LOCAL_SUFFIX_STRING)
val holderSym =
lazyVal.owner.newValue(name, lazyVal.pos, flags) setInfo refTpe
Expand All @@ -529,15 +529,16 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
val valueSetter = if (isUnit) NoSymbol else valueGetter.setterIn(refClass)
val setValue = if (isUnit) rhs else Apply(Select(Ident(holderSym), valueSetter), rhs :: Nil)
val getValue = if (isUnit) UNIT else Apply(Select(Ident(holderSym), valueGetter), Nil)
gen.mkSynchronized(Ident(holderSym),
val syncBlock = gen.mkSynchronized(Ident(holderSym),
Block(List(
If(NOT(Ident(holderSym) DOT initializedGetter),
Block(List(
setInitialized),
setValue),
EmptyTree)),
getValue)) // must read the value within the synchronized block since it's not volatile
Return(getValue))) // must read the value within the synchronized block since it's not volatile
// (there's no happens-before relation with the read of the volatile initialized field)
Block(syncBlock :: Nil, Throw(Literal(Constant(null))))
// TODO: double-checked locking
}

Expand Down