Skip to content

Simplify enclosedInlineds #4990

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 2 commits into from
Aug 24, 2018

Conversation

Blaisorblade
Copy link
Contributor

@Blaisorblade Blaisorblade commented Aug 22, 2018

WIP waiting full tests, then I explain why this is a refactoring.

Bring both inlineContext and enclosingInlineds from O(n) to O(1) without complicating the code.

Noticed while reviewing #4949.

inlineContext already normalized most of InlinedCalls, normalize all of it
instead. The new code isn't much more complex, the only tricky bit is assuming
we don't need to normalize the pre-normalized list.

In fact, this can be simplified further!
@nicolasstucki
Copy link
Contributor

If we normalize too early w will not have the full inline stack which implies that we may not be able to use it for improving the error messages. Though it is possible that normalized stack is enough. @odersky WDYT?

@Blaisorblade
Copy link
Contributor Author

Blaisorblade commented Aug 23, 2018

The existing code already normalizes the stack too much for your use case. It might have a rationale, I haven't found it yet, tho I'm not done studying this.

OTOH, maybe the context chain has enough information anyway. If not, we can change again, but not to the existing code.

EDIT: after investigation I see the idea. If one does need the full stack, it seems one just need fix inlineContext to:

override def inlineContext(call: Tree)(implicit ctx: Context): Context =
    ctx.fresh.setProperty(InlinedCalls, call :: ctx.property(InlinedCalls).getOrElse(Nil))

and add tests.
EDIT: also

- *  EmptyTree calls cancel the next-enclosing non-empty call in the list
+ *  EmptyTree calls cancel up to the next-enclosing non-empty call in the list

case Nil => Nil
/** Record an enclosing inlined call.
* EmptyTree calls (for parameters) cancel the next-enclosing call in the list instead of being added to it.
* We assume parameters are never nested inside parameters.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WIP further experiments suggest this can't be true, even tho this code works.

Copy link
Contributor

Choose a reason for hiding this comment

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

After normalization, we should not have them, so it should be fine or the normalization was not performed correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True after normalization — I thought that was also true before normalization, but that was wrong.

@Blaisorblade Blaisorblade merged commit dab03fd into scala:master Aug 24, 2018
@Blaisorblade Blaisorblade deleted the simplify-enclosedInlineds branch August 24, 2018 20:10
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