Refactor Value.Ref into Value.{SimpleRef,MemberRef,InnerRef}#491
Refactor Value.Ref into Value.{SimpleRef,MemberRef,InnerRef}#491Derppening wants to merge 31 commits into
Value.Ref into Value.{SimpleRef,MemberRef,InnerRef}#491Conversation
I have no idea what's up with the CI failure. It is only deprecated but it's treated as an error for some reason. |
|
@LPTK You can take a look at the changes first. I will mark this as ready for review once the TODO is also addressed. |
There was a problem hiding this comment.
I feel like this should have been marked as a draft and that you didn't properly review the diff. Given the amount of duplicated logic, a lot of it looks like thoughtless slop 😕
PS: thoughtless slop is perfectly fine as long as the PR is marked as Draft and you eventually clean it up 😉
| override def applyValue(v: Value): Unit = | ||
| v match | ||
| case Value.Ref(l, disamb) if !inCtx(l) && l.asClsLike.isEmpty => freeVars.add(l) | ||
| case Value.SimpleRef(l) if !inCtx(l) && l.asClsLike.isEmpty => freeVars.add(l) |
There was a problem hiding this comment.
I don't think asClsLike can be true for SimpleRef. Just look at its impl.
| case Value.Ref(l, disamb) if !inCtx(l) && l.asClsLike.isEmpty => freeVars.add(l) | ||
| case Value.SimpleRef(l) if !inCtx(l) && l.asClsLike.isEmpty => freeVars.add(l) | ||
| case Value.MemberRef(bms, _) if !inCtx(bms) && bms.asClsLike.isEmpty => freeVars.add(bms) | ||
| case Value.InnerRef(l) if !inCtx(l) && l.asClsLike.isEmpty => freeVars.add(l) |
There was a problem hiding this comment.
I think this will never meaningfully match. this references are almost always to a class-ike thing. @ychenfo what's the intent, here?
| case bms: BlockMemberSymbol => Value.MemberRef(bms, bms.defaultDisamb.get) | ||
| case sym: TempSymbol => Value.SimpleRef(sym) | ||
| case sym: VarSymbol => Value.SimpleRef(sym) | ||
| case sym: (LocalSymbol | BuiltinSymbol) => Value.SimpleRef(sym) | ||
| case sym: InnerSymbol => Value.InnerRef(sym) |
There was a problem hiding this comment.
This jungle of cases is almost certainly unnecessary. Check what type of symbol flows here and split/refine the type of this extension method, isntead of using pattern matching. Perhaps @ychenfo can help.
| case _ => () | ||
| generatedProdVars(sym).asProdStrat | ||
| case _: Value.Ref => lastWords("already handled in `RefLike` case") | ||
| case _: (Value.SimpleRef | Value.MemberRef) => lastWords("already handled in `RefLike` case") |
There was a problem hiding this comment.
I see that this Value.SimpleRef | Value.MemberRef pattern seems common enough to make them extend a base Value.Ref sealed trait that could be used here instead.
| classCtorSymbol(sym) orElse S(sym) | ||
| classCtorSymbol(sym) orElse S(sym) |
| sym match | ||
| case sym: TempSymbol => Value.SimpleRef(sym) | ||
| case sym: VarSymbol => Value.SimpleRef(sym) | ||
| case sym: BlockMemberSymbol => Value.MemberRef(sym, sym.defaultDisamb.get) | ||
| case sym: (LocalSymbol | BuiltinSymbol) => Value.SimpleRef(sym) | ||
| case sym: InnerSymbol => Value.InnerRef(sym) |
There was a problem hiding this comment.
Again some duplicated (and suspicious) logic.
| @@ -1,6 +1,5 @@ | |||
| :js | |||
|
|
|||
|
|
|||
| case Value.SimpleRef(l) => | ||
| mapping.get(l) match | ||
| case None => super.applyValue(v)(k) | ||
| case Some(newBms: BlockMemberSymbol) => |
There was a problem hiding this comment.
Will the mapping ever map a SimpleRef symbol to a BlockMemberSymbol?! 🤔
| warnStmt | ||
| k(loweringCtx(Value.Ref(sym, disamb).withLocOf(ref))) | ||
| (sym, disamb) match | ||
| case (sym: TopLevelSymbol, _) => |
| case (sym: TempSymbol, _) => | ||
| k(loweringCtx(Value.SimpleRef(sym).withLocOf(ref))) | ||
| case (sym: VarSymbol, _) => | ||
| k(loweringCtx(Value.SimpleRef(sym).withLocOf(ref))) |
There was a problem hiding this comment.
Collapse using sym: (TempSymbol | VarSymbol)
|
Sorry for all the redundant logic - I will convert this as a draft to clean this up first, then when it's ready I will re-request for your review. |
`LocalSymbol | BuiltinSymbol` cannot be class-like.
TODO:
case Value.Refintoapplyandunapplyfunctions