Skip to content

More changes to protected accessors #4603

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 4 commits into from
Jun 3, 2018

Conversation

odersky
Copy link
Contributor

@odersky odersky commented May 31, 2018

Some fixes in the AccessProxies scheme that were discovered when revising the inliner.

@odersky
Copy link
Contributor Author

odersky commented May 31, 2018

Hi Allan, I did some improvements to the protected accessor scheme. Can you use this one as a basis for the partial functions PR?

odersky added 4 commits May 31, 2018 16:33
Several fixes detected during refactorings of inliner
Use

    inline$x
    inline$x_=
    protected$x
    protected$x_=

instead of

    inline_get$x
    inline_set$x
    protected_get$x
    protected_set$x

Advantage: more idiomatic, and it's possible to make this work
on untyped trees as well.

The old scheme would have required accessors for every operator assignment
when extending it to  untyped trees.
@odersky odersky force-pushed the change-accessors branch from e02582b to 266a696 Compare May 31, 2018 14:33
@odersky
Copy link
Contributor Author

odersky commented May 31, 2018

Rebased on top of master which now contains #4597

private def rewire(reference: RefTree, accessor: Symbol)(implicit ctx: Context): Tree = {
reference match {
case Select(qual, _) => qual.select(accessor)
case Ident(name) => ref(accessor)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to desugar the Identifier here like in tpd.becomes?

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, since we always to refer to given accessor.

val sym = ctx.newSymbol(owner, name, Synthetic | Method, info, coord = pos).entered
if (sym.allOverriddenSymbols.exists(!_.is(Deferred))) sym.setFlag(Override)
sym
}

/** An accessor symbol, create a fresh one unless one exists already */
private def accessorSymbol(owner: Symbol, accessorName: TermName, accessorInfo: Type, accessed: Symbol)(implicit ctx: Context) = {
def refersToAccessed(sym: Symbol) = accessedBy.get(sym) == Some(accessed)
Copy link
Contributor

Choose a reason for hiding this comment

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

accessedBy.get(sym).contains(accessed)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. I'll roll that into another PR.

@odersky odersky merged commit 228b232 into scala:master Jun 3, 2018
@allanrenucci allanrenucci deleted the change-accessors branch June 3, 2018 13:19
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