-
Notifications
You must be signed in to change notification settings - Fork 40
Lifter revamp #384
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
Lifter revamp #384
Conversation
0d1e547 to
156d657
Compare
|
Oh, I didn't realize the handler refactor PR was made against the By the way, your rebased commit does not compile. |
hkmc2/shared/src/main/scala/hkmc2/codegen/UsedVarAnalyzer.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/UsedVarAnalyzer.scala
Outdated
Show resolved
Hide resolved
|
Remaining tasks:
|
hkmc2/shared/src/main/scala/hkmc2/codegen/UsedVarAnalyzer.scala
Outdated
Show resolved
Hide resolved
|
Seems that a lot of the complexity from before came from dealing with nested modules and objects... Things were pretty clean until I added nested modules and objects. |
|
OK so a new pain point: I currently lift classes by putting the extra variables in private fields. But since classes could be instantiated immutably, we are forced to put all variables they mutate into captures. Any idea on what to do? Or should we just give up and put them into captures? EDIT: apparently private fields remain mutable after freezing, which also fixes the other problem I was worrying about (that I never mentioned) |
AnsonYeung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need some time to read through rest of the code. I'll review the rest later.
AnsonYeung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't really look through every single line of the code. The main problem I have about the current state is that I found some code that is unreachable (never tested). If those branch is truly unreachable they should just crash instead of returning something that may not be correct. There is also some instance of dead variable and I wonder if there is some lint option to find them all and remove them.
|
Thanks, I'll address these tomorrow. |
I know, but Anson is very familiar with what the lifter does and the IR the lifter works on. Also, I can't review the PR at the moment since I am on a family vacation. |
|
OK, I realized there's a few tricky cases with objects and modules that I need to sort out again... |
|
Note that this is not yet ready to merge. I still need to deal with some problems with objects. Honestly, I might just rewrite all objects before lifting because that will make things 100x easier |
|
OK, objects are causing a lot of problems. There are a few options I have right now:
Not sure what the best option is though... |
But the semantics is different. As discussed before, what makes object definitions useful is their initialization semantics (they allow for indirect self-reference). fun f = print(A)
object A with
f // A is not fully initialized yet but can still be accessed
val x = 1
//│ > A {}
// By contrast:
fun f = print(A)
class Acls with
f // A is not accessible at all here
val x = 1
val A = new Acls
//│ > undefined
//│ A = Acls { x: 1 }
// We still need an initialization checker to catch things like this:
fun f = print(A.x)
object A with
f
val x = 1
//│ > undefinedThat said, it is probably (?) not a crucial feature.
Could you elaborate what you mean by that?
Do note that this is pretty much the same situation as supporting classes in classes, which we intentionally do not support in the lifter for now (it will be possible to properly support once we resolve all selections statically).
Except it doesn't, as it changes the initialization behavior. So, either we change the initialization semantics uniformly (making top-level objects initialize the same as nested ones after lifting, ie the same as simple classes + For this PR, though, I suggest omitting object support. We should add that support in a follow-up PR. |
|
Also, if we go with the former approach, then there's no real need to have an |
OK, I previously thought the "different initialization semantics" was just that it's a singleton object and we could use a flag or something at the definition site to denote that. I didn't realize they had the semantics you mentioned. |
|
BTW it should be ready |
LPTK
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned before, I can't really review the PR in depth for now. But it's been open for long enough, so I think we should merge it. And we'll discuss the follow up work on objects/modules later in person.
Don't forget that we need to resolve the open conversations. |
|
OK, everything is addressed |
See #369