-
Notifications
You must be signed in to change notification settings - Fork 39
Term.Resolved
#343
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
Term.Resolved
#343
Conversation
|
I am facing some problems now:
|
Use wrapping term for Sel resoultion.
|
OK I managed to wrap selections with |
|
Hello @CAG2Mark and @chengluyu, I need your help on this PR 🤧🥺, particularly regarding the lifter and the UCS/UPS normalization. Summary on this PRIn this PR, we try to disambiguate A direct consequence is that, we now have enough information in the lowering/codegen stage to defer the process of adding the I changed - case Ref(l: Local)
+ case Ref(l: Local, disamb: Opt[DefinitionSymbol[?]])and - case class Select(qual: Path, name: Tree.Ident)(val symbol: Opt[FieldSymbol])
+ case class Select(qual: Path, name: Tree.Ident)(val symbol_SelectSymbol: Opt[DefinitionSymbol[?]])Then, the JS builder automatically, based on the information encoded, decides whether or not to append the case Value.Ref(l, disamb) => l match
case l: BlockMemberSymbol if {
// TODO @Harry: refactor(ize) duplicated logic
l.hasLiftedClass &&
disamb.flatMap(d => d.asMod orElse d.asCls).exists(_ isnt ctx.builtins.Array)
} =>
doc"${getVar(l, l.toLoc)}.class"
case _ =>
getVar(l, r.toLoc) case s @ Select(qual, id) =>
val dotClass = s.symbol_SelectSymbol match
case S(ds) if {
val v = ds.asBlkMember.exists(_.hasLiftedClass) &&
(ds.asMod orElse ds.asCls).exists(_ isnt ctx.builtins.Array)
v
} => doc".class"
case _ => doc""
val name = id.name
doc"${result(qual)}${
if isValidFieldName(name)
then doc".$name"
else name.toIntOption match
case S(index) => doc"[$index]"
case N => doc"[${makeStringLiteral(name)}]"
}${dotClass}"What's the ProblemIn the lifter and the UCS/UPS normalization, there is a bunch of customized logic of appending Also, seems like the compiler largely transforms the terms in the lifter and the UCS/UPS normalization process. Some encoded information is stripped out, but I couldn't find out the reason 😥. UCS/UPS NormalizationI am taking Looking at the resolved tree for the patterns: :rt
pattern OddTree =
A |
Node(EvenTree, A, EvenTree) | Node(OddTree, A, OddTree) |
Node(EvenTree, B, OddTree) | Node(OddTree, B, EvenTree)
pattern EvenTree =
B |
Node(EvenTree, A, OddTree) | Node(OddTree, A, EvenTree) |
Node(EvenTree, B, EvenTree) | Node(OddTree, B, OddTree)
//│ Resolved tree:
//| ...
//│ left = Composition:
//│ polarity = true
//│ left = Constructor:
//│ target = Resolved{sym=object:A,typ=object:A}:
//│ t = Ref{sym=member:A} of member:A
//│ sym = object:A
//│ patternArguments = Nil
//│ arguments = N
//│ right = Constructor:
//│ target = Resolved{sym=term:class:Node.Node}:
//│ t = Ref{sym=member:Node} of member:Node
//│ sym = term:class:Node.NodeThe references to :lot
B is @compile EvenTree
//| Lowered tree:
//| ...
//│ path = Ref:
//│ l = member:A
//│ disamb = N
//| ...
//│ path = Select{sym=class:Node}:
//│ qual = Ref:
//│ l = member:Node
//│ disamb = N
//│ name = Ident of "class"while we expect it to be :lot
B is @compile EvenTree
//| Lowered tree:
//| ...
//│ path = Ref:
//│ l = member:A
//│ disamb = object:A
//| ...
//│ Ref:
//│ l = member:Node
//│ disamb = term:class:Node.NodeWould you provide some help on this case? Thanks Luyu 😉 LifterTaking The fun foo(x) =
class C(y) with
fun get = [x, y]
module C with
val empty = C(123)
C.emptyshould be compiled to JS //│ res = Resolved{sym=term:module:C.empty}:
//│ t = Sel{sym=member:empty}:
//│ prefix = Resolved{sym=module:C,typ=module:C}:
//│ t = Ref{sym=member:C} of member:C
//│ sym = module:C
//│ nme = Ident of "empty"
//│ sym = term:module:C.emptyAfte lowering, it is expected to be However, if Would you look into it? Thanks Mark 💓 |
|
Oh cool, something to do in tomorrow's conference when I am bored |
|
You can try this commit @FlandiaYingman |
|
@FlandiaYingman 🥹 To be honest, I still don’t quite understand what you want to do. Let’s set a time on Discord to discuss it in person. |
|
Finally, now only 15 cases fail.
|
hkmc2/shared/src/main/scala/hkmc2/semantics/ucs/Normalization.scala
Outdated
Show resolved
Hide resolved
hkmc2/shared/src/main/scala/hkmc2/codegen/HandlerLowering.scala
Outdated
Show resolved
Hide resolved
|
OK the reason why WASM failed is because I forgot to |
eb05912 to
18ff415
Compare
|
Now only 4 test cases fail!
|
Co-authored-by: Lionel Parreaux <lionel.parreaux@gmail.com>
Co-authored-by: Lionel Parreaux <lionel.parreaux@gmail.com>
| val loopCont = if config.rewriteWhileLoops | ||
| then Return(Call(Value.Ref(f, N), Nil)(true, true), false) | ||
| else Continue(loopLabel) |
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.
Here I saw the symbol f is a (dummy) BlockMemberSymbol denoting a while loop label (new BlockMemberSymbol("while", Nil, false)).
Is it necessary for it to be a BlockMemberSymbol? It seems like there is no meaningful disambiguation for such symbol f like here, so my opinion is to change it to another symbol type.
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.
This symbol is not for the label, but for the inserted function, and FunDefn requires a BlockMemberSymbol. Are you suggesting changing the definition of FunDefn?
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.
Ideally we should, but I guess it'd be another PR
hkmc2/shared/src/main/scala/hkmc2/semantics/ucs/Normalization.scala
Outdated
Show resolved
Hide resolved
| val loopCont = if config.rewriteWhileLoops | ||
| then Return(Call(Value.Ref(f, N), Nil)(true, true), false) | ||
| else Continue(loopLabel) |
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.
This symbol is not for the label, but for the inserted function, and FunDefn requires a BlockMemberSymbol. Are you suggesting changing the definition of FunDefn?
Co-authored-by: Lionel Parreaux <lionel.parreaux@gmail.com>
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.
Ok, let's merge this now and address the rest in follow-up PRs. Nice progress towards cleaning up the logic!
This is a draft PR that adds
Term.Resolvedto indicate that a term's symbol is resolved. This information can be used later in the lowering stage. For example, append.classto a ref to an overloaded module definition.