Skip to content

Space: Cache space decomposition & other refactoring #16937

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 16 commits into from
Feb 22, 2023

Conversation

dwijnand
Copy link
Member

Firstly, make SpaceEngine an object, in line with many other parts of the compiler, moving the cache it had for
isSubspace onto Space instances themselves, also like many other parts of the compiler. This also just helps
code navigation - avoid navigating to the interface all the time...

Then add a cache for decompose, canDecompose and simplify, so the costly result isn't computed multiple times.
And finally, look to define canDecompose in terms of decompose, so the logic is shared.

@dwijnand dwijnand assigned dwijnand and liufengyun and unassigned dwijnand Feb 16, 2023
@dwijnand dwijnand requested a review from liufengyun February 21, 2023 11:16
@dwijnand dwijnand marked this pull request as ready for review February 21, 2023 11:16
@dwijnand
Copy link
Member Author

@liufengyun it's quite a big change. I tried to explain what it includes, the reasons and present the changes in atomic diffs. But let me know what you think and how you feel about it.

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.

Very nice improvement 🎉 I only have some minor style comments.

  1. In 20026ec, it's not obvious why the change fixed the test. Adding a comment would help future maintenance.

  2. Maybe trigger a bench test.

PS: I worried introducing cache would make maintenance harder, but looking at the code, I think it's still easy to understand and maintain.

if isSubType(tp2, tp1) then b
else if canDecompose(a) then intersect(Or(decompose(a)), b)
else if isSubType(tp1, tp2) then a // problematic corner case: inheriting a case class
else intersectUnrelatedAtomicTypes(tp1, tp2)(b)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: In comparison with previous cases, what's the consideration here to introduce the ascription a but not b in the pattern?

Copy link
Member Author

Choose a reason for hiding this comment

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

I bind a because I need a Typ, not a Space, to decompose, while intersectUnrelatedAtomicTypes handles all spaces so I don't need to rebind the name.

@dwijnand dwijnand merged commit a2da1a6 into scala:main Feb 22, 2023
@dwijnand dwijnand deleted the space/object branch February 22, 2023 14:12
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 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.

3 participants