8000 Append by edwardpeters · Pull Request #353 · finos/morphir-scala · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Append #353

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

Merged
merged 35 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
414673b
Incremental
edwardpeters Aug 25, 2023
00d9336
Incremental
edwardpeters Aug 25, 2023
72fac08
Incremental
edwardpeters Aug 25, 2023
4e24ffe
Incremental
edwardpeters Aug 25, 2023
cac65ff
Incremental
edwardpeters Aug 25, 2023
131f663
Incremental
edwardpeters Aug 25, 2023
6bddc0d
Incremental
edwardpeters Aug 25, 2023
6840753
Incremental
edwardpeters Aug 25, 2023
c031f50
Incremental
edwardpeters Aug 25, 2023
a6be1cd
Formatting
edwardpeters Aug 25, 2023
879a283
Incremental
edwardpeters Aug 25, 2023
5fad32f
Formatting
edwardpeters Aug 25, 2023
2157757
Formatting
edwardpeters Aug 25, 2023
47c6fa9
Formatting
edwardpeters Aug 25, 2023
d522fa6
New tests
edwardpeters Aug 25, 2023
46e0160
Incremental
edwardpeters Aug 25, 2023
036c8fa
Test fixes
edwardpeters Aug 25, 2023
cd5d495
Formatting
edwardpeters Aug 25, 2023
ceda6da
Incremental
edwardpeters Aug 25, 2023
f3ab119
Formatting
edwardpeters Aug 25, 2023
4fffef1
Formatting
edwardpeters Aug 25, 2023
8e9a8ea
Formatting
edwardpeters Aug 25, 2023
b26f694
Incremental
edwardpeters Aug 25, 2023
7a70a5f
Merged main
edwardpeters Aug 26, 2023
88a6402
Incremental
edwardpeters Aug 26, 2023
e51d500
Incremental
edwardpeters Aug 26, 2023
43ef247
Incremental
edwardpeters Aug 26, 2023
036f84f
Incremental
edwardpeters Aug 26, 2023
d68950e
Incremental
edwardpeters Aug 26, 2023
01e3345
Incremental
edwardpeters Aug 26, 2023
0cf6dc7
Incremental
edwardpeters Aug 26, 2023
9bb7715
Incremental
edwardpeters Aug 26, 2023
5e496e7
Incremental
edwardpeters Aug 26, 2023
3c7a201
Incremental
edwardpeters Aug 26, 2023
848d9a4
Incremental
edwardpeters Aug 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"src 10000 /Morphir/Examples/App/LambdaTests.elm": "09090aa4162a5142e4b80c9209f0f6c4",
"src/Morphir/Examples/App/LetDefinitionTests.elm": "b8981542e487ee7ade8b90e1e2a6073d",
"src/Morphir/Examples/App/LetRecursionTests.elm": "e66cd3a8d23cc3c5e0e3f65fc21f7618",
"src/Morphir/Examples/App/ListTests.elm": "d583a7b08f0ffa42f7aeb47dcc9f62f2",
"src/Morphir/Examples/App/ListTests.elm": "5ff2ba56f70dcce51789f613422c7037",
"src/Morphir/Examples/App/LiteralTests.elm": "6f06586ae6503c5293c64d16e0360bd3",
"src/Morphir/Examples/App/LocalDateTests.elm": "a77f3af4f0f5e327de55bc8e09bea568",
"src/Morphir/Examples/App/LocalTimeTests.elm": "73b42eb147386ec56135f2902f218995",
Expand All @@ -19,9 +19,10 @@
"src/Morphir/Examples/App/OptionTests.elm": "7be9a6971b4cd70e2f622664ebaf8a16",
"src/Morphir/Examples/App/PatternMatchTests.elm": "2d597bd3d8d6353fe4fc5f4d9b739fca",
"src/Morphir/Examples/App/RecordTests.elm": "bf6e25596923414d93d9bc532f35293e",
"src/Morphir/Examples/App/SdkBasicTests.elm": "b742d59063447516cc851a0b87751e58",
"src/Morphir/Examples/App/SetTests.elm": "72a2dcc13ebc592e3f63c9733e064443",
"src/Morphir/Examples/App/SimpleTests.elm": "f7794a1165f7fe3e5df89b84d0bdbcd8",
"src/Morphir/Examples/App/SkdBasicTests.elm": "930eb32abe511d003720cfaffcc114b0",
"src/Morphir/Examples/App/StringTests.elm": "27820272a720e3091698413c85bedc51",
"src/Morphir/Examples/App/TupleTests.elm": "2c80092fe40ef7666906ee42214376ac",
"src/Morphir/Examples/App/TypeCheckerTests.elm": "6da55ef4bc0d30651b1119c3b84206d2",
"src/Morphir/Examples/App/UserDefinedReferenceTests.elm": "9bf29afa60bad03b200d08ac8f099b99"
Expand Down
929 changes: 929 additions & 0 deletions examples/morphir-elm-projects/evaluator-tests/morphir-ir.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions examples/morphir-elm-projects/evaluator-tests/morphir.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"RecordTests",
"SetTests",
"SimpleTests",
"StringTests",
"TupleTests",
"TypeCheckerTests",
"UserDefinedReferenceTests",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 10000 @@ listMapTest _ =
listMapTest2 : () -> List Bool
listMapTest2 _ =
map not [True,False,True]
--expected = [False,True,False]
--expected = [False,True,False]

listAppend : List a -> List a -> List a
listAppend l r = append l r
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ sdkAppendListTest _ =

-----


{-
Test: SdkBasics/identityInt
Expected: 4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Morphir.Examples.App.StringTests exposing (..)
import String exposing (append)

stringAppend : String -> String -> String
stringAppend l r = append l r
33 changes: 18 additions & 15 deletions morphir/runtime/src/org/finos/morphir/runtime/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,28 @@ object Utils {
// TODO: Move to type checker, or remove altogether
def typeCheckArg(arg: UType, param: UType, found: Map[Name, UType])(
implicit options: RTExecutionContext.Options
): Either[TypeError, Map[Name, UType]] =
): Either[TypeError, Map[Name, UType]] = {
def failIfChecked(error: TypeError): Either[TypeError, Map[Name, UType]] =
options.enableTyper match {
case EnableTyper.Enabled =>
Left(error)
case EnableTyper.Warn =>
println(s"[WARNING] ${error.getMsg}")
Right(found)
case EnableTyper.Disabled =>
Right(found)
}
(arg, param) match {
case (argType, Type.Variable(_, name)) =>
if (found.contains(name) && found(name) != argType) {
Left(InferenceConflict(s"Both ${found(name)} and $argType bound to type variable $name"))
failIfChecked(InferenceConflict(s"Both ${found(name)} and $argType bound to type variable $name"))
} else {
Right(found + (name -> argType))
}
case (l @ LeafType(), r @ LeafType()) if l == r => Right(found)
case (Type.Tuple(_, argElements), Type.Tuple(_, paramElements)) =>
if (argElements.length != paramElements.length) {
Left(new SizeMismatch(
failIfChecked(new SizeMismatch(
argElements.length,
paramElements.length,
s"Different tuple arity between arg $argElements and parameter $paramElements"
Expand All @@ -82,7 +92,7 @@ object Utils {
case (MaybeRef(argElement), MaybeRef(paramElement)) => typeCheckArg(argElement, paramElement, found)
case (Type.Record(_, argFields), Type.Record(_, paramFields)) =>
if (argFields.length != paramFields.length) {
Left(new SizeMismatch(
failIfChecked(new SizeMismatch(
argFields.length,
paramFields.length,
s"Record lengths differ between arg : $argFields and param: $paramFields"
Expand All @@ -99,25 +109,18 @@ object Utils {
paramBindings <- typeCheckArg(argReturn, paramReturn, argBindings)
} yield paramBindings
case (Type.ExtensibleRecord(_, _, _), Type.ExtensibleRecord(_, _, _)) =>
Left(new UnimplementedType(s"Extensible record type not supported (yet)"))
failIfChecked(new UnimplementedType(s"Extensible record type not supported (yet)"))
case (Type.Reference(_, argTypeName, argTypeArgs), Type.Reference(_, paramTypeName, paramTypeArgs))
if (argTypeName == paramTypeName) =>
argTypeArgs.zip(paramTypeArgs).foldLeft(Right(found): Either[TypeError, Map[Name, UType]]) {
case (acc, (argTpe, paramTpe)) =>
acc.flatMap(found => typeCheckArg(argTpe, paramTpe, found))
}
case (otherArg, otherParam) =>
options.enableTyper match {
case EnableTyper.Enabled =>
Left(new UnimplementedType(s"Cannot match $otherArg with $otherParam"))
case EnableTyper.Warn =>
println(s"[WARNING] Cannot match $otherArg with $otherParam")
Right(found)
case EnableTyper.Disabled =>
Right(found)
}

failIfChecked(TypesMismatch(otherArg, otherParam, "Could not match arg to param on entry point"))
}
}

def specificationToType(spec: UValueSpec): UType =
curryTypeFunction(spec.output, spec.inputs)

Expand Down
54 changes: 42 additions & 12 deletions morphir/runtime/src/org/finos/morphir/runtime/quick/Native.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package org.finos.morphir.runtime.quick

import org.finos.morphir.ir.Type
import org.finos.morphir.naming._
import org.finos.morphir.runtime.UnsupportedType

import scala.collection.mutable

object Dict {
object DictSDK {
val fromList: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
1,
(l: Result[Unit, Type.UType]) => {
Expand Down Expand Up @@ -45,8 +46,45 @@ object Dict {
FQName.fromString("Morphir.SDK:Dict:get") -> get
)
}
object ListSDK {
val append: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
2,
(a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) => {
val listA = a.asInstanceOf[Result.ListResult[Unit, Type.UType]]
val listB = b.asInstanceOf[Result.ListResult[Unit, Type.UType]]
Result.ListResult(listA.elements.appendedAll(listB.elements))
}
)

val cons: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
2,
(a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) => {
val listB = b.asInstanceOf[Result.ListResult[Unit, Type.UType]]
Result.ListResult(a :: listB.elements)
}
)
val sdk: Map[FQName, SDKValue[Unit, Type.UType]] = Map(
FQName.fromString("Morphir.SDK:List:append") -> append,
FQName.fromString("Morphir.SDK:List:cons") -> cons
)
}
object BasicsSDK {
val append: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
2,
(a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) =>
(a, b) match {
case (Result.ListResult(aElements), Result.ListResult(bElements)) =>
Result.ListResult(aElements.appendedAll(bElements))
case (Result.Primitive(a: String), Result.Primitive(b: String)) => Result.Primitive(a + b)
case (other1, other2) => throw new UnsupportedType(s"Append called on unrecognized types: $other1, $other2")
}
)
val sdk: Map[FQName, SDKValue[Unit, Type.UType]] = Map(
FQName.fromString("Morphir.SDK:Basics:append") -> append
)

object Set {
}
object SetSDK {
val fromList: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
1,
(l: Result[Unit, Type.UType]) => {
Expand All @@ -60,7 +98,7 @@ object Set {
)
}

object String {
object StringSDK {
val append: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
2,
(a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) =>
Expand Down Expand Up @@ -140,13 +178,6 @@ object Native {
(a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) =>
Result.Primitive(a == b)
)
val cons: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
2,
(a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) => {
val listB = b.asInstanceOf[Result.ListResult[Unit, Type.UType]]
Result.ListResult(a :: listB.elements)
}
)
val concat: SDKValue[Unit, Type.UType] = SDKValue.SDKNativeFunction(
1,
(l: Result[Unit, Type.UType]) => {
Expand Down Expand Up @@ -218,11 +249,10 @@ object Native {
FQName.fromString("Morphir.SDK:Basics:toFloat") -> toFloat,
FQName.fromString("Morphir.SDK:Basics:logBase") -> log,
FQName.fromString("Morphir.SDK:Basics:lessThan") -> lessThan,
FQName.fromString("Morphir.SDK:List:cons") -> cons,
FQName.fromString("Morphir.SDK:List:concat") -> concat,
FQName.fromString("Morphir.SDK:List:map") -> map,
FQName.fromString("Morphir.SDK:LocalDate:fromParts") -> fromParts,
FQName.fromString("Morphir.SDK:LocalTime:fromMilliseconds") -> fromMilliseconds
// FQName.fromString("Morphir.Examples.App:Example:myMap") -> map
) ++ Dict.sdk ++ Set.sdk ++ String.sdk
) ++ DictSDK.sdk ++ SetSDK.sdk ++ StringSDK.sdk ++ ListSDK.sdk ++ BasicsSDK.sdk
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object EvaluatorMDMTests extends MorphirBaseSpec {
def deriveData(input: Any): Data =
input match {
case u: Unit => Deriver.toData(u)
case b: Boolean => Deriver.toData(b)
case i: Int => Deriver.toData(i)
case s: String => Deriver.toData(s)
case ld: java.time.LocalDate => Deriver.toData(ld)
Expand Down Expand Up @@ -87,7 +88,7 @@ object EvaluatorMDMTests extends MorphirBaseSpec {

runtime.evaluate(FQName.fromString(fullName), data.head, data.tail: _*)
.provideEnvironment(MorphirEnv.live)
.toZIOWith(RTExecutionContext.default)
.toZIOWith(RTExecutionContext.typeChecked)
}

val dogRecordConceptRaw = Concept.Struct(
Expand Down Expand Up @@ -382,6 +383,13 @@ object EvaluatorMDMTests extends MorphirBaseSpec {
Data.Decimal(4.0),
Data.Decimal(5.0)
)),
testEvalMultiple("Append (and infer type")(
"ListTests",
"listAppend",
List(List(true, true), List(false, true))
)(
Data.List(Data.True, Data.True, Data.False, Data.True)
),
testEvaluation("Singleton")("listTests", "listSingletonTest")(
Data.List(Data.Int(6))
) @@ ignore @@ TestAspect.tag("Not Implemented yet")
Expand Down Expand Up @@ -502,6 +510,11 @@ object EvaluatorMDMTests extends MorphirBaseSpec {
)
))
),
suite("String")(
testEvalMultiple("String Append")("stringTests", "stringAppend", List(Data.String("Do"), Data.String("Bop")))(
Data.String("DoBop")
)
),
suite("References To user Defined Members")(
testEvaluation("Reference to value")("userDefinedReferenceTests", "userDefinedReferenceValueTest")(Data.Int(5)),
testEvaluation("Curried Function Application")("userDefinedReferenceTests", "userDefinedReferenceCurriedTest")(
Expand Down
10 changes: 8 additions & 2 deletions morphir/src/org/finos/morphir/runtime/RTExecutionContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ object EnableTyper {

final case class RTExecutionContext(options: RTExecutionContext.Options)
object RTExecutionContext {
val default: RTExecutionContext = RTExecutionContext(RTExecutionContext.Options.default)
val default: RTExecutionContext = RTExecutionContext(RTExecutionContext.Options.default)
val typeChecked: RTExecutionContext = default.copy(options = Options.typeChecked)
val typeCheckedWarning: RTExecutionContext = default.copy(options = Options.typeCheckedWarning)
val notTypeChecked: RTExecutionContext = default.copy(options = Options.notTypeChecked)

case class Options(
enableTyper: EnableTyper
)
object Options {
val default: Options = Options(EnableTyper.Enabled)
val default: Options = Options(EnableTyper.Enabled)
val typeChecked: Options = default.copy(enableTyper = EnableTyper.Enabled)
val typeCheckedWarning: Options = default.copy(enableTyper = EnableTyper.Warn)
val notTypeChecked: Options = default.copy(enableTyper = EnableTyper.Disabled)
}
}
0