Skip to content

Avoid lazy local contexts #9590

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 1 commit into from
Aug 19, 2020
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 19, 2020

These cause allocation of a LazyRef. It's better to use inContext,
which is an inline function that gives better code.

These cause allocation of a LazyRef. It's better to use inContext,
which is an inline function that gives better code.
@odersky
Copy link
Contributor Author

odersky commented Aug 19, 2020

test performance please

@dottybot
Copy link
Member

performance test scheduled: 3 job(s) in queue, 1 running.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

LGTM

goIdent(tree, start)
inContext(prepIdent(tree, start)(using outerCtx)) {
goIdent(tree, start)
}
Copy link
Contributor

@liufengyun liufengyun Aug 19, 2020

Choose a reason for hiding this comment

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

A digression: the pattern seems to suggest a useful addition to stdlib:

inline def use[T, U](o: T)(inline op: o.type ?=> U): U = op(using o)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

If we think in that direction, it seems use can be used to replace given for some use cases:

val ctxInner = prepIdent(tree, start)(using outerCtx)
use ctxInner:
  goIdent(tree, start)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, but InContext is a bit clearer for reading, I think.

@odersky odersky merged commit 6f35436 into scala:master Aug 19, 2020
@odersky odersky deleted the optimze-local-givens branch August 19, 2020 16:36
@dottybot
Copy link
Member

performance test failed:

Please check http://lamppc37.epfl.ch:8000/pull-9590-08-19-20.50.out for more information

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.

3 participants