-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fields: expand lazy vals during fields, like modules #5294
Conversation
72eb820
to
822fd93
Compare
be2c934
to
3d8a814
Compare
I checked the |
I've taken a breadth-first pass over this and haven't found any issues so far. I'll dive in deeper tomorrow. |
@adriaanm I started looking at implementing scala/scala-dev#133, but it's not clear to me what's the ultimate goal for the lazy val desugaring. Currently, the fields phase creates a variable and a getter for each lazy val. The lazyvals phase then splits up the getter into a getter and a Also, there's still some duplication between lazyvals and mixin: both have a method For scala/scala-dev#133, the idea is to expand a local
Should all of this be done in the fields phase? Or during lazyvals? |
Thanks! My goal is to move the remaining lazy desugaring from mixin to lazyvals, so that there's no duplication. I have started poking around to convince myself that |
Now I've paged back in where I left this: mixins handles lazy vals in classes and uses the same init bit logic as checkinit, so moving that to lazyvals could be tricky to do within the time budget for RC1. |
yeah, just found out the same :) |
so lazyvals only handles local lazy vals? then i think we can get rid of the phase and move the translation for locals to the fields phase. i'm happy to take a look at this, doesn't look too hard (famous last words). |
Ah, that's an interesting approach, hadn't thought of that. |
It looks like it's some strange mixture of the two (EDIT: local lazy vals and modules in classes --> both could be done during the fields phase) -- let's synch on slack how to divide the work here. |
5b5b55f
to
34f967f
Compare
wip: lrytz@9f2f990 currently crashes in backend, will pick it up tomorrow.
|
cd61abf
to
562b3ce
Compare
@adriaanm here's the desugaring for local vals: lrytz@26fbaf6. Note that this revision is not rebased on the current top of this PR. I tried rebasing on top of this PR, the result is here: lrytz@3d56b1f. But this revision doesn't pass the test I wrote. There are a few TODOs in the commit, please take a look. A few more open questions:
How should we proceed? |
b086764
to
0581b6e
Compare
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>
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>
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>
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>
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>
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>
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>
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>
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>
This likely regressed in scala#5294.
This likely regressed in scala#5294. Review feedback from retronym: - Tie annotation triaging a bit closer together - Drop all annotations from static forwarders durban kindly provided initial version of test/files/run/t10075.scala And pointed out you must force `lazy val`, since `null`-valued field is serializable regardless of its type. Test test/files/run/t10075b courtesy of retronym
This likely regressed in scala#5294. Review feedback from retronym: - Tie annotation triaging a bit closer together - Drop all annotations from static forwarders durban kindly provided initial version of test/files/run/t10075.scala And pointed out you must force `lazy val`, since `null`-valued field is serializable regardless of its type. Test test/files/run/t10075b courtesy of retronym
This likely regressed in scala#5294. Review feedback from retronym: - Tie annotation triaging a bit closer together durban kindly provided initial version of test/files/run/t10075.scala And pointed out you must force `lazy val`, since `null`-valued field is serializable regardless of its type. Test test/files/run/t10075b courtesy of retronym
Fixes the problem reported with scala#5730 by xuwei-k in scala/scala-dev#352. The problem was already present before the introduction of `applyUnapplyMethodCompleter`, as 63f7b35 (in scala#5294) introduced a similar bug where the `PolyTypeCompleter`'s `typeParams` override was masked.
TODO: implement Lukas's observation and use CompleterWrapper for other completers for polymorphic symbols Fixes the problem reported with scala#5730 by xuwei-k in scala/scala-dev#352. The problem was already present before the introduction of `applyUnapplyMethodCompleter`, as 63f7b35 (in scala#5294) introduced a similar bug where the `PolyTypeCompleter`'s `typeParams` override was masked.
Fixes the problem reported with scala#5730 by xuwei-k in scala/scala-dev#352. The problem was already present before the introduction of `applyUnapplyMethodCompleter`, as 63f7b35 (in scala#5294) introduced a similar bug where the `PolyTypeCompleter`'s `typeParams` override was masked.
## What changes were proposed in this pull request? - Support N-part identifier in SQL - N-part identifier extractor in Analyzer ## How was this patch tested? - A new unit test suite ResolveMultipartRelationSuite - CatalogLoadingSuite rblue cloud-fan mccheah Closes #23848 from jzhuge/SPARK-26946. Authored-by: John Zhuge <jzhuge@apache.org> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(follow up for #5141 )
Fields phase fully expands lazy vals and modules
Mixins is relieved of its bitmap emission duties.
Important changes
Internal details
Lazy vals remain
ValDef
s (with a method symbol for its accessor) until the fields phase, along with deferred vals and all trait vals. Code that previously only consideredDefDef
s when looking for accessors will need to widen this search toValOrDefDef
. Also,accessed
will not lead to a field in these cases (ultimately, we should delay all field creation until fields.)Lazy val accessors, fields and bitmaps are now mixed in during the fields phase, which means erasure and specialization get a better look at them. Should we also move mixins before erasure?
@lrytz did the bulk of the work in moving our encoding of local lazy vals to the scheme used by Dotty, based on a suggestion by @DarkDimius. Locking is now down on the holder of the lazy val's value / init bit, instead of on the enclosing class (which had widened from the closure class to the owner of the method, making this more prone to deadlocks).
All lazy vals and modules use double-checked locking, but modules no longer spin off their initialization to a compute method (it's short enough not to interfere with the inlining of the lazy accessor).
Notes from the implementation lab journal
remove lazy accessor logic
now that we have a single ValDef for lazy vals,
with the underlying machinery being hidden until the fields phase
leave a
@deprecated def lazyAccessor
for scala-refactoringdon't skolemize in purely synthetic getters,
but do skolemize in lazy accessor during typers
Lazy accessors have arbitrary user code, so have to skolemize.
We exempt the purely synthetic accessors (
isSyntheticAccessor
)for strict vals, and lazy accessors emitted by the fields phase
to avoid spurious type mismatches due to issues with existentials
(That bug is tracked as scala/scala-dev#165)
When we're past typer, lazy accessors are synthetic,
but before they are user-defined to make this hack less hacky,
we could rework our flag usage to allow for
requiring both the ACCESSOR and the SYNTHETIC bits
to identify synthetic accessors and trigger the exemption.
see also scala/scala-dev#165
ok 7 - pos/existentials-harmful.scala
ok 8 - pos/t2435.scala
ok 9 - pos/existentials.scala
previous attempt: skolemize type of val inside the private[this] val
because its type is only observed from inside the
accessor methods (inside the method scope its existentials are skolemized)
bean accessors have regular method types, not nullary method types
must re-infer type for param accessor
some weirdness with scoping of param accessor vals and defs?
tailcalls detect lazy vals, which are defdefs after fields
can inline constant lazy val from trait
don't mix in fields etc for an overridden lazy val
need try-lift in lazy vals: the assign is not seen in uncurry
because fields does the transform (see run/t2333.scala)
ensure field members end up final in bytecode
implicit class companion method: annot filter in completer
update check: previous error message was tangled up with unrelated
field definitions (
var s
andval s_scope
),now it behaves consistently whether those are val/vars or defs
analyzer plugin check update seems benign, but no way to know...
error message gen: there is no underlying symbol for a deferred var; look for missing getter/setter instead
avoid retypechecking valdefs while duplicating for specialize -- see pos/spec-private
Scaladoc uniformly looks to field/accessor symbol
test updates to innerClassAttribute by Lukas
TODO:
tests / review follow up
@volatile
var cannot be defined in case class with confusing error messageanalyzer.underlyingSymbol
to reflect abstract val/vars don't have a fieldcommunity build
follow ups after RC1: