Skip to content

Transform/captured vars #173

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

Merged
merged 138 commits into from
Oct 11, 2014
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 12, 2014

Review by @DarkDimius

odersky added 30 commits August 3, 2014 20:43
Added decorators for symbols that can query specific
annotations and annotation arguments (for now, -deprecated
and -migration are added)
Added method to traverse all parts of a type.
Two improvements to TreeTransform:

1) Added transformOther functionality which handles trees not handled by other parts
2) Passes down Mode.Pattern in the context when in a pattern.

TreeTransform no longer normalizes unknown trees but passes them to transformOther.
The former Companions phase has been renamed to FirstTransform. It now performs the
following optimizations:
 - adds companion objects (this was done before)
 - other normalizations that were formally done in TreeTransform,
 - rewrite native methods to stubs (this was formally done in RefChecks)
Cycles are now detected early, when an info is first completed.
Legal, f-bounded cycles are broken by a LazyRef, which will construct
its type lazily. This makes checkBounds validation of AppliedTypeTrees work
(in FirstTransform). Formerly, this stackoverflowed despite the laziness
precautions in findMember.

Todo: Do the same for class files coming from Java and Scala 2.x.
Insert LazyRefs to break cycles for F-bounded types that
are unpickled or read from Java signatures.
Now that F-bunded types are treated more robustly, we can check bounds for
non-emptyness during Typer.

This unvealed one wrong test (wonder how that passed scalac?), which got
moved to neg.
Statements are now transformed with the transform returned by prepareStats,
analogoys to the other prepare methods.
This is still disabled, because the prepare machinery in transform
does not work yet. Concretely, prepare ops need to return a new TreeTransform
but that tree transform has an undefined phaase id.

We need some architectural changes to disentangle transforms from phases.
... so that it can be combined with TreeTransform in a trait composition
in a future dientanglement of TreeTransforms and Phases.
Would be flagged as unimplemented members in refChecks otherwise
TreeTransforms are no longer phases. This allows to generate
new transforms in prepare... methods without running into the
problem that thee new transforms are undefined as phases.

It also makes for a cleaner separation of concerns.
Should have lazy flag set, otherwise forward reference checking would
fail for modules.

Note: LazyVals needed to be disabled because it also should transform
module vals, but didn't do this so far because it only tested the Lazy flag.
It turned out the module val transformation exposed some bugs in lazy vals
in that LazyVals creates symbols as a side effect and enters them into scopes.
Such mutations are allowed onyl in very specific cases (essentially only for local
throw-away scopes).
Scopes are also used in overriding pairs, and there multiple types with
the same name can be entered in a scope. So the assert to the contrary
should be limited to typechecking only.
Eta-lifting picked some arbitrary base type. It turned out that i94-nada failed once we add
a product trait to case classes (in the next commit) because Eta-Kifting picked Product
as the base type, even though the target type was bounded by Monad. We now change the scheme
so that the target type is included in the lifting, in order to avoid that we lift to
useless types.
Case classes with arity <= 1 now also get a ProductN parent trait.
This is necessary because we inherit productArity and Element methods
in case classes from the ProdictN trait.

Needed to add Product0 for this, which is not defined in Scala2.x.
After erasure, former Any members become Object members.

Also, fixed some typos and added some TODOs on addBridges.
asInstance/isInstance/ensureConforms/and/or.

They replace some former "mk..." methods.
Also renamed Boolean_and/or to _&&/||, to make it conform
to naming convention for other Definition operators.
RefChecks needs both methods.
New phase for Synthetic Method generation. Scala 2.x did it in Typer, but
it's cleaner to do it in a separate phase.
If a TypeRef with an expanded name is an alias type, print the alias instead.
Now that caes classes always inherit from ProductX, we can avoid
the special case. (We need to define _1 anyway to implement Product1).
(1) set position of companion object def
(2) companions of case classes taking multiple parameter lists do not inherit from
    a function type (reason: we can't straightforwardly converyt a curried method
    with multiple parameter lists to a function value).
For overriding checks we need a concept where a val can match a def.
Normal matches does not provide this.
Needed to keep a record of definitions in supercall arguments. These
may not see the enclosing class.
If there's a crash, we always want to see where the retyper was, not just for
tree checking.
Syntactically enclosing class is not accessible from such definitions,
so should be skipped.
Partial revert of 08c6eac "this type is a term ref to the source module". The problem with
doing this is that it introduces spurious outer references. An inner module that contains
self referenves always needs the directly enclosing class. The revert avoids this dependency
by making ThisTypes always point to TypeRefs.

Several other changes were necessary to make the builds pass: TypeRefs had to get prefixes after
erasure so that they can be reloaded. Symbols of such typerefs had to be retrieved without forcing
a denotation.

One test (blockescapes.scala) fails and is moved to pending, awaiting further resolution.

Also two other new tests in pending which currently fail (and have failed before).
Module roots were mis-characterized, which meant that module symbols were loaded twice.
Have a configurable printer to which cyclic error messages are sent.
Catch exceptions and embed into string instead of passing exception on.
Reason: i"" strings are for diagnostic output but may cause exceptions such
as CyclicReferences, stale symbols and so on. We never want to crash the
program with such an exception.
... by reverting a premature optimization in Erasure.
Better to keep the old name for easy cross-referencing with Scala 2.
Now also testing that after erasure no outer this exists. Tests suit now includes
calls to local classes and methods which need an outer pointer, as well as passing
an outer pointer along a secondary constructor.
Have a general way how a phase can establish a postcondition which will be
checked each time a later phase is tree-checked.

Moves erasure constraints from TreeChecker to Erasure's post condition.
foreachSubTree and existsSubTree are now infix methods. Streamlines their use
somewhat.
But allow pattern matching to provide outer accessors when needed
using with ensureOuterAccessors.
1) One phase too many was checked for postconditions.
2) Class members did not have their owners checked because index was not called on them.
The reason is that otherwise the non-private member super.x gets merged with the private member this.x
and that causes a double binding violation.
If definitions in a class are substituted by TreeTypeMap, the new
symbols have to show up in the `decls` scope of the class instead of the
old ones.
If the original name in a selection is a inherited name, the erased name should
also be one.
Without this patch, ast.TreeInfo does not compile wfter next commit "Erasure should keep prefixes in
TermRefs". The reason is that outer path genertion generates a data race between

 - an outer accessor created in ExplicitOuter
 - a copy of the accessor created in ElimByName in a TreeTypeMap copy.

The patch avoids the data race by using a fixed symbol for the new TermRef generated in
outer.path during erasure.

But the fix seems ad-hoc. We should try to attack the problem at the root in TypeTreeMap.
The root problem seems to be that TypeTreeMap generates a copy of symbols whnMemere the copies
of the symbols give the same named type as the originals. We can either label the copied symbols
so that any types created from them become instances of WithNonMemberSym (which probably should be
renamed then). Or else we have a "linear" version of TreeMap that overrides sym denotations instead
of creating new symbols.
Bring TermRefs in line with TypeRefs. Prefixes need to be kept so that termrefs
can be re-loaded in subsequent runs.
Avoids characterizing the "from" link in a return as a tail call
reference.
Otherwise would spuriously treat variables referenced
from while loops as captured, because their enclosing method
differs from current enclosing method.
Include a backtrace of nested calls on error.
Treat clone like the other primitive array operations, ensure it
returns a JavaArray.
Breaks out boxing functionality of captured vars from lambda lift.
1. They now keep track of changed constructors in templates, updating
   the class scope as for other members.
2. Any changed members are now entered into the new class scope at exactly
   the same position as the old one. That ensures that things like caseAccessors
   still work.
3. ChangeOwners now is reflected in the prefixes of any named types.
4. Newly created classes now get their own ClassInfo type.
5. TreeTypeMaps always crete "fresh" symbols. Fresh symbols do not share
   a NamedType reference with an existing reference to some other symbol.
   This obviates b2e0e7b, which will be reverted.

To make it work, the interface of TreeMap changed from an ownerMap function
to a substitution-like data structure working with two lists.
…rasure."

With the new more systematic treatment of fresh symbols in TreeTypeMap, this
is no longer ncessary.
@DarkDimius DarkDimius merged commit b22dc6d into scala:master Oct 11, 2014
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this pull request Mar 19, 2025
Backport "Partial Fix scala#21242: Add REPL init script setting" to 3.3 LTS
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.

2 participants