Skip to content
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

Optional args #183

Draft
wants to merge 40 commits into
base: new-definition-typing
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
20d1fa9
adding optional flag to FldFlags
mbroughani81 Sep 11, 2023
0316ade
lexing ? char in args NewLexer
mbroughani81 Sep 12, 2023
3b036b3
show parser debug in test
mbroughani81 Sep 12, 2023
5bd9365
fix in parsing
mbroughani81 Sep 13, 2023
a2ad510
delete redundant prints
mbroughani81 Sep 13, 2023
4e795d2
add opt field in Field node, and parse correctly
mbroughani81 Sep 19, 2023
e6e4ae3
add opt field for FieldType
mbroughani81 Sep 19, 2023
fec99d8
adding opt field for FieldType
mbroughani81 Sep 20, 2023
0a653b2
fix typing of funparams
mbroughani81 Sep 20, 2023
723a9a5
WIP Add helpful test cases
LPTK Sep 22, 2023
5f5fdfd
fix type show
mbroughani81 Sep 23, 2023
d8a8ed4
add subtype check for subtyping with <:<
mbroughani81 Sep 23, 2023
b432dc4
add 2 other field size member checks
mbroughani81 Sep 25, 2023
ed45749
fix problem in field type show
mbroughani81 Sep 26, 2023
ea729b5
add some debugs
mbroughani81 Sep 26, 2023
1819d25
debug the place error happens
mbroughani81 Sep 27, 2023
b924f80
fix operations defined on FieldType
mbroughani81 Sep 28, 2023
6f7a599
Merge branch 'new-definition-typing' into optional-args
mbroughani81 Sep 28, 2023
4a6c2e7
add new require for intersection
mbroughani81 Sep 28, 2023
b81c5b4
Fix minor things in test
mbroughani81 Sep 28, 2023
e511ce1
Add isSubtype for TupleTypes
mbroughani81 Sep 28, 2023
33fc41f
Add error flag for some tests
mbroughani81 Sep 28, 2023
79a51a0
Delete some extra debugs
mbroughani81 Sep 28, 2023
a190864
Delete some extra debugs
mbroughani81 Sep 28, 2023
e882b7c
Delete some extra debugs
mbroughani81 Sep 28, 2023
01ddc66
Fix some possible? bugs
mbroughani81 Sep 28, 2023
8383e09
Delete extra log in DiffTests
mbroughani81 Sep 28, 2023
27bfae9
Fix some possible future? bugs
mbroughani81 Sep 28, 2023
a136b37
Fix some possible future? bugs
mbroughani81 Sep 28, 2023
12b3dc5
Fix some possible future? bugs
mbroughani81 Sep 28, 2023
e2df709
Rename fields compatible checker
mbroughani81 Sep 29, 2023
35442de
Merge branch 'new-definition-typing' into optional-args
mbroughani81 Sep 29, 2023
5c6f3c5
Fix syntax problem in helper
mbroughani81 Sep 29, 2023
a92fc4e
Fix syntax errors
mbroughani81 Sep 29, 2023
0b43e89
Merge branch 'new-definition-typing' into optional-args
LPTK Sep 29, 2023
31b3edd
Add some notes
mbroughani81 Sep 30, 2023
b299e54
Using composed type instead of field opt
mbroughani81 Oct 2, 2023
25d7764
Revert to opt + show bracketed
mbroughani81 Oct 2, 2023
59814ac
.
mbroughani81 Oct 3, 2023
028a5b5
Add ascribing for pattern match on optional fields
mbroughani81 Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions shared/src/main/scala/mlscript/ConstraintSolver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,7 @@ class ConstraintSolver extends NormalForms { self: Typer =>
}


case (TupleType(fs0), TupleType(fs1)) if fs0.sizeCompare(fs1) <= 0 && fs0.sizeCompare(fs1.filter(x => !x._2.opt)) >= 0 => { // TODO[optional-fields] generalize (coerce compatible tuples)
println("case #1")

case (t0 @ TupleType(fs0), t1 @ TupleType(fs1)) if t0.isSubtype(t1) => {
fs0.lazyZip(fs1).foreach { case ((ln, l), (rn, r)) =>
ln.foreach { ln => rn.foreach { rn =>
if (ln =/= rn) err(
Expand Down
1 change: 1 addition & 0 deletions shared/src/main/scala/mlscript/TyperDatatypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ abstract class TyperDatatypes extends TyperHelpers { Typer: Typer =>
fields.map(f => s"${f._1.fold("")(_.name+": ")}${f._2},").mkString(" ")
override def toString = s"($showInner)"
// override def toString = s"(${fields.map(f => s"${f._1.fold("")(_+": ")}${f._2},").mkString(" ")})"
def isSubtype(that: TupleType): Boolean = fields.sizeCompare(that.fields) <= 0 && fields.sizeCompare(that.fields.filter(x => !x._2.opt)) >= 0
mbroughani81 marked this conversation as resolved.
Show resolved Hide resolved
}

case class SpliceType(elems: Ls[Either[SimpleType, FieldType]])(val prov: TypeProvenance) extends ArrayBase {
Expand Down
12 changes: 3 additions & 9 deletions shared/src/main/scala/mlscript/TyperHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,7 @@ abstract class TyperHelpers { Typer: Typer =>
case (RecordType(fs1), RecordType(fs2)) =>
RecordType(mergeSortedMap(fs1, fs2)(_ && _).toList)(prov)
case (t0 @ TupleType(fs0), t1 @ TupleType(fs1)) => {
println("case #2")

// TODO[optional-fields] update this condition
if (fs0.sizeCompare(fs1) > 0 || fs0.sizeCompare(fs1.filter(x => !x._2.opt)) < 0) BotType
if (!t0.isSubtype(t1)) BotType
else TupleType(tupleIntersection(fs0, fs1))(t0.prov)
}
case _ if !swapped => that & (this, prov, swapped = true)
Expand Down Expand Up @@ -491,13 +488,10 @@ abstract class TyperHelpers { Typer: Typer =>
// case (ClassTag(ErrTypeId, _), _) | (_, ClassTag(ErrTypeId, _)) => true
case (_: TypeTag, _: TypeTag) | (_: TV, _: TV) if this === that => true
case (ab: ArrayBase, at: ArrayType) => ab.inner <:< at.inner
case (TupleType(fs1), TupleType(fs2)) => {
// TODO[optional-fields] generalize: handle optionality; eg: [Int] <:< [Int, Int?]
println(s"case #3 ${fs1} ${fs2}")
fs1.sizeCompare(fs2) <= 0 && fs1.sizeCompare(fs2.filter(x => !x._2.opt)) >= 0 && fs1.lazyZip(fs2).forall {
case (t1 @ TupleType(fs1), t2 @ TupleType(fs2)) =>
t1.isSubtype(t2) && fs1.lazyZip(fs2).forall {
case ((_, ty1), (_, ty2)) => ty1 <:< ty2
}
}
case (RecordType(Nil), _) => TopType <:< that
case (_, RecordType(Nil)) => this <:< TopType
case (pt1 @ ClassTag(id1, ps1), pt2 @ ClassTag(id2, ps2)) => (id1 === id2) || pt1.parentsST(id2)
Expand Down