Skip to content
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

Don't lift the argument of a synchronized block in scoverage #16941

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

KacperFKorban
Copy link
Member

possible fix for lampepfl#16940

Copy link
Member

@ckipp01 ckipp01 left a comment

Choose a reason for hiding this comment

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

I'm not 100% sure why it was vals instead of defs in the first place. I also can't think of anything wrong with this, but just to make sure I also tagged @TheElectronWill on this. However it's a LGTM from me. Thanks!

@TheElectronWill
Copy link
Contributor

Will every argument be turned into a def, in all circumstances? I'm a bit worried about the performance and size overhead of that.

@nicolasstucki
Copy link
Contributor

Isn't this changing the evaluation semantics?

@nicolasstucki
Copy link
Contributor

From the test case, it seems that the failure is on a by-name argument. If so changing the binding of that by-name argument to a def is the correct fix. But we should use defs for by-name arguments.

@ckipp01 ckipp01 assigned KacperFKorban and unassigned ckipp01 May 9, 2023
@ckipp01
Copy link
Member

ckipp01 commented May 9, 2023

From the test case, it seems that the failure is on a by-name argument. If so changing the binding of that by-name argument to a def is the correct fix. But we should use defs for by-name arguments.

@KacperFKorban is it possible to just make this change and only use defs for the by-name arguments?

@mohe2015
Copy link

Any updates on this?

@KacperFKorban
Copy link
Member Author

Sorry, this PR got a bit buried for me.
@ckipp01 I tried doing that, but it doesn't fix the problem. This specific problem is with synchronized which takes a normal argument, not a by-name one. (Though by-name arguments also aren't correctly lifted)
@nicolasstucki Does lifting to defs actually change the semantics? Don't we guarantee that every lifted expression will be referenced exactly once?

@odersky
Copy link
Contributor

odersky commented Aug 17, 2023

I am not sure whether lifting to defs would break the semantics, i.e. whether we can guarantee used exactly once. Probably we can't. I would feel very nervous with such a change. Also lifting to defs certainly will make the code go much slower in many cases.

@nicolasstucki
Copy link
Contributor

Does lifting to defs actually change the semantics?

It should not. We already do that for by-name arguments of inline definitions.

Don't we guarantee that every lifted expression will be referenced exactly once?

It is referenced once at the call site, but possibly evaluated many times in the function.

@nicolasstucki
Copy link
Contributor

Also lifting to defs certainly will make the code go much slower in many cases.

In this case, lifting the by-name argument into a def should not make it much slower (or at all). We can use that def directly to encode that lambda that is passed as an argument. If it is currently not the case, then we probably have a general optimization opportunity.

@odersky
Copy link
Contributor

odersky commented Aug 17, 2023

As far as I know, cbn arguments are already lifted into defs. It's just cbv arguments that are lifted into vals.

@KacperFKorban KacperFKorban changed the title Lift arguments to defs instead of vals in coverage Don't lift the argument of a synchronized block in scoverage Aug 18, 2023
@KacperFKorban
Copy link
Member Author

Ok. In that case, I changed this fix to just avoid lifting arguments of synchronized blocks.

@KacperFKorban
Copy link
Member Author

@nicolasstucki does this look ok now?

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

I think that makes sense.

@KacperFKorban KacperFKorban merged commit 932c10d into scala:main Aug 18, 2023
17 checks passed
@KacperFKorban KacperFKorban deleted the fix-i16940 branch August 18, 2023 15:55
Kordyjan added a commit that referenced this pull request Dec 8, 2023
…age" to LTS (#19169)

Backports #16941 to the LTS branch.

PR submitted by the release tooling.
@Kordyjan Kordyjan added this to the 3.3.2 milestone Dec 14, 2023
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.

7 participants