Skip to content

Recent update#10

Open
NeilKleistGao wants to merge 10 commits into
ChingLongTin:final🐤from
NeilKleistGao:fix🦠

Hidden character warning

The head ref may contain hidden characters: "fix\ud83e\udda0"
Open

Recent update#10
NeilKleistGao wants to merge 10 commits into
ChingLongTin:final🐤from
NeilKleistGao:fix🦠

Conversation

@NeilKleistGao
Copy link
Copy Markdown
Collaborator

@NeilKleistGao NeilKleistGao commented May 28, 2026

  • Add test cases for reg exp
  • Improve 3d transform
  • Remove shape set flattening
  • Fix unexpected inlining
  • Generate functions at the top level
  • Fix subclass check and dyn merging

@ChingLongTin ChingLongTin marked this pull request as ready for review June 3, 2026 10:47
obj_8
let {obj_5}
obj_5 = new D()
obj_5
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Owner

@ChingLongTin ChingLongTin left a comment

Choose a reason for hiding this comment

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

There is a regression that should be addressed: https://github.com/ChingLongTin/mlscript/pull/10/changes#r3350061642
The remaining are some minor suggestions.

Comment on lines 47 to +50
let x = liftMany([Class(clsSym, [Lit(42)]), Arr([Lit(1), Lit("a")])])
let y = liftMany([Lit(1), Lit("a")])
selSet(x, y)
//│ ═══[RUNTIME ERROR] Error: Array out of bound
//│ ═══[RUNTIME ERROR] TypeError: arg$Class$1$[scrut1].values is not a function
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
let x = liftMany([Class(clsSym, [Lit(42)]), Arr([Lit(1), Lit("a")])])
let y = liftMany([Lit(1), Lit("a")])
selSet(x, y)
//│ ═══[RUNTIME ERROR] Error: Array out of bound
//│ ═══[RUNTIME ERROR] TypeError: arg$Class$1$[scrut1].values is not a function
let x = liftMany([Class(clsSym, [mkLit(42)]), Arr([mkLit(1), mkLit("a")])])
let y = liftMany([Lit(1), Lit("a")])
selSet(x, y)
//│ ═══[RUNTIME ERROR] Error: Array out of bound
//│ x = {Arr([{Lit(1)}, {Lit("a")}]),Class(ConcreteClassSymbol("C", fun C { class: class C }, Some([Param(None, Symbol("a"))]), [], false), [{Lit(42)}])}
//│ y = {Lit("a"),Lit(1)}

fun empty = ShapeSet(new Map)

fun lift(s: Shape) = ShapeSet(new Map([[s.hash(), s]]))
fun makeShapeSet(entries) =
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
fun makeShapeSet(entries) =
fun mkShapeSet(entries) =

import "./Block.mls"
import "./Option.mls"
import "./CachedHash.mls"
import "./ShapeSet.mjs"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

We might want to put Shape and ShapeSet in a single module in a later commit instead of having both files importing each other.

Nothing() then p1'
else new Concat(p1', p2.normalize())
fun eq(other) =
if other is Concat(p1', p2') then p1.eq(p1') and p2.eq(p2') else false
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
if other is Concat(p1', p2') then p1.eq(p1') and p2.eq(p2') else false
other is Concat(p1', p2') and p1.eq(p1') and p2.eq(p2')

other eq functions in this file can also be rewritten this way, removing the tail else false block

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

somehow, the codegen for this is worse for Exact, adding a match statement on a boolean scrut... but in Concat the extra match statement is always generated

Comment on lines +53 to +56
Class(_, params) then params.every(field =>
let values = field.values()
values.length is 1 and static(values.0)
)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
Class(_, params) then params.every(field =>
let values = field.values()
values.length is 1 and static(values.0)
)
Class(_, params) then params.every(_.values() is [v] and static(v))

Comment on lines +174 to +186
fun matchImpl(p, s, acc) =
if len(s) == 0 then
if p.canBeEmpty() then new Some(acc)
else new None
else
if p is
Nothing then new None
else
let c = s.0
if p.startsWith(c) then
matchImpl(p.derive(c), s.slice(1), acc + c)
else
if p.canBeEmpty() then new Some(acc) else new None
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
fun matchImpl(p, s, acc) =
if len(s) == 0 then
if p.canBeEmpty() then new Some(acc)
else new None
else
if p is
Nothing then new None
else
let c = s.0
if p.startsWith(c) then
matchImpl(p.derive(c), s.slice(1), acc + c)
else
if p.canBeEmpty() then new Some(acc) else new None
fun matchImpl(p, s, acc) = if
len(s) == 0 and
p.canBeEmpty() then new Some(acc)
else new None
p is Nothing then new None
let c = s.0
p.startsWith(c) then matchImpl(p.derive(c), s.slice(1), acc + c)
p.canBeEmpty() then new Some(acc)
else new None

can simplify match(All)Impl with ucs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this is also equivalent? oh, but this uses spread

  fun matchImpl(p, s, acc) = if
    p is Nothing then new None
    s is [c, ...] and p.startsWith(c) then matchImpl(p.derive(c), s.slice(1), acc + c)
    p.canBeEmpty() then new Some(acc)
    else new None

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The same suggestions in SimpleRegExp should apply here.

Comment on lines +12 to +14
match(Exact("x"), "x")
//│ = Some("x")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Dupe test case

Suggested change
match(Exact("x"), "x")
//│ = Some("x")

Comment thread hkmc2/shared/src/test/mlscript/block-staging/ShapeProp.mls Outdated
let fullBlk = foldl((acc, e) => concat(acc, e.0))(End(), ...evaledArgs)
let newArgs = evaledArgs.map(e => Arg(if e.1 is Path then e.1 else throw Error("expected path")))
[fullBlk, Call(f, newArgs), mkDyn()] // non staged function and some params unknown
argShapes.every(staticSet) then // non staged function and params known
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This seems to make the sorUnknownCall fallback inside sorStaticModuleCall unreachable.

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.

2 participants