-
Notifications
You must be signed in to change notification settings - Fork 38
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
base: hkmc2
Are you sure you want to change the base?
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!
|
|
Now only 2 test cases fail! |
| //│ companion = N | ||
| //│ res = Lit of UnitLit of false | ||
|
|
||
| // The implicit `this` should be resolved correctly... |
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.
👀
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.
What?
|
Hoooooooooray!!! Thanks @CAG2Mark and @chengluyu 💞 for the help I guess this PR is almost ready. I'll complete the cleanup tomorrow (today). In this PR, the symbols in But the good news (maybe) is that the two symbol resolution mechanism are completely separated. i.e., the lowering stage solely relies on the symbol resolved by the resolver. This shall facilitate the WASM backend and other backends (if any). |
Co-authored-by: Lionel Parreaux <[email protected]>
|
It's ready for review~ |
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.