Skip to content

Create TypedTreeMap that propagates types #144

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 2 commits into from

Conversation

DarkDimius
Copy link
Contributor

If some node in tree is transformed changing the type,
the outer node could potentially also change type.

This patch implements a TypedTreeMap that propagates those
changes until types converge. Propagation is done for tree nodes
that are able to compute their type based on their children:
Pair, Block, If, Match, CaseDef, Try, SeqLiteral, Annotated

Note: patch doesn't cover Select's, see #143 for the issue
with Select.

@DarkDimius
Copy link
Contributor Author

@odersky please review

@odersky
Copy link
Contributor

odersky commented Jul 19, 2014

Terminology: Maybe call it RetypingTreeMap? Propagating is ambiguous: the standard TreeMap also propagates types, but from old to new tree instead of from children to parent.

@DarkDimius
Copy link
Contributor Author

It doesn't actually retype it, so I believe that RetypingTreeMap is even more misleading. TypePropagatingTreeMap?

@odersky
Copy link
Contributor

odersky commented Jul 19, 2014

On Sat, Jul 19, 2014 at 2:01 PM, Dmitry Petrashko [email protected]
wrote:

It doesn't actually retype it, so I believe that RetypingTreeMap is even
more misleading. TypePropagatingTreeMap?

It runs a type assigner over it. I think retyping expresses that well.

  • Martin


Reply to this email directly or view it on GitHub
#144 (comment).

Martin Odersky
EPFL

@odersky
Copy link
Contributor

odersky commented Jul 21, 2014

I am going to touch up and merge this one.

@DarkDimius
Copy link
Contributor Author

I've got a restructured version coming. Let me push it.

@DarkDimius
Copy link
Contributor Author

@odersky I've pushed the updated version.
This one handles selects(also for types), and defines reusable propagateType methods that help in avoiding code duplication between TreeTypeMap, RetypingTreeMap and are also used in TailCalls.

case TypeApply(fun, args) =>
cpy.TypeApply(tree, transform(fun), transform(args))
case New(tpt) =>
cpy.New(tree, transform(tpt))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why duplicate these cases? I mean, why not simply do a super.transform for any missing cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason, I'll make the change.

odersky added a commit to dotty-staging/dotty that referenced this pull request Jul 21, 2014
Incorporated commits from scala#144. The logic here is very similar, modulo some minor
organization and naming changes. The only deeper difference concerns retypeSelect,
which here makes use of derivedSelect without changing kinds of tree nodes.
@odersky odersky mentioned this pull request Jul 21, 2014
odersky added a commit to dotty-staging/dotty that referenced this pull request Jul 21, 2014
Incorporated commits from scala#144. The logic here is very similar, modulo some minor
organization and naming changes. The only deeper difference concerns retypeSelect,
which here makes use of derivedSelect without changing kinds of tree nodes.
odersky added a commit to dotty-staging/dotty that referenced this pull request Jul 21, 2014
Incorporated commits from scala#144. The logic here is very similar, modulo some minor
organization and naming changes. The only deeper difference concerns retypeSelect,
which here makes use of derivedSelect without changing kinds of tree nodes.
If some node in tree is transformed changing the type,
the outer node could potentially also change type.

This patch implements a RetypingTreeMap that propagates those
changes until types converge. Propagation is done for tree nodes
that are able to compute their type based on their children:
Pair, Block, If, Match, CaseDef, Try, SeqLiteral, Annotated, Select.
@DarkDimius DarkDimius closed this Jul 23, 2014
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this pull request Mar 19, 2025
Backport "Type avoidance in MT bound inference" 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