diff --git a/.gitattributes b/.gitattributes index 40dc003569..92609e3766 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,4 @@ -*Paket.Restore.targets eol=crlf \ No newline at end of file +*Paket.Restore.targets eol=crlf + +backend/serialization/*.bin linguist-generated=true +backend/serialization/*.json linguist-generated=true diff --git a/backend/migrations/20230709_000000_migration.sql b/backend/migrations/20230709_000000_migration.sql index 0337d19689..5b96e687e2 100644 --- a/backend/migrations/20230709_000000_migration.sql +++ b/backend/migrations/20230709_000000_migration.sql @@ -147,7 +147,7 @@ system_migrations_v0 CREATE TYPE toplevel_type AS -ENUM ('handler', 'db', 'user_function', 'user_type', 'user_constant'); +ENUM ('db', 'handler'); CREATE TABLE IF NOT EXISTS toplevels_v0 diff --git a/backend/serialization/toplevels-binary-latest.bin b/backend/serialization/toplevels-binary-latest.bin index ed1a0ce242..e148c2d640 100644 Binary files a/backend/serialization/toplevels-binary-latest.bin and b/backend/serialization/toplevels-binary-latest.bin differ diff --git a/backend/serialization/toplevels-binary-pretty-latest.json b/backend/serialization/toplevels-binary-pretty-latest.json index 917c1a6221..3a8d3feb39 100644 --- a/backend/serialization/toplevels-binary-pretty-latest.json +++ b/backend/serialization/toplevels-binary-pretty-latest.json @@ -1,6 +1,6 @@ [ [ - 0, + 1, [ [ 19930486, @@ -374,9 +374,10 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "owner", [ "Mod" ], @@ -711,11 +712,11 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "dark", [ - "dark", "stdlib" ], "NonEmptyList", @@ -1756,7 +1757,7 @@ ] ], [ - 0, + 1, [ [ 199385766, @@ -2130,9 +2131,10 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "owner", [ "Mod" ], @@ -2467,11 +2469,11 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "dark", [ - "dark", "stdlib" ], "NonEmptyList", @@ -3516,7 +3518,7 @@ ] ], [ - 0, + 1, [ [ 10395769302, @@ -3890,9 +3892,10 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "owner", [ "Mod" ], @@ -4227,11 +4230,11 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "dark", [ - "dark", "stdlib" ], "NonEmptyList", @@ -5272,7 +5275,7 @@ ] ], [ - 0, + 1, [ [ 42280663, @@ -5646,9 +5649,10 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "owner", [ "Mod" ], @@ -5983,11 +5987,11 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "dark", [ - "dark", "stdlib" ], "NonEmptyList", @@ -7029,7 +7033,7 @@ ] ], [ - 1, + 0, [ [ 0, @@ -7148,9 +7152,10 @@ 0, { "ResultValue": [ - 1, + 0, [ [ + "owner", [ "Mod" ], @@ -7226,2279 +7231,5 @@ ] ] ] - ], - [ - 2, - [ - [ - 0, - [ - [], - "user", - 0 - ], - [ - "a" - ], - [ - [ - "myparam1", - [ - 23, - [ - [ - 0, - [] - ], - [ - 10, - [] - ], - [ - [ - 11, - [] - ], - [ - 12, - [] - ], - [ - 1, - [] - ], - [ - 2, - [] - ], - [ - 3, - [] - ], - [ - 4, - [] - ], - [ - 5, - [] - ], - [ - 6, - [] - ], - [ - 7, - [] - ], - [ - 8, - [] - ], - [ - 9, - [] - ], - [ - 13, - [] - ], - [ - 14, - [ - [ - 0, - [] - ] - ] - ], - [ - 23, - [ - [ - 11, - [] - ], - [ - 11, - [] - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 15, - [ - [ - 11, - [] - ] - ] - ], - [ - 16, - [ - [ - 11, - [] - ] - ] - ], - [ - 20, - [ - [ - 0, - { - "ResultValue": [ - 1, - [ - [ - [ - "Mod" - ], - "User", - 0 - ] - ] - ] - } - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 20, - [ - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "dark", - [ - "Mod1", - "Mod2" - ], - "Pack", - 0 - ] - ] - ] - } - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 21, - [ - "test" - ] - ], - [ - 22, - [ - [ - [ - 11, - [] - ], - [] - ], - [ - 11, - [] - ] - ] - ] - ] - ] - ], - "param1" - ], - [] - ], - [ - 23, - [ - [ - 0, - [] - ], - [ - 10, - [] - ], - [ - [ - 11, - [] - ], - [ - 12, - [] - ], - [ - 1, - [] - ], - [ - 2, - [] - ], - [ - 3, - [] - ], - [ - 4, - [] - ], - [ - 5, - [] - ], - [ - 6, - [] - ], - [ - 7, - [] - ], - [ - 8, - [] - ], - [ - 9, - [] - ], - [ - 13, - [] - ], - [ - 14, - [ - [ - 0, - [] - ] - ] - ], - [ - 23, - [ - [ - 11, - [] - ], - [ - 11, - [] - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 15, - [ - [ - 11, - [] - ] - ] - ], - [ - 16, - [ - [ - 11, - [] - ] - ] - ], - [ - 20, - [ - [ - 0, - { - "ResultValue": [ - 1, - [ - [ - [ - "Mod" - ], - "User", - 0 - ] - ] - ] - } - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 20, - [ - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "dark", - [ - "Mod1", - "Mod2" - ], - "Pack", - 0 - ] - ] - ] - } - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 21, - [ - "test" - ] - ], - [ - 22, - [ - [ - [ - 11, - [] - ], - [] - ], - [ - 11, - [] - ] - ] - ] - ] - ] - ], - "function description", - [ - 3, - [ - "some reason" - ] - ], - [ - 16, - [ - 14219007199254740992, - [ - 2, - [ - 189271, - [ - 0, - [ - 18274132, - "x0" - ] - ], - [ - 2, - [ - 189272, - [ - 0, - [ - 18274133, - "x1" - ] - ], - [ - 0, - [ - 27838183, - "x2" - ] - ], - [] - ] - ], - [ - [ - 2, - [ - 189273, - [ - 0, - [ - 18274134, - "x3" - ] - ], - [ - 0, - [ - 27838184, - "x4" - ] - ], - [] - ] - ] - ] - ] - ], - [ - 0, - [ - 929452387, - 5 - ] - ], - [ - 16, - [ - 620028536, - [ - 0, - [ - 5812673123, - "x2" - ] - ], - [ - 0, - [ - 452247642, - 9223372036854775807 - ] - ], - [ - 16, - [ - 68205955, - [ - 0, - [ - 458172, - "bool" - ] - ], - [ - 10, - [ - 43581311, - true - ] - ], - [ - 16, - [ - 755798860, - [ - 0, - [ - 457123, - "bool" - ] - ], - [ - 10, - [ - 97054530, - false - ] - ], - [ - 16, - [ - 244891515, - [ - 0, - [ - 1856712, - "str" - ] - ], - [ - 11, - [ - 446488682, - [ - [ - 0, - [ - "a string" - ] - ], - [ - 1, - [ - [ - 20, - [ - 402203255, - "var" - ] - ] - ] - ] - ] - ] - ], - [ - 16, - [ - 537517627, - [ - 0, - [ - 567161, - "char" - ] - ], - [ - 12, - [ - 1031176330, - "a" - ] - ], - [ - 16, - [ - 399526184, - [ - 0, - [ - 578164, - "float" - ] - ], - [ - 13, - [ - 770715427, - [ - 1, - {} - ], - "6", - "5" - ] - ], - [ - 16, - [ - 975263310, - [ - 0, - [ - 55573, - "n" - ] - ], - [ - 14, - [ - 923644248 - ] - ], - [ - 16, - [ - 43886336, - [ - 0, - [ - 44124, - "i" - ] - ], - [ - 17, - [ - 46231874, - [ - 21, - [ - 898531080, - [ - 31, - [ - 63953, - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "int64ToString", - 0 - ] - ] - ] - } - ] - ] - ], - [ - [ - 23, - [ - [ - 0, - [] - ], - [ - 10, - [] - ], - [ - [ - 11, - [] - ], - [ - 12, - [] - ], - [ - 1, - [] - ], - [ - 2, - [] - ], - [ - 3, - [] - ], - [ - 4, - [] - ], - [ - 5, - [] - ], - [ - 6, - [] - ], - [ - 7, - [] - ], - [ - 8, - [] - ], - [ - 9, - [] - ], - [ - 13, - [] - ], - [ - 14, - [ - [ - 0, - [] - ] - ] - ], - [ - 23, - [ - [ - 11, - [] - ], - [ - 11, - [] - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 15, - [ - [ - 11, - [] - ] - ] - ], - [ - 16, - [ - [ - 11, - [] - ] - ] - ], - [ - 20, - [ - [ - 0, - { - "ResultValue": [ - 1, - [ - [ - [ - "Mod" - ], - "User", - 0 - ] - ] - ] - } - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 20, - [ - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "dark", - [ - "Mod1", - "Mod2" - ], - "Pack", - 0 - ] - ] - ] - } - ], - [ - [ - 11, - [] - ] - ] - ] - ], - [ - 21, - [ - "test" - ] - ], - [ - 22, - [ - [ - [ - 11, - [] - ], - [] - ], - [ - 11, - [] - ] - ] - ] - ] - ] - ] - ], - [ - [ - 0, - [ - 160106123, - 6 - ] - ], - [] - ] - ] - ], - [ - 17, - [ - 729246077, - [ - 29, - [ - 94793109, - [ - 0, - [ - [ - 11, - [] - ] - ] - ], - [ - 0, - [ - 264400705, - 5 - ] - ], - [ - 0, - [ - 335743639, - 6 - ] - ] - ] - ], - [ - 29, - [ - 775118986, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 0, - [ - 803876589, - 5 - ] - ], - [ - 0, - [ - 219131014, - 2 - ] - ] - ] - ], - [ - 18, - [ - 947647446, - [ - [ - 0, - [ - 180359194, - "y" - ] - ], - [] - ], - [ - 29, - [ - 140609068, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 0, - [ - 450951790, - 2 - ] - ], - [ - 20, - [ - 402203255, - "y" - ] - ] - ] - ] - ] - ] - ] - ], - [ - 29, - [ - 265463935, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 29, - [ - 312092282, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 19, - [ - 974664608, - [ - 20, - [ - 1002893266, - "x" - ] - ], - "y" - ] - ], - [ - 21, - [ - 173079901, - [ - 31, - [ - 638434, - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "int64Add", - 0 - ] - ] - ] - } - ] - ] - ], - [], - [ - [ - 0, - [ - 250221144, - 6 - ] - ], - [ - [ - 0, - [ - 298149318, - 2 - ] - ] - ] - ] - ] - ] - ] - ], - [ - 22, - [ - 539797095, - [ - [ - 0, - [ - 267797631, - 5 - ] - ], - [ - 0, - [ - 352138743, - 6 - ] - ], - [ - 0, - [ - 430871955, - 7 - ] - ] - ] - ] - ] - ] - ] - ] - ], - [ - 16, - [ - 831830073, - [ - 0, - [ - 7567123, - "r" - ] - ], - [ - 23, - [ - 109539183, - [ - 0, - { - "ResultValue": [ - 1, - [ - [ - [ - "dark", - "stdlib" - ], - "NonEmptyList", - 0 - ] - ] - ] - } - ], - [ - [ - "field", - [ - 25, - [ - 786862131, - [ - 0, - [ - 555880460, - 5 - ] - ], - [ - [ - 0, - [ - 1021880969, - "fn", - [ - [ - 20, - [ - 962393769, - "x" - ] - ] - ] - ] - ], - [ - 1, - [ - 1021880969, - [ - [ - 0, - [ - 180359194, - "y" - ] - ], - [] - ], - [ - 29, - [ - 140609068, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 0, - [ - 450951790, - 2 - ] - ], - [ - 20, - [ - 402203255, - "y" - ] - ] - ] - ] - ] - ], - [ - 2, - [ - 1021880969, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 0, - [ - 962393769, - 2 - ] - ] - ] - ], - [ - 3, - [ - 1021880969, - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "int64Add", - 0 - ] - ] - ] - } - ], - [], - [ - [ - 0, - [ - 250221144, - 6 - ] - ], - [ - 0, - [ - 298149318, - 2 - ] - ] - ] - ] - ] - ] - ] - ] - ], - [ - "enum", - [ - 26, - [ - 646107057, - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "Darklang", - [ - "Stdlib", - "Result" - ], - "Result", - 0 - ] - ] - ] - } - ], - "Error", - [] - ] - ] - ] - ] - ] - ], - [ - 16, - [ - 1039625813, - [ - 0, - [ - 169324087, - "updatedR" - ] - ], - [ - 24, - [ - 619623640, - [ - 20, - [ - 81036610, - "r" - ] - ], - [ - [ - "field", - [ - 0, - [ - 401690270, - 42 - ] - ] - ], - [] - ] - ] - ], - [ - 16, - [ - 745304029, - [ - 0, - [ - 17461, - "m" - ] - ], - [ - 27, - [ - 889712088, - [ - 21, - [ - 203239466, - [ - 31, - [ - 342954, - [ - 0, - { - "ResultValue": [ - 0, - [ - [ - "modFunction", - 2 - ] - ] - ] - } - ] - ] - ], - [], - [ - [ - 0, - [ - 1015986188, - 5 - ] - ], - [] - ] - ] - ], - [ - [ - [ - 1, - [ - 1015986188, - "Ok", - [ - [ - 0, - [ - 334386852, - "x" - ] - ] - ] - ] - ], - null, - [ - 20, - [ - 863810169, - "v" - ] - ] - ], - [ - [ - 2, - [ - 928253813, - 5 - ] - ], - null, - [ - 0, - [ - 342670561, - -9223372036854775808 - ] - ] - ], - [ - [ - 12, - [ - 435227293, - true - ] - ], - null, - [ - 0, - [ - 232748650, - 7 - ] - ] - ], - [ - [ - 13, - [ - 387662539, - "c" - ] - ], - null, - [ - 12, - [ - 657848009, - "c" - ] - ] - ], - [ - [ - 18, - [ - 387662539, - [ - [ - 12, - [ - 435227293, - true - ] - ] - ] - ] - ], - null, - [ - 22, - [ - 657848009, - [ - [ - 10, - [ - 435227293, - true - ] - ] - ] - ] - ] - ], - [ - [ - 19, - [ - 596996239, - [ - 14, - [ - 949735651, - "val1" - ] - ], - [ - 19, - [ - 580612639, - [ - 14, - [ - 191110189, - "val2" - ] - ], - [ - 18, - [ - 448252771, - [ - [ - 14, - [ - 98945887, - "val3" - ] - ] - ] - ] - ] - ] - ] - ] - ], - null, - [ - 22, - [ - 657848009, - [ - [ - 10, - [ - 435227293, - true - ] - ] - ] - ] - ] - ], - [ - [ - 14, - [ - 491115870, - "string" - ] - ], - null, - [ - 11, - [ - 820329949, - [ - [ - 0, - [ - "string" - ] - ], - [ - 1, - [ - [ - 20, - [ - 1002893266, - "var" - ] - ] - ] - ] - ] - ] - ] - ], - [ - [ - 16, - [ - 701616052 - ] - ], - null, - [ - 14, - [ - 731162955 - ] - ] - ], - [ - [ - 0, - [ - 722099983, - "var" - ] - ], - null, - [ - 29, - [ - 275666765, - [ - 0, - [ - [ - 0, - [] - ] - ] - ], - [ - 0, - [ - 739193732, - 6 - ] - ], - [ - 20, - [ - 880556562, - "var" - ] - ] - ] - ] - ], - [ - [ - 15, - [ - 409097457, - [ - 0, - {} - ], - "5", - "6" - ] - ], - null, - [ - 13, - [ - 131187958, - [ - 0, - {} - ], - "5", - "6" - ] - ] - ], - [ - [ - 17, - [ - 1285610, - [ - 0, - [ - 17823641, - "a" - ] - ], - [ - 0, - [ - 58123641, - "b" - ] - ], - [ - [ - 0, - [ - 95723641, - "c" - ] - ] - ] - ] - ], - null, - [ - 10, - [ - 123716747, - true - ] - ] - ], - [ - [ - 17, - [ - 1285610, - [ - 0, - [ - 17823641, - "a" - ] - ], - [ - 0, - [ - 58123641, - "b" - ] - ], - [ - [ - 0, - [ - 95723641, - "c" - ] - ] - ] - ] - ], - [ - 10, - [ - 123716747, - true - ] - ], - [ - 10, - [ - 123716747, - true - ] - ] - ] - ] - ] - ], - [ - 16, - [ - 927055617, - [ - 0, - [ - 1782674, - "f" - ] - ], - [ - 17, - [ - 882488977, - [ - 10, - [ - 349352147, - true - ] - ], - [ - 0, - [ - 578528886, - 5 - ] - ], - [ - 0, - [ - 562930224, - 6 - ] - ] - ] - ], - [ - 16, - [ - 6345345, - [ - 0, - [ - 17274, - "partials" - ] - ], - [ - 22, - [ - 23423423, - [] - ] - ], - [ - 16, - [ - 883434, - [ - 0, - [ - 12894671, - "tuples" - ] - ], - [ - 28, - [ - 72333, - [ - 0, - [ - 34545, - 5 - ] - ], - [ - 0, - [ - 34545, - 5 - ] - ], - [ - [ - 0, - [ - 34545, - 5 - ] - ] - ] - ] - ], - [ - 16, - [ - 47462, - [ - 0, - [ - 123471, - "binopAnd" - ] - ], - [ - 29, - [ - 234234, - [ - 1, - [ - [ - 0, - [] - ] - ] - ], - [ - 10, - [ - 234234, - true - ] - ], - [ - 10, - [ - 234234, - false - ] - ] - ] - ], - [ - 16, - [ - 831830073, - [ - 0, - [ - 7567123, - "dict" - ] - ], - [ - 30, - [ - 109539183, - [ - [ - "a string", - [ - 0, - [ - 450951790, - 2 - ] - ] - ] - ] - ] - ], - [ - 16, - [ - 831830074, - [ - 0, - [ - 7567124, - "int8" - ] - ], - [ - 2, - [ - 7567124, - 127 - ] - ], - [ - 16, - [ - 831830075, - [ - 0, - [ - 7567125, - "uint8" - ] - ], - [ - 3, - [ - 7567125, - 255 - ] - ], - [ - 16, - [ - 831830076, - [ - 0, - [ - 7567126, - "int16" - ] - ], - [ - 4, - [ - 7567126, - 32767 - ] - ], - [ - 16, - [ - 831830077, - [ - 0, - [ - 7567127, - "uint16" - ] - ], - [ - 5, - [ - 7567128, - 65535 - ] - ], - [ - 16, - [ - 831830078, - [ - 0, - [ - 7567128, - "int32" - ] - ], - [ - 6, - [ - 7567128, - 2147483647 - ] - ], - [ - 16, - [ - 831830079, - [ - 0, - [ - 7567129, - "uint32" - ] - ], - [ - 7, - [ - 7567129, - 4294967295 - ] - ], - [ - 16, - [ - 831830080, - [ - 0, - [ - 7567130, - "int128" - ] - ], - [ - 8, - [ - 7567130, - "////////////////////fw==" - ] - ], - [ - 16, - [ - 831830081, - [ - 0, - [ - 756730, - "uint128" - ] - ], - [ - 9, - [ - 7567130, - "/////////////////////wA=" - ] - ], - [ - 16, - [ - 831830082, - [ - 0, - [ - 756731, - "uint64" - ] - ], - [ - 1, - [ - 7567132, - 18446744073709551615 - ] - ], - [ - 0, - [ - 34545, - 5 - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ] - ], - [ - 4, - [ - [ - 0, - [ - [], - "pi", - 0 - ], - "constant description", - [ - 3, - [ - "some reason" - ] - ], - [ - 15, - [ - [ - 0, - [ - 314 - ] - ], - [ - 10, - [ - true - ] - ], - [ - [ - 11, - [ - "string" - ] - ], - [ - 14, - [] - ], - [ - 13, - [ - [ - 0, - {} - ], - "3", - "14" - ] - ], - [ - 12, - [ - "c" - ] - ], - [ - 14, - [] - ], - [ - 1, - [ - 3 - ] - ], - [ - 2, - [ - 4 - ] - ], - [ - 3, - [ - 3 - ] - ], - [ - 4, - [ - 4 - ] - ], - [ - 5, - [ - 3 - ] - ], - [ - 6, - [ - 4 - ] - ], - [ - 7, - [ - 3 - ] - ], - [ - 8, - [ - "/w==" - ] - ], - [ - 9, - [ - "AQ==" - ] - ] - ] - ] - ] - ] - ] ] ] \ No newline at end of file diff --git a/backend/serialization/vanilla_LibCloud-TraceCloudStorage-CloudStorageFormat_simple.json b/backend/serialization/vanilla_LibCloud-TraceCloudStorage-CloudStorageFormat_simple.json index 8def8d2b43..c03d8a9cdc 100644 --- a/backend/serialization/vanilla_LibCloud-TraceCloudStorage-CloudStorageFormat_simple.json +++ b/backend/serialization/vanilla_LibCloud-TraceCloudStorage-CloudStorageFormat_simple.json @@ -6,8 +6,9 @@ { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -15,8 +16,9 @@ ] }, { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -3642,6 +3644,45 @@ "\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDDB0\u200D\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83D\uDCBB\u200D\u200D" ] }, + "enum": { + "DEnum": [ + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + [], + "String", + [ + { + "DString": [ + "test" + ] + } + ] + ] + }, "escaped": { "DString": [ "\u0014\u0004" @@ -7586,206 +7627,76 @@ "record": { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "Foo", + "name": "Request", "version": 0 } ] }, { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "FooAlias", + "name": "Request", "version": 0 } ] }, [], { - "foo": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record2": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "FooAlias", - "version": 0 - } - ] - }, - [ - { - "Unknown": [] - }, - { - "Known": [ + "body": { + "DList": [ { - "KTBool": [] - } - ] - } - ], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DUnit": [] - } - } - ] - }, - "record3": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DString": [ - "x" - ] - } - } - ] - }, - "record4": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [ - { - "Known": [ - { - "KTBool": [] - } - ] - }, - { - "Known": [ - { - "KTChar": [] - } + "Known": [ + { + "KTUInt8": [] + } + ] + }, + [] ] }, - { - "Known": [ + "headers": { + "DList": [ { - "KTCustomType": [ + "Known": [ { - "UserProgram": [ + "KTTuple": [ { - "modules": [], - "name": "Foo", - "version": 0 - } + "Known": [ + { + "KTString": [] + } + ] + }, + { + "Known": [ + { + "KTString": [] + } + ] + }, + [] ] - }, - [] + } ] - } + }, + [] ] - } - ], - { - "foo\\\\bar": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record5": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "$type": { - "DInt64": [ - 5 + }, + "url": { + "DString": [ + "https://darklang.com" ] } } @@ -7994,12 +7905,13 @@ 7777772986753, "testFn", 2, - "CCTYZMOkcnY", + "n0F0Btndqzc", { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -8007,8 +7919,9 @@ ] }, { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -11634,6 +11547,45 @@ "\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDDB0\u200D\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83D\uDCBB\u200D\u200D" ] }, + "enum": { + "DEnum": [ + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + [], + "String", + [ + { + "DString": [ + "test" + ] + } + ] + ] + }, "escaped": { "DString": [ "\u0014\u0004" @@ -15578,206 +15530,76 @@ "record": { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "Foo", + "name": "Request", "version": 0 } ] }, { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "FooAlias", + "name": "Request", "version": 0 } ] }, [], { - "foo": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record2": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "FooAlias", - "version": 0 - } - ] - }, - [ - { - "Unknown": [] - }, - { - "Known": [ + "body": { + "DList": [ { - "KTBool": [] - } - ] - } - ], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DUnit": [] - } - } - ] - }, - "record3": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DString": [ - "x" - ] - } - } - ] - }, - "record4": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [ - { - "Known": [ - { - "KTBool": [] - } - ] - }, - { - "Known": [ - { - "KTChar": [] - } + "Known": [ + { + "KTUInt8": [] + } + ] + }, + [] ] }, - { - "Known": [ + "headers": { + "DList": [ { - "KTCustomType": [ + "Known": [ { - "UserProgram": [ + "KTTuple": [ { - "modules": [], - "name": "Foo", - "version": 0 - } + "Known": [ + { + "KTString": [] + } + ] + }, + { + "Known": [ + { + "KTString": [] + } + ] + }, + [] ] - }, - [] + } ] - } + }, + [] ] - } - ], - { - "foo\\\\bar": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record5": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "$type": { - "DInt64": [ - 5 + }, + "url": { + "DString": [ + "https://darklang.com" ] } } diff --git a/backend/serialization/vanilla_LibExecution-AnalysisTypes-TraceData_testTraceData.json b/backend/serialization/vanilla_LibExecution-AnalysisTypes-TraceData_testTraceData.json index 1cf6d668f1..b509ecefa2 100644 --- a/backend/serialization/vanilla_LibExecution-AnalysisTypes-TraceData_testTraceData.json +++ b/backend/serialization/vanilla_LibExecution-AnalysisTypes-TraceData_testTraceData.json @@ -5,8 +5,9 @@ { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -14,8 +15,9 @@ ] }, { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -3641,6 +3643,45 @@ "\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDDB0\u200D\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83D\uDCBB\u200D\u200D" ] }, + "enum": { + "DEnum": [ + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + [], + "String", + [ + { + "DString": [ + "test" + ] + } + ] + ] + }, "escaped": { "DString": [ "\u0014\u0004" @@ -7734,206 +7775,76 @@ "record": { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "Foo", + "name": "Request", "version": 0 } ] }, { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "FooAlias", + "name": "Request", "version": 0 } ] }, [], { - "foo": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record2": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "FooAlias", - "version": 0 - } - ] - }, - [ - { - "Unknown": [] - }, - { - "Known": [ + "body": { + "DList": [ { - "KTBool": [] - } - ] - } - ], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DUnit": [] - } - } - ] - }, - "record3": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DString": [ - "x" - ] - } - } - ] - }, - "record4": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [ - { - "Known": [ - { - "KTBool": [] - } - ] - }, - { - "Known": [ - { - "KTChar": [] - } + "Known": [ + { + "KTUInt8": [] + } + ] + }, + [] ] }, - { - "Known": [ + "headers": { + "DList": [ { - "KTCustomType": [ + "Known": [ { - "UserProgram": [ + "KTTuple": [ { - "modules": [], - "name": "Foo", - "version": 0 - } + "Known": [ + { + "KTString": [] + } + ] + }, + { + "Known": [ + { + "KTString": [] + } + ] + }, + [] ] - }, - [] + } ] - } - ] - } - ], - { - "foo\\\\bar": { - "DInt64": [ - 5 + }, + [] ] - } - } - ] - }, - "record5": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "$type": { - "DInt64": [ - 5 + }, + "url": { + "DString": [ + "https://darklang.com" ] } } @@ -8145,8 +8056,9 @@ { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -8154,8 +8066,9 @@ ] }, { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -11781,6 +11694,45 @@ "\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDDB0\u200D\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83D\uDCBB\u200D\u200D" ] }, + "enum": { + "DEnum": [ + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + [], + "String", + [ + { + "DString": [ + "test" + ] + } + ] + ] + }, "escaped": { "DString": [ "\u0014\u0004" @@ -15874,206 +15826,76 @@ "record": { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "Foo", + "name": "Request", "version": 0 } ] }, { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "FooAlias", + "name": "Request", "version": 0 } ] }, [], { - "foo": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record2": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "FooAlias", - "version": 0 - } - ] - }, - [ - { - "Unknown": [] - }, - { - "Known": [ + "body": { + "DList": [ { - "KTBool": [] - } - ] - } - ], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DUnit": [] - } - } - ] - }, - "record3": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DString": [ - "x" - ] - } - } - ] - }, - "record4": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [ - { - "Known": [ - { - "KTBool": [] - } - ] - }, - { - "Known": [ - { - "KTChar": [] - } + "Known": [ + { + "KTUInt8": [] + } + ] + }, + [] ] }, - { - "Known": [ + "headers": { + "DList": [ { - "KTCustomType": [ + "Known": [ { - "UserProgram": [ + "KTTuple": [ { - "modules": [], - "name": "Foo", - "version": 0 - } + "Known": [ + { + "KTString": [] + } + ] + }, + { + "Known": [ + { + "KTString": [] + } + ] + }, + [] ] - }, - [] + } ] - } - ] - } - ], - { - "foo\\\\bar": { - "DInt64": [ - 5 + }, + [] ] - } - } - ] - }, - "record5": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "$type": { - "DInt64": [ - 5 + }, + "url": { + "DString": [ + "https://darklang.com" ] } } diff --git a/backend/serialization/vanilla_LibExecution-DvalReprInternalRoundtrippable-FormatV0-Dval_complete.json b/backend/serialization/vanilla_LibExecution-DvalReprInternalRoundtrippable-FormatV0-Dval_complete.json index 6bbf695995..14bdada246 100644 --- a/backend/serialization/vanilla_LibExecution-DvalReprInternalRoundtrippable-FormatV0-Dval_complete.json +++ b/backend/serialization/vanilla_LibExecution-DvalReprInternalRoundtrippable-FormatV0-Dval_complete.json @@ -1,8 +1,9 @@ { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -10,8 +11,9 @@ ] }, { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [], "name": "MyType", "version": 0 @@ -3637,6 +3639,45 @@ "\uD83E\uDDD1\uD83C\uDFFD\u200D\uD83E\uDDB0\u200D\uD83E\uDDD1\uD83C\uDFFC\u200D\uD83D\uDCBB\u200D\u200D" ] }, + "enum": { + "DEnum": [ + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + { + "Package": [ + { + "owner": "Darklang", + "modules": [ + "Stdlib", + "AltJson" + ], + "name": "Json", + "version": 0 + } + ] + }, + [], + "String", + [ + { + "DString": [ + "test" + ] + } + ] + ] + }, "escaped": { "DString": [ "\u0014\u0004" @@ -7581,206 +7622,76 @@ "record": { "DRecord": [ { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "Foo", + "name": "Request", "version": 0 } ] }, { - "UserProgram": [ + "Package": [ { + "owner": "Darklang", "modules": [ - "Two", - "Modules" + "Stdlib", + "Http" ], - "name": "FooAlias", + "name": "Request", "version": 0 } ] }, [], { - "foo": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record2": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "FooAlias", - "version": 0 - } - ] - }, - [ - { - "Unknown": [] - }, - { - "Known": [ + "body": { + "DList": [ { - "KTBool": [] - } - ] - } - ], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DUnit": [] - } - } - ] - }, - "record3": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "type": { - "DString": [ - "weird" - ] - }, - "value": { - "DString": [ - "x" - ] - } - } - ] - }, - "record4": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [ - { - "Known": [ - { - "KTBool": [] - } - ] - }, - { - "Known": [ - { - "KTChar": [] - } + "Known": [ + { + "KTUInt8": [] + } + ] + }, + [] ] }, - { - "Known": [ + "headers": { + "DList": [ { - "KTCustomType": [ + "Known": [ { - "UserProgram": [ + "KTTuple": [ { - "modules": [], - "name": "Foo", - "version": 0 - } + "Known": [ + { + "KTString": [] + } + ] + }, + { + "Known": [ + { + "KTString": [] + } + ] + }, + [] ] - }, - [] + } ] - } + }, + [] ] - } - ], - { - "foo\\\\bar": { - "DInt64": [ - 5 - ] - } - } - ] - }, - "record5": { - "DRecord": [ - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - { - "UserProgram": [ - { - "modules": [], - "name": "Foo", - "version": 0 - } - ] - }, - [], - { - "$type": { - "DInt64": [ - 5 + }, + "url": { + "DString": [ + "https://darklang.com" ] } } diff --git a/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageConstant-T_constant.json b/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageConstant-T_constant.json new file mode 100644 index 0000000000..623e1e6e22 --- /dev/null +++ b/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageConstant-T_constant.json @@ -0,0 +1,104 @@ +{ + "tlid": 777777928475, + "id": "31d72f73-0f99-5a9b-949c-b95705ae7c4d", + "name": { + "owner": "dark", + "modules": [ + "stdlib", + "Int64", + "Int64" + ], + "name": "testConstant", + "version": 0 + }, + "description": "test", + "deprecated": { + "NotDeprecated": [] + }, + "body": { + "CTuple": [ + { + "CInt64": [ + 314 + ] + }, + { + "CBool": [ + true + ] + }, + [ + { + "CString": [ + "string" + ] + }, + { + "CUnit": [] + }, + { + "CFloat": [ + { + "Positive": [] + }, + "3", + "14" + ] + }, + { + "CChar": [ + "c" + ] + }, + { + "CUnit": [] + }, + { + "CUInt64": [ + 3 + ] + }, + { + "CInt8": [ + 4 + ] + }, + { + "CUInt8": [ + 3 + ] + }, + { + "CInt16": [ + 4 + ] + }, + { + "CUInt16": [ + 3 + ] + }, + { + "CInt32": [ + 4 + ] + }, + { + "CUInt32": [ + 3 + ] + }, + { + "CInt128": [ + "-1" + ] + }, + { + "CUInt128": [ + "1" + ] + } + ] + ] + } +} \ No newline at end of file diff --git a/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_function.json b/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageFn-T_function.json similarity index 57% rename from backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_function.json rename to backend/serialization/vanilla_LibExecution-ProgramTypes-PackageFn-T_function.json index c6d95f205c..7834d77f3f 100644 --- a/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_function.json +++ b/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageFn-T_function.json @@ -1,805 +1,503 @@ { - "TLFunction": [ - { - "tlid": 0, - "name": { - "modules": [], - "name": "user", - "version": 0 - }, - "typeParams": [ - "a" - ], - "parameters": [ - { - "name": "myparam1", - "typ": { - "TTuple": [ + "tlid": 777777928475, + "id": "31d72f73-0f99-5a9b-949c-b95705ae7c4d", + "name": { + "owner": "dark", + "modules": [ + "stdlib", + "Int64", + "Int64" + ], + "name": "mod", + "version": 0 + }, + "body": { + "ELet": [ + "14219007199254740992", + { + "LPTuple": [ + 189271, + { + "LPVariable": [ + 18274132, + "x0" + ] + }, + { + "LPTuple": [ + 189272, { - "TInt64": [] + "LPVariable": [ + 18274133, + "x1" + ] }, { - "TFloat": [] + "LPVariable": [ + 27838183, + "x2" + ] }, - [ - { - "TBool": [] - }, - { - "TUnit": [] - }, - { - "TUInt64": [] - }, - { - "TInt8": [] - }, - { - "TUInt8": [] - }, - { - "TInt16": [] - }, - { - "TUInt16": [] - }, - { - "TInt32": [] - }, - { - "TUInt32": [] - }, - { - "TInt128": [] - }, - { - "TUInt128": [] - }, - { - "TString": [] - }, - { - "TList": [ - { - "TInt64": [] - } - ] - }, - { - "TTuple": [ - { - "TBool": [] - }, - { - "TBool": [] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TDict": [ - { - "TBool": [] - } - ] - }, - { - "TDB": [ - { - "TBool": [] - } - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "UserProgram": [ - { - "modules": [ - "Mod" - ], - "name": "User", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "Package": [ - { - "owner": "dark", - "modules": [ - "Mod1", - "Mod2" - ], - "name": "Pack", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TVariable": [ - "test" - ] - }, - { - "TFn": [ - [ - { - "TBool": [] - } - ], - { - "TBool": [] - } - ] - } - ] + [] ] }, - "description": "param1" - } - ], - "returnType": { - "TTuple": [ - { - "TInt64": [] - }, - { - "TFloat": [] - }, [ { - "TBool": [] - }, - { - "TUnit": [] - }, - { - "TUInt64": [] - }, - { - "TInt8": [] - }, - { - "TUInt8": [] - }, - { - "TInt16": [] - }, - { - "TUInt16": [] - }, - { - "TInt32": [] - }, - { - "TUInt32": [] - }, - { - "TInt128": [] - }, - { - "TUInt128": [] - }, - { - "TString": [] - }, - { - "TList": [ - { - "TInt64": [] - } - ] - }, - { - "TTuple": [ - { - "TBool": [] - }, - { - "TBool": [] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TDict": [ - { - "TBool": [] - } - ] - }, - { - "TDB": [ - { - "TBool": [] - } - ] - }, - { - "TCustomType": [ + "LPTuple": [ + 189273, { - "Ok": [ - { - "UserProgram": [ - { - "modules": [ - "Mod" - ], - "name": "User", - "version": 0 - } - ] - } + "LPVariable": [ + 18274134, + "x3" ] }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TCustomType": [ { - "Ok": [ - { - "Package": [ - { - "owner": "dark", - "modules": [ - "Mod1", - "Mod2" - ], - "name": "Pack", - "version": 0 - } - ] - } + "LPVariable": [ + 27838184, + "x4" ] }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TVariable": [ - "test" - ] - }, - { - "TFn": [ - [ - { - "TBool": [] - } - ], - { - "TBool": [] - } + [] ] } ] ] }, - "description": "function description", - "deprecated": { - "DeprecatedBecause": [ - "some reason" + { + "EInt64": [ + 929452387, + 5 ] }, - "body": { + { "ELet": [ - "14219007199254740992", + 620028536, { - "LPTuple": [ - 189271, - { - "LPVariable": [ - 18274132, - "x0" - ] - }, - { - "LPTuple": [ - 189272, - { - "LPVariable": [ - 18274133, - "x1" - ] - }, - { - "LPVariable": [ - 27838183, - "x2" - ] - }, - [] - ] - }, - [ - { - "LPTuple": [ - 189273, - { - "LPVariable": [ - 18274134, - "x3" - ] - }, - { - "LPVariable": [ - 27838184, - "x4" - ] - }, - [] - ] - } - ] + "LPVariable": [ + 5812673123, + "x2" ] }, { "EInt64": [ - 929452387, - 5 + 452247642, + "9223372036854775807" ] }, { "ELet": [ - 620028536, + 68205955, { "LPVariable": [ - 5812673123, - "x2" + 458172, + "bool" ] }, { - "EInt64": [ - 452247642, - "9223372036854775807" + "EBool": [ + 43581311, + true ] }, { "ELet": [ - 68205955, + 755798860, { "LPVariable": [ - 458172, + 457123, "bool" ] }, { "EBool": [ - 43581311, - true + 97054530, + false ] }, { "ELet": [ - 755798860, + 244891515, { "LPVariable": [ - 457123, - "bool" + 1856712, + "str" ] }, { - "EBool": [ - 97054530, - false + "EString": [ + 446488682, + [ + { + "StringText": [ + "a string" + ] + }, + { + "StringInterpolation": [ + { + "EVariable": [ + 402203255, + "var" + ] + } + ] + } + ] ] }, { "ELet": [ - 244891515, + 537517627, { "LPVariable": [ - 1856712, - "str" + 567161, + "char" ] }, { - "EString": [ - 446488682, - [ - { - "StringText": [ - "a string" - ] - }, - { - "StringInterpolation": [ - { - "EVariable": [ - 402203255, - "var" - ] - } - ] - } - ] + "EChar": [ + 1031176330, + "a" ] }, { "ELet": [ - 537517627, + 399526184, { "LPVariable": [ - 567161, - "char" + 578164, + "float" ] }, { - "EChar": [ - 1031176330, - "a" + "EFloat": [ + 770715427, + { + "Negative": [] + }, + "6", + "5" ] }, { "ELet": [ - 399526184, + 975263310, { "LPVariable": [ - 578164, - "float" + 55573, + "n" ] }, { - "EFloat": [ - 770715427, - { - "Negative": [] - }, - "6", - "5" + "EUnit": [ + 923644248 ] }, { "ELet": [ - 975263310, + 43886336, { "LPVariable": [ - 55573, - "n" - ] - }, - { - "EUnit": [ - 923644248 + 44124, + "i" ] }, { - "ELet": [ - 43886336, + "EIf": [ + 46231874, { - "LPVariable": [ - 44124, - "i" - ] - }, - { - "EIf": [ - 46231874, + "EApply": [ + 898531080, { - "EApply": [ - 898531080, + "EFnName": [ + 63953, { - "EFnName": [ - 63953, + "Ok": [ { - "Ok": [ + "Builtin": [ { - "Builtin": [ - { - "name": "int64ToString", - "version": 0 - } - ] + "name": "int64ToString", + "version": 0 } ] } ] - }, - [ + } + ] + }, + [ + { + "TTuple": [ { - "TTuple": [ - { - "TInt64": [] - }, - { - "TFloat": [] - }, - [ - { - "TBool": [] - }, - { - "TUnit": [] - }, - { - "TUInt64": [] - }, - { - "TInt8": [] - }, - { - "TUInt8": [] - }, - { - "TInt16": [] - }, - { - "TUInt16": [] - }, - { - "TInt32": [] - }, - { - "TUInt32": [] - }, - { - "TInt128": [] - }, - { - "TUInt128": [] - }, - { - "TString": [] - }, + "TInt64": [] + }, + { + "TFloat": [] + }, + [ + { + "TBool": [] + }, + { + "TUnit": [] + }, + { + "TUInt64": [] + }, + { + "TInt8": [] + }, + { + "TUInt8": [] + }, + { + "TInt16": [] + }, + { + "TUInt16": [] + }, + { + "TInt32": [] + }, + { + "TUInt32": [] + }, + { + "TInt128": [] + }, + { + "TUInt128": [] + }, + { + "TString": [] + }, + { + "TList": [ { - "TList": [ - { - "TInt64": [] - } - ] - }, + "TInt64": [] + } + ] + }, + { + "TTuple": [ { - "TTuple": [ - { - "TBool": [] - }, - { - "TBool": [] - }, - [ - { - "TBool": [] - } - ] - ] + "TBool": [] }, { - "TDict": [ - { - "TBool": [] - } - ] + "TBool": [] }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TDict": [ { - "TDB": [ - { - "TBool": [] - } - ] - }, + "TBool": [] + } + ] + }, + { + "TDB": [ + { + "TBool": [] + } + ] + }, + { + "TCustomType": [ { - "TCustomType": [ + "Ok": [ { - "Ok": [ + "Package": [ { - "UserProgram": [ - { - "modules": [ - "Mod" - ], - "name": "User", - "version": 0 - } - ] + "owner": "owner", + "modules": [ + "Mod" + ], + "name": "User", + "version": 0 } ] - }, - [ - { - "TBool": [] - } - ] + } ] }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TCustomType": [ { - "TCustomType": [ + "Ok": [ { - "Ok": [ + "Package": [ { - "Package": [ - { - "owner": "dark", - "modules": [ - "Mod1", - "Mod2" - ], - "name": "Pack", - "version": 0 - } - ] + "owner": "dark", + "modules": [ + "Mod1", + "Mod2" + ], + "name": "Pack", + "version": 0 } ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TVariable": [ - "test" - ] - }, - { - "TFn": [ - [ - { - "TBool": [] - } - ], - { - "TBool": [] } ] - } - ] - ] - } - ], - [ - { - "EInt64": [ - 160106123, - 6 - ] - } - ] - ] - }, - { - "EIf": [ - 729246077, - { - "EInfix": [ - 94793109, - { - "InfixFnCall": [ - { - "ComparisonNotEquals": [] - } + }, + [ + { + "TBool": [] + } + ] ] }, { - "EInt64": [ - 264400705, - 5 + "TVariable": [ + "test" ] }, { - "EInt64": [ - 335743639, - 6 + "TFn": [ + [ + { + "TBool": [] + } + ], + { + "TBool": [] + } ] } ] - }, + ] + } + ], + [ + { + "EInt64": [ + 160106123, + 6 + ] + } + ] + ] + }, + { + "EIf": [ + 729246077, + { + "EInfix": [ + 94793109, { - "EInfix": [ - 775118986, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, + "InfixFnCall": [ { - "EInt64": [ - 803876589, - 5 - ] - }, + "ComparisonNotEquals": [] + } + ] + }, + { + "EInt64": [ + 264400705, + 5 + ] + }, + { + "EInt64": [ + 335743639, + 6 + ] + } + ] + }, + { + "EInfix": [ + 775118986, + { + "InfixFnCall": [ { - "EInt64": [ - 219131014, - 2 - ] + "ArithmeticPlus": [] } ] }, { - "Some": [ + "EInt64": [ + 803876589, + 5 + ] + }, + { + "EInt64": [ + 219131014, + 2 + ] + } + ] + }, + { + "Some": [ + { + "ELambda": [ + 947647446, + [ + { + "LPVariable": [ + 180359194, + "y" + ] + } + ], { - "ELambda": [ - 947647446, - [ - { - "LPVariable": [ - 180359194, - "y" - ] - } - ], + "EInfix": [ + 140609068, { - "EInfix": [ - 140609068, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 450951790, - 2 - ] - }, + "InfixFnCall": [ { - "EVariable": [ - 402203255, - "y" - ] + "ArithmeticPlus": [] } ] + }, + { + "EInt64": [ + 450951790, + 2 + ] + }, + { + "EVariable": [ + 402203255, + "y" + ] } ] } ] } ] - }, + } + ] + }, + { + "Some": [ { - "Some": [ + "EInfix": [ + 265463935, + { + "InfixFnCall": [ + { + "ArithmeticPlus": [] + } + ] + }, { "EInfix": [ - 265463935, + 312092282, { "InfixFnCall": [ { @@ -808,192 +506,156 @@ ] }, { - "EInfix": [ - 312092282, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, + "EFieldAccess": [ + 974664608, { - "EFieldAccess": [ - 974664608, - { - "EVariable": [ - 1002893266, - "x" - ] - }, - "y" + "EVariable": [ + 1002893266, + "x" ] }, + "y" + ] + }, + { + "EApply": [ + 173079901, { - "EApply": [ - 173079901, + "EFnName": [ + 638434, { - "EFnName": [ - 638434, + "Ok": [ { - "Ok": [ + "Builtin": [ { - "Builtin": [ - { - "name": "int64Add", - "version": 0 - } - ] + "name": "int64Add", + "version": 0 } ] } ] - }, - [], - [ - { - "EInt64": [ - 250221144, - 6 - ] - }, - { - "EInt64": [ - 298149318, - 2 - ] - } - ] + } ] - } - ] - }, - { - "EList": [ - 539797095, + }, + [], [ { "EInt64": [ - 267797631, - 5 - ] - }, - { - "EInt64": [ - 352138743, + 250221144, 6 ] }, { "EInt64": [ - 430871955, - 7 + 298149318, + 2 ] } ] ] } ] + }, + { + "EList": [ + 539797095, + [ + { + "EInt64": [ + 267797631, + 5 + ] + }, + { + "EInt64": [ + 352138743, + 6 + ] + }, + { + "EInt64": [ + 430871955, + 7 + ] + } + ] + ] } ] } ] + } + ] + }, + { + "ELet": [ + 831830073, + { + "LPVariable": [ + 7567123, + "r" + ] }, { - "ELet": [ - 831830073, - { - "LPVariable": [ - 7567123, - "r" - ] - }, + "ERecord": [ + 109539183, { - "ERecord": [ - 109539183, + "Ok": [ { - "Ok": [ + "Package": [ { - "UserProgram": [ - { - "modules": [ - "dark", - "stdlib" - ], - "name": "NonEmptyList", - "version": 0 - } - ] + "owner": "dark", + "modules": [ + "stdlib" + ], + "name": "NonEmptyList", + "version": 0 } ] - }, - [ - [ - "field", + } + ] + }, + [ + [ + "field", + { + "EPipe": [ + 786862131, { - "EPipe": [ - 786862131, - { - "EInt64": [ - 555880460, - 5 + "EInt64": [ + 555880460, + 5 + ] + }, + [ + { + "EPipeVariable": [ + 1021880969, + "fn", + [ + { + "EVariable": [ + 962393769, + "x" + ] + } ] - }, - [ - { - "EPipeVariable": [ - 1021880969, - "fn", - [ - { - "EVariable": [ - 962393769, - "x" - ] - } + ] + }, + { + "EPipeLambda": [ + 1021880969, + [ + { + "LPVariable": [ + 180359194, + "y" ] - ] - }, - { - "EPipeLambda": [ - 1021880969, - [ - { - "LPVariable": [ - 180359194, - "y" - ] - } - ], - { - "EInfix": [ - 140609068, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 450951790, - 2 - ] - }, - { - "EVariable": [ - 402203255, - "y" - ] - } - ] - } - ] - }, + } + ], { - "EPipeInfix": [ - 1021880969, + "EInfix": [ + 140609068, { "InfixFnCall": [ { @@ -1003,765 +665,789 @@ }, { "EInt64": [ - 962393769, + 450951790, 2 ] + }, + { + "EVariable": [ + 402203255, + "y" + ] + } + ] + } + ] + }, + { + "EPipeInfix": [ + 1021880969, + { + "InfixFnCall": [ + { + "ArithmeticPlus": [] } ] }, { - "EPipeFnCall": [ - 1021880969, + "EInt64": [ + 962393769, + 2 + ] + } + ] + }, + { + "EPipeFnCall": [ + 1021880969, + { + "Ok": [ { - "Ok": [ + "Builtin": [ { - "Builtin": [ - { - "name": "int64Add", - "version": 0 - } - ] + "name": "int64Add", + "version": 0 } ] - }, - [], - [ - { - "EInt64": [ - 250221144, - 6 - ] - }, - { - "EInt64": [ - 298149318, - 2 - ] - } - ] + } ] - } + }, + [], + [ + { + "EInt64": [ + 250221144, + 6 + ] + }, + { + "EInt64": [ + 298149318, + 2 + ] + } + ] ] - ] - } - ], - [ - "enum", + } + ] + ] + } + ], + [ + "enum", + { + "EEnum": [ + 646107057, { - "EEnum": [ - 646107057, + "Ok": [ { - "Ok": [ + "Package": [ { - "Package": [ - { - "owner": "Darklang", - "modules": [ - "Stdlib", - "Result" - ], - "name": "Result", - "version": 0 - } - ] + "owner": "Darklang", + "modules": [ + "Stdlib", + "Result" + ], + "name": "Result", + "version": 0 } ] - }, - "Error", - [] + } ] - } + }, + "Error", + [] ] - ] + } + ] + ] + ] + }, + { + "ELet": [ + 1039625813, + { + "LPVariable": [ + 169324087, + "updatedR" ] }, { - "ELet": [ - 1039625813, + "ERecordUpdate": [ + 619623640, { - "LPVariable": [ - 169324087, - "updatedR" + "EVariable": [ + 81036610, + "r" ] }, - { - "ERecordUpdate": [ - 619623640, + [ + [ + "field", { - "EVariable": [ - 81036610, - "r" - ] - }, - [ - [ - "field", - { - "EInt64": [ - 401690270, - 42 - ] - } + "EInt64": [ + 401690270, + 42 ] - ] + } + ] + ] + ] + }, + { + "ELet": [ + 745304029, + { + "LPVariable": [ + 17461, + "m" ] }, { - "ELet": [ - 745304029, - { - "LPVariable": [ - 17461, - "m" - ] - }, + "EMatch": [ + 889712088, { - "EMatch": [ - 889712088, + "EApply": [ + 203239466, { - "EApply": [ - 203239466, + "EFnName": [ + 342954, { - "EFnName": [ - 342954, + "Ok": [ { - "Ok": [ + "Builtin": [ { - "Builtin": [ - { - "name": "modFunction", - "version": 2 - } - ] + "name": "modFunction", + "version": 2 } ] } ] - }, - [], + } + ] + }, + [], + [ + { + "EInt64": [ + 1015986188, + 5 + ] + } + ] + ] + }, + [ + { + "pat": { + "MPEnum": [ + 1015986188, + "Ok", [ { - "EInt64": [ - 1015986188, - 5 + "MPVariable": [ + 334386852, + "x" ] } ] ] }, - [ - { - "pat": { - "MPEnum": [ - 1015986188, - "Ok", - [ - { - "MPVariable": [ - 334386852, - "x" - ] - } + "whenCondition": null, + "rhs": { + "EVariable": [ + 863810169, + "v" + ] + } + }, + { + "pat": { + "MPInt64": [ + 928253813, + 5 + ] + }, + "whenCondition": null, + "rhs": { + "EInt64": [ + 342670561, + "-9223372036854775808" + ] + } + }, + { + "pat": { + "MPBool": [ + 435227293, + true + ] + }, + "whenCondition": null, + "rhs": { + "EInt64": [ + 232748650, + 7 + ] + } + }, + { + "pat": { + "MPChar": [ + 387662539, + "c" + ] + }, + "whenCondition": null, + "rhs": { + "EChar": [ + 657848009, + "c" + ] + } + }, + { + "pat": { + "MPList": [ + 387662539, + [ + { + "MPBool": [ + 435227293, + true ] - ] - }, - "whenCondition": null, - "rhs": { - "EVariable": [ - 863810169, - "v" - ] - } - }, - { - "pat": { - "MPInt64": [ - 928253813, - 5 - ] - }, - "whenCondition": null, - "rhs": { - "EInt64": [ - 342670561, - "-9223372036854775808" - ] - } - }, - { - "pat": { - "MPBool": [ - 435227293, - true - ] - }, - "whenCondition": null, - "rhs": { - "EInt64": [ - 232748650, - 7 - ] - } - }, - { - "pat": { - "MPChar": [ - 387662539, - "c" - ] - }, - "whenCondition": null, - "rhs": { - "EChar": [ - 657848009, - "c" - ] - } - }, - { - "pat": { - "MPList": [ - 387662539, - [ - { - "MPBool": [ - 435227293, - true - ] - } + } + ] + ] + }, + "whenCondition": null, + "rhs": { + "EList": [ + 657848009, + [ + { + "EBool": [ + 435227293, + true ] + } + ] + ] + } + }, + { + "pat": { + "MPListCons": [ + 596996239, + { + "MPString": [ + 949735651, + "val1" ] }, - "whenCondition": null, - "rhs": { - "EList": [ - 657848009, - [ - { - "EBool": [ - 435227293, - true - ] - } - ] - ] - } - }, - { - "pat": { + { "MPListCons": [ - 596996239, + 580612639, { "MPString": [ - 949735651, - "val1" + 191110189, + "val2" ] }, { - "MPListCons": [ - 580612639, - { - "MPString": [ - 191110189, - "val2" - ] - }, - { - "MPList": [ - 448252771, - [ - { - "MPString": [ - 98945887, - "val3" - ] - } + "MPList": [ + 448252771, + [ + { + "MPString": [ + 98945887, + "val3" ] - ] - } + } + ] ] } ] - }, - "whenCondition": null, - "rhs": { - "EList": [ - 657848009, - [ - { - "EBool": [ - 435227293, - true - ] - } - ] - ] } - }, - { - "pat": { - "MPString": [ - 491115870, - "string" - ] - }, - "whenCondition": null, - "rhs": { - "EString": [ - 820329949, - [ - { - "StringText": [ - "string" - ] - }, + ] + }, + "whenCondition": null, + "rhs": { + "EList": [ + 657848009, + [ + { + "EBool": [ + 435227293, + true + ] + } + ] + ] + } + }, + { + "pat": { + "MPString": [ + 491115870, + "string" + ] + }, + "whenCondition": null, + "rhs": { + "EString": [ + 820329949, + [ + { + "StringText": [ + "string" + ] + }, + { + "StringInterpolation": [ { - "StringInterpolation": [ - { - "EVariable": [ - 1002893266, - "var" - ] - } + "EVariable": [ + 1002893266, + "var" ] } ] - ] - } - }, - { - "pat": { - "MPUnit": [ - 701616052 - ] - }, - "whenCondition": null, - "rhs": { - "EUnit": [ - 731162955 - ] - } - }, - { - "pat": { - "MPVariable": [ - 722099983, - "var" - ] - }, - "whenCondition": null, - "rhs": { - "EInfix": [ - 275666765, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 739193732, - 6 - ] - }, + } + ] + ] + } + }, + { + "pat": { + "MPUnit": [ + 701616052 + ] + }, + "whenCondition": null, + "rhs": { + "EUnit": [ + 731162955 + ] + } + }, + { + "pat": { + "MPVariable": [ + 722099983, + "var" + ] + }, + "whenCondition": null, + "rhs": { + "EInfix": [ + 275666765, + { + "InfixFnCall": [ { - "EVariable": [ - 880556562, - "var" - ] + "ArithmeticPlus": [] } ] - } - }, - { - "pat": { - "MPFloat": [ - 409097457, - { - "Positive": [] - }, - "5", - "6" + }, + { + "EInt64": [ + 739193732, + 6 ] }, - "whenCondition": null, - "rhs": { - "EFloat": [ - 131187958, - { - "Positive": [] - }, - "5", - "6" + { + "EVariable": [ + 880556562, + "var" ] } - }, - { - "pat": { - "MPTuple": [ - 1285610, - { - "MPVariable": [ - 17823641, - "a" - ] - }, - { - "MPVariable": [ - 58123641, - "b" - ] - }, - [ - { - "MPVariable": [ - 95723641, - "c" - ] - } - ] + ] + } + }, + { + "pat": { + "MPFloat": [ + 409097457, + { + "Positive": [] + }, + "5", + "6" + ] + }, + "whenCondition": null, + "rhs": { + "EFloat": [ + 131187958, + { + "Positive": [] + }, + "5", + "6" + ] + } + }, + { + "pat": { + "MPTuple": [ + 1285610, + { + "MPVariable": [ + 17823641, + "a" ] }, - "whenCondition": null, - "rhs": { - "EBool": [ - 123716747, - true + { + "MPVariable": [ + 58123641, + "b" ] - } - }, - { - "pat": { - "MPTuple": [ - 1285610, - { - "MPVariable": [ - 17823641, - "a" - ] - }, - { - "MPVariable": [ - 58123641, - "b" - ] - }, - [ - { - "MPVariable": [ - 95723641, - "c" - ] - } + }, + [ + { + "MPVariable": [ + 95723641, + "c" ] + } + ] + ] + }, + "whenCondition": null, + "rhs": { + "EBool": [ + 123716747, + true + ] + } + }, + { + "pat": { + "MPTuple": [ + 1285610, + { + "MPVariable": [ + 17823641, + "a" ] }, - "whenCondition": { - "Some": [ - { - "EBool": [ - 123716747, - true - ] - } + { + "MPVariable": [ + 58123641, + "b" ] }, - "rhs": { + [ + { + "MPVariable": [ + 95723641, + "c" + ] + } + ] + ] + }, + "whenCondition": { + "Some": [ + { "EBool": [ 123716747, true ] } - } - ] + ] + }, + "rhs": { + "EBool": [ + 123716747, + true + ] + } + } + ] + ] + }, + { + "ELet": [ + 927055617, + { + "LPVariable": [ + 1782674, + "f" ] }, { - "ELet": [ - 927055617, + "EIf": [ + 882488977, { - "LPVariable": [ - 1782674, - "f" + "EBool": [ + 349352147, + true ] }, { - "EIf": [ - 882488977, - { - "EBool": [ - 349352147, - true - ] - }, + "EInt64": [ + 578528886, + 5 + ] + }, + { + "Some": [ { "EInt64": [ - 578528886, - 5 - ] - }, - { - "Some": [ - { - "EInt64": [ - 562930224, - 6 - ] - } + 562930224, + 6 ] } ] + } + ] + }, + { + "ELet": [ + 6345345, + { + "LPVariable": [ + 17274, + "partials" + ] + }, + { + "EList": [ + 23423423, + [] + ] }, { "ELet": [ - 6345345, + 883434, { "LPVariable": [ - 17274, - "partials" + 12894671, + "tuples" ] }, { - "EList": [ - 23423423, - [] + "ETuple": [ + 72333, + { + "EInt64": [ + 34545, + 5 + ] + }, + { + "EInt64": [ + 34545, + 5 + ] + }, + [ + { + "EInt64": [ + 34545, + 5 + ] + } + ] ] }, { "ELet": [ - 883434, + 47462, { "LPVariable": [ - 12894671, - "tuples" + 123471, + "binopAnd" ] }, { - "ETuple": [ - 72333, + "EInfix": [ + 234234, { - "EInt64": [ - 34545, - 5 + "BinOp": [ + { + "BinOpAnd": [] + } ] }, { - "EInt64": [ - 34545, - 5 + "EBool": [ + 234234, + true ] }, - [ - { - "EInt64": [ - 34545, - 5 - ] - } - ] + { + "EBool": [ + 234234, + false + ] + } ] }, { "ELet": [ - 47462, + 831830073, { "LPVariable": [ - 123471, - "binopAnd" + 7567123, + "dict" ] }, { - "EInfix": [ - 234234, - { - "BinOp": [ + "EDict": [ + 109539183, + [ + [ + "a string", { - "BinOpAnd": [] + "EInt64": [ + 450951790, + 2 + ] } ] - }, - { - "EBool": [ - 234234, - true - ] - }, - { - "EBool": [ - 234234, - false - ] - } + ] ] }, { "ELet": [ - 831830073, + 831830074, { "LPVariable": [ - 7567123, - "dict" + 7567124, + "int8" ] }, { - "EDict": [ - 109539183, - [ - [ - "a string", - { - "EInt64": [ - 450951790, - 2 - ] - } - ] - ] + "EInt8": [ + 7567124, + 127 ] }, { "ELet": [ - 831830074, + 831830075, { "LPVariable": [ - 7567124, - "int8" + 7567125, + "uint8" ] }, { - "EInt8": [ - 7567124, - 127 + "EUInt8": [ + 7567125, + 255 ] }, { "ELet": [ - 831830075, + 831830076, { "LPVariable": [ - 7567125, - "uint8" + 7567126, + "int16" ] }, { - "EUInt8": [ - 7567125, - 255 + "EInt16": [ + 7567126, + 32767 ] }, { "ELet": [ - 831830076, + 831830077, { "LPVariable": [ - 7567126, - "int16" + 7567127, + "uint16" ] }, { - "EInt16": [ - 7567126, - 32767 + "EUInt16": [ + 7567128, + 65535 ] }, { "ELet": [ - 831830077, + 831830078, { "LPVariable": [ - 7567127, - "uint16" + 7567128, + "int32" ] }, { - "EUInt16": [ + "EInt32": [ 7567128, - 65535 + 2147483647 ] }, { "ELet": [ - 831830078, + 831830079, { "LPVariable": [ - 7567128, - "int32" + 7567129, + "uint32" ] }, { - "EInt32": [ - 7567128, - 2147483647 + "EUInt32": [ + 7567129, + 4294967295 ] }, { "ELet": [ - 831830079, + 831830080, { "LPVariable": [ - 7567129, - "uint32" + 7567130, + "int128" ] }, { - "EUInt32": [ - 7567129, - 4294967295 + "EInt128": [ + 7567130, + "170141183460469231731687303715884105727" ] }, { "ELet": [ - 831830080, + 831830081, { "LPVariable": [ - 7567130, - "int128" + 756730, + "uint128" ] }, { - "EInt128": [ + "EUInt128": [ 7567130, - "170141183460469231731687303715884105727" + "340282366920938463463374607431768211455" ] }, { "ELet": [ - 831830081, + 831830082, { "LPVariable": [ - 756730, - "uint128" + 756731, + "uint64" ] }, { - "EUInt128": [ - 7567130, - "340282366920938463463374607431768211455" + "EUInt64": [ + 7567132, + "18446744073709551615" ] }, { - "ELet": [ - 831830082, - { - "LPVariable": [ - 756731, - "uint64" - ] - }, - { - "EUInt64": [ - 7567132, - "18446744073709551615" - ] - }, - { - "EInt64": [ - 34545, - 5 - ] - } + "EInt64": [ + 34545, + 5 ] } ] @@ -1814,6 +1500,323 @@ } ] } + ] + }, + "typeParams": [ + "a" + ], + "parameters": [ + { + "name": "param", + "typ": { + "TTuple": [ + { + "TInt64": [] + }, + { + "TFloat": [] + }, + [ + { + "TBool": [] + }, + { + "TUnit": [] + }, + { + "TUInt64": [] + }, + { + "TInt8": [] + }, + { + "TUInt8": [] + }, + { + "TInt16": [] + }, + { + "TUInt16": [] + }, + { + "TInt32": [] + }, + { + "TUInt32": [] + }, + { + "TInt128": [] + }, + { + "TUInt128": [] + }, + { + "TString": [] + }, + { + "TList": [ + { + "TInt64": [] + } + ] + }, + { + "TTuple": [ + { + "TBool": [] + }, + { + "TBool": [] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TDict": [ + { + "TBool": [] + } + ] + }, + { + "TDB": [ + { + "TBool": [] + } + ] + }, + { + "TCustomType": [ + { + "Ok": [ + { + "Package": [ + { + "owner": "owner", + "modules": [ + "Mod" + ], + "name": "User", + "version": 0 + } + ] + } + ] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TCustomType": [ + { + "Ok": [ + { + "Package": [ + { + "owner": "dark", + "modules": [ + "Mod1", + "Mod2" + ], + "name": "Pack", + "version": 0 + } + ] + } + ] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TVariable": [ + "test" + ] + }, + { + "TFn": [ + [ + { + "TBool": [] + } + ], + { + "TBool": [] + } + ] + } + ] + ] + }, + "description": "desc" } - ] + ], + "returnType": { + "TTuple": [ + { + "TInt64": [] + }, + { + "TFloat": [] + }, + [ + { + "TBool": [] + }, + { + "TUnit": [] + }, + { + "TUInt64": [] + }, + { + "TInt8": [] + }, + { + "TUInt8": [] + }, + { + "TInt16": [] + }, + { + "TUInt16": [] + }, + { + "TInt32": [] + }, + { + "TUInt32": [] + }, + { + "TInt128": [] + }, + { + "TUInt128": [] + }, + { + "TString": [] + }, + { + "TList": [ + { + "TInt64": [] + } + ] + }, + { + "TTuple": [ + { + "TBool": [] + }, + { + "TBool": [] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TDict": [ + { + "TBool": [] + } + ] + }, + { + "TDB": [ + { + "TBool": [] + } + ] + }, + { + "TCustomType": [ + { + "Ok": [ + { + "Package": [ + { + "owner": "owner", + "modules": [ + "Mod" + ], + "name": "User", + "version": 0 + } + ] + } + ] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TCustomType": [ + { + "Ok": [ + { + "Package": [ + { + "owner": "dark", + "modules": [ + "Mod1", + "Mod2" + ], + "name": "Pack", + "version": 0 + } + ] + } + ] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TVariable": [ + "test" + ] + }, + { + "TFn": [ + [ + { + "TBool": [] + } + ], + { + "TBool": [] + } + ] + } + ] + ] + }, + "description": "test", + "deprecated": { + "NotDeprecated": [] + } } \ No newline at end of file diff --git a/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageType-T_type.json b/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageType-T_type.json new file mode 100644 index 0000000000..804355bc2d --- /dev/null +++ b/backend/serialization/vanilla_LibExecution-ProgramTypes-PackageType-T_type.json @@ -0,0 +1,200 @@ +{ + "tlid": 777777928475, + "id": "31d72f73-0f99-5a9b-949c-b95705ae7c4d", + "name": { + "owner": "darklang", + "modules": [ + "stdlib", + "Int64", + "Int64" + ], + "name": "Int64", + "version": 0 + }, + "declaration": { + "typeParams": [ + "a" + ], + "definition": { + "Enum": [ + [ + { + "name": "caseA", + "fields": [], + "description": "" + }, + { + "name": "caseB", + "fields": [ + { + "typ": { + "TTuple": [ + { + "TInt64": [] + }, + { + "TFloat": [] + }, + [ + { + "TBool": [] + }, + { + "TUnit": [] + }, + { + "TUInt64": [] + }, + { + "TInt8": [] + }, + { + "TUInt8": [] + }, + { + "TInt16": [] + }, + { + "TUInt16": [] + }, + { + "TInt32": [] + }, + { + "TUInt32": [] + }, + { + "TInt128": [] + }, + { + "TUInt128": [] + }, + { + "TString": [] + }, + { + "TList": [ + { + "TInt64": [] + } + ] + }, + { + "TTuple": [ + { + "TBool": [] + }, + { + "TBool": [] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TDict": [ + { + "TBool": [] + } + ] + }, + { + "TDB": [ + { + "TBool": [] + } + ] + }, + { + "TCustomType": [ + { + "Ok": [ + { + "Package": [ + { + "owner": "owner", + "modules": [ + "Mod" + ], + "name": "User", + "version": 0 + } + ] + } + ] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TCustomType": [ + { + "Ok": [ + { + "Package": [ + { + "owner": "dark", + "modules": [ + "Mod1", + "Mod2" + ], + "name": "Pack", + "version": 0 + } + ] + } + ] + }, + [ + { + "TBool": [] + } + ] + ] + }, + { + "TVariable": [ + "test" + ] + }, + { + "TFn": [ + [ + { + "TBool": [] + } + ], + { + "TBool": [] + } + ] + } + ] + ] + }, + "label": { + "Some": [ + "i" + ] + }, + "description": "" + } + ], + "description": "" + } + ] + ] + } + }, + "description": "test", + "deprecated": { + "NotDeprecated": [] + } +} \ No newline at end of file diff --git a/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_db.json b/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_db.json index 55bf44aca1..bbad3b9244 100644 --- a/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_db.json +++ b/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_db.json @@ -90,8 +90,9 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [ "Mod" ], diff --git a/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_httphandler.json b/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_httphandler.json index 8913f36793..cd73606c64 100644 --- a/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_httphandler.json +++ b/backend/serialization/vanilla_LibExecution-ProgramTypes-Toplevel-T_httphandler.json @@ -303,8 +303,9 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [ "Mod" ], @@ -592,10 +593,10 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "dark", "modules": [ - "dark", "stdlib" ], "name": "NonEmptyList", diff --git a/backend/serialization/vanilla_Microsoft-FSharp-Collections-FSharpList-1-LibExecution-ProgramTypes-Toplevel-T-_complete.json b/backend/serialization/vanilla_Microsoft-FSharp-Collections-FSharpList-1-LibExecution-ProgramTypes-Toplevel-T-_complete.json index 7181d95550..ba6a236b5b 100644 --- a/backend/serialization/vanilla_Microsoft-FSharp-Collections-FSharpList-1-LibExecution-ProgramTypes-Toplevel-T-_complete.json +++ b/backend/serialization/vanilla_Microsoft-FSharp-Collections-FSharpList-1-LibExecution-ProgramTypes-Toplevel-T-_complete.json @@ -304,8 +304,9 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [ "Mod" ], @@ -593,10 +594,10 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "dark", "modules": [ - "dark", "stdlib" ], "name": "NonEmptyList", @@ -1806,8 +1807,9 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [ "Mod" ], @@ -2095,10 +2097,10 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "dark", "modules": [ - "dark", "stdlib" ], "name": "NonEmptyList", @@ -3311,8 +3313,9 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [ "Mod" ], @@ -3600,10 +3603,10 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "dark", "modules": [ - "dark", "stdlib" ], "name": "NonEmptyList", @@ -4813,8 +4816,9 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "owner", "modules": [ "Mod" ], @@ -5102,10 +5106,10 @@ { "Ok": [ { - "UserProgram": [ + "Package": [ { + "owner": "dark", "modules": [ - "dark", "stdlib" ], "name": "NonEmptyList", @@ -6098,30 +6102,6 @@ } ] }, - { - "TCustomType": [ - { - "Ok": [ - { - "UserProgram": [ - { - "modules": [ - "Mod" - ], - "name": "User", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, { "TCustomType": [ { @@ -6129,305 +6109,7 @@ { "Package": [ { - "owner": "dark", - "modules": [ - "Mod1", - "Mod2" - ], - "name": "Pack", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TVariable": [ - "test" - ] - }, - { - "TFn": [ - [ - { - "TBool": [] - } - ], - { - "TBool": [] - } - ] - } - ] - ] - } - } - ] - }, - { - "TLFunction": [ - { - "tlid": 0, - "name": { - "modules": [], - "name": "user", - "version": 0 - }, - "typeParams": [ - "a" - ], - "parameters": [ - { - "name": "myparam1", - "typ": { - "TTuple": [ - { - "TInt64": [] - }, - { - "TFloat": [] - }, - [ - { - "TBool": [] - }, - { - "TUnit": [] - }, - { - "TUInt64": [] - }, - { - "TInt8": [] - }, - { - "TUInt8": [] - }, - { - "TInt16": [] - }, - { - "TUInt16": [] - }, - { - "TInt32": [] - }, - { - "TUInt32": [] - }, - { - "TInt128": [] - }, - { - "TUInt128": [] - }, - { - "TString": [] - }, - { - "TList": [ - { - "TInt64": [] - } - ] - }, - { - "TTuple": [ - { - "TBool": [] - }, - { - "TBool": [] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TDict": [ - { - "TBool": [] - } - ] - }, - { - "TDB": [ - { - "TBool": [] - } - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "UserProgram": [ - { - "modules": [ - "Mod" - ], - "name": "User", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "Package": [ - { - "owner": "dark", - "modules": [ - "Mod1", - "Mod2" - ], - "name": "Pack", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TVariable": [ - "test" - ] - }, - { - "TFn": [ - [ - { - "TBool": [] - } - ], - { - "TBool": [] - } - ] - } - ] - ] - }, - "description": "param1" - } - ], - "returnType": { - "TTuple": [ - { - "TInt64": [] - }, - { - "TFloat": [] - }, - [ - { - "TBool": [] - }, - { - "TUnit": [] - }, - { - "TUInt64": [] - }, - { - "TInt8": [] - }, - { - "TUInt8": [] - }, - { - "TInt16": [] - }, - { - "TUInt16": [] - }, - { - "TInt32": [] - }, - { - "TUInt32": [] - }, - { - "TInt128": [] - }, - { - "TUInt128": [] - }, - { - "TString": [] - }, - { - "TList": [ - { - "TInt64": [] - } - ] - }, - { - "TTuple": [ - { - "TBool": [] - }, - { - "TBool": [] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TDict": [ - { - "TBool": [] - } - ] - }, - { - "TDB": [ - { - "TBool": [] - } - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "UserProgram": [ - { + "owner": "owner", "modules": [ "Mod" ], @@ -6490,1606 +6172,6 @@ } ] ] - }, - "description": "function description", - "deprecated": { - "DeprecatedBecause": [ - "some reason" - ] - }, - "body": { - "ELet": [ - "14219007199254740992", - { - "LPTuple": [ - 189271, - { - "LPVariable": [ - 18274132, - "x0" - ] - }, - { - "LPTuple": [ - 189272, - { - "LPVariable": [ - 18274133, - "x1" - ] - }, - { - "LPVariable": [ - 27838183, - "x2" - ] - }, - [] - ] - }, - [ - { - "LPTuple": [ - 189273, - { - "LPVariable": [ - 18274134, - "x3" - ] - }, - { - "LPVariable": [ - 27838184, - "x4" - ] - }, - [] - ] - } - ] - ] - }, - { - "EInt64": [ - 929452387, - 5 - ] - }, - { - "ELet": [ - 620028536, - { - "LPVariable": [ - 5812673123, - "x2" - ] - }, - { - "EInt64": [ - 452247642, - "9223372036854775807" - ] - }, - { - "ELet": [ - 68205955, - { - "LPVariable": [ - 458172, - "bool" - ] - }, - { - "EBool": [ - 43581311, - true - ] - }, - { - "ELet": [ - 755798860, - { - "LPVariable": [ - 457123, - "bool" - ] - }, - { - "EBool": [ - 97054530, - false - ] - }, - { - "ELet": [ - 244891515, - { - "LPVariable": [ - 1856712, - "str" - ] - }, - { - "EString": [ - 446488682, - [ - { - "StringText": [ - "a string" - ] - }, - { - "StringInterpolation": [ - { - "EVariable": [ - 402203255, - "var" - ] - } - ] - } - ] - ] - }, - { - "ELet": [ - 537517627, - { - "LPVariable": [ - 567161, - "char" - ] - }, - { - "EChar": [ - 1031176330, - "a" - ] - }, - { - "ELet": [ - 399526184, - { - "LPVariable": [ - 578164, - "float" - ] - }, - { - "EFloat": [ - 770715427, - { - "Negative": [] - }, - "6", - "5" - ] - }, - { - "ELet": [ - 975263310, - { - "LPVariable": [ - 55573, - "n" - ] - }, - { - "EUnit": [ - 923644248 - ] - }, - { - "ELet": [ - 43886336, - { - "LPVariable": [ - 44124, - "i" - ] - }, - { - "EIf": [ - 46231874, - { - "EApply": [ - 898531080, - { - "EFnName": [ - 63953, - { - "Ok": [ - { - "Builtin": [ - { - "name": "int64ToString", - "version": 0 - } - ] - } - ] - } - ] - }, - [ - { - "TTuple": [ - { - "TInt64": [] - }, - { - "TFloat": [] - }, - [ - { - "TBool": [] - }, - { - "TUnit": [] - }, - { - "TUInt64": [] - }, - { - "TInt8": [] - }, - { - "TUInt8": [] - }, - { - "TInt16": [] - }, - { - "TUInt16": [] - }, - { - "TInt32": [] - }, - { - "TUInt32": [] - }, - { - "TInt128": [] - }, - { - "TUInt128": [] - }, - { - "TString": [] - }, - { - "TList": [ - { - "TInt64": [] - } - ] - }, - { - "TTuple": [ - { - "TBool": [] - }, - { - "TBool": [] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TDict": [ - { - "TBool": [] - } - ] - }, - { - "TDB": [ - { - "TBool": [] - } - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "UserProgram": [ - { - "modules": [ - "Mod" - ], - "name": "User", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TCustomType": [ - { - "Ok": [ - { - "Package": [ - { - "owner": "dark", - "modules": [ - "Mod1", - "Mod2" - ], - "name": "Pack", - "version": 0 - } - ] - } - ] - }, - [ - { - "TBool": [] - } - ] - ] - }, - { - "TVariable": [ - "test" - ] - }, - { - "TFn": [ - [ - { - "TBool": [] - } - ], - { - "TBool": [] - } - ] - } - ] - ] - } - ], - [ - { - "EInt64": [ - 160106123, - 6 - ] - } - ] - ] - }, - { - "EIf": [ - 729246077, - { - "EInfix": [ - 94793109, - { - "InfixFnCall": [ - { - "ComparisonNotEquals": [] - } - ] - }, - { - "EInt64": [ - 264400705, - 5 - ] - }, - { - "EInt64": [ - 335743639, - 6 - ] - } - ] - }, - { - "EInfix": [ - 775118986, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 803876589, - 5 - ] - }, - { - "EInt64": [ - 219131014, - 2 - ] - } - ] - }, - { - "Some": [ - { - "ELambda": [ - 947647446, - [ - { - "LPVariable": [ - 180359194, - "y" - ] - } - ], - { - "EInfix": [ - 140609068, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 450951790, - 2 - ] - }, - { - "EVariable": [ - 402203255, - "y" - ] - } - ] - } - ] - } - ] - } - ] - }, - { - "Some": [ - { - "EInfix": [ - 265463935, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInfix": [ - 312092282, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EFieldAccess": [ - 974664608, - { - "EVariable": [ - 1002893266, - "x" - ] - }, - "y" - ] - }, - { - "EApply": [ - 173079901, - { - "EFnName": [ - 638434, - { - "Ok": [ - { - "Builtin": [ - { - "name": "int64Add", - "version": 0 - } - ] - } - ] - } - ] - }, - [], - [ - { - "EInt64": [ - 250221144, - 6 - ] - }, - { - "EInt64": [ - 298149318, - 2 - ] - } - ] - ] - } - ] - }, - { - "EList": [ - 539797095, - [ - { - "EInt64": [ - 267797631, - 5 - ] - }, - { - "EInt64": [ - 352138743, - 6 - ] - }, - { - "EInt64": [ - 430871955, - 7 - ] - } - ] - ] - } - ] - } - ] - } - ] - }, - { - "ELet": [ - 831830073, - { - "LPVariable": [ - 7567123, - "r" - ] - }, - { - "ERecord": [ - 109539183, - { - "Ok": [ - { - "UserProgram": [ - { - "modules": [ - "dark", - "stdlib" - ], - "name": "NonEmptyList", - "version": 0 - } - ] - } - ] - }, - [ - [ - "field", - { - "EPipe": [ - 786862131, - { - "EInt64": [ - 555880460, - 5 - ] - }, - [ - { - "EPipeVariable": [ - 1021880969, - "fn", - [ - { - "EVariable": [ - 962393769, - "x" - ] - } - ] - ] - }, - { - "EPipeLambda": [ - 1021880969, - [ - { - "LPVariable": [ - 180359194, - "y" - ] - } - ], - { - "EInfix": [ - 140609068, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 450951790, - 2 - ] - }, - { - "EVariable": [ - 402203255, - "y" - ] - } - ] - } - ] - }, - { - "EPipeInfix": [ - 1021880969, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 962393769, - 2 - ] - } - ] - }, - { - "EPipeFnCall": [ - 1021880969, - { - "Ok": [ - { - "Builtin": [ - { - "name": "int64Add", - "version": 0 - } - ] - } - ] - }, - [], - [ - { - "EInt64": [ - 250221144, - 6 - ] - }, - { - "EInt64": [ - 298149318, - 2 - ] - } - ] - ] - } - ] - ] - } - ], - [ - "enum", - { - "EEnum": [ - 646107057, - { - "Ok": [ - { - "Package": [ - { - "owner": "Darklang", - "modules": [ - "Stdlib", - "Result" - ], - "name": "Result", - "version": 0 - } - ] - } - ] - }, - "Error", - [] - ] - } - ] - ] - ] - }, - { - "ELet": [ - 1039625813, - { - "LPVariable": [ - 169324087, - "updatedR" - ] - }, - { - "ERecordUpdate": [ - 619623640, - { - "EVariable": [ - 81036610, - "r" - ] - }, - [ - [ - "field", - { - "EInt64": [ - 401690270, - 42 - ] - } - ] - ] - ] - }, - { - "ELet": [ - 745304029, - { - "LPVariable": [ - 17461, - "m" - ] - }, - { - "EMatch": [ - 889712088, - { - "EApply": [ - 203239466, - { - "EFnName": [ - 342954, - { - "Ok": [ - { - "Builtin": [ - { - "name": "modFunction", - "version": 2 - } - ] - } - ] - } - ] - }, - [], - [ - { - "EInt64": [ - 1015986188, - 5 - ] - } - ] - ] - }, - [ - { - "pat": { - "MPEnum": [ - 1015986188, - "Ok", - [ - { - "MPVariable": [ - 334386852, - "x" - ] - } - ] - ] - }, - "whenCondition": null, - "rhs": { - "EVariable": [ - 863810169, - "v" - ] - } - }, - { - "pat": { - "MPInt64": [ - 928253813, - 5 - ] - }, - "whenCondition": null, - "rhs": { - "EInt64": [ - 342670561, - "-9223372036854775808" - ] - } - }, - { - "pat": { - "MPBool": [ - 435227293, - true - ] - }, - "whenCondition": null, - "rhs": { - "EInt64": [ - 232748650, - 7 - ] - } - }, - { - "pat": { - "MPChar": [ - 387662539, - "c" - ] - }, - "whenCondition": null, - "rhs": { - "EChar": [ - 657848009, - "c" - ] - } - }, - { - "pat": { - "MPList": [ - 387662539, - [ - { - "MPBool": [ - 435227293, - true - ] - } - ] - ] - }, - "whenCondition": null, - "rhs": { - "EList": [ - 657848009, - [ - { - "EBool": [ - 435227293, - true - ] - } - ] - ] - } - }, - { - "pat": { - "MPListCons": [ - 596996239, - { - "MPString": [ - 949735651, - "val1" - ] - }, - { - "MPListCons": [ - 580612639, - { - "MPString": [ - 191110189, - "val2" - ] - }, - { - "MPList": [ - 448252771, - [ - { - "MPString": [ - 98945887, - "val3" - ] - } - ] - ] - } - ] - } - ] - }, - "whenCondition": null, - "rhs": { - "EList": [ - 657848009, - [ - { - "EBool": [ - 435227293, - true - ] - } - ] - ] - } - }, - { - "pat": { - "MPString": [ - 491115870, - "string" - ] - }, - "whenCondition": null, - "rhs": { - "EString": [ - 820329949, - [ - { - "StringText": [ - "string" - ] - }, - { - "StringInterpolation": [ - { - "EVariable": [ - 1002893266, - "var" - ] - } - ] - } - ] - ] - } - }, - { - "pat": { - "MPUnit": [ - 701616052 - ] - }, - "whenCondition": null, - "rhs": { - "EUnit": [ - 731162955 - ] - } - }, - { - "pat": { - "MPVariable": [ - 722099983, - "var" - ] - }, - "whenCondition": null, - "rhs": { - "EInfix": [ - 275666765, - { - "InfixFnCall": [ - { - "ArithmeticPlus": [] - } - ] - }, - { - "EInt64": [ - 739193732, - 6 - ] - }, - { - "EVariable": [ - 880556562, - "var" - ] - } - ] - } - }, - { - "pat": { - "MPFloat": [ - 409097457, - { - "Positive": [] - }, - "5", - "6" - ] - }, - "whenCondition": null, - "rhs": { - "EFloat": [ - 131187958, - { - "Positive": [] - }, - "5", - "6" - ] - } - }, - { - "pat": { - "MPTuple": [ - 1285610, - { - "MPVariable": [ - 17823641, - "a" - ] - }, - { - "MPVariable": [ - 58123641, - "b" - ] - }, - [ - { - "MPVariable": [ - 95723641, - "c" - ] - } - ] - ] - }, - "whenCondition": null, - "rhs": { - "EBool": [ - 123716747, - true - ] - } - }, - { - "pat": { - "MPTuple": [ - 1285610, - { - "MPVariable": [ - 17823641, - "a" - ] - }, - { - "MPVariable": [ - 58123641, - "b" - ] - }, - [ - { - "MPVariable": [ - 95723641, - "c" - ] - } - ] - ] - }, - "whenCondition": { - "Some": [ - { - "EBool": [ - 123716747, - true - ] - } - ] - }, - "rhs": { - "EBool": [ - 123716747, - true - ] - } - } - ] - ] - }, - { - "ELet": [ - 927055617, - { - "LPVariable": [ - 1782674, - "f" - ] - }, - { - "EIf": [ - 882488977, - { - "EBool": [ - 349352147, - true - ] - }, - { - "EInt64": [ - 578528886, - 5 - ] - }, - { - "Some": [ - { - "EInt64": [ - 562930224, - 6 - ] - } - ] - } - ] - }, - { - "ELet": [ - 6345345, - { - "LPVariable": [ - 17274, - "partials" - ] - }, - { - "EList": [ - 23423423, - [] - ] - }, - { - "ELet": [ - 883434, - { - "LPVariable": [ - 12894671, - "tuples" - ] - }, - { - "ETuple": [ - 72333, - { - "EInt64": [ - 34545, - 5 - ] - }, - { - "EInt64": [ - 34545, - 5 - ] - }, - [ - { - "EInt64": [ - 34545, - 5 - ] - } - ] - ] - }, - { - "ELet": [ - 47462, - { - "LPVariable": [ - 123471, - "binopAnd" - ] - }, - { - "EInfix": [ - 234234, - { - "BinOp": [ - { - "BinOpAnd": [] - } - ] - }, - { - "EBool": [ - 234234, - true - ] - }, - { - "EBool": [ - 234234, - false - ] - } - ] - }, - { - "ELet": [ - 831830073, - { - "LPVariable": [ - 7567123, - "dict" - ] - }, - { - "EDict": [ - 109539183, - [ - [ - "a string", - { - "EInt64": [ - 450951790, - 2 - ] - } - ] - ] - ] - }, - { - "ELet": [ - 831830074, - { - "LPVariable": [ - 7567124, - "int8" - ] - }, - { - "EInt8": [ - 7567124, - 127 - ] - }, - { - "ELet": [ - 831830075, - { - "LPVariable": [ - 7567125, - "uint8" - ] - }, - { - "EUInt8": [ - 7567125, - 255 - ] - }, - { - "ELet": [ - 831830076, - { - "LPVariable": [ - 7567126, - "int16" - ] - }, - { - "EInt16": [ - 7567126, - 32767 - ] - }, - { - "ELet": [ - 831830077, - { - "LPVariable": [ - 7567127, - "uint16" - ] - }, - { - "EUInt16": [ - 7567128, - 65535 - ] - }, - { - "ELet": [ - 831830078, - { - "LPVariable": [ - 7567128, - "int32" - ] - }, - { - "EInt32": [ - 7567128, - 2147483647 - ] - }, - { - "ELet": [ - 831830079, - { - "LPVariable": [ - 7567129, - "uint32" - ] - }, - { - "EUInt32": [ - 7567129, - 4294967295 - ] - }, - { - "ELet": [ - 831830080, - { - "LPVariable": [ - 7567130, - "int128" - ] - }, - { - "EInt128": [ - 7567130, - "170141183460469231731687303715884105727" - ] - }, - { - "ELet": [ - 831830081, - { - "LPVariable": [ - 756730, - "uint128" - ] - }, - { - "EUInt128": [ - 7567130, - "340282366920938463463374607431768211455" - ] - }, - { - "ELet": [ - 831830082, - { - "LPVariable": [ - 756731, - "uint64" - ] - }, - { - "EUInt64": [ - 7567132, - "18446744073709551615" - ] - }, - { - "EInt64": [ - 34545, - 5 - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - ] - } - } - ] - }, - { - "TLConstant": [ - { - "tlid": 0, - "name": { - "modules": [], - "name": "pi", - "version": 0 - }, - "description": "constant description", - "deprecated": { - "DeprecatedBecause": [ - "some reason" - ] - }, - "body": { - "CTuple": [ - { - "CInt64": [ - 314 - ] - }, - { - "CBool": [ - true - ] - }, - [ - { - "CString": [ - "string" - ] - }, - { - "CUnit": [] - }, - { - "CFloat": [ - { - "Positive": [] - }, - "3", - "14" - ] - }, - { - "CChar": [ - "c" - ] - }, - { - "CUnit": [] - }, - { - "CUInt64": [ - 3 - ] - }, - { - "CInt8": [ - 4 - ] - }, - { - "CUInt8": [ - 3 - ] - }, - { - "CInt16": [ - 4 - ] - }, - { - "CUInt16": [ - 3 - ] - }, - { - "CInt32": [ - 4 - ] - }, - { - "CUInt32": [ - 3 - ] - }, - { - "CInt128": [ - "-1" - ] - }, - { - "CUInt128": [ - "1" - ] - } - ] - ] } } ] diff --git a/backend/src/BuiltinCli/Libs/Output.fs b/backend/src/BuiltinCli/Libs/Output.fs index 6c0c5e73cf..a6f8ebcc37 100644 --- a/backend/src/BuiltinCli/Libs/Output.fs +++ b/backend/src/BuiltinCli/Libs/Output.fs @@ -42,24 +42,6 @@ let fns : List = | _ -> incorrectArgs ()) sqlSpec = NotQueryable previewable = Impure - deprecated = NotDeprecated } - - - { name = fn "debug" 0 - typeParams = [] - parameters = - [ Param.make "value" (TVariable "a") "The value to be printed." - Param.make "label" TString "The label to be printed." ] - returnType = TVariable "a" - description = "Prints the given to the standard output" - fn = - (function - | _, _, [ value; DString label ] -> - print $"DEBUG: {label} - {value}" - Ply value - | _ -> incorrectArgs ()) - sqlSpec = NotQueryable - previewable = Impure deprecated = NotDeprecated } ] diff --git a/backend/src/BuiltinCliHost/Libs/Cli.fs b/backend/src/BuiltinCliHost/Libs/Cli.fs index c688fb011d..6c42077e51 100644 --- a/backend/src/BuiltinCliHost/Libs/Cli.fs +++ b/backend/src/BuiltinCliHost/Libs/Cli.fs @@ -100,12 +100,15 @@ let execute let (program : Program) = { canvasID = System.Guid.NewGuid() internalFnsAllowed = false - types = mod'.types |> List.map PT2RT.UserType.toRT |> Map.fromListBy _.name - constants = - mod'.constants |> List.map PT2RT.UserConstant.toRT |> Map.fromListBy _.name secrets = [] - dbs = Map.empty - fns = mod'.fns |> List.map PT2RT.UserFunction.toRT |> Map.fromListBy _.name } + dbs = Map.empty } + + let packageManager = + PackageManager.withExtras + packageManager + (mod'.types |> List.map PT2RT.PackageType.toRT) + (mod'.constants |> List.map PT2RT.PackageConstant.toRT) + (mod'.fns |> List.map PT2RT.PackageFn.toRT) let state = Exe.createState @@ -155,15 +158,15 @@ let fns : List = CliRuntimeError.UncaughtException(msg, metadata) |> CliRuntimeError.RTE.toRuntimeError - let! parsedScript = uply { try return! LibParser.Canvas.parse + "CliScript" + "CanvasName" state.builtins state.packageManager - (NR.UserStuff.fromProgram state.program) NR.OnMissing.Allow filename code @@ -243,7 +246,6 @@ let fns : List = LibParser.NameResolver.resolveFnName (state.builtins.fns |> Map.keys |> Set) state.packageManager - (NR.UserStuff.fromProgram state.program).fns NR.OnMissing.Allow // OK? [] (WT.Unresolved name) @@ -383,7 +385,6 @@ let fns : List = LibParser.NameResolver.resolveFnName (state.builtins.fns |> Map.keys |> Set) state.packageManager - (NR.UserStuff.fromProgram state.program).fns NR.OnMissing.Allow // ok? [] (WT.Unresolved name) diff --git a/backend/src/BuiltinDarkInternal/Libs/Canvases.fs b/backend/src/BuiltinDarkInternal/Libs/Canvases.fs index 4827e1f004..ee1e932873 100644 --- a/backend/src/BuiltinDarkInternal/Libs/Canvases.fs +++ b/backend/src/BuiltinDarkInternal/Libs/Canvases.fs @@ -102,8 +102,6 @@ let fns : List = if Map.containsKey tlid c.deletedHandlers || Map.containsKey tlid c.deletedDBs - || Map.containsKey tlid c.deletedUserTypes - || Map.containsKey tlid c.deletedUserFunctions then do! Canvas.deleteToplevelForever canvasID tlid return DBool true @@ -129,21 +127,7 @@ let fns : List = (function | _, _, [ DUuid canvasID ] -> uply { - let! canvas = Canvas.loadAll canvasID - - let types = - canvas.userTypes - |> Map.values - |> Seq.toList - |> List.map PT2DT.UserType.toDT - let types = DList(VT.customType PT2DT.UserType.typeName [], types) - - let fns = - canvas.userFunctions - |> Map.values - |> Seq.toList - |> List.map PT2DT.UserFunction.toDT - let fns = DList(VT.customType PT2DT.UserFunction.typeName [], fns) + let! _canvas = Canvas.loadAll canvasID // let dbs = // Map.values canvas.dbs @@ -169,10 +153,9 @@ let fns : List = // |> Some) // |> Dval.list VT.unknownTODO - let typeName = packageCanvasType [] "Program" 0 return - DRecord(typeName, typeName, [], Map [ "types", types; "fns", fns ]) + DRecord(typeName, typeName, [], Map []) |> Dval.resultOk (KTCustomType(typeName, [])) KTString } | _ -> incorrectArgs ()) diff --git a/backend/src/BuiltinExecution/Libs/LanguageTools.fs b/backend/src/BuiltinExecution/Libs/LanguageTools.fs index 0432ae693a..7ae98d650e 100644 --- a/backend/src/BuiltinExecution/Libs/LanguageTools.fs +++ b/backend/src/BuiltinExecution/Libs/LanguageTools.fs @@ -19,8 +19,39 @@ let typ FQTypeName.fqPackage "Darklang" ([ "LanguageTools" ] @ addlModules) name version +let typeNameToStr = DvalReprDeveloper.typeName + let fns : List = - [ { name = fn "languageToolsAllBuiltinFns" 0 + [ { name = fn "languageToolsAllBuiltinConstants" 0 + typeParams = [] + parameters = [ Param.make "unit" TUnit "" ] + returnType = TList(TCustomType(Ok(typ [] "BuiltinConstant" 0), [])) + description = + "Returns a list of the Builtin constants (usually not to be accessed directly)." + fn = + (function + | state, _, [ DUnit ] -> + let constTypeName = typ [] "BuiltinConstant" 0 + + let consts = + state.builtins.constants + |> Map.toList + |> List.map (fun (key, data) -> + let fields = + [ "name", DString(FQConstantName.builtinToString key) + "description", DString data.description + "returnType", DString(typeNameToStr data.typ) ] + + DRecord(constTypeName, constTypeName, [], Map fields)) + + DList(VT.customType constTypeName [], consts) |> Ply + | _ -> incorrectArgs ()) + sqlSpec = NotQueryable + previewable = Impure + deprecated = NotDeprecated } + + + { name = fn "languageToolsAllBuiltinFns" 0 typeParams = [] parameters = [ Param.make "unit" TUnit "" ] returnType = TList(TCustomType(Ok(typ [] "BuiltinFunction" 0), [])) @@ -29,7 +60,6 @@ let fns : List = fn = (function | state, _, [ DUnit ] -> - let typeNameToStr = LibExecution.DvalReprDeveloper.typeName let fnParamTypeName = typ [] "BuiltinFunctionParameter" 0 let fnTypeName = typ [] "BuiltinFunction" 0 @@ -59,6 +89,28 @@ let fns : List = | _ -> incorrectArgs ()) sqlSpec = NotQueryable previewable = Impure + deprecated = NotDeprecated } + + + // This exists because the above-defined fn returns a big list, + // and List.filter fails on such a big list due to stack overflow + // (a bug to fix...) TODO + { name = fn "languageToolsBuiltinFnExists" 0 + typeParams = [] + parameters = [ Param.make "name" TString ""; Param.make "version" TInt64 "" ] + returnType = TBool + description = "Returns whether or not some builtin fn exists" + fn = + (function + | state, _, [ DString name; DInt64 version ] -> + let name : FQFnName.Builtin = { name = name; version = int version } + + let found = state.builtins.fns |> Map.find name |> Option.isSome + + DBool found |> Ply + | _ -> incorrectArgs ()) + sqlSpec = NotQueryable + previewable = Impure deprecated = NotDeprecated } ] diff --git a/backend/src/BuiltinExecution/Libs/NoModule.fs b/backend/src/BuiltinExecution/Libs/NoModule.fs index a89b58b66b..ffdd0442c7 100644 --- a/backend/src/BuiltinExecution/Libs/NoModule.fs +++ b/backend/src/BuiltinExecution/Libs/NoModule.fs @@ -423,6 +423,25 @@ let fns : List = sqlSpec = NotQueryable previewable = Pure + deprecated = NotDeprecated } + + + { name = fn "debug" 0 + typeParams = [] + parameters = + [ Param.make "label" TString "The label to be printed." + Param.make "value" (TVariable "a") "The value to be printed." ] + returnType = TUnit + description = "Prints the given to the standard output" + fn = + (function + | _, _, [ DString label; value ] -> + // TODO: call upon the Dark equivalent fn instead of rlying on DvalReprDeveloper + print $"DEBUG: {label} - {DvalReprDeveloper.toRepr value}" + Ply DUnit + | _ -> incorrectArgs ()) + sqlSpec = NotQueryable + previewable = Impure deprecated = NotDeprecated } ] diff --git a/backend/src/Cli/Cli.fs b/backend/src/Cli/Cli.fs index c25c969807..63174d4f65 100644 --- a/backend/src/Cli/Cli.fs +++ b/backend/src/Cli/Cli.fs @@ -66,9 +66,6 @@ let state () = let program : RT.Program = { canvasID = System.Guid.NewGuid() internalFnsAllowed = false - fns = Map.empty - types = Map.empty - constants = Map.empty dbs = Map.empty secrets = [] } @@ -129,9 +126,6 @@ let main (args : string[]) = let errorSourceStr = match source with | Some(tlid, id) -> - let foundProgramTL = - state.program.fns.Values |> Seq.tryFind (fun fn -> fn.tlid = tlid) - let foundPackageTL = state.packageManager.getFnByTLID tlid // TODO don't do this hacky stuff @@ -139,14 +133,11 @@ let main (args : string[]) = |> Async.AwaitTask |> Async.RunSynchronously - match foundProgramTL, foundPackageTL with - | Some programFn, _ -> - $"user fn {RT.FQFnName.userProgramToString programFn.name}, expr {id}" - - | None, Some packageFn -> + match foundPackageTL with + | Some packageFn -> $"package fn {RT.FQFnName.packageToString packageFn.name}, expr {id}" - | None, None -> $"tlid {tlid}, expr {id}" + | None -> $"tlid {tlid}, expr {id}" | None -> "(unknown)" diff --git a/backend/src/LibBinarySerialization/ProgramTypesToSerializedTypes.fs b/backend/src/LibBinarySerialization/ProgramTypesToSerializedTypes.fs index f147b9571b..8e972d574d 100644 --- a/backend/src/LibBinarySerialization/ProgramTypesToSerializedTypes.fs +++ b/backend/src/LibBinarySerialization/ProgramTypesToSerializedTypes.fs @@ -107,26 +107,13 @@ module FQTypeName = name = name.name version = name.version } - module UserProgram = - let toST (name : PT.FQTypeName.UserProgram) : ST.FQTypeName.UserProgram = - { modules = name.modules; name = name.name; version = name.version } - - let toPT (name : ST.FQTypeName.UserProgram) : PT.FQTypeName.UserProgram = - { modules = name.modules; name = name.name; version = name.version } - - - let toST (name : PT.FQTypeName.FQTypeName) : ST.FQTypeName.FQTypeName = match name with | PT.FQTypeName.Package name -> ST.FQTypeName.Package(Package.toST name) - | PT.FQTypeName.UserProgram name -> - ST.FQTypeName.UserProgram(UserProgram.toST name) let toPT (name : ST.FQTypeName.FQTypeName) : PT.FQTypeName.FQTypeName = match name with | ST.FQTypeName.Package name -> PT.FQTypeName.Package(Package.toPT name) - | ST.FQTypeName.UserProgram name -> - PT.FQTypeName.UserProgram(UserProgram.toPT name) module FQConstantName = @@ -150,21 +137,12 @@ module FQConstantName = name = name.name version = name.version } - module UserProgram = - let toST (name : PT.FQConstantName.UserProgram) : ST.FQConstantName.UserProgram = - { modules = name.modules; name = name.name; version = name.version } - - let toPT (name : ST.FQConstantName.UserProgram) : PT.FQConstantName.UserProgram = - { modules = name.modules; name = name.name; version = name.version } - let toST (name : PT.FQConstantName.FQConstantName) : ST.FQConstantName.FQConstantName = match name with | PT.FQConstantName.Builtin name -> ST.FQConstantName.Builtin(Builtin.toST name) | PT.FQConstantName.Package name -> ST.FQConstantName.Package(Package.toST name) - | PT.FQConstantName.UserProgram name -> - ST.FQConstantName.UserProgram(UserProgram.toST name) let toPT (name : ST.FQConstantName.FQConstantName) @@ -172,8 +150,6 @@ module FQConstantName = match name with | ST.FQConstantName.Builtin name -> PT.FQConstantName.Builtin(Builtin.toPT name) | ST.FQConstantName.Package name -> PT.FQConstantName.Package(Package.toPT name) - | ST.FQConstantName.UserProgram name -> - PT.FQConstantName.UserProgram(UserProgram.toPT name) module FQFnName = @@ -197,24 +173,15 @@ module FQFnName = name = name.name version = name.version } - module UserProgram = - let toST (name : PT.FQFnName.UserProgram) : ST.FQFnName.UserProgram = - { modules = name.modules; name = name.name; version = name.version } - - let toPT (name : ST.FQFnName.UserProgram) : PT.FQFnName.UserProgram = - { modules = name.modules; name = name.name; version = name.version } - let toST (name : PT.FQFnName.FQFnName) : ST.FQFnName.FQFnName = match name with | PT.FQFnName.Builtin name -> ST.FQFnName.Builtin(Builtin.toST name) | PT.FQFnName.Package name -> ST.FQFnName.Package(Package.toST name) - | PT.FQFnName.UserProgram name -> ST.FQFnName.UserProgram(UserProgram.toST name) let toPT (name : ST.FQFnName.FQFnName) : PT.FQFnName.FQFnName = match name with | ST.FQFnName.Builtin name -> PT.FQFnName.Builtin(Builtin.toPT name) | ST.FQFnName.Package name -> PT.FQFnName.Package(Package.toPT name) - | ST.FQFnName.UserProgram name -> PT.FQFnName.UserProgram(UserProgram.toPT name) module InfixFnName = @@ -754,6 +721,71 @@ module TypeDeclaration = { typeParams = d.typeParams; definition = Definition.toPT d.definition } +module PackageType = + let toST (pt : PT.PackageType.T) : ST.PackageType.T = + { name = FQTypeName.Package.toST pt.name + description = pt.description + declaration = TypeDeclaration.toST pt.declaration + deprecated = Deprecation.toST FQTypeName.toST pt.deprecated + id = pt.id + tlid = pt.tlid } + + let toPT (pt : ST.PackageType.T) : PT.PackageType.T = + { name = FQTypeName.Package.toPT pt.name + description = pt.description + declaration = TypeDeclaration.toPT pt.declaration + deprecated = Deprecation.toPT FQTypeName.toPT pt.deprecated + id = pt.id + tlid = pt.tlid } + +module PackageConstant = + let toST (pc : PT.PackageConstant.T) : ST.PackageConstant.T = + { tlid = pc.tlid + id = pc.id + name = FQConstantName.Package.toST pc.name + body = Const.toST pc.body + description = pc.description + deprecated = Deprecation.toST FQConstantName.toST pc.deprecated } + + let toPT (pc : ST.PackageConstant.T) : PT.PackageConstant.T = + { tlid = pc.tlid + id = pc.id + name = FQConstantName.Package.toPT pc.name + body = Const.toPT pc.body + description = pc.description + deprecated = Deprecation.toPT FQConstantName.toPT pc.deprecated } + +module PackageFn = + module Parameter = + let toST (p : PT.PackageFn.Parameter) : ST.PackageFn.Parameter = + { name = p.name; typ = TypeReference.toST p.typ; description = p.description } + + let toPT (p : ST.PackageFn.Parameter) : PT.PackageFn.Parameter = + { name = p.name; typ = TypeReference.toPT p.typ; description = p.description } + + let toST (fn : PT.PackageFn.T) : ST.PackageFn.T = + { name = FQFnName.Package.toST fn.name + parameters = NEList.map Parameter.toST fn.parameters |> NEList.toST + returnType = TypeReference.toST fn.returnType + description = fn.description + deprecated = Deprecation.toST FQFnName.toST fn.deprecated + body = Expr.toST fn.body + typeParams = fn.typeParams + id = fn.id + tlid = fn.tlid } + + let toPT (fn : ST.PackageFn.T) : PT.PackageFn.T = + { name = FQFnName.Package.toPT fn.name + parameters = fn.parameters |> NEList.toPT |> NEList.map Parameter.toPT + returnType = TypeReference.toPT fn.returnType + description = fn.description + deprecated = Deprecation.toPT FQFnName.toPT fn.deprecated + body = Expr.toPT fn.body + typeParams = fn.typeParams + id = fn.id + tlid = fn.tlid } + + module Handler = module CronInterval = let toST (ci : PT.Handler.CronInterval) : ST.Handler.CronInterval = @@ -810,145 +842,14 @@ module DB = version = db.version typ = TypeReference.toPT db.typ } -module UserType = - let toST (t : PT.UserType.T) : ST.UserType.T = - { tlid = t.tlid - name = FQTypeName.UserProgram.toST t.name - declaration = TypeDeclaration.toST t.declaration - description = t.description - deprecated = Deprecation.toST FQTypeName.toST t.deprecated } - - let toPT (t : ST.UserType.T) : PT.UserType.T = - { tlid = t.tlid - name = FQTypeName.UserProgram.toPT t.name - declaration = TypeDeclaration.toPT t.declaration - description = t.description - deprecated = Deprecation.toPT FQTypeName.toPT t.deprecated } - - -module UserFunction = - module Parameter = - let toST (p : PT.UserFunction.Parameter) : ST.UserFunction.Parameter = - { name = p.name; typ = TypeReference.toST p.typ; description = p.description } - - let toPT (p : ST.UserFunction.Parameter) : PT.UserFunction.Parameter = - { name = p.name; typ = TypeReference.toPT p.typ; description = p.description } - - let toST (f : PT.UserFunction.T) : ST.UserFunction.T = - { tlid = f.tlid - name = FQFnName.UserProgram.toST f.name - typeParams = f.typeParams - parameters = NEList.map Parameter.toST f.parameters |> NEList.toST - returnType = TypeReference.toST f.returnType - description = f.description - deprecated = Deprecation.toST FQFnName.toST f.deprecated - body = Expr.toST f.body } - - let toPT (f : ST.UserFunction.T) : PT.UserFunction.T = - { tlid = f.tlid - name = FQFnName.UserProgram.toPT f.name - typeParams = f.typeParams - parameters = f.parameters |> NEList.toPT |> NEList.map Parameter.toPT - returnType = TypeReference.toPT f.returnType - description = f.description - deprecated = Deprecation.toPT FQFnName.toPT f.deprecated - body = Expr.toPT f.body } - - -module UserConstant = - let toST (c : PT.UserConstant.T) : ST.UserConstant.T = - { tlid = c.tlid - name = FQConstantName.UserProgram.toST c.name - description = c.description - deprecated = Deprecation.toST FQConstantName.toST c.deprecated - body = Const.toST c.body } - - let toPT (c : ST.UserConstant.T) : PT.UserConstant.T = - { tlid = c.tlid - name = FQConstantName.UserProgram.toPT c.name - description = c.description - deprecated = Deprecation.toPT FQConstantName.toPT c.deprecated - body = Const.toPT c.body } - module Toplevel = let toST (tl : PT.Toplevel.T) : ST.Toplevel.T = match tl with - | PT.Toplevel.TLHandler h -> ST.Toplevel.TLHandler(Handler.toST h) | PT.Toplevel.TLDB db -> ST.Toplevel.TLDB(DB.toST db) - | PT.Toplevel.TLFunction f -> ST.Toplevel.TLFunction(UserFunction.toST f) - | PT.Toplevel.TLType ut -> ST.Toplevel.TLType(UserType.toST ut) - | PT.Toplevel.TLConstant c -> ST.Toplevel.TLConstant(UserConstant.toST c) + | PT.Toplevel.TLHandler h -> ST.Toplevel.TLHandler(Handler.toST h) let toPT (tl : ST.Toplevel.T) : PT.Toplevel.T = match tl with - | ST.Toplevel.TLHandler h -> PT.Toplevel.TLHandler(Handler.toPT h) | ST.Toplevel.TLDB db -> PT.Toplevel.TLDB(DB.toPT db) - | ST.Toplevel.TLFunction f -> PT.Toplevel.TLFunction(UserFunction.toPT f) - | ST.Toplevel.TLType ut -> PT.Toplevel.TLType(UserType.toPT ut) - | ST.Toplevel.TLConstant c -> PT.Toplevel.TLConstant(UserConstant.toPT c) - - -module PackageFn = - module Parameter = - let toST (p : PT.PackageFn.Parameter) : ST.PackageFn.Parameter = - { name = p.name; typ = TypeReference.toST p.typ; description = p.description } - - let toPT (p : ST.PackageFn.Parameter) : PT.PackageFn.Parameter = - { name = p.name; typ = TypeReference.toPT p.typ; description = p.description } - - let toST (fn : PT.PackageFn.T) : ST.PackageFn.T = - { name = FQFnName.Package.toST fn.name - parameters = NEList.map Parameter.toST fn.parameters |> NEList.toST - returnType = TypeReference.toST fn.returnType - description = fn.description - deprecated = Deprecation.toST FQFnName.toST fn.deprecated - body = Expr.toST fn.body - typeParams = fn.typeParams - id = fn.id - tlid = fn.tlid } - - let toPT (fn : ST.PackageFn.T) : PT.PackageFn.T = - { name = FQFnName.Package.toPT fn.name - parameters = fn.parameters |> NEList.toPT |> NEList.map Parameter.toPT - returnType = TypeReference.toPT fn.returnType - description = fn.description - deprecated = Deprecation.toPT FQFnName.toPT fn.deprecated - body = Expr.toPT fn.body - typeParams = fn.typeParams - id = fn.id - tlid = fn.tlid } - -module PackageType = - let toST (pt : PT.PackageType.T) : ST.PackageType.T = - { name = FQTypeName.Package.toST pt.name - description = pt.description - declaration = TypeDeclaration.toST pt.declaration - deprecated = Deprecation.toST FQTypeName.toST pt.deprecated - id = pt.id - tlid = pt.tlid } - - let toPT (pt : ST.PackageType.T) : PT.PackageType.T = - { name = FQTypeName.Package.toPT pt.name - description = pt.description - declaration = TypeDeclaration.toPT pt.declaration - deprecated = Deprecation.toPT FQTypeName.toPT pt.deprecated - id = pt.id - tlid = pt.tlid } - -module PackageConstant = - let toST (pc : PT.PackageConstant.T) : ST.PackageConstant.T = - { tlid = pc.tlid - id = pc.id - name = FQConstantName.Package.toST pc.name - body = Const.toST pc.body - description = pc.description - deprecated = Deprecation.toST FQConstantName.toST pc.deprecated } - - let toPT (pc : ST.PackageConstant.T) : PT.PackageConstant.T = - { tlid = pc.tlid - id = pc.id - name = FQConstantName.Package.toPT pc.name - body = Const.toPT pc.body - description = pc.description - deprecated = Deprecation.toPT FQConstantName.toPT pc.deprecated } + | ST.Toplevel.TLHandler h -> PT.Toplevel.TLHandler(Handler.toPT h) diff --git a/backend/src/LibBinarySerialization/SerializedTypes.fs b/backend/src/LibBinarySerialization/SerializedTypes.fs index 054bd018dd..7db39e0517 100644 --- a/backend/src/LibBinarySerialization/SerializedTypes.fs +++ b/backend/src/LibBinarySerialization/SerializedTypes.fs @@ -66,18 +66,7 @@ module FQTypeName = version : int } [] - type UserProgram = - { [] - modules : List - [] - name : string - [] - version : int } - - [] - type FQTypeName = - | Package of Package - | UserProgram of UserProgram + type FQTypeName = Package of Package module FQConstantName = @@ -99,20 +88,10 @@ module FQConstantName = [] version : int } - [] - type UserProgram = - { [] - modules : List - [] - name : string - [] - version : int } - [] type FQConstantName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram module FQFnName = @@ -134,20 +113,10 @@ module FQFnName = [] version : int } - [] - type UserProgram = - { [] - modules : List - [] - name : string - [] - version : int } - [] type FQFnName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram module NameResolutionError = @@ -484,63 +453,6 @@ module PackageFn = // -- User stuff -module UserType = - [] - type T = - { [] - tlid : tlid - [] - name : FQTypeName.UserProgram - [] - declaration : TypeDeclaration.T - [] - description : string - [] - deprecated : Deprecation } - - -module UserConstant = - [] - type T = - { [] - tlid : tlid - [] - name : FQConstantName.UserProgram - [] - description : string - [] - deprecated : Deprecation - [] - body : Const } - -module UserFunction = - [] - type Parameter = - { [] - name : string - [] - typ : TypeReference - [] - description : string } - - [] - type T = - { [] - tlid : tlid - [] - name : FQFnName.UserProgram - [] - typeParams : List - [] - parameters : NEList - [] - returnType : TypeReference - [] - description : string - [] - deprecated : Deprecation - [] - body : Expr } module Handler = [] @@ -586,8 +498,5 @@ module DB = module Toplevel = [] type T = - | TLHandler of Handler.T | TLDB of DB.T - | TLFunction of UserFunction.T - | TLType of UserType.T - | TLConstant of UserConstant.T + | TLHandler of Handler.T diff --git a/backend/src/LibCloud/Canvas.fs b/backend/src/LibCloud/Canvas.fs index 14d7e9a2f5..9735a28530 100644 --- a/backend/src/LibCloud/Canvas.fs +++ b/backend/src/LibCloud/Canvas.fs @@ -96,17 +96,12 @@ let getOwner (id : CanvasID) : Task> = /// type T = { id : CanvasID + + secrets : Map handlers : Map dbs : Map - userFunctions : Map - userTypes : Map - userConstants : Map deletedHandlers : Map - deletedDBs : Map - deletedUserFunctions : Map - deletedUserTypes : Map - deletedUserConstants : Map - secrets : Map } + deletedDBs : Map } let addToplevel (deleted : Serialize.Deleted) (tl : PT.Toplevel.T) (c : T) : T = let tlid = PT.Toplevel.toTLID tl @@ -116,22 +111,10 @@ let addToplevel (deleted : Serialize.Deleted) (tl : PT.Toplevel.T) (c : T) : T = { c with handlers = Map.add tlid h c.handlers } | Serialize.NotDeleted, PT.Toplevel.TLDB db -> { c with dbs = Map.add tlid db c.dbs } - | Serialize.NotDeleted, PT.Toplevel.TLType t -> - { c with userTypes = Map.add tlid t c.userTypes } - | Serialize.NotDeleted, PT.Toplevel.TLFunction f -> - { c with userFunctions = Map.add tlid f c.userFunctions } - | Serialize.NotDeleted, PT.Toplevel.TLConstant cn -> - { c with userConstants = Map.add tlid cn c.userConstants } | Serialize.Deleted, PT.Toplevel.TLHandler h -> { c with deletedHandlers = Map.add tlid h c.deletedHandlers } | Serialize.Deleted, PT.Toplevel.TLDB db -> { c with deletedDBs = Map.add tlid db c.deletedDBs } - | Serialize.Deleted, PT.Toplevel.TLType t -> - { c with deletedUserTypes = Map.add tlid t c.deletedUserTypes } - | Serialize.Deleted, PT.Toplevel.TLFunction f -> - { c with deletedUserFunctions = Map.add tlid f c.deletedUserFunctions } - | Serialize.Deleted, PT.Toplevel.TLConstant cn -> - { c with deletedUserConstants = Map.add tlid cn c.deletedUserConstants } let addToplevels (tls : List) (canvas : T) : T = @@ -140,22 +123,14 @@ let addToplevels (tls : List) (canvas : T) : let toplevels (c : T) : Map = let map f l = Map.map f l |> Map.toSeq - [ map PT.Toplevel.TLHandler c.handlers - map PT.Toplevel.TLDB c.dbs - map PT.Toplevel.TLType c.userTypes - map PT.Toplevel.TLFunction c.userFunctions - map PT.Toplevel.TLConstant c.userConstants ] + [ map PT.Toplevel.TLHandler c.handlers; map PT.Toplevel.TLDB c.dbs ] |> Seq.concat |> Map let deletedToplevels (c : T) : Map = let map f l = Map.map f l |> Map.toSeq - [ map PT.Toplevel.TLHandler c.deletedHandlers - map PT.Toplevel.TLDB c.deletedDBs - map PT.Toplevel.TLType c.deletedUserTypes - map PT.Toplevel.TLFunction c.deletedUserFunctions - map PT.Toplevel.TLConstant c.deletedUserConstants ] + [ map PT.Toplevel.TLHandler c.deletedHandlers; map PT.Toplevel.TLDB c.deletedDBs ] |> Seq.concat |> Map @@ -196,35 +171,6 @@ let deleteHandler (tlid : tlid) c = handlers = Map.remove h.tlid c.handlers deletedHandlers = Map.add h.tlid h c.deletedHandlers } -let setFunction (f : PT.UserFunction.T) (c : T) : T = - // if the fn had been deleted, remove it from the deleted set. This handles - // a data race where a Set comes in after a Delete. - { c with - userFunctions = Map.add f.tlid f c.userFunctions - deletedUserFunctions = Map.remove f.tlid c.deletedUserFunctions } - -let setType (t : PT.UserType.T) (c : T) : T = - // if the tipe had been deleted, remove it from the deleted set. This handles - // a data race where a Set comes in after a Delete. - { c with - userTypes = Map.add t.tlid t c.userTypes - deletedUserTypes = Map.remove t.tlid c.deletedUserTypes } - -let deleteFunction (tlid : tlid) (c : T) : T = - match Map.get tlid c.userFunctions with - | None -> c - | Some f -> - { c with - userFunctions = Map.remove tlid c.userFunctions - deletedUserFunctions = Map.add tlid f c.deletedUserFunctions } - -let deleteType (tlid : tlid) (c : T) : T = - match Map.get tlid c.userTypes with - | None -> c - | Some t -> - { c with - userTypes = Map.remove tlid c.userTypes - deletedUserTypes = Map.add tlid t c.deletedUserTypes } // CLEANUP Historically, on the backend, toplevel meant handler or DB // we want to de-conflate the concepts @@ -266,14 +212,8 @@ let empty (id : CanvasID) = { id = id handlers = Map.empty dbs = Map.empty - userFunctions = Map.empty - userTypes = Map.empty - userConstants = Map.empty deletedHandlers = Map.empty deletedDBs = Map.empty - deletedUserFunctions = Map.empty - deletedUserTypes = Map.empty - deletedUserConstants = Map.empty secrets = Map.empty } let loadFrom (id : CanvasID) (tlids : List) : Task = @@ -364,31 +304,11 @@ let getToplevel (tlid : tlid) (c : T) : Option Option.map (fun h -> (Serialize.Deleted, PT.Toplevel.TLDB h)) - let userFunction () = - Map.find tlid c.userFunctions - |> Option.map (fun h -> (Serialize.NotDeleted, PT.Toplevel.TLFunction h)) - - let deletedUserFunction () = - Map.find tlid c.deletedUserFunctions - |> Option.map (fun h -> (Serialize.Deleted, PT.Toplevel.TLFunction h)) - - let userType () = - Map.find tlid c.userTypes - |> Option.map (fun h -> (Serialize.NotDeleted, PT.Toplevel.TLType h)) - - let deletedUserType () = - Map.find tlid c.deletedUserTypes - |> Option.map (fun h -> (Serialize.Deleted, PT.Toplevel.TLType h)) handler () |> Option.orElseWith deletedHandler |> Option.orElseWith db |> Option.orElseWith deletedDB - |> Option.orElseWith userFunction - |> Option.orElseWith deletedUserFunction - |> Option.orElseWith userType - |> Option.orElseWith deletedUserType - let deleteToplevelForever (canvasID : CanvasID) (tlid : tlid) : Task = @@ -404,9 +324,6 @@ let toplevelToDBTypeString (tl : PT.Toplevel.T) : string = match tl with | PT.Toplevel.TLDB _ -> "db" | PT.Toplevel.TLHandler _ -> "handler" - | PT.Toplevel.TLFunction _ -> "user_function" - | PT.Toplevel.TLType _ -> "user_type" - | PT.Toplevel.TLConstant _ -> "user_constant" /// Save just the TLIDs listed (a canvas may load more tlids to support /// calling/testing these TLs, even though those TLs do not need to be updated) @@ -444,10 +361,7 @@ let saveTLIDs PTParser.Handler.Spec.toName spec, PTParser.Handler.Spec.toModifier spec ) - | PT.Toplevel.TLDB _ - | PT.Toplevel.TLType _ - | PT.Toplevel.TLConstant _ - | PT.Toplevel.TLFunction _ -> None + | PT.Toplevel.TLDB _ -> None let (module_, name, modifier) = // Only save info used to find handlers when the handler has not been deleted @@ -556,35 +470,11 @@ let toProgram (c : T) : Ply = |> List.map (fun db -> (db.name, PT2RT.DB.toRT db)) |> Map.ofList - let userFns = - c.userFunctions - |> Map.values - |> List.map (fun f -> - (PT2RT.FQFnName.UserProgram.toRT f.name, PT2RT.UserFunction.toRT f)) - |> Map.ofList - - let userTypes = - c.userTypes - |> Map.values - |> List.map (fun t -> - (PT2RT.FQTypeName.UserProgram.toRT t.name, PT2RT.UserType.toRT t)) - |> Map.ofList - - let userConstants = - c.userConstants - |> Map.values - |> List.map (fun c -> - (PT2RT.FQConstantName.UserProgram.toRT c.name, PT2RT.UserConstant.toRT c)) - |> Map.ofList - let secrets = c.secrets |> Map.values |> List.map PT2RT.Secret.toRT return { canvasID = c.id internalFnsAllowed = List.contains c.id Config.allowedDarkInternalCanvasIDs - fns = userFns - types = userTypes - constants = userConstants dbs = dbs secrets = secrets } } diff --git a/backend/src/LibCloud/Serialize.fs b/backend/src/LibCloud/Serialize.fs index 9c2a1b67db..fcfd186d18 100644 --- a/backend/src/LibCloud/Serialize.fs +++ b/backend/src/LibCloud/Serialize.fs @@ -42,10 +42,8 @@ let loadToplevels WHERE canvas_id = @canvasID AND tlid = ANY (@tlids) AND ( - ((tipe = 'handler'::toplevel_type OR tipe = 'db'::toplevel_type)) - OR tipe = 'user_function'::toplevel_type - OR tipe = 'user_type'::toplevel_type - OR tipe = 'user_constant'::toplevel_type + tipe = 'db'::toplevel_type + OR tipe = 'handler'::toplevel_type )" |> Sql.parameters [ "canvasID", Sql.uuid canvasID; "tlids", Sql.idArray tlids ] |> Sql.executeAsync (fun read -> diff --git a/backend/src/LibCloud/SqlCompiler.fs b/backend/src/LibCloud/SqlCompiler.fs index af6f01e533..025faf353f 100644 --- a/backend/src/LibCloud/SqlCompiler.fs +++ b/backend/src/LibCloud/SqlCompiler.fs @@ -320,21 +320,6 @@ let rec inline' |> Map.ofList return! inline' fns paramName paramToArgMap body | None -> return expr - | FQFnName.UserProgram u -> - match Map.get u fns.userProgram with - | Some fn -> - let parameters = - fn.parameters - |> NEList.map (fun p -> p.name, p.typ) - |> NEList.toList - let body = fn.body - let paramToArgMap = - List.zip parameters arguments - |> List.map (fun ((name, _), arg) -> name, arg) - |> Map.ofList - return! inline' fns paramName paramToArgMap body - | None -> return expr - | _ -> return expr } | ELet(_, lpVariable, expr, body) -> @@ -417,14 +402,12 @@ let rec lambdaToSql match constantName with | FQConstantName.Builtin b -> match Map.get b constants.builtIn with - | None -> return! error $"No built-in constant {nameStr} found" | Some c -> return c.body + | None -> return! error $"No built-in constant {nameStr} found" | FQConstantName.Package p -> match! constants.package p with - | None -> return error $"No package constant {nameStr} found" | Some c -> return LibExecution.Interpreter.evalConst source c.body - | FQConstantName.UserProgram _ -> - return error $"User constants are not yet supported" + | None -> return error $"No package constant {nameStr} found" } do! typecheckDval nameStr types constant expectedType let random = randomString 8 diff --git a/backend/src/LibCloudExecution/CloudExecution.fs b/backend/src/LibCloudExecution/CloudExecution.fs index 061441015e..6707eab009 100644 --- a/backend/src/LibCloudExecution/CloudExecution.fs +++ b/backend/src/LibCloudExecution/CloudExecution.fs @@ -89,28 +89,15 @@ let executeHandler HashSet.add h.tlid tracing.results.tlids let! result = Exe.executeExpr state h.tlid inputVars h.ast - let findUserBody (tlid : tlid) : Option = - program.fns - |> Map.values - |> List.find (fun (fn : RT.UserFunction.T) -> fn.tlid = tlid) - |> Option.map (fun (fn : RT.UserFunction.T) -> string fn.name, fn.body) - let findPackageBody (tlid : tlid) : Ply> = packageManager.getFnByTLID tlid |> Ply.map ( Option.map (fun (pkg : RT.PackageFn.T) -> string pkg.name, pkg.body) ) - let findBody (tlid : tlid) : Ply> = - uply { - match findUserBody tlid with - | Some body -> return Some body - | None -> return! findPackageBody tlid - } - let sourceOf (tlid : tlid) (id : id) : Ply = uply { - let! data = findBody tlid + let! data = findPackageBody tlid let mutable result = "unknown caller", "unknown body", "unknown expr" match data with | None -> () diff --git a/backend/src/LibExecution/AnalysisTypes.fs b/backend/src/LibExecution/AnalysisTypes.fs index eb99892526..3a4b3244bf 100644 --- a/backend/src/LibExecution/AnalysisTypes.fs +++ b/backend/src/LibExecution/AnalysisTypes.fs @@ -100,9 +100,6 @@ type AnalysisRequest = tlid : tlid traceID : TraceID.T traceData : TraceData - userFns : List - userTypes : List - userConstants : List dbs : List expr : RT.Expr packageFns : List diff --git a/backend/src/LibExecution/DvalReprInternalQueryable.fs b/backend/src/LibExecution/DvalReprInternalQueryable.fs index de52873b9f..4907ac9a12 100644 --- a/backend/src/LibExecution/DvalReprInternalQueryable.fs +++ b/backend/src/LibExecution/DvalReprInternalQueryable.fs @@ -425,22 +425,22 @@ let parseJsonV0 (types : Types) (typ : TypeReference) (str : string) : Ply module Test = let rec isQueryableDval (dval : Dval) : bool = match dval with - | DInt64 _ - | DUInt64 _ + | DUnit + | DBool _ | DInt8 _ | DUInt8 _ | DInt16 _ | DUInt16 _ | DInt32 _ | DUInt32 _ + | DInt64 _ + | DUInt64 _ | DInt128 _ | DUInt128 _ + | DFloat _ + | DChar _ | DString _ - | DUnit - | DBool _ | DDateTime _ - | DChar _ - | DFloat _ | DUuid _ -> true // VTTODO these should probably just check the valueType, not any internal data diff --git a/backend/src/LibExecution/DvalReprInternalRoundtrippable.fs b/backend/src/LibExecution/DvalReprInternalRoundtrippable.fs index c64cbc13b9..756f839614 100644 --- a/backend/src/LibExecution/DvalReprInternalRoundtrippable.fs +++ b/backend/src/LibExecution/DvalReprInternalRoundtrippable.fs @@ -24,22 +24,14 @@ module FormatV0 = // change RT.Dval. module FQTypeName = - type UserProgram = { modules : List; name : string; version : int } - type Package = { owner : string; modules : List; name : string; version : int } - type FQTypeName = - | Package of Package - | UserProgram of UserProgram + type FQTypeName = Package of Package let toRT (t : FQTypeName) : RT.FQTypeName.FQTypeName = match t with - | UserProgram { modules = modules; name = name; version = version } -> - RT.FQTypeName.UserProgram - { modules = modules; name = name; version = version } - | Package { owner = owner; modules = modules; name = name; version = version } -> RT.FQTypeName.Package { owner = owner; modules = modules; name = name; version = version } @@ -47,11 +39,6 @@ module FormatV0 = let fromRT (t : RT.FQTypeName.FQTypeName) : FQTypeName = match t with - | RT.FQTypeName.UserProgram { modules = modules - name = name - version = version } -> - FQTypeName.UserProgram { modules = modules; name = name; version = version } - | RT.FQTypeName.Package { owner = owner modules = modules name = name @@ -64,25 +51,18 @@ module FormatV0 = module FQFnName = type Builtin = { name : string; version : int } - type UserProgram = { modules : List; name : string; version : int } - type Package = { owner : string; modules : List; name : string; version : int } type FQFnName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram - let toRT (fn : FQFnName) : RT.FQFnName.FQFnName = match fn with | Builtin { name = name; version = version } -> RT.FQFnName.Builtin { name = name; version = version } - | UserProgram { modules = modules; name = name; version = version } -> - RT.FQFnName.UserProgram { modules = modules; name = name; version = version } - | Package { owner = owner; modules = modules; name = name; version = version } -> RT.FQFnName.Package { owner = owner; modules = modules; name = name; version = version } @@ -92,9 +72,6 @@ module FormatV0 = | RT.FQFnName.Builtin { name = name; version = version } -> FQFnName.Builtin { name = name; version = version } - | RT.FQFnName.UserProgram { modules = modules; name = name; version = version } -> - FQFnName.UserProgram { modules = modules; name = name; version = version } - | RT.FQFnName.Package { owner = owner modules = modules name = name diff --git a/backend/src/LibExecution/Interpreter.fs b/backend/src/LibExecution/Interpreter.fs index 33ae36ff04..be0ef7b66c 100644 --- a/backend/src/LibExecution/Interpreter.fs +++ b/backend/src/LibExecution/Interpreter.fs @@ -331,12 +331,6 @@ let rec eval return! ExecutionError.raise source (ExecutionError.ConstDoesntExist name) | Some constant -> return evalConst source constant.body - | FQConstantName.UserProgram c -> - match Map.find c state.program.constants with - | None -> - return! ExecutionError.raise source (ExecutionError.ConstDoesntExist name) - | Some constant -> return evalConst source constant.body - | ELet(id, pattern, rhs, body) -> let source = sourceID id @@ -924,8 +918,6 @@ and callFn let! fn = state.packageManager.getFn pkg return Option.map packageFnToFn fn } - | FQFnName.UserProgram u -> - Map.find u state.program.fns |> Option.map userFnToFn |> Ply match fn with | Some fn -> @@ -1017,8 +1009,7 @@ and execFn return result } - | PackageFunction(tlid, body) - | UserProgramFunction(tlid, body) -> + | PackageFunction(tlid, body) -> state.tracing.traceTLID tlid let state = { state with caller = caller } let symTable = diff --git a/backend/src/LibExecution/ProgramTypes.fs b/backend/src/LibExecution/ProgramTypes.fs index 6845fff1c7..35a1727809 100644 --- a/backend/src/LibExecution/ProgramTypes.fs +++ b/backend/src/LibExecution/ProgramTypes.fs @@ -34,6 +34,20 @@ let assert' assert_ "version can't be negative" [ "version", version ] (version >= 0) +let packageName + (owner : string) + (modules : List) + (name : string) + (version : int) + : string = + let nameParts = + match owner with + | "Tests" -> modules @ [ name ] + | _ -> "PACKAGE" :: owner :: modules @ [ name ] + let name = nameParts |> String.concat "." + + if version = 0 then name else $"{name}_v{version}" + /// Fully-Qualified Type Name /// /// Used to reference a type defined in a Package or by a User @@ -46,12 +60,7 @@ module FQTypeName = name : string version : int } - /// Part of the user's program (eg canvas or cli) - type UserProgram = { modules : List; name : string; version : int } - - type FQTypeName = - | Package of Package - | UserProgram of UserProgram + type FQTypeName = Package of Package let assertTypeName (name : string) : unit = assertRe "type name must match" typeNamePattern name @@ -73,35 +82,12 @@ module FQTypeName = : FQTypeName = Package(package owner modules name version) - let userProgram - (modules : List) - (name : string) - (version : int) - : UserProgram = - assert' modules name version assertTypeName - { modules = modules; name = name; version = version } - - let fqUserProgram - (modules : List) - (name : string) - (version : int) - : FQTypeName = - UserProgram(userProgram modules name version) - - let packageToString (s : Package) : string = - let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - - let userProgramToString (s : UserProgram) : string = - let name = s.modules @ [ s.name ] |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - + packageName s.owner s.modules s.name s.version let toString (name : FQTypeName) : string = match name with | Package p -> packageToString p - | UserProgram up -> userProgramToString up @@ -121,16 +107,9 @@ module FQConstantName = name : string version : int } - /// Part of the user's program (eg canvas or cli) - /// - /// TODO: consider whether modules should be a NonEmptyList - type UserProgram = { modules : List; name : string; version : int } - - type FQConstantName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram let assertConstantName (name : string) : unit = @@ -160,40 +139,18 @@ module FQConstantName = : FQConstantName = Package(package owner modules name version) - let userProgram - (modules : List) - (name : string) - (version : int) - : UserProgram = - assert' modules name version assertConstantName - { modules = modules; name = name; version = version } - - let fqUserProgram - (modules : List) - (name : string) - (version : int) - : FQConstantName = - UserProgram(userProgram modules name version) - let builtinToString (s : Builtin) : string = let name = s.name if s.version = 0 then name else $"{name}_v{s.version}" let packageToString (s : Package) : string = - let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - - let userProgramToString (s : UserProgram) : string = - let name = s.modules @ [ s.name ] |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - + packageName s.owner s.modules s.name s.version let toString (name : FQConstantName) : string = match name with | Builtin b -> builtinToString b | Package p -> packageToString p - | UserProgram up -> userProgramToString up /// A Fully-Qualified Function Name @@ -213,14 +170,9 @@ module FQFnName = name : string version : int } - /// Part of the user's program (eg canvas or cli) - type UserProgram = { modules : List; name : string; version : int } - - type FQFnName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram let assertFnName (name : string) : unit = assertRe $"Fn name must match" fnNamePattern name @@ -252,40 +204,17 @@ module FQFnName = : FQFnName = Package(package owner modules name version) - let userProgram - (modules : List) - (name : string) - (version : int) - : UserProgram = - assert' modules name version assertFnName - { modules = modules; name = name; version = version } - - let fqUserProgram - (modules : List) - (name : string) - (version : int) - : FQFnName = - UserProgram(userProgram modules name version) - - let builtinToString (s : Builtin) : string = let name = s.name if s.version = 0 then name else $"{name}_v{s.version}" let packageToString (s : Package) : string = - let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - - let userProgramToString (s : UserProgram) : string = - let name = s.modules @ [ s.name ] |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - + packageName s.owner s.modules s.name s.version let toString (name : FQFnName) : string = match name with | Builtin b -> builtinToString b | Package p -> packageToString p - | UserProgram up -> userProgramToString up // In ProgramTypes, names (FnNames, TypeNames, ConstantNames) have already been @@ -667,23 +596,23 @@ type Deprecation<'name> = // Package things // -- -module PackageConstant = +module PackageType = type T = { tlid : tlid id : System.Guid - name : FQConstantName.Package + name : FQTypeName.Package + declaration : TypeDeclaration.T description : string - deprecated : Deprecation - body : Const } + deprecated : Deprecation } -module PackageType = +module PackageConstant = type T = { tlid : tlid id : System.Guid - name : FQTypeName.Package - declaration : TypeDeclaration.T + name : FQConstantName.Package description : string - deprecated : Deprecation } + deprecated : Deprecation + body : Const } module PackageFn = type Parameter = { name : string; typ : TypeReference; description : string } @@ -714,36 +643,6 @@ type Packages = // -- // User things // -- - -module UserType = - type T = - { tlid : tlid - name : FQTypeName.UserProgram - declaration : TypeDeclaration.T - description : string - deprecated : Deprecation } - -module UserConstant = - type T = - { tlid : tlid - name : FQConstantName.UserProgram - description : string - deprecated : Deprecation - body : Const } - -module UserFunction = - type Parameter = { name : string; typ : TypeReference; description : string } - - type T = - { tlid : tlid - name : FQFnName.UserProgram - typeParams : List - parameters : NEList - returnType : TypeReference - description : string - deprecated : Deprecation - body : Expr } - module DB = type T = { tlid : tlid; name : string; version : int; typ : TypeReference } @@ -779,16 +678,10 @@ module Handler = module Toplevel = type T = - | TLType of UserType.T - | TLConstant of UserConstant.T | TLDB of DB.T - | TLFunction of UserFunction.T | TLHandler of Handler.T let toTLID (tl : T) : tlid = match tl with - | TLType t -> t.tlid - | TLConstant c -> c.tlid | TLDB db -> db.tlid - | TLFunction f -> f.tlid | TLHandler h -> h.tlid diff --git a/backend/src/LibExecution/ProgramTypesToDarkTypes.fs b/backend/src/LibExecution/ProgramTypesToDarkTypes.fs index 550b852d84..d2bdcf9b4e 100644 --- a/backend/src/LibExecution/ProgramTypesToDarkTypes.fs +++ b/backend/src/LibExecution/ProgramTypesToDarkTypes.fs @@ -86,28 +86,10 @@ module FQTypeName = | _ -> Exception.raiseInternal "Invalid FQTypeName.Package" [] - module UserProgram = - let toDT (u : PT.FQTypeName.UserProgram) : Dval = - let fields = - [ "modules", DList(VT.string, List.map DString u.modules) - "name", DString u.name - "version", DInt64 u.version ] - let typeName = ptTyp [ "FQTypeName" ] "UserProgram" 0 - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : PT.FQTypeName.UserProgram = - match d with - | DRecord(_, _, _, fields) -> - { modules = modulesField fields - name = nameField fields - version = versionField fields } - | _ -> Exception.raiseInternal "Invalid FQTypeName.UserProgram" [] - let toDT (u : PT.FQTypeName.FQTypeName) : Dval = let (caseName, fields) = match u with | PT.FQTypeName.Package u -> "Package", [ Package.toDT u ] - | PT.FQTypeName.UserProgram u -> "UserProgram", [ UserProgram.toDT u ] let typeName = ptTyp [ "FQTypeName" ] "FQTypeName" 0 DEnum(typeName, typeName, [], caseName, fields) @@ -116,10 +98,6 @@ module FQTypeName = let fromDT (d : Dval) : PT.FQTypeName.FQTypeName = match d with | DEnum(_, _, [], "Package", [ u ]) -> PT.FQTypeName.Package(Package.fromDT u) - - | DEnum(_, _, [], "UserProgram", [ u ]) -> - PT.FQTypeName.UserProgram(UserProgram.fromDT u) - | _ -> Exception.raiseInternal "Invalid FQTypeName" [] @@ -158,30 +136,11 @@ module FQFnName = | _ -> Exception.raiseInternal "Invalid FQFnName.Package" [] - module UserProgram = - let toDT (u : PT.FQFnName.UserProgram) : Dval = - let fields = - [ "modules", DList(VT.string, List.map DString u.modules) - "name", DString u.name - "version", DInt64 u.version ] - let typeName = ptTyp [ "FQFnName" ] "UserProgram" 0 - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : PT.FQFnName.UserProgram = - match d with - | DRecord(_, _, _, fields) -> - { modules = modulesField fields - name = nameField fields - version = versionField fields } - | _ -> Exception.raiseInternal "Invalid FQFnName.UserProgram" [] - - let toDT (u : PT.FQFnName.FQFnName) : Dval = let (caseName, fields) = match u with | PT.FQFnName.Builtin u -> "Builtin", [ Builtin.toDT u ] | PT.FQFnName.Package u -> "Package", [ Package.toDT u ] - | PT.FQFnName.UserProgram u -> "UserProgram", [ UserProgram.toDT u ] let typeName = ptTyp [ "FQFnName" ] "FQFnName" 0 DEnum(typeName, typeName, [], caseName, fields) @@ -189,12 +148,7 @@ module FQFnName = let fromDT (d : Dval) : PT.FQFnName.FQFnName = match d with | DEnum(_, _, [], "Builtin", [ u ]) -> PT.FQFnName.Builtin(Builtin.fromDT u) - | DEnum(_, _, [], "Package", [ u ]) -> PT.FQFnName.Package(Package.fromDT u) - - | DEnum(_, _, [], "UserProgram", [ u ]) -> - PT.FQFnName.UserProgram(UserProgram.fromDT u) - | _ -> Exception.raiseInternal "Invalid FQFnName" [] @@ -232,29 +186,11 @@ module FQConstantName = version = versionField fields } | _ -> Exception.raiseInternal "Invalid FQConstantName.Package" [] - module UserProgram = - let toDT (u : PT.FQConstantName.UserProgram) : Dval = - let fields = - [ "modules", DList(VT.string, List.map DString u.modules) - "name", DString u.name - "version", DInt64 u.version ] - let typeName = ptTyp [ "FQConstantName" ] "UserProgram" 0 - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : PT.FQConstantName.UserProgram = - match d with - | DRecord(_, _, _, fields) -> - { modules = modulesField fields - name = nameField fields - version = versionField fields } - | _ -> Exception.raiseInternal "Invalid FQConstantName.UserProgram" [] - let toDT (u : PT.FQConstantName.FQConstantName) : Dval = let (caseName, fields) = match u with | PT.FQConstantName.Builtin u -> "Builtin", [ Builtin.toDT u ] | PT.FQConstantName.Package u -> "Package", [ Package.toDT u ] - | PT.FQConstantName.UserProgram u -> "UserProgram", [ UserProgram.toDT u ] let typeName = ptTyp [ "FQConstantName" ] "FQConstantName" 0 DEnum(typeName, typeName, [], caseName, fields) @@ -267,9 +203,6 @@ module FQConstantName = | DEnum(_, _, [], "Package", [ u ]) -> PT.FQConstantName.Package(Package.fromDT u) - | DEnum(_, _, [], "UserProgram", [ u ]) -> - PT.FQConstantName.UserProgram(UserProgram.fromDT u) - | _ -> Exception.raiseInternal "Invalid FQConstantName" [] @@ -1388,116 +1321,6 @@ module DB = | _ -> Exception.raiseInternal "Invalid DB" [] -module UserType = - let typeName = ptTyp [] "UserType" 0 - - let toDT (ut : PT.UserType.T) : Dval = - let fields = - [ "tlid", DUInt64(uint64 ut.tlid) - "name", ut.name |> FQTypeName.UserProgram.toDT - "description", ut.description |> DString - "declaration", ut.declaration |> TypeDeclaration.toDT - "deprecated", - ut.deprecated |> Deprecation.toDT Deprecation.knownType FQTypeName.toDT ] - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : PT.UserType.T = - match d with - | DRecord(_, _, _, fields) -> - { tlid = fields |> D.uint64Field "tlid" - name = fields |> D.field "name" |> FQTypeName.UserProgram.fromDT - declaration = fields |> D.field "declaration" |> TypeDeclaration.fromDT - description = fields |> D.stringField "description" - deprecated = - fields |> D.field "deprecated" |> Deprecation.fromDT FQTypeName.fromDT } - | _ -> Exception.raiseInternal "Invalid UserType" [] - - -module UserFunction = - module Parameter = - let knownType = KTCustomType(ptTyp [ "UserFunction" ] "Parameter" 0, []) - - let toDT (p : PT.UserFunction.Parameter) : Dval = - let typeName = ptTyp [ "UserFunction" ] "Parameter" 0 - let fields = - [ "name", DString p.name - "typ", TypeReference.toDT p.typ - "description", DString p.description ] - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : PT.UserFunction.Parameter = - match d with - | DRecord(_, _, _, fields) -> - { name = fields |> D.stringField "name" - typ = fields |> D.field "typ" |> TypeReference.fromDT - description = fields |> D.stringField "description" } - | _ -> Exception.raiseInternal "Invalid UserFunction.Parameter" [] - - - let typeName = ptTyp [ "UserFunction" ] "UserFunction" 0 - - let toDT (userFn : PT.UserFunction.T) : Dval = - let fields = - [ ("tlid", DUInt64(uint64 userFn.tlid)) - ("name", FQFnName.UserProgram.toDT userFn.name) - ("typeParams", DList(VT.string, List.map DString userFn.typeParams)) - ("parameters", - DList( - VT.known Parameter.knownType, - userFn.parameters |> NEList.toList |> List.map Parameter.toDT - )) - ("returnType", TypeReference.toDT userFn.returnType) - ("body", Expr.toDT userFn.body) - ("description", DString userFn.description) - ("deprecated", - Deprecation.toDT FQFnName.knownType FQFnName.toDT userFn.deprecated) ] - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : PT.UserFunction.T = - match d with - | DRecord(_, _, _, fields) -> - { tlid = fields |> D.uint64Field "tlid" - name = fields |> D.field "name" |> FQFnName.UserProgram.fromDT - typeParams = fields |> D.stringListField "typeParams" - parameters = - fields - |> D.listField "parameters" - |> List.map Parameter.fromDT - |> NEList.ofListUnsafe "userFunction needs more than one parameter" [] - returnType = fields |> D.field "returnType" |> TypeReference.fromDT - body = fields |> D.field "body" |> Expr.fromDT - description = fields |> D.stringField "description" - deprecated = - fields |> D.field "deprecated" |> Deprecation.fromDT FQFnName.fromDT } - | _ -> Exception.raiseInternal "Invalid UserFunction" [] - -module UserConstant = - let toDT (userConstant : PT.UserConstant.T) : Dval = - let typeName = ptTyp [] "UserConstant" 0 - let fields = - [ "tlid", DUInt64(uint64 userConstant.tlid) - "name", FQConstantName.UserProgram.toDT userConstant.name - "body", Const.toDT userConstant.body - "description", DString userConstant.description - "deprecated", - Deprecation.toDT - FQConstantName.knownType - FQConstantName.toDT - userConstant.deprecated ] - DRecord(typeName, typeName, [], Map fields) - - - let fromDT (d : Dval) : PT.UserConstant.T = - match d with - | DRecord(_, _, _, fields) -> - { tlid = fields |> D.uint64Field "tlid" - name = fields |> D.field "name" |> FQConstantName.UserProgram.fromDT - body = fields |> D.field "body" |> Const.fromDT - description = fields |> D.stringField "description" - deprecated = - fields |> D.field "deprecated" |> Deprecation.fromDT FQConstantName.fromDT } - | _ -> Exception.raiseInternal "Invalid UserConstant" [] - module Secret = let toDT (s : PT.Secret.T) : Dval = let typeName = ptTyp [] "Secret" 0 @@ -1544,6 +1367,33 @@ module PackageType = | _ -> Exception.raiseInternal "Invalid PackageType" [] +module PackageConstant = + let typeName = ptTyp [] "PackageConstant" 0 + + let toDT (p : PT.PackageConstant.T) : Dval = + let fields = + [ "tlid", DUInt64(uint64 p.tlid) + "id", DUuid p.id + "name", FQConstantName.Package.toDT p.name + "body", Const.toDT p.body + "description", DString p.description + "deprecated", + Deprecation.toDT FQConstantName.knownType FQConstantName.toDT p.deprecated ] + DRecord(typeName, typeName, [], Map fields) + + let fromDT (d : Dval) : PT.PackageConstant.T = + match d with + | DRecord(_, _, _, fields) -> + { tlid = fields |> D.uint64Field "tlid" + id = fields |> D.uuidField "id" + name = fields |> D.field "name" |> FQConstantName.Package.fromDT + body = fields |> D.field "body" |> Const.fromDT + description = fields |> D.stringField "description" + deprecated = + fields |> D.field "deprecated" |> Deprecation.fromDT FQConstantName.fromDT } + | _ -> Exception.raiseInternal "Invalid PackageConstant" [] + + module PackageFn = module Parameter = let knownType = KTCustomType(ptTyp [ "PackageFn" ] "Parameter" 0, []) @@ -1604,31 +1454,3 @@ module PackageFn = deprecated = fields |> D.field "deprecated" |> Deprecation.fromDT FQFnName.fromDT } | _ -> Exception.raiseInternal "Invalid PackageFn" [] - - -module PackageConstant = - let typeName = ptTyp [] "PackageConstant" 0 - - let toDT (p : PT.PackageConstant.T) : Dval = - let fields = - [ "tlid", DUInt64(uint64 p.tlid) - "id", DUuid p.id - "name", FQConstantName.Package.toDT p.name - "body", Const.toDT p.body - "description", DString p.description - "deprecated", - Deprecation.toDT FQConstantName.knownType FQConstantName.toDT p.deprecated ] - DRecord(typeName, typeName, [], Map fields) - - - let fromDT (d : Dval) : PT.PackageConstant.T = - match d with - | DRecord(_, _, _, fields) -> - { tlid = fields |> D.uint64Field "tlid" - id = fields |> D.uuidField "id" - name = fields |> D.field "name" |> FQConstantName.Package.fromDT - body = fields |> D.field "body" |> Const.fromDT - description = fields |> D.stringField "description" - deprecated = - fields |> D.field "deprecated" |> Deprecation.fromDT FQConstantName.fromDT } - | _ -> Exception.raiseInternal "Invalid PackageConstant" [] diff --git a/backend/src/LibExecution/ProgramTypesToRuntimeTypes.fs b/backend/src/LibExecution/ProgramTypesToRuntimeTypes.fs index 46e6343f98..e303e00abf 100644 --- a/backend/src/LibExecution/ProgramTypesToRuntimeTypes.fs +++ b/backend/src/LibExecution/ProgramTypesToRuntimeTypes.fs @@ -15,23 +15,14 @@ module FQTypeName = let fromRT (p : RT.FQTypeName.Package) : PT.FQTypeName.Package = { owner = p.owner; modules = p.modules; name = p.name; version = p.version } - module UserProgram = - let toRT (u : PT.FQTypeName.UserProgram) : RT.FQTypeName.UserProgram = - { modules = u.modules; name = u.name; version = u.version } - - let fromRT (u : RT.FQTypeName.UserProgram) : PT.FQTypeName.UserProgram = - { modules = u.modules; name = u.name; version = u.version } let toRT (fqtn : PT.FQTypeName.FQTypeName) : RT.FQTypeName.FQTypeName = match fqtn with | PT.FQTypeName.Package p -> RT.FQTypeName.Package(Package.toRT p) - | PT.FQTypeName.UserProgram u -> RT.FQTypeName.UserProgram(UserProgram.toRT u) let fromRT (fqtn : RT.FQTypeName.FQTypeName) : Option = match fqtn with | RT.FQTypeName.Package p -> PT.FQTypeName.Package(Package.fromRT p) |> Some - | RT.FQTypeName.UserProgram u -> - PT.FQTypeName.UserProgram(UserProgram.fromRT u) |> Some module FQConstantName = @@ -49,12 +40,6 @@ module FQConstantName = let fromRT (c : RT.FQConstantName.Package) : PT.FQConstantName.Package = { owner = c.owner; modules = c.modules; name = c.name; version = c.version } - module UserProgram = - let toRT (c : PT.FQConstantName.UserProgram) : RT.FQConstantName.UserProgram = - { modules = c.modules; name = c.name; version = c.version } - - let fromRT (c : RT.FQConstantName.UserProgram) : PT.FQConstantName.UserProgram = - { modules = c.modules; name = c.name; version = c.version } let toRT (name : PT.FQConstantName.FQConstantName) @@ -62,8 +47,6 @@ module FQConstantName = match name with | PT.FQConstantName.Builtin s -> RT.FQConstantName.Builtin(Builtin.toRT s) | PT.FQConstantName.Package p -> RT.FQConstantName.Package(Package.toRT p) - | PT.FQConstantName.UserProgram u -> - RT.FQConstantName.UserProgram(UserProgram.toRT u) module FQFnName = @@ -81,18 +64,10 @@ module FQFnName = let fromRT (p : RT.FQFnName.Package) : PT.FQFnName.Package = { owner = p.owner; modules = p.modules; name = p.name; version = p.version } - module UserProgram = - let toRT (u : PT.FQFnName.UserProgram) : RT.FQFnName.UserProgram = - { modules = u.modules; name = u.name; version = u.version } - - let fromRT (u : RT.FQFnName.UserProgram) : PT.FQFnName.UserProgram = - { modules = u.modules; name = u.name; version = u.version } - let toRT (fqfn : PT.FQFnName.FQFnName) : RT.FQFnName.FQFnName = match fqfn with | PT.FQFnName.Builtin s -> RT.FQFnName.Builtin(Builtin.toRT s) | PT.FQFnName.Package p -> RT.FQFnName.Package(Package.toRT p) - | PT.FQFnName.UserProgram u -> RT.FQFnName.UserProgram(UserProgram.toRT u) module NameResolution = @@ -449,12 +424,15 @@ module TypeDeclaration = // -- module PackageType = let toRT (t : PT.PackageType.T) : RT.PackageType.T = - { name = FQTypeName.Package.toRT t.name + { tlid = t.tlid + name = FQTypeName.Package.toRT t.name declaration = TypeDeclaration.toRT t.declaration } module PackageConstant = let toRT (c : PT.PackageConstant.T) : RT.PackageConstant.T = - { name = FQConstantName.Package.toRT c.name; body = Const.toRT c.body } + { tlid = c.tlid + name = FQConstantName.Package.toRT c.name + body = Const.toRT c.body } module PackageFn = module Parameter = @@ -474,33 +452,6 @@ module PackageFn = // -- // User stuff // -- - -module UserType = - let toRT (t : PT.UserType.T) : RT.UserType.T = - { tlid = t.tlid - name = FQTypeName.UserProgram.toRT t.name - declaration = TypeDeclaration.toRT t.declaration } - -module UserConstant = - let toRT (c : PT.UserConstant.T) : RT.UserConstant.T = - { tlid = c.tlid - name = FQConstantName.UserProgram.toRT c.name - body = Const.toRT c.body } - -module UserFunction = - module Parameter = - let toRT (p : PT.UserFunction.Parameter) : RT.UserFunction.Parameter = - { name = p.name; typ = TypeReference.toRT p.typ } - - let toRT (f : PT.UserFunction.T) : RT.UserFunction.T = - { tlid = f.tlid - name = FQFnName.UserProgram.toRT f.name - typeParams = f.typeParams - parameters = NEList.map Parameter.toRT f.parameters - returnType = TypeReference.toRT f.returnType - body = Expr.toRT f.body } - - module Handler = module CronInterval = let toRT (ci : PT.Handler.CronInterval) : RT.Handler.CronInterval = @@ -538,8 +489,5 @@ module Secret = module Toplevel = let toRT (tl : PT.Toplevel.T) : RT.Toplevel.T = match tl with - | PT.Toplevel.TLType t -> RT.Toplevel.TLType(UserType.toRT t) - | PT.Toplevel.TLConstant c -> RT.Toplevel.TLConstant(UserConstant.toRT c) | PT.Toplevel.TLDB db -> RT.Toplevel.TLDB(DB.toRT db) - | PT.Toplevel.TLFunction f -> RT.Toplevel.TLFunction(UserFunction.toRT f) | PT.Toplevel.TLHandler h -> RT.Toplevel.TLHandler(Handler.toRT h) diff --git a/backend/src/LibExecution/RuntimeTypes.fs b/backend/src/LibExecution/RuntimeTypes.fs index af3b7b2353..c3fbc1cf01 100644 --- a/backend/src/LibExecution/RuntimeTypes.fs +++ b/backend/src/LibExecution/RuntimeTypes.fs @@ -57,9 +57,23 @@ let assert' assert_ "version can't be negative" [ "version", version ] (version >= 0) +let packageName + (owner : string) + (modules : List) + (name : string) + (version : int) + : string = + let nameParts = + match owner with + | "Tests" -> modules @ [ name ] + | _ -> "PACKAGE" :: owner :: modules @ [ name ] + let name = nameParts |> String.concat "." + + if version = 0 then name else $"{name}_v{version}" + /// Fully-Qualified Type Name /// -/// Used to reference a type defined in a Package or by a User +/// Used to reference a type defined in a Package module FQTypeName = /// The name of a type in the package manager type Package = @@ -69,13 +83,7 @@ module FQTypeName = name : string version : int } - /// Part of the user's program (eg canvas or cli) - type UserProgram = { modules : List; name : string; version : int } - - type FQTypeName = - | Package of Package - | UserProgram of UserProgram - + type FQTypeName = Package of Package let assertTypeName (name : string) : unit = assertRe "type name must match" typeNamePattern name @@ -97,46 +105,23 @@ module FQTypeName = : FQTypeName = Package(package owner modules name version) - let userProgram - (modules : List) - (name : string) - (version : int) - : UserProgram = - assert' modules name version assertTypeName - { modules = modules; name = name; version = version } - - let fqUserProgram - (modules : List) - (name : string) - (version : int) - : FQTypeName = - UserProgram(userProgram modules name version) - - let packageToString (s : Package) : string = - let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - - let userProgramToString (s : UserProgram) : string = - let name = s.modules @ [ s.name ] |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" + packageName s.owner s.modules s.name s.version let toString (name : FQTypeName) : string = match name with | Package pkg -> packageToString pkg - | UserProgram user -> userProgramToString user let toShortName (name : FQTypeName) : string = match name with - | UserProgram { name = name; version = version } | Package { name = name; version = version } -> if version = 0 then name else $"{name}_v{version}" /// A Fully-Qualified Constant Name /// -/// Used to reference a constant defined by the runtime, in a Package, or by a User +/// Used to reference a constant defined by the runtime or in a Package module FQConstantName = /// A constant built into the runtime /// @@ -149,15 +134,9 @@ module FQConstantName = name : string version : int } - /// Part of the user's program (eg canvas or cli) - /// - /// TODO: consider whether modules should be a NonEmptyList - type UserProgram = { modules : List; name : string; version : int } - type FQConstantName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram let assertConstantName (name : string) : unit = @@ -187,44 +166,23 @@ module FQConstantName = : FQConstantName = Package(package owner modules name version) - let userProgram - (modules : List) - (name : string) - (version : int) - : UserProgram = - assert' modules name version assertConstantName - { modules = modules; name = name; version = version } - - let fqUserProgram - (modules : List) - (name : string) - (version : int) - : FQConstantName = - UserProgram(userProgram modules name version) - let builtinToString (s : Builtin) : string = let name = s.name if s.version = 0 then name else $"{name}_v{s.version}" let packageToString (s : Package) : string = - let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - - let userProgramToString (s : UserProgram) : string = - let name = s.modules @ [ s.name ] |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" + packageName s.owner s.modules s.name s.version let toString (name : FQConstantName) : string = match name with | Builtin b -> builtinToString b | Package p -> packageToString p - | UserProgram u -> userProgramToString u /// A Fully-Qualified Function Name /// -/// Used to reference a function defined by the runtime, in a Package, or by a User +/// Used to reference a function defined by the runtime or in a Package module FQFnName = /// A function built into the runtime /// @@ -239,14 +197,9 @@ module FQFnName = name : string version : int } - /// Part of the user's program (eg canvas or cli) - type UserProgram = { modules : List; name : string; version : int } - - type FQFnName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram let assertFnName (name : string) : unit = @@ -280,39 +233,18 @@ module FQFnName = : FQFnName = Package(package owner modules name version) - let userProgram - (modules : List) - (name : string) - (version : int) - : UserProgram = - assert' modules name version assertFnName - { modules = modules; name = name; version = version } - - let fqUserProgram - (modules : List) - (name : string) - (version : int) - : FQFnName = - UserProgram(userProgram modules name version) - let builtinToString (s : Builtin) : string = let name = s.name if s.version = 0 then name else $"{name}_v{s.version}" let packageToString (s : Package) : string = - let name = ("PACKAGE" :: s.owner :: s.modules @ [ s.name ]) |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" - - let userProgramToString (s : UserProgram) : string = - let name = s.modules @ [ s.name ] |> String.concat "." - if s.version = 0 then name else $"{name}_v{s.version}" + packageName s.owner s.modules s.name s.version let toString (name : FQFnName) : string = match name with | Builtin b -> builtinToString b | Package pkg -> packageToString pkg - | UserProgram user -> userProgramToString user let isInternalFn (fnName : Builtin) : bool = fnName.name.Contains("darkInternal") @@ -1302,10 +1234,11 @@ type Const = // ------------ module PackageType = - type T = { name : FQTypeName.Package; declaration : TypeDeclaration.T } + type T = + { tlid : tlid; name : FQTypeName.Package; declaration : TypeDeclaration.T } module PackageConstant = - type T = { name : FQConstantName.Package; body : Const } + type T = { tlid : tlid; name : FQConstantName.Package; body : Const } module PackageFn = type Parameter = { name : string; typ : TypeReference } @@ -1322,24 +1255,6 @@ module PackageFn = // ------------ // User stuff // ------------ -module UserType = - type T = - { tlid : tlid; name : FQTypeName.UserProgram; declaration : TypeDeclaration.T } - -module UserConstant = - type T = { tlid : tlid; name : FQConstantName.UserProgram; body : Const } - -module UserFunction = - type Parameter = { name : string; typ : TypeReference } - - type T = - { tlid : tlid - name : FQFnName.UserProgram - typeParams : List - parameters : NEList - returnType : TypeReference - body : Expr } - module DB = type T = { tlid : tlid; name : string; typ : TypeReference; version : int } @@ -1367,17 +1282,11 @@ module Toplevel = type T = | TLHandler of Handler.T | TLDB of DB.T - | TLFunction of UserFunction.T - | TLType of UserType.T - | TLConstant of UserConstant.T let toTLID (tl : T) : tlid = match tl with | TLHandler h -> h.tlid | TLDB db -> db.tlid - | TLFunction f -> f.tlid - | TLType t -> t.tlid - | TLConstant c -> c.tlid @@ -1497,7 +1406,6 @@ and BuiltInFnSig = and FnImpl = | BuiltInFunction of BuiltInFnSig - | UserProgramFunction of tlid * Expr | PackageFunction of tlid * Expr @@ -1516,10 +1424,6 @@ and Program = { canvasID : CanvasID internalFnsAllowed : bool // whether this canvas is allowed call internal functions - types : Map - constants : Map - fns : Map - dbs : Map secrets : List } @@ -1552,7 +1456,7 @@ and PackageManager = init : Ply } - static member Empty = + static member empty = { getType = (fun _ -> Ply None) getFn = (fun _ -> Ply None) getFnByTLID = (fun _ -> Ply None) @@ -1560,6 +1464,36 @@ and PackageManager = init = uply { return () } } + /// Allows you to side-load a few 'extras' in-memory, along + /// the normal fetching functionality. (Mostly helpful for tests) + static member withExtras + (pm : PackageManager) + (types : List) + (constants : List) + (fns : List) + : PackageManager = + { getType = + fun name -> + match types |> List.tryFind (fun t -> t.name = name) with + | Some t -> Some t |> Ply + | None -> pm.getType name + getConstant = + fun name -> + match constants |> List.tryFind (fun c -> c.name = name) with + | Some c -> Some c |> Ply + | None -> pm.getConstant name + getFn = + fun name -> + match fns |> List.tryFind (fun f -> f.name = name) with + | Some f -> Some f |> Ply + | None -> pm.getFn name + getFnByTLID = + fun tlid -> + match fns |> List.tryFind (fun f -> f.tlid = tlid) with + | Some f -> Some f |> Ply + | None -> pm.getFnByTLID tlid + init = pm.init } + and ExceptionReporter = ExecutionState -> Metadata -> exn -> unit and Notifier = ExecutionState -> string -> Metadata -> unit @@ -1582,7 +1516,7 @@ and ExecutionState = notify : Notifier // -- Set at the start of an execution -- - program : Program // TODO: rename to UserCode? + program : Program // TODO: rename to Canvas? // -- Can change over time during execution -- @@ -1599,36 +1533,29 @@ and ExecutionState = and Types = { typeSymbolTable : TypeSymbolTable - package : FQTypeName.Package -> Ply> - userProgram : Map } + package : FQTypeName.Package -> Ply> } and Constants = { builtIn : Map - package : FQConstantName.Package -> Ply> - userProgram : Map } + package : FQConstantName.Package -> Ply> } and Functions = { builtIn : Map - package : FQFnName.Package -> Ply> - userProgram : Map } + package : FQFnName.Package -> Ply> } module ExecutionState = let availableTypes (state : ExecutionState) : Types = { typeSymbolTable = state.typeSymbolTable - package = state.packageManager.getType - userProgram = state.program.types } + package = state.packageManager.getType } let availableConstants (state : ExecutionState) : Constants = { builtIn = state.builtins.constants - package = state.packageManager.getConstant - userProgram = state.program.constants } + package = state.packageManager.getConstant } let availableFunctions (state : ExecutionState) : Functions = - { builtIn = state.builtins.fns - package = state.packageManager.getFn - userProgram = state.program.fns } + { builtIn = state.builtins.fns; package = state.packageManager.getFn } @@ -1636,8 +1563,7 @@ module Types = let empty = { typeSymbolTable = Map.empty - package = (fun _ -> Ply None) - userProgram = Map.empty } + package = (fun _ -> Ply None) } let find // TODO: swap these args @@ -1648,9 +1574,6 @@ module Types = | FQTypeName.Package pkg -> types.package pkg |> Ply.map (Option.map _.declaration) - | FQTypeName.UserProgram user -> - Map.find user types.userProgram |> Option.map _.declaration |> Ply - // Swap concrete types for type parameters let rec substitute (typeParams : List) @@ -1755,14 +1678,3 @@ let packageFnToFn (fn : PackageFn.T) : Fn = previewable = Impure sqlSpec = NotQueryable fn = PackageFunction(fn.tlid, fn.body) } - -let userFnToFn (fn : UserFunction.T) : Fn = - let toParam (p : UserFunction.Parameter) : Param = { name = p.name; typ = p.typ } - - { name = FQFnName.UserProgram fn.name - typeParams = fn.typeParams - parameters = NEList.map toParam fn.parameters - returnType = fn.returnType - previewable = Impure - sqlSpec = NotQueryable - fn = UserProgramFunction(fn.tlid, fn.body) } diff --git a/backend/src/LibExecution/RuntimeTypesToDarkTypes.fs b/backend/src/LibExecution/RuntimeTypesToDarkTypes.fs index 19e22c66fa..9b04eff976 100644 --- a/backend/src/LibExecution/RuntimeTypesToDarkTypes.fs +++ b/backend/src/LibExecution/RuntimeTypesToDarkTypes.fs @@ -60,28 +60,10 @@ module FQTypeName = | _ -> Exception.raiseInternal "Invalid FQTypeName.Package" [] - module UserProgram = - let toDT (u : FQTypeName.UserProgram) : Dval = - let fields = - [ "modules", DList(VT.string, List.map DString u.modules) - "name", DString u.name - "version", DInt64 u.version ] - let typeName = rtTyp [ "FQTypeName" ] "UserProgram" 0 - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : FQTypeName.UserProgram = - match d with - | DRecord(_, _, _, fields) -> - { modules = modulesField fields - name = nameField fields - version = versionField fields } - | _ -> Exception.raiseInternal "Invalid FQTypeName.UserProgram" [] - let toDT (u : FQTypeName.FQTypeName) : Dval = let (caseName, fields) = match u with | FQTypeName.Package u -> "Package", [ Package.toDT u ] - | FQTypeName.UserProgram u -> "UserProgram", [ UserProgram.toDT u ] let typeName = rtTyp [ "FQTypeName" ] "FQTypeName" 0 DEnum(typeName, typeName, [], caseName, fields) @@ -90,10 +72,6 @@ module FQTypeName = let fromDT (d : Dval) : FQTypeName.FQTypeName = match d with | DEnum(_, _, [], "Package", [ u ]) -> FQTypeName.Package(Package.fromDT u) - - | DEnum(_, _, [], "UserProgram", [ u ]) -> - FQTypeName.UserProgram(UserProgram.fromDT u) - | _ -> Exception.raiseInternal "Invalid FQTypeName" [] @@ -131,29 +109,11 @@ module FQConstantName = version = versionField fields } | _ -> Exception.raiseInternal "Invalid FQConstantName.Package" [] - module UserProgram = - let toDT (u : FQConstantName.UserProgram) : Dval = - let fields = - [ "modules", DList(VT.string, List.map DString u.modules) - "name", DString u.name - "version", DInt64 u.version ] - let typeName = rtTyp [ "FQConstantName" ] "UserProgram" 0 - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : FQConstantName.UserProgram = - match d with - | DRecord(_, _, _, fields) -> - { modules = modulesField fields - name = nameField fields - version = versionField fields } - | _ -> Exception.raiseInternal "Invalid FQConstantName.UserProgram" [] - let toDT (u : FQConstantName.FQConstantName) : Dval = let (caseName, fields) = match u with | FQConstantName.Builtin u -> "Builtin", [ Builtin.toDT u ] | FQConstantName.Package u -> "Package", [ Package.toDT u ] - | FQConstantName.UserProgram u -> "UserProgram", [ UserProgram.toDT u ] let typeName = rtTyp [ "FQConstantName" ] "FQConstantName" 0 DEnum(typeName, typeName, [], caseName, fields) @@ -164,9 +124,6 @@ module FQConstantName = | DEnum(_, _, [], "Package", [ u ]) -> FQConstantName.Package(Package.fromDT u) - | DEnum(_, _, [], "UserProgram", [ u ]) -> - FQConstantName.UserProgram(UserProgram.fromDT u) - | _ -> Exception.raiseInternal "Invalid FQConstantName" [] @@ -205,30 +162,11 @@ module FQFnName = | _ -> Exception.raiseInternal "Invalid FQFnName.Package" [] - module UserProgram = - let toDT (u : FQFnName.UserProgram) : Dval = - let fields = - [ "modules", DList(VT.string, List.map DString u.modules) - "name", DString u.name - "version", DInt64 u.version ] - let typeName = rtTyp [ "FQFnName" ] "UserProgram" 0 - DRecord(typeName, typeName, [], Map fields) - - let fromDT (d : Dval) : FQFnName.UserProgram = - match d with - | DRecord(_, _, _, fields) -> - { modules = modulesField fields - name = nameField fields - version = versionField fields } - | _ -> Exception.raiseInternal "Invalid FQFnName.UserProgram" [] - - let toDT (u : FQFnName.FQFnName) : Dval = let (caseName, fields) = match u with | FQFnName.Builtin u -> "Builtin", [ Builtin.toDT u ] | FQFnName.Package u -> "Package", [ Package.toDT u ] - | FQFnName.UserProgram u -> "UserProgram", [ UserProgram.toDT u ] let typeName = rtTyp [ "FQFnName" ] "FQFnName" 0 DEnum(typeName, typeName, [], caseName, fields) @@ -239,9 +177,6 @@ module FQFnName = | DEnum(_, _, [], "Package", [ u ]) -> FQFnName.Package(Package.fromDT u) - | DEnum(_, _, [], "UserProgram", [ u ]) -> - FQFnName.UserProgram(UserProgram.fromDT u) - | _ -> Exception.raiseInternal "Invalid FQFnName" [] diff --git a/backend/src/LibParser/Canvas.fs b/backend/src/LibParser/Canvas.fs index d9901d4f69..f3804087b1 100644 --- a/backend/src/LibParser/Canvas.fs +++ b/backend/src/LibParser/Canvas.fs @@ -4,28 +4,32 @@ open FSharp.Compiler.Syntax open Prelude -module FS2WT = FSharpToWrittenTypes +module RT = LibExecution.RuntimeTypes +module PT = LibExecution.ProgramTypes +module PT2RT = LibExecution.ProgramTypesToRuntimeTypes + module WT = WrittenTypes +module FS2WT = FSharpToWrittenTypes module WT2PT = WrittenTypesToProgramTypes -module PT = LibExecution.ProgramTypes -module RT = LibExecution.RuntimeTypes module NR = NameResolver open Utils open ParserException type WTCanvasModule = - { name : List - types : List - constants : List + { owner : string + name : List + types : List + constants : List dbs : List - fns : List + fns : List // TODO: consider breaking this down into httpHandlers, crons, workers, and repls handlers : List exprs : List } -let emptyWTModule = - { name = [] +let emptyRootWTModule owner canvasName = + { owner = owner + name = [ "Canvas"; canvasName ] types = [] constants = [] dbs = [] @@ -34,10 +38,12 @@ let emptyWTModule = exprs = [] } type PTCanvasModule = - { types : List - constants : List + { // These will end up in the package manager + types : List + constants : List + fns : List + dbs : List - fns : List // TODO: consider breaking this down into httpHandlers, crons, workers, and repls handlers : List exprs : List } @@ -101,7 +107,7 @@ let parseLetBinding (m : WTCanvasModule) (letBinding : SynBinding) : WTCanvasMod WT.ELet(gid (), FS2WT.LetPattern.fromSynPat pat, expr, WT.EUnit(gid ())) { m with exprs = m.exprs @ [ newExpr ] } | Some _ -> - let newFn = FS2WT.UserFunction.fromSynBinding m.name letBinding + let newFn = FS2WT.PackageFn.fromSynBinding m.owner m.name letBinding { m with fns = newFn :: m.fns } | [ attr ] -> @@ -178,7 +184,7 @@ let parseTypeDefn (m : WTCanvasModule) (typeDefn : SynTypeDefn) : WTCanvasModule if isDB then [ UserDB.fromSynTypeDefn typeDefn ], [] else - [], [ FS2WT.UserType.fromSynTypeDefn m.name typeDefn ] + [], [ FS2WT.PackageType.fromSynTypeDefn m.owner m.name typeDefn ] { m with types = m.types @ newTypes; dbs = m.dbs @ newDBs } @@ -198,7 +204,11 @@ let parseTypeDefn (m : WTCanvasModule) (typeDefn : SynTypeDefn) : WTCanvasModule /// or as DBs (i.e. with `[] DBName = Type`) /// - ? expressions are parsed as init commands (not currently supported) /// - anything else fails -let parseDecls (decls : List) : WTCanvasModule = +let parseDecls + (owner : string) + (canvasName : string) + (decls : List) + : WTCanvasModule = List.fold (fun m decl -> match decl with @@ -216,104 +226,109 @@ let parseDecls (decls : List) : WTCanvasModule = "Unsupported declaration" [ "decl", decl ] (Some decl.Range)) - emptyWTModule + (emptyRootWTModule owner canvasName) decls let toPT (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (m : WTCanvasModule) : Ply = uply { let! types = m.types - |> Ply.List.mapSequentially (WT2PT.UserType.toPT pm userStuff onMissing m.name) - let! fns = - m.fns |> Ply.List.mapSequentially ( - WT2PT.UserFunction.toPT builtins pm userStuff onMissing m.name + WT2PT.PackageType.toPT pm onMissing (m.owner :: m.name) ) + let! constants = m.constants |> Ply.List.mapSequentially ( - WT2PT.UserConstant.toPT pm userStuff onMissing m.name + WT2PT.PackageConstant.toPT pm onMissing (m.owner :: m.name) ) + let! dbs = - m.dbs |> Ply.List.mapSequentially (WT2PT.DB.toPT pm userStuff onMissing m.name) + m.dbs + |> Ply.List.mapSequentially (WT2PT.DB.toPT pm onMissing (m.owner :: m.name)) + + let! fns = + m.fns + |> Ply.List.mapSequentially ( + WT2PT.PackageFn.toPT builtins pm onMissing (m.owner :: m.name) + ) + let! handlers = m.handlers |> Ply.List.mapSequentially (fun (spec, expr) -> uply { let spec = WT2PT.Handler.Spec.toPT spec - let! expr = WT2PT.Expr.toPT builtins pm userStuff onMissing m.name expr + let! expr = WT2PT.Expr.toPT builtins pm onMissing (m.owner :: m.name) expr return (spec, expr) }) + let! exprs = m.exprs |> Ply.List.mapSequentially ( - WT2PT.Expr.toPT builtins pm userStuff onMissing m.name + WT2PT.Expr.toPT builtins pm onMissing (m.owner :: m.name) ) return { types = types - fns = fns constants = constants dbs = dbs + fns = fns handlers = handlers exprs = exprs } } let parse + (owner : string) + (canvasName : string) (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) (source : string) : Ply = - let parsedAsFSharp = parseAsFSharpSourceFile filename source - - let decls = - match parsedAsFSharp with - | ParsedImplFileInput(_, - _, - _, - _, - _, - [ SynModuleOrNamespace(_, _, _, decls, _, _, _, _, _) ], - _, - _, - _) -> decls - | _ -> - raiseParserError - "Wrong shape tree - parseable canvas definitions must contain a single module with declarations inside" - [ "parsedAsFsharp", parsedAsFSharp ] - None // whole file - // To WrittenTypes - let module' = parseDecls decls + uply { + let parsedAsFSharp = parseAsFSharpSourceFile filename source + + let decls = + match parsedAsFSharp with + | ParsedImplFileInput(_, + _, + _, + _, + _, + [ SynModuleOrNamespace(_, _, _, decls, _, _, _, _, _) ], + _, + _, + _) -> decls + | _ -> + raiseParserError + "Wrong shape tree - parseable canvas definitions must contain a single module with declarations inside" + [ "parsedAsFsharp", parsedAsFSharp ] + None // whole file + + let moduleWT = parseDecls owner canvasName decls + debuG "Parsed module" moduleWT - // To ProgramTypes -- with the 'new stuff' in context - let updatedUserStuff : NR.UserStuff = - { types = Set.union userStuff.types (module'.types |> List.map _.name |> Set) - constants = - Set.union userStuff.constants (module'.constants |> List.map _.name |> Set) - fns = Set.union userStuff.fns (module'.fns |> List.map _.name |> Set) } + // Initial pass, so we can re-parse with all names in context + let! result = toPT builtins pm onMissing moduleWT - toPT builtins pm updatedUserStuff onMissing module' + let pm = + RT.PackageManager.withExtras + pm + (result.types |> List.map PT2RT.PackageType.toRT) + (result.constants |> List.map PT2RT.PackageConstant.toRT) + (result.fns |> List.map PT2RT.PackageFn.toRT) + // Now, parse again, but with the names in context (so fewer are marked as unresolved) + let! result = toPT builtins pm onMissing moduleWT -let parseFromFile - (builtins : RT.Builtins) - (pm : RT.PackageManager) - (userStuff : NR.UserStuff) - (onMissing : NR.OnMissing) - (filename : string) - : Ply = - filename - |> System.IO.File.ReadAllText - |> parse builtins pm userStuff onMissing filename + return result + } diff --git a/backend/src/LibParser/FSharpToWrittenTypes.fs b/backend/src/LibParser/FSharpToWrittenTypes.fs index 8cd9189bf1..25cc7859bd 100644 --- a/backend/src/LibParser/FSharpToWrittenTypes.fs +++ b/backend/src/LibParser/FSharpToWrittenTypes.fs @@ -838,23 +838,7 @@ module Function = returnType = returnType body = Expr.fromSynExpr expr } -module UserFunction = - let fromSynBinding - (moduleName : List) - (b : SynBinding) - : WT.UserFunction.T = - let f = Function.fromSynBinding b - { name = PT.FQFnName.userProgram moduleName f.name f.version - typeParams = f.typeParams - parameters = - f.parameters - |> NEList.map (fun p -> { name = p.name; description = ""; typ = p.typ }) - returnType = f.returnType - description = "" - body = f.body } - module Constant = - type T = { name : string; version : int; body : WT.Const } let fromSynExpr (expr : SynExpr) : WT.Const = @@ -916,17 +900,6 @@ module Constant = (Some binding.RangeOfBindingWithRhs) -module UserConstant = - let fromSynBinding - (moduleName : List) - (b : SynBinding) - : WT.UserConstant.T = - let c = Constant.fromSynBinding b - { name = PT.FQConstantName.userProgram moduleName c.name c.version - description = "" - body = c.body } - - module PackageFn = let fromSynBinding (owner : string) @@ -1059,26 +1032,6 @@ module TypeDeclaration = (Some typeDef.Range) -module UserType = - let fromSynTypeDefn - (moduleName : List) - (typeDef : SynTypeDefn) - : WT.UserType.T = - let (typeParams, names, definition) = - TypeDeclaration.Definition.fromSynTypeDefn typeDef - let (name, version) = - List.last names - |> Exception.unwrapOptionInternal - "user type should have name" - [ "typeDef", typeDef ] - |> Expr.parseTypeName - |> Exception.unwrapResultInternal [] - let modules = moduleName @ names |> List.initial - - { name = PT.FQTypeName.userProgram modules name version - description = "" - declaration = { definition = definition; typeParams = typeParams } } - module PackageType = let fromSynTypeDefn (owner : string) diff --git a/backend/src/LibParser/NameResolver.fs b/backend/src/LibParser/NameResolver.fs index 89cd63104e..d27014c2ab 100644 --- a/backend/src/LibParser/NameResolver.fs +++ b/backend/src/LibParser/NameResolver.fs @@ -10,19 +10,6 @@ module RT = LibExecution.RuntimeTypes module NRE = LibExecution.NameResolutionError -type UserStuff = - { types : Set - constants : Set - fns : Set } - - static member empty = { types = Set.empty; constants = Set.empty; fns = Set.empty } - static member fromProgram(program : RT.Program) : UserStuff = - let map fn items = items |> Map.keys |> List.map fn |> Set - { types = program.types |> map PT2RT.FQTypeName.UserProgram.fromRT - constants = program.constants |> map PT2RT.FQConstantName.UserProgram.fromRT - fns = program.fns |> map PT2RT.FQFnName.UserProgram.fromRT } - - /// If a name is not found, should we raise an exception? /// /// - when the local package DB is fully empty, and we're filling it in for the @@ -66,6 +53,9 @@ type GenericName = { modules : List; name : string; version : int } /// - Darklang.Option.Option /// - Option.Option /// , in that order (most specific first). +/// +/// TODO?: accept an Option of the _owner_ as well. +/// I think that'll be useful in many contexts to help resolve names... let namesToTry (currentModule : List) (given : GenericName) @@ -90,7 +80,6 @@ let namesToTry let resolveTypeName (packageManager : RT.PackageManager) - (userTypes : Set) (onMissing : OnMissing) (currentModule : List) (name : WT.Name) @@ -119,18 +108,12 @@ let resolveTypeName (name : GenericName) : Ply> = uply { - let (userProgram : PT.FQTypeName.UserProgram) = - { modules = name.modules; name = name.name; version = name.version } - - if Set.contains userProgram userTypes then - return Ok(PT.FQTypeName.UserProgram userProgram) - else - match name.modules with - | [] -> return Error() - | owner :: modules -> - let name = PT.FQTypeName.package owner modules name.name name.version - let! packageName = tryPackageName name - return packageName |> Result.mapError (fun _ -> ()) + match name.modules with + | [] -> return Error() + | owner :: modules -> + let name = PT.FQTypeName.package owner modules name.name name.version + let! packageName = tryPackageName name + return packageName |> Result.mapError (fun _ -> ()) } uply { @@ -165,7 +148,6 @@ let resolveTypeName let resolveConstantName (builtinConstants : Set) (packageManager : RT.PackageManager) - (userConstants : Set) (onMissing : OnMissing) (currentModule : List) (name : WT.Name) @@ -193,25 +175,21 @@ let resolveConstantName (name : GenericName) : Ply> = uply { - let (userProgram : PT.FQConstantName.UserProgram) = - { modules = name.modules; name = name.name; version = name.version } - - if name.modules = [ "Builtin" ] then - let (builtInRT : RT.FQConstantName.Builtin) = - { name = name.name; version = name.version } - if Set.contains builtInRT builtinConstants then - let (builtInPT : PT.FQConstantName.Builtin) = + match name.modules with + | [] -> return Error() + | owner :: modules -> + if owner = "Builtin" && modules = [] then + let (builtInRT : RT.FQConstantName.Builtin) = { name = name.name; version = name.version } - return Ok(PT.FQConstantName.Builtin builtInPT) + + if Set.contains builtInRT builtinConstants then + let (builtInPT : PT.FQConstantName.Builtin) = + { name = name.name; version = name.version } + return Ok(PT.FQConstantName.Builtin builtInPT) + else + return Error() else - return Error() - elif Set.contains userProgram userConstants then - return Ok(PT.FQConstantName.UserProgram userProgram) - else - match name.modules with - | [] -> return Error() - | owner :: modules -> let name = PT.FQConstantName.package owner modules name.name name.version let! packageName = tryPackageName name return packageName |> Result.mapError (fun _ -> ()) @@ -247,7 +225,6 @@ let resolveConstantName let resolveFnName (builtinFns : Set) (packageManager : RT.PackageManager) - (userFns : Set) (onMissing : OnMissing) (currentModule : List) (name : WT.Name) @@ -272,26 +249,21 @@ let resolveFnName let tryResolve (name : GenericName) : Ply> = uply { - let (userProgram : PT.FQFnName.UserProgram) = - { modules = name.modules; name = name.name; version = name.version } + match name.modules with + | [] -> return Error() + | owner :: modules -> + if owner = "Builtin" && modules = [] then + let (builtInRT : RT.FQFnName.Builtin) = + { name = name.name; version = name.version } - if name.modules = [ "Builtin" ] then - let (builtInRT : RT.FQFnName.Builtin) = - { name = name.name; version = name.version } + if Set.contains builtInRT builtinFns then + let (builtInPT : PT.FQFnName.Builtin) = + { name = name.name; version = name.version } + return Ok(PT.FQFnName.Builtin builtInPT) + else + return Error() - if Set.contains builtInRT builtinFns then - let (builtInPT : PT.FQFnName.Builtin) = - { name = name.name; version = name.version } - return Ok(PT.FQFnName.Builtin builtInPT) else - return Error() - - elif Set.contains userProgram userFns then - return Ok(PT.FQFnName.UserProgram userProgram) - else - match name.modules with - | [] -> return Error() - | owner :: modules -> let name = PT.FQFnName.package owner modules name.name name.version let! packageName = tryPackageName name return packageName |> Result.mapError (fun _ -> ()) diff --git a/backend/src/LibParser/Package.fs b/backend/src/LibParser/Package.fs index d729e2f010..102179eb93 100644 --- a/backend/src/LibParser/Package.fs +++ b/backend/src/LibParser/Package.fs @@ -100,7 +100,6 @@ let rec parseDecls let parse (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) (contents : string) @@ -133,30 +132,18 @@ let parse let! fns = modul.fns |> Ply.List.mapSequentially (fun fn -> - WT2PT.PackageFn.toPT - builtins - pm - userStuff - onMissing - (fnNameToModules fn.name) - fn) + WT2PT.PackageFn.toPT builtins pm onMissing (fnNameToModules fn.name) fn) let! types = modul.types |> Ply.List.mapSequentially (fun typ -> - WT2PT.PackageType.toPT - pm - userStuff - onMissing - (typeNameToModules typ.name) - typ) + WT2PT.PackageType.toPT pm onMissing (typeNameToModules typ.name) typ) let! constants = modul.constants |> Ply.List.mapSequentially (fun constant -> WT2PT.PackageConstant.toPT pm - userStuff onMissing (constantNameToModules constant.name) constant) diff --git a/backend/src/LibParser/Parser.fs b/backend/src/LibParser/Parser.fs index 123fbe7ebc..ab6949a39e 100644 --- a/backend/src/LibParser/Parser.fs +++ b/backend/src/LibParser/Parser.fs @@ -23,50 +23,44 @@ let initialParse (filename : string) (code : string) : WT.Expr = let parsePTExpr (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) (code : string) : Ply = - code - |> initialParse filename - |> WT2PT.Expr.toPT builtins pm userStuff onMissing [] + code |> initialParse filename |> WT2PT.Expr.toPT builtins pm onMissing [] let parseSimple (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) (code : string) : Ply = - parsePTExpr builtins pm userStuff onMissing filename code + parsePTExpr builtins pm onMissing filename code let parseRTExpr (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) (code : string) : Ply = code - |> parsePTExpr builtins pm userStuff onMissing filename + |> parsePTExpr builtins pm onMissing filename |> Ply.map LibExecution.ProgramTypesToRuntimeTypes.Expr.toRT let parsePackageFile (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (path : string) (contents : string) : Ply = uply { - let! pModule = Package.parse builtins pm userStuff onMissing path contents + let! pModule = Package.parse builtins pm onMissing path contents return { types = pModule.types; constants = pModule.constants; fns = pModule.fns } } diff --git a/backend/src/LibParser/TestModule.fs b/backend/src/LibParser/TestModule.fs index 2eac1e2a63..9d2ec59281 100644 --- a/backend/src/LibParser/TestModule.fs +++ b/backend/src/LibParser/TestModule.fs @@ -19,9 +19,9 @@ type WTTest = type WTModule = { name : List - types : List - fns : List - constants : List + types : List + fns : List + constants : List dbs : List tests : List } @@ -33,9 +33,9 @@ type PTTest = type PTModule = { name : List - types : List - fns : List - constants : List + types : List + fns : List + constants : List dbs : List tests : List } @@ -47,9 +47,9 @@ type RTTest = type RTModule = { name : List - types : List - fns : List - constants : List + types : List + fns : List + constants : List dbs : List tests : List } @@ -95,11 +95,14 @@ let parseTest (ast : SynExpr) : WTTest = | _ -> Exception.raiseInternal "Test case not in format `x = y`" [ "ast", ast ] -let parseFile (parsedAsFSharp : ParsedImplFileInput) : List = +let parseFile + (owner : string) + (parsedAsFSharp : ParsedImplFileInput) + : List = let parseTypeDecl - (moduleName : List) + (currentModule : List) (typeDefn : SynTypeDefn) - : List * List = + : List * List = match typeDefn with | SynTypeDefn(SynComponentInfo(attrs, _, _, _, _, _, _, _), _, _, _, _, _) -> let attrs = attrs |> List.map _.Attributes |> List.concat @@ -108,25 +111,27 @@ let parseFile (parsedAsFSharp : ParsedImplFileInput) : List = |> List.exists (fun attr -> longIdentToList attr.TypeName.LongIdent = [ "DB" ]) if isDB then + // TODO [ UserDB.fromSynTypeDefn typeDefn ], [] else - [], [ FS2WT.UserType.fromSynTypeDefn moduleName typeDefn ] + [], [ FS2WT.PackageType.fromSynTypeDefn owner currentModule typeDefn ] + let parseSynBinding - (moduleName : List) + (currentModule : List) (binding : SynBinding) - : List * List = + : List * List = match binding with | SynBinding(_, _, _, _, _, _, _, signature, _, _, _, _, _) -> match signature with | SynPat.LongIdent(SynLongIdent _, _, _, _, _, _) -> - [ FS2WT.UserFunction.fromSynBinding moduleName binding ], [] + [ FS2WT.PackageFn.fromSynBinding owner currentModule binding ], [] | SynPat.Named _ -> - [], [ FS2WT.UserConstant.fromSynBinding moduleName binding ] + [], [ FS2WT.PackageConstant.fromSynBinding owner currentModule binding ] | _ -> Exception.raiseInternal $"Unsupported binding" [ "binding", binding ] let rec parseModule - (moduleName : List) + (currentModule : List) (parentDBs : List) (decls : List) : List = @@ -135,16 +140,16 @@ let parseFile (parsedAsFSharp : ParsedImplFileInput) : List = (fun ((m : WTModule), nested) decl -> match decl with | SynModuleDecl.Let(_, bindings, _) -> - let (newUserFns, newUserConstants) = - bindings |> List.map (parseSynBinding moduleName) |> List.unzip + let (newUserFns, newPackageConstants) = + bindings |> List.map (parseSynBinding currentModule) |> List.unzip ({ m with fns = m.fns @ List.concat newUserFns - constants = m.constants @ List.concat newUserConstants }, + constants = m.constants @ List.concat newPackageConstants }, nested) | SynModuleDecl.Types(defns, _) -> let (dbs, types) = - List.map (parseTypeDecl moduleName) defns |> List.unzip + List.map (parseTypeDecl currentModule) defns |> List.unzip ({ m with types = m.types @ List.concat types dbs = m.dbs @ List.concat dbs }, @@ -166,9 +171,10 @@ let parseFile (parsedAsFSharp : ParsedImplFileInput) : List = _, _, _) -> - (m, parseModule (moduleName @ [ modName.idText ]) m.dbs decls @ nested) + (m, + parseModule (currentModule @ [ modName.idText ]) m.dbs decls @ nested) | _ -> Exception.raiseInternal $"Unsupported declaration" [ "decl", decl ]) - ({ emptyWTModule with name = moduleName; dbs = parentDBs }, []) + ({ emptyWTModule with name = currentModule; dbs = parentDBs }, []) decls m :: nested @@ -191,33 +197,39 @@ let parseFile (parsedAsFSharp : ParsedImplFileInput) : List = let toPT + (owner : string) (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (m : WTModule) : Ply = uply { - let! fns = - m.fns - |> Ply.List.mapSequentially ( - WT2PT.UserFunction.toPT builtins pm userStuff onMissing m.name - ) + let currentModule = owner :: m.name + let! types = m.types - |> Ply.List.mapSequentially (WT2PT.UserType.toPT pm userStuff onMissing m.name) + |> Ply.List.mapSequentially (WT2PT.PackageType.toPT pm onMissing currentModule) + let! constants = m.constants |> Ply.List.mapSequentially ( - WT2PT.UserConstant.toPT pm userStuff onMissing m.name + WT2PT.PackageConstant.toPT pm onMissing currentModule ) + let! dbs = - m.dbs |> Ply.List.mapSequentially (WT2PT.DB.toPT pm userStuff onMissing m.name) + m.dbs |> Ply.List.mapSequentially (WT2PT.DB.toPT pm onMissing currentModule) + + let! fns = + m.fns + |> Ply.List.mapSequentially ( + WT2PT.PackageFn.toPT builtins pm onMissing currentModule + ) + let! (tests : List) = m.tests |> Ply.List.mapSequentially (fun test -> uply { - let exprToPT = WT2PT.Expr.toPT builtins pm userStuff onMissing m.name + let exprToPT = WT2PT.Expr.toPT builtins pm onMissing currentModule let! actual = exprToPT test.actual let! expected = exprToPT test.expected return @@ -242,34 +254,33 @@ let toPT /// Returns a flattened list of modules in the file. let parseTestFile + (owner : string) (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) : Ply> = uply { - let modules = + let modulesWT = filename |> System.IO.File.ReadAllText |> parseAsFSharpSourceFile filename - |> parseFile + |> parseFile owner - let fns = - modules |> List.map _.fns |> List.concat |> List.map _.name |> Set.ofList - let types = - modules |> List.map _.types |> List.concat |> List.map _.name |> Set.ofList - let constants = - modules |> List.map _.constants |> List.concat |> List.map _.name |> Set.ofList + // Initial pass, so we can re-parse with all names in context + let! (result : List) = + modulesWT |> Ply.List.mapSequentially (toPT owner builtins pm onMissing) - let updatedUserStuff : NR.UserStuff = - { types = Set.union userStuff.types types - constants = Set.union userStuff.constants constants - fns = Set.union userStuff.fns fns } + // Now, parse again, but with the names in context (so fewer are marked as unresolved) + let pm = + RT.PackageManager.withExtras + pm + (result |> List.collect _.types |> List.map PT2RT.PackageType.toRT) + (result |> List.collect _.constants |> List.map PT2RT.PackageConstant.toRT) + (result |> List.collect _.fns |> List.map PT2RT.PackageFn.toRT) - let! result = - modules - |> Ply.List.mapSequentially (toPT builtins pm updatedUserStuff onMissing) + let! (result : List) = + modulesWT |> Ply.List.mapSequentially (toPT owner builtins pm onMissing) return result } @@ -277,7 +288,6 @@ let parseTestFile let parseSingleTestFromFile (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (filename : string) (testSource : string) @@ -289,7 +299,7 @@ let parseSingleTestFromFile |> singleExprFromImplFile |> parseTest - let mapExpr = WT2PT.Expr.toPT builtins pm userStuff onMissing [] + let mapExpr = WT2PT.Expr.toPT builtins pm onMissing [] let! actual = wtTest.actual |> mapExpr |> Ply.map PT2RT.Expr.toRT let! expected = wtTest.expected |> mapExpr |> Ply.map PT2RT.Expr.toRT diff --git a/backend/src/LibParser/WrittenTypes.fs b/backend/src/LibParser/WrittenTypes.fs index 52caa774b4..c6314ed0a2 100644 --- a/backend/src/LibParser/WrittenTypes.fs +++ b/backend/src/LibParser/WrittenTypes.fs @@ -259,48 +259,14 @@ module TypeDeclaration = type T = { typeParams : List; definition : Definition } -module Handler = - type CronInterval = - | EveryFortnight - | EveryWeek - | EveryDay - | Every12Hours - | EveryHour - | EveryMinute - - type Spec = - | HTTP of route : string * method : string - | Worker of name : string - | Cron of name : string * interval : CronInterval - | REPL of name : string - - type T = { ast : Expr; spec : Spec } - - -module DB = - type T = { name : string; version : int; typ : TypeReference } - -module UserType = +module PackageType = type T = - { name : PT.FQTypeName.UserProgram + { name : PT.FQTypeName.Package declaration : TypeDeclaration.T description : string } -module UserFunction = - type Parameter = { name : string; typ : TypeReference; description : string } - - type T = - { name : PT.FQFnName.UserProgram - typeParams : List - parameters : NEList - returnType : TypeReference - description : string - body : Expr } - -module UserConstant = - type T = - { name : PT.FQConstantName.UserProgram; description : string; body : Const } - +module PackageConstant = + type T = { name : PT.FQConstantName.Package; description : string; body : Const } module PackageFn = type Parameter = { name : string; typ : TypeReference; description : string } @@ -313,11 +279,23 @@ module PackageFn = returnType : TypeReference description : string } -module PackageType = - type T = - { name : PT.FQTypeName.Package - declaration : TypeDeclaration.T - description : string } -module PackageConstant = - type T = { name : PT.FQConstantName.Package; description : string; body : Const } +module DB = + type T = { name : string; version : int; typ : TypeReference } + +module Handler = + type CronInterval = + | EveryFortnight + | EveryWeek + | EveryDay + | Every12Hours + | EveryHour + | EveryMinute + + type Spec = + | HTTP of route : string * method : string + | Worker of name : string + | Cron of name : string * interval : CronInterval + | REPL of name : string + + type T = { ast : Expr; spec : Spec } diff --git a/backend/src/LibParser/WrittenTypesToProgramTypes.fs b/backend/src/LibParser/WrittenTypesToProgramTypes.fs index f4a9a94202..17022ab602 100644 --- a/backend/src/LibParser/WrittenTypesToProgramTypes.fs +++ b/backend/src/LibParser/WrittenTypesToProgramTypes.fs @@ -30,12 +30,11 @@ module InfixFnName = module TypeReference = let rec toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (t : WT.TypeReference) : Ply = - let toPT = toPT pm userStuff onMissing currentModule + let toPT = toPT pm onMissing currentModule uply { match t with | WT.TUnit -> return PT.TUnit @@ -67,7 +66,7 @@ module TypeReference = | WT.TDict typ -> return! toPT typ |> Ply.map PT.TDict | WT.TCustomType(t, typeArgs) -> - let! t = NR.resolveTypeName pm userStuff.types onMissing currentModule t + let! t = NR.resolveTypeName pm onMissing currentModule t let! typeArgs = Ply.List.mapSequentially toPT typeArgs return PT.TCustomType(t, typeArgs) @@ -131,7 +130,6 @@ module MatchPattern = module Expr = let resolveTypeName (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (names : List) @@ -148,17 +146,16 @@ module Expr = ) | head :: tail -> let name = NEList.ofList head tail |> WT.Unresolved - NR.resolveTypeName pm userStuff.types onMissing currentModule name + NR.resolveTypeName pm onMissing currentModule name let rec toPT (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (e : WT.Expr) : Ply = - let toPT = toPT builtins pm userStuff onMissing currentModule + let toPT = toPT builtins pm onMissing currentModule uply { match e with | WT.EChar(id, char) -> return PT.EChar(id, char) @@ -175,7 +172,7 @@ module Expr = | WT.EString(id, segments) -> let! segments = Ply.List.mapSequentially - (stringSegmentToPT builtins pm userStuff onMissing currentModule) + (stringSegmentToPT builtins pm onMissing currentModule) segments return PT.EString(id, segments) | WT.EFloat(id, sign, whole, fraction) -> @@ -183,12 +180,12 @@ module Expr = | WT.EBool(id, b) -> return PT.EBool(id, b) | WT.EUnit id -> return PT.EUnit id | WT.EVariable(id, var) -> + if var = "format" then debuG "format" (currentModule) // This could be a UserConstant let! constant = NR.resolveConstantName (builtins.constants |> Map.keys |> Set) pm - userStuff.constants NR.OnMissing.Allow currentModule (WT.Unresolved(NEList.singleton var)) @@ -204,7 +201,6 @@ module Expr = NR.resolveFnName (builtins.fns |> Map.keys |> Set) pm - userStuff.fns NR.OnMissing.Allow currentModule name @@ -215,7 +211,6 @@ module Expr = NR.resolveConstantName (builtins.constants |> Map.keys |> Set) pm - userStuff.constants onMissing currentModule name @@ -224,7 +219,7 @@ module Expr = let! name = toPT name let! typeArgs = Ply.List.mapSequentially - (TypeReference.toPT pm userStuff onMissing currentModule) + (TypeReference.toPT pm onMissing currentModule) typeArgs let! args = Ply.NEList.mapSequentially toPT args @@ -234,7 +229,6 @@ module Expr = NR.resolveFnName (builtins.fns |> Map.keys |> Set) pm - userStuff.fns NR.OnMissing.Allow currentModule name @@ -274,8 +268,7 @@ module Expr = let! theRest = Ply.List.mapSequentially toPT theRest return PT.ETuple(id, first, second, theRest) | WT.ERecord(id, typeName, fields) -> - let! typeName = - NR.resolveTypeName pm userStuff.types onMissing currentModule typeName + let! typeName = NR.resolveTypeName pm onMissing currentModule typeName let! fields = Ply.List.mapSequentially (fun (fieldName, fieldExpr) -> @@ -299,12 +292,11 @@ module Expr = let! expr1 = toPT expr1 let! rest = Ply.List.mapSequentially - (pipeExprToPT builtins pm userStuff onMissing currentModule) + (pipeExprToPT builtins pm onMissing currentModule) rest return PT.EPipe(pipeID, expr1, rest) | WT.EEnum(id, typeName, caseName, exprs) -> - let! typeName = - resolveTypeName pm userStuff onMissing currentModule typeName caseName + let! typeName = resolveTypeName pm onMissing currentModule typeName caseName let! exprs = Ply.List.mapSequentially toPT exprs return PT.EEnum(id, typeName, caseName, exprs) | WT.EMatch(id, mexpr, cases) -> @@ -351,7 +343,6 @@ module Expr = and stringSegmentToPT (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (segment : WT.StringSegment) @@ -359,18 +350,17 @@ module Expr = match segment with | WT.StringText text -> Ply(PT.StringText text) | WT.StringInterpolation expr -> - toPT builtins pm userStuff onMissing currentModule expr + toPT builtins pm onMissing currentModule expr |> Ply.map (fun interpolated -> PT.StringInterpolation interpolated) and pipeExprToPT (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (pipeExpr : WT.PipeExpr) : Ply = - let toPT = toPT builtins pm userStuff onMissing currentModule + let toPT = toPT builtins pm onMissing currentModule uply { match pipeExpr with @@ -380,7 +370,6 @@ module Expr = NR.resolveFnName (builtins.fns |> Map.keys |> Set) pm - userStuff.fns NR.OnMissing.Allow currentModule asUserFnName @@ -408,7 +397,6 @@ module Expr = NR.resolveFnName (builtins.fns |> Map.keys |> Set) pm - userStuff.fns NR.OnMissing.Allow currentModule name @@ -422,20 +410,18 @@ module Expr = NR.resolveFnName (builtins.fns |> Map.keys |> Set) pm - userStuff.fns onMissing currentModule name let! typeArgs = Ply.List.mapSequentially - (TypeReference.toPT pm userStuff onMissing currentModule) + (TypeReference.toPT pm onMissing currentModule) typeArgs let! args = Ply.List.mapSequentially toPT args return PT.EPipeFnCall(id, fnName, typeArgs, args) | WT.EPipeEnum(id, typeName, caseName, fields) -> - let! typeName = - resolveTypeName pm userStuff onMissing currentModule typeName caseName + let! typeName = resolveTypeName pm onMissing currentModule typeName caseName let! fields = Ply.List.mapSequentially toPT fields return PT.EPipeEnum(id, typeName, caseName, fields) } @@ -443,12 +429,11 @@ module Expr = module Const = let rec toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (c : WT.Const) : Ply = - let toPT = toPT pm userStuff onMissing currentModule + let toPT = toPT pm onMissing currentModule uply { match c with | WT.CUnit -> return PT.CUnit @@ -490,7 +475,7 @@ module Const = | WT.CEnum(typeName, caseName, fields) -> let! typeName = - Expr.resolveTypeName pm userStuff onMissing currentModule typeName caseName + Expr.resolveTypeName pm onMissing currentModule typeName caseName let! fields = Ply.List.mapSequentially toPT fields return PT.CEnum(typeName, caseName, fields) } @@ -500,33 +485,30 @@ module TypeDeclaration = module RecordField = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (f : WT.TypeDeclaration.RecordField) : Ply = uply { - let! typ = TypeReference.toPT pm userStuff onMissing currentModule f.typ + let! typ = TypeReference.toPT pm onMissing currentModule f.typ return { name = f.name; typ = typ; description = f.description } } module EnumField = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (f : WT.TypeDeclaration.EnumField) : Ply = uply { - let! typ = TypeReference.toPT pm userStuff onMissing currentModule f.typ + let! typ = TypeReference.toPT pm onMissing currentModule f.typ return { typ = typ; label = f.label; description = f.description } } module EnumCase = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (c : WT.TypeDeclaration.EnumCase) @@ -534,7 +516,7 @@ module TypeDeclaration = uply { let! fields = Ply.List.mapSequentially - (EnumField.toPT pm userStuff onMissing currentModule) + (EnumField.toPT pm onMissing currentModule) c.fields return { name = c.name; fields = fields; description = c.description } } @@ -542,7 +524,6 @@ module TypeDeclaration = module Definition = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (d : WT.TypeDeclaration.Definition) @@ -550,20 +531,20 @@ module TypeDeclaration = uply { match d with | WT.TypeDeclaration.Alias typ -> - let! typ = TypeReference.toPT pm userStuff onMissing currentModule typ + let! typ = TypeReference.toPT pm onMissing currentModule typ return PT.TypeDeclaration.Alias typ | WT.TypeDeclaration.Record fields -> let! fields = Ply.NEList.mapSequentially - (RecordField.toPT pm userStuff onMissing currentModule) + (RecordField.toPT pm onMissing currentModule) fields return PT.TypeDeclaration.Record fields | WT.TypeDeclaration.Enum cases -> let! cases = Ply.NEList.mapSequentially - (EnumCase.toPT pm userStuff onMissing currentModule) + (EnumCase.toPT pm onMissing currentModule) cases return PT.TypeDeclaration.Enum cases } @@ -571,13 +552,12 @@ module TypeDeclaration = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (d : WT.TypeDeclaration.T) : Ply = uply { - let! def = Definition.toPT pm userStuff onMissing currentModule d.definition + let! def = Definition.toPT pm onMissing currentModule d.definition return { typeParams = d.typeParams; definition = def } } @@ -586,14 +566,13 @@ module TypeDeclaration = module PackageType = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (pt : WT.PackageType.T) : Ply = uply { let! declaration = - TypeDeclaration.toPT pm userStuff onMissing currentModule pt.declaration + TypeDeclaration.toPT pm onMissing currentModule pt.declaration return { name = pt.name description = pt.description @@ -606,13 +585,12 @@ module PackageType = module PackageConstant = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (c : WT.PackageConstant.T) : Ply = uply { - let! body = Const.toPT pm userStuff onMissing currentModule c.body + let! body = Const.toPT pm onMissing currentModule c.body return { name = c.name description = c.description @@ -627,20 +605,18 @@ module PackageFn = module Parameter = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (p : WT.PackageFn.Parameter) : Ply = uply { - let! typ = TypeReference.toPT pm userStuff onMissing currentModule p.typ + let! typ = TypeReference.toPT pm onMissing currentModule p.typ return { name = p.name; typ = typ; description = p.description } } let toPT (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (fn : WT.PackageFn.T) @@ -648,11 +624,10 @@ module PackageFn = uply { let! parameters = Ply.NEList.mapSequentially - (Parameter.toPT pm userStuff onMissing currentModule) + (Parameter.toPT pm onMissing currentModule) fn.parameters - let! returnType = - TypeReference.toPT pm userStuff onMissing currentModule fn.returnType - let! body = Expr.toPT builtins pm userStuff onMissing currentModule fn.body + let! returnType = TypeReference.toPT pm onMissing currentModule fn.returnType + let! body = Expr.toPT builtins pm onMissing currentModule fn.body return { name = fn.name @@ -668,101 +643,19 @@ module PackageFn = -module UserType = - let toPT - (pm : RT.PackageManager) - (userStuff : NR.UserStuff) - (onMissing : NR.OnMissing) - (currentModule : List) - (t : WT.UserType.T) - : Ply = - uply { - let! declaration = - TypeDeclaration.toPT pm userStuff onMissing currentModule t.declaration - return - { tlid = gid () - name = t.name - declaration = declaration - description = t.description - deprecated = PT.NotDeprecated } - } - - -module UserConstant = - let toPT - (pm : RT.PackageManager) - (userStuff : NR.UserStuff) - (onMissing : NR.OnMissing) - (currentModule : List) - (c : WT.UserConstant.T) - : Ply = - uply { - let! body = Const.toPT pm userStuff onMissing currentModule c.body - return - { tlid = gid () - name = c.name - description = c.description - deprecated = PT.NotDeprecated - body = body } - } - module DB = let toPT (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (db : WT.DB.T) : Ply = uply { - let! typ = TypeReference.toPT pm userStuff onMissing currentModule db.typ + let! typ = TypeReference.toPT pm onMissing currentModule db.typ return { tlid = gid (); name = db.name; version = db.version; typ = typ } } -module UserFunction = - module Parameter = - let toPT - (pm : RT.PackageManager) - (userStuff : NR.UserStuff) - (onMissing : NR.OnMissing) - (currentModule : List) - (p : WT.UserFunction.Parameter) - : Ply = - uply { - let! typ = TypeReference.toPT pm userStuff onMissing currentModule p.typ - return { name = p.name; typ = typ; description = p.description } - } - - let toPT - (builtins : RT.Builtins) - (pm : RT.PackageManager) - (userStuff : NR.UserStuff) - (onMissing : NR.OnMissing) - (currentModule : List) - (f : WT.UserFunction.T) - : Ply = - uply { - let! parameters = - Ply.NEList.mapSequentially - (Parameter.toPT pm userStuff onMissing currentModule) - f.parameters - - let! returnType = - TypeReference.toPT pm userStuff onMissing currentModule f.returnType - let! body = Expr.toPT builtins pm userStuff onMissing currentModule f.body - - return - { tlid = gid () - name = f.name - typeParams = f.typeParams - parameters = parameters - returnType = returnType - description = f.description - deprecated = PT.NotDeprecated - body = body } - } - module Handler = module CronInterval = @@ -787,12 +680,11 @@ module Handler = let toPT (builtins : RT.Builtins) (pm : RT.PackageManager) - (userStuff : NR.UserStuff) (onMissing : NR.OnMissing) (currentModule : List) (h : WT.Handler.T) : Ply = uply { - let! ast = Expr.toPT builtins pm userStuff onMissing currentModule h.ast + let! ast = Expr.toPT builtins pm onMissing currentModule h.ast return { tlid = gid (); ast = ast; spec = Spec.toPT h.spec } } diff --git a/backend/src/LocalExec/Canvas.fs b/backend/src/LocalExec/Canvas.fs index f731055a0c..b9711890f9 100644 --- a/backend/src/LocalExec/Canvas.fs +++ b/backend/src/LocalExec/Canvas.fs @@ -77,21 +77,37 @@ let loadFromDisk return ownerID } + // i.e. dark-packages -> ("Darklang", "Packages") + let (ownerName, canvasName) = + if String.startsWith "dark-" canvasName then + let canvasName = canvasName |> String.dropLeft 5 + // capitialize first letter + let canvasName = canvasName[0].ToString().ToUpper() + canvasName.Substring 1 + ("Darklang", canvasName) + else + raise ( + System.Exception + $"Currently only prepared to parse Darklang (dark-) canvases" + ) + + // TODO this doesn't purge any added types/consts/fns from PM... maybe we should? do! purgeDataFromInternalSqlTables canvasID do! LibCloud.Canvas.createWithExactID canvasID ownerID domain let! tls = uply { + let fileName = $"{canvasDir}/{config.Main}.dark" + let source = System.IO.File.ReadAllText fileName + let! canvas = - LibParser.Canvas.parseFromFile + LibParser.Canvas.parse + ownerName + canvasName Builtins.accessibleByCanvas pm - NR.UserStuff.empty NR.OnMissing.ThrowError - $"{canvasDir}/{config.Main}.dark" - - let types = canvas.types |> List.map PT.Toplevel.TLType - let fns = canvas.fns |> List.map PT.Toplevel.TLFunction + fileName + source let handlers = canvas.handlers @@ -100,9 +116,12 @@ let loadFromDisk let dbs = canvas.dbs |> List.map PT.Toplevel.TLDB + do! LibCloud.PackageManager.savePackageTypes canvas.types + do! LibCloud.PackageManager.savePackageConstants canvas.constants + do! LibCloud.PackageManager.savePackageFunctions canvas.fns + return - (types @ dbs @ fns @ handlers) - |> List.map (fun tl -> tl, LibCloud.Serialize.NotDeleted) + (dbs @ handlers) |> List.map (fun tl -> tl, LibCloud.Serialize.NotDeleted) } print $"Saving {List.length tls} toplevels to canvas" diff --git a/backend/src/LocalExec/LoadPackagesFromDisk.fs b/backend/src/LocalExec/LoadPackagesFromDisk.fs index 08c18dafa4..cff35f99f1 100644 --- a/backend/src/LocalExec/LoadPackagesFromDisk.fs +++ b/backend/src/LocalExec/LoadPackagesFromDisk.fs @@ -29,10 +29,10 @@ let load (builtins : RT.Builtins) : Ply = filesWithContents // TODO: parallelize |> Ply.List.mapSequentially (fun (path, contents) -> + //debuG "parsing" path LibParser.Parser.parsePackageFile builtins - RT.PackageManager.Empty - NR.UserStuff.empty + RT.PackageManager.empty NR.OnMissing.Allow path contents) @@ -46,7 +46,6 @@ let load (builtins : RT.Builtins) : Ply = LibParser.Parser.parsePackageFile builtins (inMemPackageManagerFromPackages packages) - NR.UserStuff.empty NR.OnMissing.ThrowError path contents) diff --git a/backend/src/Wasm/DarkEditor.fs b/backend/src/Wasm/DarkEditor.fs index 771b1d6e26..8fc1a0c62b 100644 --- a/backend/src/Wasm/DarkEditor.fs +++ b/backend/src/Wasm/DarkEditor.fs @@ -15,9 +15,9 @@ let debug (arg : string) = WasmHelpers.callJSFunction "console.log" [ arg ] /// Source of the editor (types, functions) type EditorSource = - { types : List - fns : List - constants : List } + { types : List + constants : List + fns : List } @@ -69,7 +69,7 @@ let LoadClient (canvasName : string) : Task = LibExecution.Execution.executeFunction state None - (FQFnName.fqUserProgram [] "init" 0) + (FQFnName.fqPackage "TODO" [] "init" 0) [] (NEList.singleton DUnit) @@ -107,7 +107,7 @@ let HandleEvent (serializedEvent : string) : Task = LibExecution.Execution.executeFunction state None - (FQFnName.fqUserProgram [] "handleEvent" 0) + (FQFnName.fqPackage "TODO" [] "handleEvent" 0) [] (NEList.singleton (DString serializedEvent)) diff --git a/backend/src/Wasm/EvalHelpers.fs b/backend/src/Wasm/EvalHelpers.fs index 3b60cc881d..b64e0ad8ef 100644 --- a/backend/src/Wasm/EvalHelpers.fs +++ b/backend/src/Wasm/EvalHelpers.fs @@ -6,22 +6,23 @@ open LibExecution.RuntimeTypes let getStateForEval (builtins : Builtins) - (types : List) - (constants : List) - (fns : List) + (_types : List) + (_constants : List) + (_fns : List) : ExecutionState = // TODO - let packageManager : PackageManager = PackageManager.Empty + let packageManager : PackageManager = PackageManager.empty let program : Program = { canvasID = CanvasID.Empty internalFnsAllowed = true - types = Map.fromListBy (_.name) types - constants = Map.fromListBy (_.name) constants + // types = Map.fromListBy (_.name) types + // constants = Map.fromListBy (_.name) constants dbs = Map.empty secrets = List.empty - fns = Map.fromListBy (_.name) fns } + //fns = Map.fromListBy (_.name) fns + } { builtins = builtins tracing = LibExecution.Execution.noTracing diff --git a/backend/src/Wasm/Libs/Editor.fs b/backend/src/Wasm/Libs/Editor.fs index 69ecaab2c2..dd1b4456b4 100644 --- a/backend/src/Wasm/Libs/Editor.fs +++ b/backend/src/Wasm/Libs/Editor.fs @@ -12,17 +12,17 @@ module Dval = LibExecution.Dval module TypeChecker = LibExecution.TypeChecker type Editor = - { types : List - constants : List - functions : List + { types : List + constants : List + functions : List currentState : Dval } /// A "user program" that can be executed by the interpreter type UserProgramSource = - { types : List - constants : List - fns : List + { types : List + constants : List + fns : List // (exprs to eval, in order) exprs : List } diff --git a/backend/testfiles/execution/cloud/db.dark b/backend/testfiles/execution/cloud/db.dark index 56096c604b..4e809334d4 100644 --- a/backend/testfiles/execution/cloud/db.dark +++ b/backend/testfiles/execution/cloud/db.dark @@ -235,7 +235,7 @@ type MyTlid = [] type MyTlidDB = MyTlid -module addToTest = +module AddToTest = (let test = Builtin.dbSet (MyTlid { mytlid = 1234UL }) "test" MyTlidDB (Builtin.dbGetAll MyTlidDB)) = [ MyTlid { mytlid = 1234UL } ] diff --git a/backend/testfiles/execution/stdlib/alt-json.dark b/backend/testfiles/execution/stdlib/alt-json.dark index c89ee5d29d..69c1cc0734 100644 --- a/backend/testfiles/execution/stdlib/alt-json.dark +++ b/backend/testfiles/execution/stdlib/alt-json.dark @@ -4,8 +4,6 @@ type Json = Stdlib.AltJson.Json type ParseError = Stdlib.AltJson.ParseError.ParseError - - // TODO: backfill a _lot_ from json.dark // TODO: think - should it be impossible for a JNumber to hold anything that isn't alowed by JSON diff --git a/backend/testfiles/execution/stdlib/list.dark b/backend/testfiles/execution/stdlib/list.dark index 3a1cb9e6f0..61af9f13c3 100644 --- a/backend/testfiles/execution/stdlib/list.dark +++ b/backend/testfiles/execution/stdlib/list.dark @@ -502,4 +502,10 @@ Stdlib.List.chunkBySize_v0 [ 1L; 2L; 3L; 4L ] 0L = Stdlib.Result.Result.Error Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero Stdlib.List.chunkBySize_v0 [ 1L; 2L; 3L; 4L ] -1L = Stdlib.Result.Result.Error - Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero \ No newline at end of file + Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero + + +Stdlib.List.splitLast [] = Stdlib.Option.Option.None +Stdlib.List.splitLast [ 1L ] = Stdlib.Option.Option.Some(([], 1L)) +Stdlib.List.splitLast [ 1L; 2L ] = Stdlib.Option.Option.Some(([ 1L ], 2L)) +Stdlib.List.splitLast [ 1L; 2L; 3L ] = Stdlib.Option.Option.Some(([ 1L; 2L ], 3L)) \ No newline at end of file diff --git a/backend/testfiles/execution/stdlib/parser.dark b/backend/testfiles/execution/stdlib/parser.dark index c8e3937d1b..470287618a 100644 --- a/backend/testfiles/execution/stdlib/parser.dark +++ b/backend/testfiles/execution/stdlib/parser.dark @@ -155,6 +155,11 @@ module TextToTextRoundtripping = let prettyPrintCliScript (parsedFile: PACKAGE.Darklang.LanguageTools.WrittenTypes.ParsedFile) : String = + let owner = "Tests" + let modules = [] + + let onMissing = PACKAGE.Darklang.LanguageTools.NameResolver.OnMissing.Allow + let script = match parsedFile with | CliScript script -> script @@ -164,30 +169,35 @@ module TextToTextRoundtripping = match typeOrFn with | Type typeDecl -> let prettyPrinted = - (PACKAGE.Darklang.LanguageTools.NameResolver.empty ()) - |> PACKAGE.Darklang.LanguageTools.WrittenTypesToProgramTypes.TypeDeclaration.toUserTypePT - typeDecl - |> PACKAGE.Darklang.PrettyPrinter.ProgramTypes.userType + (PACKAGE.Darklang.LanguageTools.WrittenTypesToProgramTypes.TypeDeclaration.toPackageTypePT + onMissing + owner + modules + typeDecl) + |> PACKAGE.Darklang.PrettyPrinter.ProgramTypes.packageType acc |> Stdlib.List.push prettyPrinted | Function fnDecl -> let prettyPrinted = - (PACKAGE.Darklang.LanguageTools.NameResolver.empty ()) - |> PACKAGE.Darklang.LanguageTools.WrittenTypesToProgramTypes.FunctionDeclaration.toUserFnPT - fnDecl - |> PACKAGE.Darklang.PrettyPrinter.ProgramTypes.userFunction + (PACKAGE.Darklang.LanguageTools.WrittenTypesToProgramTypes.FunctionDeclaration.toPackageFnPT + onMissing + owner + modules + fnDecl) + |> PACKAGE.Darklang.PrettyPrinter.ProgramTypes.packageFn acc |> Stdlib.List.push prettyPrinted)) |> Stdlib.List.reverse let exprsPart = // List (Stdlib.List.fold script.exprsToEval [] (fun acc expr -> - let prettyPrinted = - (PACKAGE.Darklang.LanguageTools.NameResolver.empty ()) - |> PACKAGE.Darklang.LanguageTools.WrittenTypesToProgramTypes.Expr.toPT + let pt = + PACKAGE.Darklang.LanguageTools.WrittenTypesToProgramTypes.Expr.toPT + onMissing expr - |> PACKAGE.Darklang.PrettyPrinter.ProgramTypes.expr + + let prettyPrinted = pt |> PACKAGE.Darklang.PrettyPrinter.ProgramTypes.expr acc |> Stdlib.List.push prettyPrinted)) |> Stdlib.List.reverse @@ -237,13 +247,17 @@ module TextToTextRoundtripping = ("type ID = Test" |> roundtripCliScript) = "type ID =\n Test" // fully-qualified package name (multi-part) - ("type MyOption = PACKAGE.Darklang.Stdlib.Option.Option" |> roundtripCliScript) = "type MyOption =\n PACKAGE.Darklang.Stdlib.Option.Option_v0" - ("type MyOption = Stdlib.Option.Option" |> roundtripCliScript) = "type MyOption =\n PACKAGE.Darklang.Stdlib.Option.Option_v0" + ("type MyOption = PACKAGE.Darklang.Stdlib.Option.Option" |> roundtripCliScript) = "type MyOption =\n PACKAGE.Darklang.Stdlib.Option.Option" + ("type MyOption = Stdlib.Option.Option" |> roundtripCliScript) = "type MyOption =\n PACKAGE.Darklang.Stdlib.Option.Option" module TypeDeclaration = ("type SimpleAlias = Unit" |> roundtripCliScript) = "type SimpleAlias =\n Unit" + // // Enum type TODO + // ("type Thing = | A | B of Int64 | C of String * Bool" |> roundtripCliScript) = "type Thing =\n | A\n | B of Int64\n | C of String * Bool" + + // record type ("type Person = {name: String}" |> roundtripCliScript) = "type Person =\n { name: String }" @@ -339,13 +353,23 @@ module TextToTextRoundtripping = ("(1L, \"hello\", 2L, true)" |> roundtripCliScript) = "(1L, \"hello\", 2L, true)" ("(1L, 2L + 3L, 4L)" |> roundtripCliScript) = "(1L, (2L) + (3L), 4L)" - // record literal - ("Person {name =\"John\"} " |> roundtripCliScript) = "Person { name = \"John\" }" - ("Person {name =\"John\"; age = 30L} " |> roundtripCliScript) = "Person { name = \"John\"; age = 30L }" - ("Person {name =\"John\"; age = 30L; hasPet = true} " |> roundtripCliScript) = "Person { name = \"John\"; age = 30L; hasPet = true }" + // record literals + type Person1 = { name: String } + type Person2 = { name: String; age: Int64 } + + ("Person1 {name =\"John\"} " |> roundtripCliScript) = "Person1 { name = \"John\" }" + ("Person2 {name =\"John\"; age = 30L} " |> roundtripCliScript) = "Person2 { name = \"John\"; age = 30L }" + ("Person3 {name =\"John\"; age = 30L; hasPet = true} " |> roundtripCliScript) = "Person3 { name = \"John\"; age = 30L; hasPet = true }" + + + // // enum literals TODO + // type MyEnum = + // | A + // | B of String * Int64 + + // ("MyEnum.A" |> roundtripCliScript) = "MyEnum.A" + // ("MyEnum.B (\"test\", 12L)" |> roundtripCliScript) = "MyEnum.B (\"test\", 12L)" - ("Person {name =\"John\"; age = 30L; hasPet = true; pet = Pet {name = \"Luna\"}} " - |> roundtripCliScript) = "Person { name = \"John\"; age = 30L; hasPet = true; pet = Pet { name = \"Luna\" } }" // enum literal ("Color.Red" |> roundtripCliScript) = "Color.Red" @@ -473,37 +497,37 @@ else ("true || false" |> roundtripCliScript) = "(true) || (false)" ("(and true false)" |> roundtripCliScript) = "and true false" ("(Bool.and true false)" |> roundtripCliScript) = "Bool.and true false" - ("(PACKAGE.Darklang.Stdlib.Bool.and true false)" |> roundtripCliScript) = "PACKAGE.Darklang.Stdlib.Bool.and_v0 true false" - ("(Stdlib.Bool.and true false)" |> roundtripCliScript) = "PACKAGE.Darklang.Stdlib.Bool.and_v0 true false" + ("(PACKAGE.Darklang.Stdlib.Bool.and true false)" |> roundtripCliScript) = "PACKAGE.Darklang.Stdlib.Bool.and true false" + ("(Stdlib.Bool.and true false)" |> roundtripCliScript) = "PACKAGE.Darklang.Stdlib.Bool.and true false" ("(Builtin.int64Add 1L 2L)" |> roundtripCliScript) = "Builtin.int64Add 1L 2L" module FunctionDeclaration = // single 'normal' param ("let helloWorld (i: Int64): String = \"Hello world\"" |> roundtripCliScript) = "let helloWorld (i: Int64): String =\n \"Hello world\"" - ("let double2 (i: PACKAGE.Darklang.LanguageTools.ID_v0) : Int64 = i + i" - |> roundtripCliScript) = "let double2 (i: PACKAGE.Darklang.LanguageTools.ID_v0): Int64 =\n (i) + (i)" + ("let double2 (i: PACKAGE.Darklang.LanguageTools.ID) : Int64 = i + i" + |> roundtripCliScript) = "let double2 (i: PACKAGE.Darklang.LanguageTools.ID): Int64 =\n (i) + (i)" // () param ("let emptyString () : String = \"\"" |> roundtripCliScript) = "let emptyString (_: Unit): String =\n \"\"" // multiple params - ("let isHigher (a: Int64) (b: Int64) : Bool = (Stdlib.Int64.greaterThan_v0 a b)" - |> roundtripCliScript) = "let isHigher (a: Int64) (b: Int64): Bool =\n PACKAGE.Darklang.Stdlib.Int64.greaterThan_v0 a b" + ("let isHigher (a: Int64) (b: Int64) : Bool = (Stdlib.Int64.greaterThan a b)" + |> roundtripCliScript) = "let isHigher (a: Int64) (b: Int64): Bool =\n PACKAGE.Darklang.Stdlib.Int64.greaterThan a b" module FnCalls = //package function call ("let sum (a : Int64) (b : Int64) : Int64 = (PACKAGE.Darklang.Stdlib.Int64.add a b)" - |> roundtripCliScript) = "let sum (a: Int64) (b: Int64): Int64 =\n PACKAGE.Darklang.Stdlib.Int64.add_v0 a b" + |> roundtripCliScript) = "let sum (a: Int64) (b: Int64): Int64 =\n PACKAGE.Darklang.Stdlib.Int64.add a b" - module CliScript = - // TODO the output here is a bit broken - (""" + module CliScript = + // CLEANUP the output here is a bit broken + (""" type BookID = Int64 let getTitle (bookId: BookID): String = @@ -515,7 +539,7 @@ let curiousGeorgeBookId = 101L 0L """ - |> roundtripCliScript) = """type BookID = + |> roundtripCliScript) = """type BookID = Int64 let getTitle (bookId: BookID): String = diff --git a/backend/testfiles/execution/stdlib/string.dark b/backend/testfiles/execution/stdlib/string.dark index 88f2ad252d..3bccda1d31 100644 --- a/backend/testfiles/execution/stdlib/string.dark +++ b/backend/testfiles/execution/stdlib/string.dark @@ -506,6 +506,7 @@ module ToList = module Split = + Stdlib.String.split "hello world" "notfound" = [ "hello world" ] Stdlib.String.split "hello😄world" "😄" = [ "hello"; "world" ] Stdlib.String.split "hello&&&&world" "&&&&" = [ "hello"; "world" ] Stdlib.String.split "hello34564world34564sun" "😄" = [ "hello34564world34564sun" ] diff --git a/backend/tests/TestUtils/RTShortcuts.fs b/backend/tests/TestUtils/RTShortcuts.fs index 5861f1a77f..e3b57a0f12 100644 --- a/backend/tests/TestUtils/RTShortcuts.fs +++ b/backend/tests/TestUtils/RTShortcuts.fs @@ -13,11 +13,6 @@ let eBuiltinFnName (name : string) (version : int) : Expr = |> PT2RT.FQFnName.toRT |> fun x -> EFnName(gid (), x) -let eUserFnName (name : string) : Expr = - PT.FQFnName.fqUserProgram [] name 0 - |> PT2RT.FQFnName.toRT - |> fun x -> EFnName(gid (), x) - let eFn' (function_ : string) @@ -36,13 +31,6 @@ let eFn : Expr = eFn' function_ version typeArgs args -let eUserFn - (function_ : string) - (typeArgs : List) - (args : List) - : Expr = - let args = NEList.ofListUnsafe "eUserFn" [] args - EApply(gid (), (eUserFnName function_), typeArgs, args) let eApply (target : Expr) @@ -101,25 +89,32 @@ let eEnum : Expr = EEnum(gid (), typeName, name, args) -let userTypeName +let packageTypeName + (owner : string) (modules : List) (name : string) (version : int) - : FQTypeName.UserProgram = - { modules = modules; name = name; version = version } + : FQTypeName.Package = + { owner = owner; modules = modules; name = name; version = version } -let fqUserTypeName (modules : List) (name : string) (version : int) = - FQTypeName.UserProgram(userTypeName modules name version) +let fqPackageTypeName + (owner : string) + (modules : List) + (name : string) + (version : int) + = + FQTypeName.Package(packageTypeName owner modules name version) let eTuple (first : Expr) (second : Expr) (theRest : Expr list) : Expr = ETuple(gid (), first, second, theRest) -let userTypeReference +let packageTypeReference + (owner : string) (modules : List) (name : string) (version : int) : TypeReference = - TCustomType(Ok(fqUserTypeName modules name version), []) + TCustomType(Ok(fqPackageTypeName owner modules name version), []) let customTypeRecord (fields : List) : TypeDeclaration.T = let fields = @@ -132,11 +127,12 @@ let customTypeRecord (fields : List) : TypeDeclaration.T { typeParams = []; definition = TypeDeclaration.Record(NEList.ofList hd rest) } let userTypeRecord + (owner : string) (modules : List) (name : string) (version : int) (fields : List) - : UserType.T = + : PackageType.T = { tlid = gid () - name = { modules = modules; name = name; version = version } + name = { owner = owner; modules = modules; name = name; version = version } declaration = customTypeRecord fields } diff --git a/backend/tests/TestUtils/TestUtils.fs b/backend/tests/TestUtils/TestUtils.fs index b320ca84af..615c639363 100644 --- a/backend/tests/TestUtils/TestUtils.fs +++ b/backend/tests/TestUtils/TestUtils.fs @@ -79,17 +79,19 @@ let testCron let testWorker (name : string) (ast : PT.Expr) : PT.Handler.T = { tlid = gid (); ast = ast; spec = PT.Handler.Worker name } -let testUserFn +let testPackageFn + (owner : string) (name : string) (typeParams : List) (parameters : NEList) (returnType : PT.TypeReference) (body : PT.Expr) - : PT.UserFunction.T = - { tlid = gid () + : PT.PackageFn.T = + { id = System.Guid.NewGuid() + tlid = gid () body = body description = "" - name = PT.FQFnName.userProgram [] name 0 + name = PT.FQFnName.package owner [] name 0 typeParams = typeParams deprecated = PT.NotDeprecated parameters = @@ -99,14 +101,15 @@ let testUserFn returnType = returnType } let testUserRecordType - (name : PT.FQTypeName.UserProgram) + (name : PT.FQTypeName.Package) (firstField : string * PT.TypeReference) (additionalFields : List) - : PT.UserType.T = + : PT.PackageType.T = let mapField (name, typ) : PT.TypeDeclaration.RecordField = { name = name; typ = typ; description = "" } - { tlid = gid () + { id = System.Guid.NewGuid() + tlid = gid () name = name description = "" deprecated = PT.NotDeprecated @@ -149,13 +152,11 @@ let packageManager = LibCloud.PackageManager.packageManager let executionStateFor + (pm : RT.PackageManager) (canvasID : CanvasID) (internalFnsAllowed : bool) (allowLocalHttpAccess : bool) (dbs : Map) - (userTypes : Map) - (userFunctions : Map) - (userConstants : Map) : Task = task { let! domains = Canvas.domainsForCanvasID canvasID @@ -163,10 +164,7 @@ let executionStateFor let program : RT.Program = { canvasID = canvasID internalFnsAllowed = internalFnsAllowed - fns = userFunctions - types = userTypes dbs = dbs - constants = userConstants secrets = [] } let testContext : RT.TestContext = @@ -210,13 +208,7 @@ let executionStateFor let builtins = if allowLocalHttpAccess then localBuiltIns else cloudBuiltIns let state = - Exe.createState - builtins - packageManager - Exe.noTracing - exceptionReporter - notifier - program + Exe.createState builtins pm Exe.noTracing exceptionReporter notifier program let state = { state with test = testContext } return state } @@ -448,16 +440,11 @@ module Expect = let err () = errorFn path (string actual) (string expected) match actual, expected with - | FQTypeName.UserProgram a, FQTypeName.UserProgram e -> - if a.name <> e.name then err () - if a.version <> e.version then err () | FQTypeName.Package a, FQTypeName.Package e -> if a.owner <> e.owner then err () if a.modules <> e.modules then err () if a.name <> e.name then err () if a.version <> e.version then err () - | FQTypeName.UserProgram _, _ - | FQTypeName.Package _, _ -> err () let rec matchPatternEqualityBaseFn (checkIDs : bool) @@ -1098,47 +1085,71 @@ let interestingDvals : List = ("int string3", DString "0", TString) ("uuid string", DString "7d9e5495-b068-4364-a2cc-3633ab4d13e6", TString) ("list", DList(ValueType.Known KTInt64, [ Dval.int64 4 ]), TList TInt64) + ("record", DRecord( - S.fqUserTypeName [ "Two"; "Modules" ] "Foo" 0, - S.fqUserTypeName [ "Two"; "Modules" ] "FooAlias" 0, - [], - Map.ofList [ "foo", Dval.int64 5 ] - ), - TCustomType(Ok(S.fqUserTypeName [ "Two"; "Modules" ] "Foo" 0), [])) - ("record2", - DRecord( - S.fqUserTypeName [] "Foo" 0, - S.fqUserTypeName [] "FooAlias" 0, - [ VT.unknown; VT.bool ], - Map.ofList [ ("type", DString "weird"); ("value", DUnit) ] - ), - TCustomType(Ok(S.fqUserTypeName [] "Foo" 0), [])) - ("record3", - DRecord( - S.fqUserTypeName [] "Foo" 0, - S.fqUserTypeName [] "Foo" 0, + S.fqPackageTypeName "Darklang" [ "Stdlib"; "Http" ] "Request" 0, + S.fqPackageTypeName "Darklang" [ "Stdlib"; "Http" ] "Request" 0, [], - Map.ofList [ ("type", DString "weird"); ("value", DString "x") ] + Map.ofList + [ "url", DString "https://darklang.com" + "headers", Dval.list (KTTuple(VT.string, VT.string, [])) [] + "body", Dval.list KTUInt8 [] ] ), - TCustomType(Ok(S.fqUserTypeName [] "Foo" 0), [])) - // More Json.NET tests - ("record4", - DRecord( - S.fqUserTypeName [] "Foo" 0, - S.fqUserTypeName [] "Foo" 0, - [ VT.bool; VT.char; (VT.customType (S.fqUserTypeName [] "Foo" 0)) [] ], - Map.ofList [ "foo\\\\bar", Dval.int64 5 ] - ), - TCustomType(Ok(S.fqUserTypeName [] "Foo" 0), [])) - ("record5", - DRecord( - S.fqUserTypeName [] "Foo" 0, - S.fqUserTypeName [] "Foo" 0, + TCustomType( + Ok(S.fqPackageTypeName "Darklang" [ "Stdlib"; "Http" ] "Request" 0), + [] + )) + + ("enum", + DEnum( + S.fqPackageTypeName "Darklang" [ "Stdlib"; "AltJson" ] "Json" 0, + S.fqPackageTypeName "Darklang" [ "Stdlib"; "AltJson" ] "Json" 0, [], - Map.ofList [ "$type", Dval.int64 5 ] + "String", + [ DString "test" ] ), - TCustomType(Ok(S.fqUserTypeName [] "Foo" 0), [])) + TCustomType( + Ok(S.fqPackageTypeName "Darklang" [ "Stdlib"; "AltJson" ] "Json" 0), + [] + )) + + // TODO: extract what's useful in here, and create smaller tests for each + // ("record2", + // DRecord( + // S.fqPackageTypeName "Test" [] "Foo" 0, + // S.fqPackageTypeName "Test" [] "FooAlias" 0, + // [ VT.unknown; VT.bool ], + // Map.ofList [ ("type", DString "weird"); ("value", DUnit) ] + // ), + // TCustomType(Ok(S.fqPackageTypeName "Test" [] "Foo" 0), [])) + // ("record3", + // DRecord( + // S.fqPackageTypeName "Test" [] "Foo" 0, + // S.fqPackageTypeName "Test" [] "Foo" 0, + // [], + // Map.ofList [ ("type", DString "weird"); ("value", DString "x") ] + // ), + // TCustomType(Ok(S.fqPackageTypeName "Test" [] "Foo" 0), [])) + // // More Json.NET tests + // ("record4", + // DRecord( + // S.fqPackageTypeName "Test" [] "Foo" 0, + // S.fqPackageTypeName "Test" [] "Foo" 0, + // [ VT.bool + // VT.char + // (VT.customType (S.fqPackageTypeName "Test" [] "Foo" 0)) [] ], + // Map.ofList [ "foo\\\\bar", Dval.int64 5 ] + // ), + // TCustomType(Ok(S.fqPackageTypeName "Test" [] "Foo" 0), [])) + // ("record5", + // DRecord( + // S.fqPackageTypeName "Test" [] "Foo" 0, + // S.fqPackageTypeName "Test" [] "Foo" 0, + // [], + // Map.ofList [ "$type", Dval.int64 5 ] + // ), + // TCustomType(Ok(S.fqPackageTypeName "Test" [] "Foo" 0), [])) ("dict", DDict(VT.unknown, Map [ "foo", Dval.int64 5 ]), TDict TInt64) ("dict3", DDict(VT.unknown, Map [ ("type", DString "weird"); ("value", DString "x") ]), diff --git a/backend/tests/Tests/BwdServer.Tests.fs b/backend/tests/Tests/BwdServer.Tests.fs index 61ccea37d8..224e64bf28 100644 --- a/backend/tests/Tests/BwdServer.Tests.fs +++ b/backend/tests/Tests/BwdServer.Tests.fs @@ -49,7 +49,6 @@ let parse code = LibParser.Parser.parsePTExpr localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "BwdServer.Tests.fs" code diff --git a/backend/tests/Tests/Canvas.Tests.fs b/backend/tests/Tests/Canvas.Tests.fs index abc6f2bb8b..8b291e4697 100644 --- a/backend/tests/Tests/Canvas.Tests.fs +++ b/backend/tests/Tests/Canvas.Tests.fs @@ -23,7 +23,6 @@ let parse (code : string) : Task = LibParser.Parser.parseSimple localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "tests.canvas.fs" code @@ -55,33 +54,6 @@ let testHttpOplistRoundtrip = } -let testHttpOplistLoadsUserTypes = - testTask "httpOplistLoadsUserTypes" { - let! canvasID = initializeTestCanvas "http_oplist_loads_user_types" - let handler = testHttpRouteHandler "/path" "GET" (PT.EInt64(gid (), 5L)) - let typ = - testUserRecordType - ({ modules = []; name = "test-tipe"; version = 0 }) - ("age", PT.TInt64) - [] - - do! - Canvas.saveTLIDs - canvasID - [ (PT.Toplevel.TLHandler handler, Serialize.NotDeleted) - (PT.Toplevel.TLType typ, Serialize.NotDeleted) ] - - let! (c2 : Canvas.T) = - Canvas.loadHttpHandlers - canvasID - (PTParser.Handler.Spec.toName handler.spec) - (PTParser.Handler.Spec.toModifier handler.spec) - Expect.equal (c2.userTypes[typ.tlid]) typ "user types" - } - - - - let testHttpLoadIgnoresDeletedHandler = testTask "Http load ignores deleted handler" { let! canvasID = initializeTestCanvas "http-load-ignores-deleted-handler" @@ -119,41 +91,6 @@ let testHttpLoadIgnoresDeletedHandler = Expect.equal dbRow (None, None, None, Some true) "Row should be cleared" } -let testHttpLoadIgnoresDeletedFns = - testTask "Http load ignores deleted fns" { - let! canvasID = initializeTestCanvas "http-load-ignores-deleted-fns" - - let handler = testHttpRouteHandler "/path" "GET" (PT.EInt64(gid (), 5L)) - let ps = (NEList.singleton "param") - - let! fivePlusThreeParsed = parse "5 + 3" - let f = testUserFn "testfn" [] ps (PT.TVariable "a") fivePlusThreeParsed - - let! sixPlusFourParsed = parse "6 + 4" - let fNew = testUserFn "testfnNew" [] ps (PT.TVariable "a") sixPlusFourParsed - - do! - Canvas.saveTLIDs - canvasID - [ (PT.Toplevel.TLHandler handler, Serialize.NotDeleted) - (PT.Toplevel.TLFunction f, Serialize.NotDeleted) ] - // TLIDs are saved in parallel, so do them in separate calls - do! - Canvas.saveTLIDs - canvasID - [ (PT.Toplevel.TLFunction f, Serialize.Deleted) - (PT.Toplevel.TLFunction fNew, Serialize.NotDeleted) ] - - let! (c2 : Canvas.T) = - Canvas.loadHttpHandlers - canvasID - (PTParser.Handler.Spec.toName handler.spec) - (PTParser.Handler.Spec.toModifier handler.spec) - - Expect.equal c2.handlers[handler.tlid] handler "handler is loaded " - Expect.equal c2.userFunctions.Count 1 "only one function is loaded from cache" - Expect.equal c2.userFunctions[fNew.tlid] fNew "later func is loaded" - } let testSetHandlerAfterDelete = testTask "handler set after delete" { @@ -185,41 +122,6 @@ let testSetHandlerAfterDelete = Expect.equal c2.handlers.Count 1 "only live is in handlers" } -let testSetFunctionAfterDelete = - testTask "function set after delete" { - let! canvasID = initializeTestCanvas "db-set-function-after-delete" - let ps = NEList.singleton "param" - let! e1 = parse "5 + 3" - let! e2 = parse "6 + 4" - let f1 = testUserFn "testfn" [] ps (PT.TVariable "a") e1 - let f2 = testUserFn "testfn" [] ps (PT.TVariable "a") e2 - - // Just the deleted handler - do! Canvas.saveTLIDs canvasID [ (PT.Toplevel.TLFunction f1, Serialize.Deleted) ] - - let! (c1 : Canvas.T) = Canvas.loadAll canvasID - - Expect.equal - (Map.find f1.tlid c1.deletedUserFunctions) - (Some f1) - "deleted in deleted" - Expect.equal c1.deletedUserFunctions.Count 1 "only deleted in deleted" - Expect.equal c1.userFunctions.Count 0 "deleted not present" - - // And the new one (the deleted is still there) - do! - Canvas.saveTLIDs canvasID [ (PT.Toplevel.TLFunction f2, Serialize.NotDeleted) ] - - let! (c2 : Canvas.T) = Canvas.loadAll canvasID - - Expect.equal - (Map.find f1.tlid c2.deletedUserFunctions) - (Some f1) - "deleted still in deleted" - Expect.equal c2.deletedUserFunctions.Count 1 "only deleted still in deleted" - Expect.equal (Map.find f2.tlid c2.userFunctions) (Some f2) "live is present" - Expect.equal c2.userFunctions.Count 1 "only live is present" - } let testLoadAllDBs = @@ -246,9 +148,6 @@ let tests = "canvas" [ testHttpOplistRoundtrip testDBOplistRoundtrip - testHttpOplistLoadsUserTypes - testHttpLoadIgnoresDeletedFns testHttpLoadIgnoresDeletedHandler testSetHandlerAfterDelete - testSetFunctionAfterDelete testLoadAllDBs ] diff --git a/backend/tests/Tests/Cron.Tests.fs b/backend/tests/Tests/Cron.Tests.fs index b1d336037b..2a9c01dd2f 100644 --- a/backend/tests/Tests/Cron.Tests.fs +++ b/backend/tests/Tests/Cron.Tests.fs @@ -19,7 +19,6 @@ let p (code : string) : Task = LibParser.Parser.parseSimple localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "cron.tests.fs" code diff --git a/backend/tests/Tests/DvalRepr.Tests.fs b/backend/tests/Tests/DvalRepr.Tests.fs index fc38586982..8e4cff4260 100644 --- a/backend/tests/Tests/DvalRepr.Tests.fs +++ b/backend/tests/Tests/DvalRepr.Tests.fs @@ -34,25 +34,28 @@ let queryableRoundtripsSuccessfullyInRecord ) : Task = task { - let typeName = S.userTypeName [] "MyType" 0 + let typeName = S.packageTypeName "Tests" [] "MyType" 0 let record = RT.DRecord( - RT.FQTypeName.UserProgram typeName, - RT.FQTypeName.UserProgram typeName, + RT.FQTypeName.Package typeName, + RT.FQTypeName.Package typeName, [], Map.ofList [ "field", dv ] ) - let typeRef = S.userTypeReference [] "MyType" 0 + let typeRef = S.packageTypeReference "Tests" [] "MyType" 0 let types : RT.Types = - { defaultTypes () with - userProgram = - Map - [ typeName, + { typeSymbolTable = Map.empty + package = + fun name -> + if name = typeName then + let packageType : RT.PackageType.T = { name = typeName tlid = 8UL - declaration = S.customTypeRecord [ "field", fieldTyp ] } ] } - + declaration = S.customTypeRecord [ "field", fieldTyp ] } + packageType |> Some |> Ply + else + packageManager.getType name } let! roundtripped = record diff --git a/backend/tests/Tests/Execution.Tests.fs b/backend/tests/Tests/Execution.Tests.fs index 51a6366915..1ed716c41a 100644 --- a/backend/tests/Tests/Execution.Tests.fs +++ b/backend/tests/Tests/Execution.Tests.fs @@ -11,66 +11,23 @@ open TestUtils.TestUtils open LibExecution.RuntimeTypes open TestUtils.RTShortcuts -module VT = ValueType -module Dval = LibExecution.Dval module Exe = LibExecution.Execution -module RuntimeTypesAst = LibExecution.RuntimeTypesAst module AT = LibExecution.AnalysisTypes module PT = LibExecution.ProgramTypes -module PTParser = LibExecution.ProgramTypesParser module PT2RT = LibExecution.ProgramTypesToRuntimeTypes -type Dictionary<'k, 'v> = System.Collections.Generic.Dictionary<'k, 'v> - -let executionStateForPreview - (dbs : Map) - (types : Map) - (fns : Map) - (constants : Map) - : Task = - task { - let canvasID = System.Guid.NewGuid() - let! state = executionStateFor canvasID false false dbs types fns constants - let results, traceFn = Exe.traceDvals () - - let state = { state with tracing.traceDval = traceFn } - return (results, state) - } - -let execSaveDvals - (dbs : List) - (userTypes : List) - (userFns : List) - (userConstants : List) - (ast : Expr) - : Task = - task { - let tlid = 777777827493UL - let types = userTypes |> List.map (fun typ -> typ.name, typ) |> Map.ofList - let fns = userFns |> List.map (fun fn -> fn.name, fn) |> Map.ofList - let dbs = dbs |> List.map (fun db -> db.name, db) |> Map.ofList - let constants = userConstants |> List.map (fun c -> c.name, c) |> Map.ofList - - let! (results, state) = executionStateForPreview dbs types fns constants - - let inputVars = Map.empty - let! _result = Exe.executeExpr state tlid inputVars ast - - return results - } - let testExecFunctionTLIDs : Test = testTask "test that exec function returns the right tlids in the trace" { let! meta = initializeTestCanvas "exec-function-tlids" let name = "testFunction" let ps = NEList.singleton "param" - let (fn : UserFunction.T) = - testUserFn name [] ps (PT.TVariable "a") (PT.EInt64(gid (), 5)) - |> PT2RT.UserFunction.toRT - let fns = Map.ofList [ (fn.name, fn) ] - let! state = executionStateFor meta false false Map.empty Map.empty fns Map.empty + let (fn : PackageFn.T) = + testPackageFn "owner" name [] ps (PT.TVariable "a") (PT.EInt64(gid (), 5)) + |> PT2RT.PackageFn.toRT + let pm = PackageManager.withExtras packageManager [] [] [ fn ] + let! state = executionStateFor pm meta false false Map.empty let tlids, traceFn = Exe.traceTLIDs () @@ -80,7 +37,7 @@ let testExecFunctionTLIDs : Test = Exe.executeFunction state None - (FQFnName.UserProgram fn.name) + (FQFnName.Package fn.name) [] (NEList.singleton DUnit) diff --git a/backend/tests/Tests/HttpClient.Tests.fs b/backend/tests/Tests/HttpClient.Tests.fs index 04eeed277b..2ed836ba0e 100644 --- a/backend/tests/Tests/HttpClient.Tests.fs +++ b/backend/tests/Tests/HttpClient.Tests.fs @@ -90,7 +90,6 @@ let parseTest test = LibParser.TestModule.parseSingleTestFromFile localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError test @@ -154,8 +153,7 @@ let makeTest versionName filename = // Set up the canvas let canvasID = System.Guid.NewGuid() let tlid = 7777772398743UL - let! state = - executionStateFor canvasID false true Map.empty Map.empty Map.empty Map.empty + let! state = executionStateFor packageManager canvasID false true Map.empty // Parse the Dark code let! (test : LibParser.TestModule.RTTest) = diff --git a/backend/tests/Tests/LibExecution.Tests.fs b/backend/tests/Tests/LibExecution.Tests.fs index 5dbd6caf60..fe14878b11 100644 --- a/backend/tests/Tests/LibExecution.Tests.fs +++ b/backend/tests/Tests/LibExecution.Tests.fs @@ -50,14 +50,12 @@ let setupDBs (canvasID : CanvasID) (dbs : List) : Task = let t (internalFnsAllowed : bool) (canvasName : string) + (pm : RT.PackageManager) (actualExpr : PT.Expr) (expectedExpr : PT.Expr) (filename : string) (lineNumber : int) (dbs : List) - (types : List) - (functions : List) - (constants : List) (workers : List) : Test = testTask $"line{lineNumber}" { @@ -72,36 +70,12 @@ let t let tlid = 777777297845223UL - let rtTypes = - types - |> List.map (fun typ -> - (PT2RT.FQTypeName.UserProgram.toRT typ.name, PT2RT.UserType.toRT typ)) - |> Map.ofList - let rtDBs = dbs |> List.map (fun db -> (db.name, PT2RT.DB.toRT db)) |> Map.ofList - let rtFunctions = - functions - |> List.map (fun fn -> - (PT2RT.FQFnName.UserProgram.toRT fn.name, PT2RT.UserFunction.toRT fn)) - |> Map.ofList - - let rtConstants = - constants - |> List.map (fun c -> - (PT2RT.FQConstantName.UserProgram.toRT c.name, PT2RT.UserConstant.toRT c)) - |> Map.ofList - let! (state : RT.ExecutionState) = - executionStateFor - canvasID - internalFnsAllowed - false - rtDBs - rtTypes - rtFunctions - rtConstants + executionStateFor pm canvasID internalFnsAllowed false rtDBs + let red = "\u001b[31m" let green = "\u001b[32m" let bold = "\u001b[1;37m" @@ -242,9 +216,9 @@ let baseDir = "testfiles/execution/" let fileTests () : Test = let parseTestFile fileName = LibParser.TestModule.parseTestFile + "Tests" localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.Allow fileName @@ -265,10 +239,15 @@ let fileTests () : Test = let modules = $"{dir}/{filename}" |> parseTestFile |> (fun ply -> ply.Result) - // Within a module, tests have access to - let fns = modules |> List.collect _.fns - let types = modules |> List.collect _.types - let constants = modules |> List.collect _.constants + let pm = + RT.PackageManager.withExtras + packageManager + (modules |> List.collect _.types |> List.map PT2RT.PackageType.toRT) + (modules + |> List.collect _.constants + |> List.map PT2RT.PackageConstant.toRT) + (modules |> List.collect _.fns |> List.map PT2RT.PackageFn.toRT) + let tests = modules |> List.map (fun m -> @@ -277,18 +256,15 @@ let fileTests () : Test = t initializeCanvas test.name + pm test.actual test.expected filename test.lineNumber m.dbs - types - fns - constants [])) |> List.concat - testList testName tests with e -> print $"Exception in {file}: {e.Message}" diff --git a/backend/tests/Tests/Parser.Tests.fs b/backend/tests/Tests/Parser.Tests.fs index d561509a0a..a53e11dbad 100644 --- a/backend/tests/Tests/Parser.Tests.fs +++ b/backend/tests/Tests/Parser.Tests.fs @@ -12,6 +12,7 @@ module PT2RT = LibExecution.ProgramTypesToRuntimeTypes module NR = LibParser.NameResolver let id = 0UL // since we're ignoring IDs, just use the same one everywhere + let exprRTs = let t name testStr expectedExpr = testTask name { @@ -19,7 +20,6 @@ let exprRTs = LibParser.Parser.parseRTExpr localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.Allow "parser.tests.fs" testStr @@ -30,7 +30,7 @@ let exprRTs = testList - "Parser tests" + "Exprs" // TODO: order these by simplicity, and add more tests [ // First, let's start with some simple ones @@ -119,6 +119,5 @@ let exprRTs = ) )) ] -//let canvases let tests = testList "Parser" [ exprRTs ] diff --git a/backend/tests/Tests/ProgramTypes.Tests.fs b/backend/tests/Tests/ProgramTypes.Tests.fs index 5e7d5551f8..7e31efd35c 100644 --- a/backend/tests/Tests/ProgramTypes.Tests.fs +++ b/backend/tests/Tests/ProgramTypes.Tests.fs @@ -27,7 +27,6 @@ let testPipesToRuntimeTypes = |> LibParser.Parser.parseRTExpr localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "programTypes.tests.fs" |> Ply.toTask diff --git a/backend/tests/Tests/Queue.Tests.fs b/backend/tests/Tests/Queue.Tests.fs index ebd38c3195..cd633c7211 100644 --- a/backend/tests/Tests/Queue.Tests.fs +++ b/backend/tests/Tests/Queue.Tests.fs @@ -29,7 +29,6 @@ let p (code : string) : Task = LibParser.Parser.parsePTExpr localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "Queue.Tests.fs" code diff --git a/backend/tests/Tests/QueueSchedulingRules.Tests.fs b/backend/tests/Tests/QueueSchedulingRules.Tests.fs index 53166dedb3..426c23aee3 100644 --- a/backend/tests/Tests/QueueSchedulingRules.Tests.fs +++ b/backend/tests/Tests/QueueSchedulingRules.Tests.fs @@ -21,7 +21,6 @@ let p (code : string) : Task = LibParser.Parser.parsePTExpr localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "queueschedulingrules.fs" code diff --git a/backend/tests/Tests/Serialization.DarkTypes.Tests.fs b/backend/tests/Tests/Serialization.DarkTypes.Tests.fs index d2252d1286..766aedecfc 100644 --- a/backend/tests/Tests/Serialization.DarkTypes.Tests.fs +++ b/backend/tests/Tests/Serialization.DarkTypes.Tests.fs @@ -30,8 +30,7 @@ module RoundtripTests = let types : RT.Types = { typeSymbolTable = Map.empty - package = packageManager.getType - userProgram = Map.empty } + package = packageManager.getType } let testRoundtrip (testName : string) @@ -206,22 +205,6 @@ module RoundtripTests = PT2DT.PackageConstant.fromDT None - testRoundtripList - "PT.UserFunction" - (pkg [ "UserFunction" ] "UserFunction" 0) - V.ProgramTypes.userFunctions - PT2DT.UserFunction.toDT - PT2DT.UserFunction.fromDT - None - - testRoundtripList - "PT.UserConstants" - (pkg [] "UserConstant" 0) - V.ProgramTypes.userConstants - PT2DT.UserConstant.toDT - PT2DT.UserConstant.fromDT - None - testRoundtripList "PT.Secret" (pkg [] "Secret" 0) @@ -244,9 +227,7 @@ module RoundtripTests = V.ProgramTypes.Handler.handlers PT2DT.Handler.toDT PT2DT.Handler.fromDT - None - - ] + None ] let tests = diff --git a/backend/tests/Tests/Serialization.TestValues.fs b/backend/tests/Tests/Serialization.TestValues.fs index 420cddc102..97929cd594 100644 --- a/backend/tests/Tests/Serialization.TestValues.fs +++ b/backend/tests/Tests/Serialization.TestValues.fs @@ -23,20 +23,16 @@ let tlids : List = [ 1UL; 0UL; uint64 -1L ] module RuntimeTypes = let fqTypeNames : List = - [ RT.FQTypeName.UserProgram { modules = [ "X" ]; name = "userfn"; version = 0 } - RT.FQTypeName.Package + [ RT.FQTypeName.Package { owner = "a"; modules = [ "b"; "C" ]; name = "d"; version = 2 } ] let fqFnNames : List = - [ RT.FQFnName.UserProgram { modules = [ "X" ]; name = "userfn"; version = 0 } - RT.FQFnName.Builtin { name = "aB"; version = 1 } + [ RT.FQFnName.Builtin { name = "aB"; version = 1 } RT.FQFnName.Package { owner = "a"; modules = [ "b"; "C" ]; name = "d"; version = 2 } ] let fqConstantNames : List = - [ RT.FQConstantName.UserProgram - { modules = [ "X" ]; name = "userfn"; version = 0 } - RT.FQConstantName.Builtin { name = "aB"; version = 1 } + [ RT.FQConstantName.Builtin { name = "aB"; version = 1 } RT.FQConstantName.Package { owner = "a"; modules = [ "b"; "C" ]; name = "d"; version = 2 } ] @@ -60,7 +56,10 @@ module RuntimeTypes = RT.TDict RT.TBool RT.TDB RT.TBool RT.TCustomType( - Ok(RT.FQTypeName.UserProgram { modules = []; name = "User"; version = 0 }), + Ok( + RT.FQTypeName.Package + { owner = "test"; modules = []; name = "User"; version = 0 } + ), [ RT.TBool ] ) RT.TCustomType( @@ -176,7 +175,8 @@ module RuntimeTypes = 128384UL, RT.EFnName( 2236UL, - RT.FQFnName.UserProgram { modules = []; name = "fn"; version = 0 } + RT.FQFnName.Package + { owner = "test"; modules = []; name = "fn"; version = 0 } ), [], (NEList.singleton (RT.EUnit(7756UL))) @@ -190,8 +190,11 @@ module RuntimeTypes = ) RT.ERecord( 8167384UL, - RT.FQTypeName.UserProgram( - { modules = [ "MyModule"; "Name" ]; name = "NonEmptyList"; version = 0 } + RT.FQTypeName.Package( + { owner = "owner" + modules = [ "MyModule"; "Name" ] + name = "NonEmptyList" + version = 0 } ), NEList.singleton ("a9df8", RT.EUnit(71631UL)) ) @@ -212,7 +215,8 @@ module RuntimeTypes = RT.EOr(8375723UL, RT.EBool(83289473UL, true), RT.EBool(383674673UL, false)) RT.EEnum( 8375723UL, - RT.FQTypeName.UserProgram { modules = []; name = "MyEnum"; version = 0 }, + RT.FQTypeName.Package + { owner = "owner"; modules = []; name = "MyEnum"; version = 0 }, "A", [ RT.EUnit(81264012UL) ] ) ] @@ -252,7 +256,8 @@ module RuntimeTypes = let dval : RT.Dval = let typeName = - RT.FQTypeName.UserProgram { modules = []; name = "MyType"; version = 0 } + RT.FQTypeName.Package + { owner = "owner"; modules = []; name = "MyType"; version = 0 } sampleDvals |> List.map (fun (name, (dv, _)) -> name, dv) |> fun fields -> RT.DRecord(typeName, typeName, [], Map fields) @@ -263,8 +268,7 @@ module ProgramTypes = let signs = [ Sign.Positive; Sign.Negative ] let fqFnNames : List = - [ PT.FQFnName.UserProgram { modules = []; name = "fn"; version = 0 } - PT.FQFnName.Builtin { name = "int64Increment"; version = 1 } + [ PT.FQFnName.Builtin { name = "int64Increment"; version = 1 } PT.FQFnName.Package { owner = "twilio"; modules = [ "Twilio" ]; name = "sms"; version = 1 } ] @@ -348,8 +352,8 @@ module ProgramTypes = PT.TDB PT.TBool PT.TCustomType( Ok( - PT.FQTypeName.UserProgram - { modules = [ "Mod" ]; name = "User"; version = 0 } + PT.FQTypeName.Package + { owner = "owner"; modules = [ "Mod" ]; name = "User"; version = 0 } ), [ PT.TBool ] ) @@ -509,8 +513,9 @@ module ProgramTypes = PT.ERecord( 109539183UL, Ok( - PT.FQTypeName.UserProgram( - { modules = [ "dark"; "stdlib" ] + PT.FQTypeName.Package( + { owner = "dark" + modules = [ "stdlib" ] name = "NonEmptyList" version = 0 } ) @@ -856,29 +861,6 @@ module ProgramTypes = let userDBs : List = [ userDB ] - let userFunction : PT.UserFunction.T = - { tlid = 0UL - name = { modules = []; name = "user"; version = 0 } - typeParams = [ "a" ] - parameters = - NEList.singleton - { name = "myparam1"; typ = typeReference; description = "param1" } - returnType = typeReference - description = "function description" - deprecated = PT.DeprecatedBecause "some reason" - body = expr } - - let userFunctions : List = [ userFunction ] - - let userConstant : PT.UserConstant.T = - { tlid = 0UL - name = { modules = []; name = "pi"; version = 0 } - description = "constant description" - deprecated = PT.DeprecatedBecause "some reason" - body = constValue } - - let userConstants : List = [ userConstant ] - // TODO: serialize stdlib types? // (also make sure we roundtrip test them) @@ -941,9 +923,7 @@ module ProgramTypes = let toplevels : List = [ List.map PT.Toplevel.TLHandler Handler.handlers - List.map PT.Toplevel.TLDB [ userDB ] - List.map PT.Toplevel.TLFunction userFunctions - List.map PT.Toplevel.TLConstant userConstants ] + List.map PT.Toplevel.TLDB [ userDB ] ] |> List.concat let userSecret : PT.Secret.T = { name = "APIKEY"; value = "hunter2"; version = 0 } diff --git a/backend/tests/Tests/Serialization.Vanilla.Tests.fs b/backend/tests/Tests/Serialization.Vanilla.Tests.fs index 0e0c368fd2..747357df34 100644 --- a/backend/tests/Tests/Serialization.Vanilla.Tests.fs +++ b/backend/tests/Tests/Serialization.Vanilla.Tests.fs @@ -76,18 +76,25 @@ module PersistedSerializations = (V.RuntimeTypes.dval |> LibExecution.DvalReprInternalRoundtrippable.FormatV0.fromRT) + v "type" V.ProgramTypes.packageType + + v + "constant" + V.ProgramTypes.packageConstant + + v "function" V.ProgramTypes.packageFn + v> "complete" V.ProgramTypes.toplevels + v "httphandler" (PT.Toplevel.TLHandler V.ProgramTypes.Handler.http) + v "db" (PT.Toplevel.TLDB V.ProgramTypes.userDB) - v - "function" - (PT.Toplevel.TLFunction V.ProgramTypes.userFunction) // ------------------ // LibCloud diff --git a/backend/tests/Tests/SqlCompiler.Tests.fs b/backend/tests/Tests/SqlCompiler.Tests.fs index 7b347b5013..87dcdc7e3a 100644 --- a/backend/tests/Tests/SqlCompiler.Tests.fs +++ b/backend/tests/Tests/SqlCompiler.Tests.fs @@ -19,17 +19,15 @@ let p (code : string) : Task = LibParser.Parser.parseRTExpr localBuiltIns packageManager - NR.UserStuff.empty NR.OnMissing.ThrowError "sqlcompiler.tests.fs" code |> Ply.toTask -let parse (userFns : List) (code : string) : Task = +let parse (fns : List) (code : string) : Task = LibParser.Parser.parseRTExpr localBuiltIns - packageManager - { NR.UserStuff.empty with fns = Set userFns } + (PackageManager.withExtras packageManager [] [] fns) NR.OnMissing.ThrowError "sqlcompiler.tests.fs" code @@ -45,20 +43,24 @@ let compile task { let canvasID = System.Guid.NewGuid() - let typeName : FQTypeName.UserProgram = - { modules = []; name = "MyType"; version = 0 } + let typeName : FQTypeName.Package = + { owner = "Tests"; modules = []; name = "MyType"; version = 0 } let field : TypeDeclaration.RecordField = { name = rowName; typ = rowType } - let userType : UserType.T = + let typ : PackageType.T = { tlid = gid () name = typeName declaration = { typeParams = [] definition = TypeDeclaration.Record(NEList.singleton field) } } - let userTypes = Map [ typeName, userType ] - let typeReference = TCustomType(Ok(FQTypeName.UserProgram typeName), []) + let typeReference = TCustomType(Ok(FQTypeName.Package typeName), []) let! state = - executionStateFor canvasID false false Map.empty userTypes Map.empty Map.empty + executionStateFor + (PackageManager.withExtras packageManager [ typ ] [] []) + canvasID + false + false + Map.empty try let! compiled = @@ -154,14 +156,7 @@ let compileTests = let inlineWorksAtRoot = testTask "inlineWorksAtRoot" { let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty + executionStateFor packageManager (System.Guid.NewGuid()) false false Map.empty let fns = ExecutionState.availableFunctions state let! expr = p "let y = 5 in let x = 6 in (3 + (let x = 7 in y))" @@ -173,14 +168,7 @@ let inlineWorksAtRoot = let inlineWorksWithNested = testTask "inlineWorksWithNested" { let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty + executionStateFor packageManager (System.Guid.NewGuid()) false false Map.empty let fns = ExecutionState.availableFunctions state let! expr = p "let x = 5 in (let x = 6 in (3 + (let x = 7 in x)))" @@ -189,17 +177,11 @@ let inlineWorksWithNested = return Expect.equalExprIgnoringIDs result expected } + let inlineWorksWithPackageFunctionsSqlBinOp = testTask "inlineWorksWithPackageFunctionsSqlBinOp" { let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty + executionStateFor packageManager (System.Guid.NewGuid()) false false Map.empty let fns = ExecutionState.availableFunctions state let! expr = p @@ -210,17 +192,11 @@ let inlineWorksWithPackageFunctionsSqlBinOp = return Expect.equalExprIgnoringIDs result expected } + let inlineWorksWithPackageFunctionsSqlFunction = testTask "inlineWorksWithPackageFunctionsSqlFunction" { let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty + executionStateFor packageManager (System.Guid.NewGuid()) false false Map.empty let fns = ExecutionState.availableFunctions state let! expr = p @@ -232,99 +208,9 @@ let inlineWorksWithPackageFunctionsSqlFunction = } -let inlineWorksWithUserFunctions = - testTask "inlineWorksWithUserFunctions" { - let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty - - let userAddBody = - PT.EInfix( - 0UL, - PT.InfixFnCall(PT.ArithmeticPlus), - PT.EVariable(0UL, "a"), - PT.EVariable(0UL, "b") - ) - - let (userAdd : UserFunction.T) = - testUserFn "userAdd" [] (NEList.doubleton "a" "b") PT.TInt64 userAddBody - |> PT2RT.UserFunction.toRT - - let existingFunctions = ExecutionState.availableFunctions state - let updatedUserProgram = - Map.add userAdd.name userAdd existingFunctions.userProgram - let fns = { existingFunctions with userProgram = updatedUserProgram } - - let! expr = - parse - [ PT.FQFnName.userProgram [] "userAdd" 0 ] - "let a = 1 in let b = 9 in let c = userAdd 6 4 in (p.height == c) && (p.age == b)" - - let! expected = p "p.height == (6 + 4) && p.age == 9" - let! result = (C.inline' fns "value" Map.empty expr) |> Ply.toTask - return Expect.equalExprIgnoringIDs result expected - } - -let inlineWorksWithPackageAndUserFunctions = - testTask "inlineWorksWithPackageAndUserFunctions" { - let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty - - let (userAnd : UserFunction.T) = - testUserFn - "userAnd" - [] - (NEList.doubleton "a" "b") - PT.TBool - (PT.EInfix( - 0UL, - PT.BinOp(PT.BinOpAnd), - PT.EVariable(0UL, "a"), - PT.EVariable(0UL, "b") - )) - |> PT2RT.UserFunction.toRT - - let existingFunctions = ExecutionState.availableFunctions state - let updatedUserProgram = - Map.add userAnd.name userAnd existingFunctions.userProgram - let fns = { existingFunctions with userProgram = updatedUserProgram } - - let! expr = - parse - [ PT.FQFnName.userProgram [] "userAnd" 0 ] - "userAnd user.human (PACKAGE.Darklang.Stdlib.Int64.lessThan_v0 user.height (PACKAGE.Darklang.Stdlib.Int64.add height 1))" - - let! expected = p "user.human && (user.height < (height + 1))" - let! result = (C.inline' fns "value" Map.empty expr) |> Ply.toTask - return Expect.equalExprIgnoringIDs result expected - } - let inlineFunctionArguments = testTask "inlineWorksArguments" { - let! state = - executionStateFor - (System.Guid.NewGuid()) - false - false - Map.empty - Map.empty - Map.empty - Map.empty - - let userAddBody = + let fnBody = PT.EInfix( 0UL, PT.InfixFnCall(PT.ArithmeticPlus), @@ -332,21 +218,17 @@ let inlineFunctionArguments = PT.EVariable(0UL, "b") ) - let (userAdd : UserFunction.T) = - testUserFn "userAdd" [] (NEList.doubleton "a" "b") PT.TInt64 userAddBody - |> PT2RT.UserFunction.toRT - - let existingFunctions = ExecutionState.availableFunctions state - let updatedUserProgram = - Map.add userAdd.name userAdd existingFunctions.userProgram - let fns = { existingFunctions with userProgram = updatedUserProgram } + let (fn : PackageFn.T) = + testPackageFn "Tests" "userAdd" [] (NEList.doubleton "a" "b") PT.TInt64 fnBody + |> PT2RT.PackageFn.toRT - let userFns = [ PT.FQFnName.userProgram [] "userAdd" 0 ] + let fns : Functions = + { builtIn = localBuiltIns.fns; package = fun _name -> Ply(Some fn) } let! expr = - parse userFns "let a = 1 in let b = 9 in (p.height == userAdd 6 (b - 4))" + parse [ fn ] "let a = 1 in let b = 9 in (p.height == Tests.userAdd 6 (b - 4))" - let! expected = parse userFns "p.height == 6 + (9 - 4)" + let! expected = parse [ fn ] "p.height == 6 + (9 - 4)" let! result = (C.inline' fns "value" Map.empty expr) |> Ply.toTask return Expect.equalExprIgnoringIDs result expected } @@ -359,15 +241,7 @@ let partialEvaluation = task { let canvasID = System.Guid.NewGuid() let tlid = 777777982742UL - let! state = - executionStateFor - canvasID - false - false - Map.empty - Map.empty - Map.empty - Map.empty + let! state = executionStateFor packageManager canvasID false false Map.empty let! expr = p expr let result = C.partiallyEvaluate state tlid Map.empty (Map vars) "x" expr let! (dvals, result) = Ply.TplPrimitives.runPlyAsTask result @@ -416,10 +290,7 @@ let partialEvaluation = DBool true) (("myVar || myVar2", [ "myVar", DBool true; "myVar2", DBool false ]), DBool true) - (("myVar || myVar2", [ "myVar", DBool true; "myVar2", DBool true ]), DBool true) - - - ] + (("myVar || myVar2", [ "myVar", DBool true; "myVar2", DBool true ]), DBool true) ] let tests = @@ -429,8 +300,6 @@ let tests = inlineWorksWithNested inlineWorksWithPackageFunctionsSqlBinOp inlineWorksWithPackageFunctionsSqlFunction - inlineWorksWithUserFunctions - inlineWorksWithPackageAndUserFunctions inlineFunctionArguments partialEvaluation compileTests ] diff --git a/backend/tests/Tests/Tests.fs b/backend/tests/Tests/Tests.fs index 0730815fba..3e34363cd5 100644 --- a/backend/tests/Tests/Tests.fs +++ b/backend/tests/Tests/Tests.fs @@ -7,6 +7,7 @@ open System.Threading.Tasks open Prelude +module PT = LibExecution.ProgramTypes module Telemetry = LibService.Telemetry module CTPusher = LibClientTypes.Pusher @@ -17,6 +18,9 @@ let initSerializers () = // These are serializers used in the tests that are not used in the main program Json.Vanilla.allow> "tests" Json.Vanilla.allow "testTraceData" + Json.Vanilla.allow "Canvas.loadJsonFromDisk" + Json.Vanilla.allow "Canvas.loadJsonFromDisk" + Json.Vanilla.allow "Canvas.loadJsonFromDisk" [] diff --git a/packages/darklang/cli/cli.dark b/packages/darklang/cli/cli.dark index 8d5a885f0e..cdd484fff7 100644 --- a/packages/darklang/cli/cli.dark +++ b/packages/darklang/cli/cli.dark @@ -61,7 +61,7 @@ module Darklang = (args: List) : Int64 = if Stdlib.List.member_v0 flags "wip-parser" then - let nameResolver = LanguageTools.NameResolver.empty () + let onMissing = LanguageTools.NameResolver.OnMissing.Allow let args = args @@ -75,7 +75,7 @@ module Darklang = | CliScript script -> script.exprsToEval) |> Stdlib.List.flatten |> Stdlib.List.map (fun arg -> - LanguageTools.WrittenTypesToProgramTypes.Expr.toPT nameResolver arg) + LanguageTools.WrittenTypesToProgramTypes.Expr.toPT onMissing arg) match Builtin.cliExecuteFunctionWithNewParser fnName args with | Ok result -> diff --git a/packages/darklang/dark-packages.dark b/packages/darklang/dark-packages.dark index f486c78eb7..be0f2f2753 100644 --- a/packages/darklang/dark-packages.dark +++ b/packages/darklang/dark-packages.dark @@ -26,16 +26,9 @@ module Darklang = let parseVersion (name: String) : (String * Int64) = - let parts = Stdlib.String.split name "_v" - let name = (Stdlib.List.head parts) |> Builtin.unwrap - - let version = - (Stdlib.List.last parts) - |> Builtin.unwrap - |> Builtin.int64Parse - |> Builtin.unwrap - - (name, version) + match Stdlib.String.split name "_v" with + | [ name ] -> (name, 0L) + | [ name; version ] -> (name, version |> Builtin.int64Parse |> Builtin.unwrap) let parseName (name: String) : GenericName = diff --git a/packages/darklang/internal.dark b/packages/darklang/internal.dark index 8559674c97..06c0b9679e 100644 --- a/packages/darklang/internal.dark +++ b/packages/darklang/internal.dark @@ -19,11 +19,8 @@ module Darklang = /// A program on a canvas type Program = { id: Uuid - types: List - fns: List // TODO: - //constants: List //dbs: List //httpHandlers: List } diff --git a/packages/darklang/languageTools/common.dark b/packages/darklang/languageTools/common.dark index c09d7f2e8b..c138337c52 100644 --- a/packages/darklang/languageTools/common.dark +++ b/packages/darklang/languageTools/common.dark @@ -16,4 +16,10 @@ module Darklang = { name: String description: String parameters: List - returnType: String } \ No newline at end of file + returnType: String } + + /// A Darklang builtin constant + type BuiltinConstant = + { name: String + description: String + ``type``: String } \ No newline at end of file diff --git a/packages/darklang/languageTools/nameResolver.dark b/packages/darklang/languageTools/nameResolver.dark index 5f3cafa5dc..66762a8b67 100644 --- a/packages/darklang/languageTools/nameResolver.dark +++ b/packages/darklang/languageTools/nameResolver.dark @@ -1,407 +1,322 @@ -// CLEANUP : there is room for refactoring here to reduce duplicated code module Darklang = module LanguageTools = module NameResolver = - type NameResolutionSettings = { allowError: Bool } - - - let empty () : NameResolver.NameResolutionSettings = - NameResolver.NameResolutionSettings { allowError = true } - + /// If a name is not found, should we raise an error? + /// + /// sometimes when parsing, we're not sure whether something is: + /// - a variable + /// - or something else, like a constant or fn. + /// During these times, and others, we wantto allow errors, so we can + /// parse it as a variable as a fallback if nothing is found under that name. + type OnMissing = + | ThrowError + | Allow + + // TODO: we should probably just return the Result, and let the caller + // handle the error if they want to... + let throwIfRelevant + (onMissing: OnMissing) + (result: ProgramTypes.NameResolution<'a>) + : ProgramTypes.NameResolution<'a> = + result + |> Stdlib.Result.mapError (fun err -> + match onMissing with + | ThrowError -> err // TODO: something + | Allow -> err) + + + type GenericName = + { modules: List + name: String + version: Int64 } + + /// If we're 'given' the name `Option.Option` + /// and we're parsing in `Darklang.Stdlib`, + /// + /// We should look for the thing in the following places: + /// - Darklang.Stdlib.Option.Option + /// - Darklang.Option.Option + /// - Option.Option + /// , in that order (most specific first). let namesToTry - (given: List) - (modules: List) - : List> = - match modules with - | [] -> [ given ] - | _ -> - let rest = Stdlib.List.dropLast modules - let current = Stdlib.List.append modules given - Stdlib.List.append [ current ] (namesToTry given rest) - + (currentModule: List) + (given: GenericName) + : List = + let addl = + match given.modules with + | "Stdlib" :: _ -> + [ { given with + modules = Stdlib.List.append [ "Darklang" ] given.modules } ] + | "PACKAGE" :: owner :: modules -> + [ { given with + modules = Stdlib.List.append [ owner ] modules } ] + | _ -> [] + + Stdlib.List.append (namesToTryHelper currentModule given) addl + + // TODO we can do this without a helper function, + // by removing the recursion and using a fold. + let namesToTryHelper + (modulesToPrepend: List) + (given: GenericName) + : List = + match Stdlib.List.splitLast modulesToPrepend with + | None -> [ given ] + | Some(allButLast, _last) -> + let newNameToTry = + { given with + modules = Stdlib.List.append modulesToPrepend given.modules } + + Stdlib.List.append [ newNameToTry ] (namesToTryHelper allButLast) module TypeName = - - // TODO: rename this - let resolveNameTypeName - (parser: String -> Stdlib.Result.Result) + let err + (errType: RuntimeErrors.NameResolution.ErrorType) (names: List) - (packageThingExists: String -> Bool) - (nameErrorType: LanguageTools.RuntimeErrors.NameResolution.NameType) - : LanguageTools.ProgramTypes.NameResolution = - let modules = Stdlib.List.dropLast names - let name = Stdlib.List.last names - - match name with - | None -> - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.InvalidPackageName - nameType = nameErrorType - names = names } - ) - | Some name -> - match modules with - | "Stdlib" :: otherModules -> - let name = (parser name) |> Builtin.unwrap - - let fqName = - [ "Darklang"; "Stdlib" ] - |> Stdlib.List.append otherModules - |> Stdlib.List.append [ name ] - |> Stdlib.String.join "." - - let packageThingExists = packageThingExists fqName - - if packageThingExists then - Stdlib.Result.Result.Ok( - (ProgramTypes.FQTypeName.Package - { owner = "Darklang" - modules = Stdlib.List.append [ "Stdlib" ] otherModules - name = name - version = 0L }) - |> ProgramTypes.FQTypeName.FQTypeName.Package - ) - else - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - nameType = nameErrorType - names = Stdlib.List.append otherModules [ name ] } - ) - - | "PACKAGE" :: owner :: modules -> - - let name = (parser name) |> Builtin.unwrap - - let fqName = - [ owner ] - |> Stdlib.List.append modules - |> Stdlib.List.append [ name ] - |> Stdlib.String.join "." - - let packageThingExists = packageThingExists fqName - - if packageThingExists then - Stdlib.Result.Result.Ok( - (ProgramTypes.FQTypeName.Package - { owner = owner - modules = modules - name = name - version = 0L }) - |> ProgramTypes.FQTypeName.FQTypeName.Package - ) - else - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - nameType = nameErrorType - names = Stdlib.List.append modules [ name ] } - ) - - | modules -> - // TODO : check if user program exists - Stdlib.Result.Result.Ok( - (ProgramTypes.FQTypeName.UserProgram - { modules = modules - name = name - version = 0L }) - |> ProgramTypes.FQTypeName.FQTypeName.UserProgram - ) + : ProgramTypes.NameResolution = + (LanguageTools.RuntimeErrors.NameResolution.Error + { nameType = LanguageTools.RuntimeErrors.NameResolution.NameType.Type + errorType = + LanguageTools.RuntimeErrors.NameResolution.ErrorType.InvalidPackageName + names = names }) + |> Stdlib.Result.Result.Error + + + let tryResolve + (name: GenericName) + : Stdlib.Result.Result = + match name.modules with + | [] -> Stdlib.Result.Result.Error() + | owner :: modules -> + let nameForLookup = + (Stdlib.List.flatten [ name.modules; [ name.name ] ]) + |> Stdlib.String.join "." + + match PackageManager.Type.byName nameForLookup with + | Ok _found -> + (ProgramTypes.FQTypeName.Package + { owner = owner + modules = modules + name = name.name + version = name.version }) + |> ProgramTypes.FQTypeName.FQTypeName.Package + |> Stdlib.Result.Result.Ok + | Error _ -> Stdlib.Result.Result.Error() - let resolveTypeName - (parser: String -> Stdlib.Result.Result) - (nameErrorType: LanguageTools.RuntimeErrors.NameResolution.NameType) - (packageThingExists: String -> Bool) - (allowError: Bool) + let resolve + (onMissing: OnMissing) (currentModule: List) - (name: LanguageTools.WrittenTypes.Name) - : LanguageTools.ProgramTypes.NameResolution = - + (name: WrittenTypes.Name) + : ProgramTypes.NameResolution = match name with - | Unresolved(_, given) -> - let result = - Stdlib.List.fold - (NameResolver.namesToTry given currentModule) - - (Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { nameType = nameErrorType - errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - names = given } - )) - - (fun currentResult pathToTry -> - match currentResult with - | Ok _ -> currentResult - | Error _ -> - let newResult = - resolveNameTypeName - parser - pathToTry - packageThingExists - nameErrorType - - match newResult with - | Ok _ -> newResult - | Error _ -> currentResult) - - match result with - | Ok result -> Stdlib.Result.Result.Ok result - | Error err -> - if allowError then - Stdlib.Result.Result.Error err - else - Stdlib.Result.Result.Error "TODO: Raise exception" - - - | _ -> Stdlib.Result.Result.Error "TODO : builtin and user program" - - - let packageTypeExists (typeName: String) : Bool = - (LanguageTools.PackageManager.Type.byName typeName) |> Stdlib.Result.isOk - - - let maybeResolve - (resolver: NameResolver.NameResolutionSettings) - (currentModule: List) - (name: LanguageTools.WrittenTypes.Name) - : LanguageTools.ProgramTypes.NameResolution = + // TODO remodel things appropriately so this is not needed + | KnownBuiltin(_name, _version) -> "Builtin types don't exist" // TODO: error + + | Unresolved(_range, given) -> + let modules = Stdlib.List.dropLast given + let name = Stdlib.List.last given + + // TODO: handle versions... (parse out the _v[n] part if present) + match name with + | None -> + err RuntimeErrors.NameResolution.ErrorType.InvalidPackageName given + | Some name -> + let genericName = + GenericName + { modules = modules + name = name + version = 0L } - resolveTypeName - LanguageTools.Parser.parseName - LanguageTools.RuntimeErrors.NameResolution.NameType.Type - TypeName.packageTypeExists - currentModule - true - name + let result = + Stdlib.List.fold + (namesToTry currentModule genericName) + (err RuntimeErrors.NameResolution.ErrorType.NotFound given) + (fun currentResult nameToTry -> + match currentResult with + | Ok _ -> currentResult + | Error _ -> + match tryResolve nameToTry with + | Error() -> currentResult + | Ok success -> Stdlib.Result.Result.Ok success) - let resolve - (resolver: NameResolver.NameResolutionSettings) - (currentModule: List) - (name: LanguageTools.WrittenTypes.Name) - : LanguageTools.ProgramTypes.NameResolution = - resolveTypeName - LanguageTools.Parser.parseName - LanguageTools.RuntimeErrors.NameResolution.NameType.Type - TypeName.packageTypeExists - resolver.allowError - currentModule - name + throwIfRelevant onMissing result - module FnName = - // helper fuctions for the resolve function - // TODO: rename this - let resolveNameFnName - (parser: String -> Stdlib.Result.Result) + module ConstantName = + let err + (errType: RuntimeErrors.NameResolution.ErrorType) (names: List) - (packageThingExists: String -> Bool) - (builtinThingExists: String -> Bool) - (nameErrorType: LanguageTools.RuntimeErrors.NameResolution.NameType) - : LanguageTools.ProgramTypes.NameResolution = - let modules = Stdlib.List.dropLast names - let name = Stdlib.List.last names - - match name with - | None -> - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.InvalidPackageName - nameType = nameErrorType - names = names } - ) - | Some name -> - match modules with - | "Stdlib" :: otherModules -> - let name = (parser name) |> Builtin.unwrap - - let fqName = - [ "Darklang"; "Stdlib" ] - |> Stdlib.List.append otherModules - |> Stdlib.List.append [ name ] - |> Stdlib.String.join "." - - let packageThingExists = packageThingExists fqName - - if packageThingExists then - Stdlib.Result.Result.Ok( - (ProgramTypes.FQFnName.Package - { owner = "Darklang" - modules = Stdlib.List.append [ "Stdlib" ] otherModules - name = name - version = 0L }) - |> ProgramTypes.FQFnName.FQFnName.Package - ) - else - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - nameType = nameErrorType - names = Stdlib.List.append otherModules [ name ] } - ) - - | "PACKAGE" :: owner :: modules -> - let name = (parser name) |> Builtin.unwrap - - let fqName = - [ owner ] - |> Stdlib.List.append modules - |> Stdlib.List.append [ name ] - |> Stdlib.String.join "." - - let packageThingExists = packageThingExists fqName - - if packageThingExists then - Stdlib.Result.Result.Ok( - (ProgramTypes.FQFnName.Package - { owner = owner - modules = modules - name = name - version = 0L }) - |> ProgramTypes.FQFnName.FQFnName.Package - ) - else - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - nameType = nameErrorType - names = Stdlib.List.append modules [ name ] } - ) - - | [ "Builtin" ] -> - let builtinName = name + : ProgramTypes.NameResolution = + (LanguageTools.RuntimeErrors.NameResolution.Error + { nameType = LanguageTools.RuntimeErrors.NameResolution.NameType.Constant + errorType = errType + names = names }) + |> Stdlib.Result.Result.Error - let builtinExists = builtinThingExists builtinName - if builtinExists then - let builtIn = - (ProgramTypes.FQFnName.Builtin { name = name; version = 0L }) + let builtinThingExists (name: String) : Bool = + (Builtin.languageToolsAllBuiltinConstants ()) + |> Stdlib.List.findFirst (fun f -> f.name == name) + |> Stdlib.Option.isSome - Stdlib.Result.Result.Ok( - builtIn |> ProgramTypes.FQFnName.FQFnName.Builtin - ) + let tryResolve + (name: GenericName) + : Stdlib.Result.Result = + match name.modules with + | [] -> Stdlib.Result.Result.Error() + | owner :: modules -> + let nameForLookup = + (Stdlib.List.flatten [ name.modules; [ name.name ] ]) + |> Stdlib.String.join "." + + if owner == "Builtin" && modules == [] then + if builtinThingExists nameForLookup then + (ProgramTypes.FQConstantName.Builtin + { name = name.name + version = name.version }) + |> ProgramTypes.FQConstantName.FQConstantName.Builtin + |> Stdlib.Result.Result.Ok else - Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - nameType = nameErrorType - names = [ name ] } - ) - - | modules -> - // TODO : check if user program exists - Stdlib.Result.Result.Ok( - (ProgramTypes.FQFnName.UserProgram - { modules = modules - name = name - version = 0L }) - |> ProgramTypes.FQFnName.FQFnName.UserProgram - ) + Error() + else + match PackageManager.Constant.byName nameForLookup with + | Ok _found -> + (ProgramTypes.FQConstantName.Package + { owner = owner + modules = modules + name = name.name + version = name.version }) + |> ProgramTypes.FQConstantName.FQConstantName.Package + |> Stdlib.Result.Result.Ok + | Error _ -> Stdlib.Result.Result.Error() - let resolveFnName - (parser: String -> Stdlib.Result.Result) - (nameErrorType: LanguageTools.RuntimeErrors.NameResolution.NameType) - (packageThingExists: String -> Bool) - (builtinThingExists: String -> Bool) - (allowError: Bool) + let resolve + (onMissing: OnMissing) (currentModule: List) - (name: LanguageTools.WrittenTypesToProgramTypes.Name) - : LanguageTools.ProgramTypes.NameResolution = - + (name: WrittenTypes.Name) + : ProgramTypes.NameResolution = match name with - | Unresolved given -> - let result = - Stdlib.List.fold - (NameResolver.namesToTry given currentModule) - - (Stdlib.Result.Result.Error( - LanguageTools.RuntimeErrors.NameResolution.Error - { nameType = nameErrorType - errorType = - LanguageTools.RuntimeErrors.NameResolution.ErrorType.NotFound - names = given } - )) - - (fun currentResult pathToTry -> - match currentResult with - | Ok _ -> currentResult - | Error _ -> - let newResult = - resolveNameFnName - parser - pathToTry - packageThingExists - builtinThingExists - nameErrorType - - match newResult with - | Ok _ -> newResult - | Error _ -> currentResult) - - match result with - | Ok result -> Stdlib.Result.Result.Ok result - | Error err -> - if allowError then - Stdlib.Result.Result.Error err - else - Stdlib.Result.Result.Error "TODO: Raise exception" + // TODO remodel things appropriately so this is not needed + | KnownBuiltin(_name, _version) -> "Builtin types don't exist" // TODO: error + + | Unresolved(_range, given) -> + let modules = Stdlib.List.dropLast given + let name = Stdlib.List.last given + + // TODO: handle versions... (parse out the _v[n] part if present) + match name with + | None -> + err RuntimeErrors.NameResolution.ErrorType.InvalidPackageName given + | Some name -> + let genericName = + GenericName + { modules = modules + name = name + version = 0L } + let result = + Stdlib.List.fold + (namesToTry currentModule genericName) + (err RuntimeErrors.NameResolution.ErrorType.NotFound given) + (fun currentResult nameToTry -> + match currentResult with + | Ok _ -> currentResult + | Error _ -> + match tryResolve nameToTry with + | Error() -> currentResult + | Ok success -> Stdlib.Result.Result.Ok success) - | _ -> Stdlib.Result.Result.Error "TODO : builtin and user program" + throwIfRelevant onMissing result - let packageFnExists (fnName: String) : Bool = - (LanguageTools.PackageManager.Function.byName fnName) |> Stdlib.Result.isOk - let builtinThingExists (fnName: String) : Bool = - (Builtin.languageToolsAllBuiltinFns ()) - |> Stdlib.List.findFirst (fun f -> f.name == fnName) - |> Stdlib.Option.isSome + module FnName = + let err + (errType: RuntimeErrors.NameResolution.ErrorType) + (names: List) + : ProgramTypes.NameResolution = + (LanguageTools.RuntimeErrors.NameResolution.Error + { nameType = LanguageTools.RuntimeErrors.NameResolution.NameType.Function + errorType = errType + names = names }) + |> Stdlib.Result.Result.Error + + + + let tryResolve + (name: GenericName) + : Stdlib.Result.Result = + match name.modules with + | [] -> Stdlib.Result.Result.Error() + | owner :: modules -> + if owner == "Builtin" && modules == [] then + if Builtin.languageToolsBuiltinFnExists name.name name.version then + (ProgramTypes.FQFnName.Builtin + { name = name.name + version = name.version }) + |> ProgramTypes.FQFnName.FQFnName.Builtin + |> Stdlib.Result.Result.Ok + else + Stdlib.Result.Result.Error() + else + let nameForLookup = + (Stdlib.List.flatten [ name.modules; [ name.name ] ]) + |> Stdlib.String.join "." + match PackageManager.Function.byName nameForLookup with + | Ok _found -> + (ProgramTypes.FQFnName.Package + { owner = owner + modules = modules + name = name.name + version = name.version }) + |> ProgramTypes.FQFnName.FQFnName.Package + |> Stdlib.Result.Result.Ok + | Error _ -> Stdlib.Result.Result.Error() - let maybeResolve - (resolver: NameResolver.NameResolutionSettings) - (currentModule: List) - (name: LanguageTools.WrittenTypesToProgramTypes.Name) - : LanguageTools.ProgramTypes.NameResolution = - - resolveFnName - LanguageTools.Parser.parseName - LanguageTools.RuntimeErrors.NameResolution.NameType.Function - FnName.packageFnExists - FnName.builtinThingExists - currentModule - true - name let resolve - (resolver: NameResolver.NameResolutionSettings) + (onMissing: OnMissing) (currentModule: List) - (name: LanguageTools.WrittenTypesToProgramTypes.Name) - : LanguageTools.ProgramTypes.NameResolution = - - resolveFnName - LanguageTools.Parser.parseName - LanguageTools.RuntimeErrors.NameResolution.NameType.Function - FnName.packageFnExists - FnName.builtinThingExists - resolver.allowError - currentModule - name \ No newline at end of file + (name: WrittenTypes.Name) + : ProgramTypes.NameResolution = + match name with + // TODO remodel things appropriately so this is not needed + | KnownBuiltin(_name, _version) -> "Builtin types don't exist" // TODO: error + + | Unresolved(_range, given) -> + let modules = Stdlib.List.dropLast given + let name = Stdlib.List.last given + + // TODO: handle versions... (parse out the _v[n] part if present) + match name with + | None -> + err RuntimeErrors.NameResolution.ErrorType.InvalidPackageName given + | Some name -> + let genericName = + GenericName + { modules = modules + name = name + version = 0L } + + let result = + Stdlib.List.fold + (namesToTry currentModule genericName) + (err RuntimeErrors.NameResolution.ErrorType.NotFound given) + (fun currentResult nameToTry -> + match currentResult with + | Ok _ -> currentResult + | Error _ -> + match tryResolve nameToTry with + | Error() -> currentResult + | Ok success -> Stdlib.Result.Result.Ok success) + + throwIfRelevant onMissing result \ No newline at end of file diff --git a/packages/darklang/languageTools/packageManager.dark b/packages/darklang/languageTools/packageManager.dark index 05aba17d43..81383b9175 100644 --- a/packages/darklang/languageTools/packageManager.dark +++ b/packages/darklang/languageTools/packageManager.dark @@ -95,6 +95,9 @@ module Darklang = // else // (FetchError.Not200 response) |> Stdlib.Result.Result.Error + + // TODO: this type signature is totally wrong, + // yet we're not complaining in the runtime type-checker? let byName (typeName: String) : Stdlib.Result.Result = @@ -146,6 +149,31 @@ module Darklang = | e -> Stdlib.Result.Result.Error e + module Constant = + // let getAll (baseUrl: String) : String = "TODO" + + // let getByTlid (baseUrl: String) (tlid: String) : String = "TODO" + + let byName + (fnName: String) + : Stdlib.Result.Result = + let fn = + Stdlib.HttpClient.request + "GET" + $"{baseUrl ()}/constant/by-name/{fnName}" + [] + [] + + let statusCode = + fn + |> Stdlib.Result.map (fun response -> response.statusCode) + |> Builtin.unwrap + + match statusCode with + | 200L -> Stdlib.Result.Result.Ok fn + | e -> Stdlib.Result.Result.Error e + + // let getByFullyQualifiedName (baseUrl: String) (name: String) : String = // "TODO" diff --git a/packages/darklang/languageTools/programTypes.dark b/packages/darklang/languageTools/programTypes.dark index a73ff698d8..0511c3515d 100644 --- a/packages/darklang/languageTools/programTypes.dark +++ b/packages/darklang/languageTools/programTypes.dark @@ -13,18 +13,10 @@ module Darklang = name: String version: Int64 } - /// Part of the user's program (eg canvas or cli) - type UserProgram = - { modules: List - name: String - version: Int64 } + type FQTypeName = Package of Package - type FQTypeName = - | Package of Package - | UserProgram of UserProgram - - module FQFnName = + module FQConstantName = type Builtin = { name: String; version: Int64 } type Package = @@ -33,18 +25,12 @@ module Darklang = name: String version: Int64 } - type UserProgram = - { modules: List - name: String - version: Int64 } - - type FQFnName = + type FQConstantName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram - module FQConstantName = + module FQFnName = type Builtin = { name: String; version: Int64 } type Package = @@ -53,15 +39,11 @@ module Darklang = name: String version: Int64 } - type UserProgram = - { modules: List - name: String - version: Int64 } - - type FQConstantName = + type FQFnName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram + + type NameResolution<'a> = @@ -397,76 +379,54 @@ module Darklang = definition: Definition } - module Handler = - type CronInterval = - | EveryDay - | EveryWeek - | EveryFortnight - | EveryHour - | Every12Hours - | EveryMinute - - type Spec = - | HTTP of route: String * method: String - | Worker of name: String - | Cron of name: String * interval: CronInterval - | REPL of name: String - - type Handler = { tlid: TLID; ast: Expr; spec: Spec } - - - type DB = + // Package space + type PackageType = { tlid: TLID - name: String - version: Int64 - typ: TypeReference } + id: Uuid + name: FQTypeName.Package + declaration: TypeDeclaration.TypeDeclaration + description: String + deprecated: Deprecation } - /// A type that a User defined within a Canvas - type UserType = + type PackageConstant = { tlid: TLID - name: FQTypeName.UserProgram + id: Uuid + name: FQConstantName.Package + body: Const description: String - declaration: TypeDeclaration.TypeDeclaration - deprecated: Deprecation } + deprecated: Deprecation } - module UserFunction = + + module PackageFn = type Parameter = { name: String typ: TypeReference description: String } - type UserFunction = + type PackageFn = { tlid: TLID - name: FQFnName.UserProgram + id: Uuid + name: FQFnName.Package + body: Expr typeParams: List parameters: List returnType: TypeReference description: String - deprecated: Deprecation - body: Expr } - - type UserConstant = - { tlid: TLID - name: FQConstantName.UserProgram - description: String - deprecated: Deprecation - body: Const } + deprecated: Deprecation } + type Packages = + { types: List + constants: List + fns: List } - // module Toplevel = - // type T = - // | TLHandler of Handler.Handler - // | TLDB of DB - // | TLFunction of UserFunction.UserFunction - // | TLType of UserType.T - // let toTLID (tl : T) : tlid = - // match tl with - // | TLHandler h -> h.tlid - // | TLDB db -> db.tlid - // | TLFunction f -> f.tlid - // | TLType t -> t.tlid + // User/Canvas space + type DB = + { tlid: TLID + name: String + version: Int64 + typ: TypeReference } type Secret = @@ -475,41 +435,30 @@ module Darklang = version: Int64 } - type PackageType = - { tlid: TLID - id: Uuid - name: FQTypeName.Package - declaration: TypeDeclaration.TypeDeclaration - description: String - deprecated: Deprecation } + module Handler = + type CronInterval = + | EveryDay + | EveryWeek + | EveryFortnight + | EveryHour + | Every12Hours + | EveryMinute - module PackageFn = - type Parameter = - { name: String - typ: TypeReference - description: String } + type Spec = + | HTTP of route: String * method: String + | Worker of name: String + | Cron of name: String * interval: CronInterval + | REPL of name: String - type PackageFn = - { tlid: TLID - id: Uuid - name: FQFnName.Package - body: Expr - typeParams: List - parameters: List - returnType: TypeReference - description: String - deprecated: Deprecation } + type Handler = { tlid: TLID; ast: Expr; spec: Spec } - type PackageConstant = - { tlid: TLID - id: Uuid - name: FQConstantName.Package - body: Const - description: String - deprecated: Deprecation } +// module Toplevel = +// type T = +// | TLDB of DB +// | TLHandler of Handler.Handler - type Packages = - { types: List - constants: List - fns: List } \ No newline at end of file +// let toTLID (tl : T) : tlid = +// match tl with +// | TLDB db -> db.tlid +// | TLHandler h -> h.tlid \ No newline at end of file diff --git a/packages/darklang/languageTools/runtimeTypes.dark b/packages/darklang/languageTools/runtimeTypes.dark index f70e34550b..c808a98d35 100644 --- a/packages/darklang/languageTools/runtimeTypes.dark +++ b/packages/darklang/languageTools/runtimeTypes.dark @@ -13,14 +13,7 @@ module Darklang = name: String version: Int64 } - type UserProgram = - { modules: List - name: String - version: Int64 } - - type FQTypeName = - | Package of Package - | UserProgram of UserProgram + type FQTypeName = Package of Package module FQFnName = @@ -32,15 +25,9 @@ module Darklang = name: String version: Int64 } - type UserProgram = - { modules: List - name: String - version: Int64 } - type FQFnName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram /// A Fully-Qualified Constant Name @@ -54,15 +41,9 @@ module Darklang = name: String version: Int64 } - type UserProgram = - { modules: List - name: String - version: Int64 } - type FQConstantName = | Builtin of Builtin | Package of Package - | UserProgram of UserProgram type NameResolution<'a> = Stdlib.Result.Result<'a, RuntimeError> diff --git a/packages/darklang/languageTools/writtenTypesToProgramTypes.dark b/packages/darklang/languageTools/writtenTypesToProgramTypes.dark index edc84d8121..d77a76725f 100644 --- a/packages/darklang/languageTools/writtenTypesToProgramTypes.dark +++ b/packages/darklang/languageTools/writtenTypesToProgramTypes.dark @@ -8,7 +8,6 @@ module Darklang = let gtlid () : UInt64 = Stdlib.UInt64.random 0UL 9223372036854775807UL - type Name = Unresolved of List module Identifiers = module Type = @@ -16,50 +15,43 @@ module Darklang = module QualifiedType = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (i: WrittenTypes.QualifiedTypeIdentifier) - : ProgramTypes.FQTypeName.FQTypeName = - let currentModule = Stdlib.List.map i.modules (fun (m, _) -> m.name) - let nametoResolve = [ i.typ.name ] - - let resolvedName = - NameResolver.TypeName.resolve - resolver - currentModule - (WrittenTypes.Name.Unresolved(i.range, nametoResolve)) + : ProgramTypes.NameResolution = + let nameToResolve = + Stdlib.List.append + (Stdlib.List.map i.modules (fun (m, _) -> m.name)) + [ i.typ.name ] + + NameResolver.TypeName.resolve + onMissing + [] + (WrittenTypes.Name.Unresolved(i.range, nameToResolve)) - match resolvedName with - | Ok n -> n - // TODO: Handle errors properly - | Error e -> $"TODO: handle error {e}" module Fn = let toPT (fn: WrittenTypes.FnIdentifier) : String = fn.name module QualifiedFn = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (i: WrittenTypes.QualifiedFnIdentifier) - : ProgramTypes.FQFnName.FQFnName = - let modules = Stdlib.List.map i.modules (fun (m, _) -> m.name) - let nametoResolve = [ i.fn.name ] - - let resolvedName = - NameResolver.FnName.resolve - resolver - modules - (WrittenTypesToProgramTypes.Name.Unresolved nametoResolve) - - match resolvedName with - | Ok name -> name - // TODO: Handle errors properly - | Error e -> $"TODO: handle error {e}" + : ProgramTypes.NameResolution = + let nameToResolve = + Stdlib.List.append + (Stdlib.List.map i.modules (fun (m, _) -> m.name)) + [ i.fn.name ] + + NameResolver.FnName.resolve + onMissing + [] + (WrittenTypes.Name.Unresolved(i.range, nameToResolve)) module TypeReference = module Builtin = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (t: WrittenTypes.TypeReference.Builtin) : ProgramTypes.TypeReference = match t with @@ -79,21 +71,21 @@ module Darklang = | TChar _range -> ProgramTypes.TypeReference.TChar | TString _range -> ProgramTypes.TypeReference.TString | TList(_range, _, _, typ, _) -> - let typ = TypeReference.toPT resolver typ + let typ = TypeReference.toPT onMissing typ ProgramTypes.TypeReference.TList(typ) | TDict(_range, _, _, valueType, _) -> - let valueType = TypeReference.toPT resolver valueType + let valueType = TypeReference.toPT onMissing valueType ProgramTypes.TypeReference.TDict valueType | TTuple(_range, firstType, _, secondType, restTypes, _, _) -> - let firstType = TypeReference.toPT resolver firstType - let secondType = TypeReference.toPT resolver secondType + let firstType = TypeReference.toPT onMissing firstType + let secondType = TypeReference.toPT onMissing secondType let restTypes = Stdlib.List.map restTypes (fun (_, t) -> - TypeReference.toPT resolver t) + TypeReference.toPT onMissing t) ProgramTypes.TypeReference.TTuple(firstType, secondType, restTypes) @@ -102,31 +94,28 @@ module Darklang = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (t: WrittenTypes.TypeReference.TypeReference) : ProgramTypes.TypeReference = match t with - | Builtin b -> Builtin.toPT resolver b + | Builtin b -> Builtin.toPT onMissing b | QualifiedName qn -> - let typeName = Identifiers.QualifiedType.toPT resolver qn + let typeName = Identifiers.QualifiedType.toPT onMissing qn - ProgramTypes.TypeReference.TCustomType( - Stdlib.Result.Result.Ok typeName, - [] - ) + ProgramTypes.TypeReference.TCustomType(typeName, []) module TypeDeclaration = module RecordField = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (f: WrittenTypes.TypeDeclaration.RecordField) : ProgramTypes.TypeDeclaration.RecordField = let name = f.name |> Stdlib.Tuple2.second ProgramTypes.TypeDeclaration.RecordField { name = name - typ = TypeReference.toPT resolver f.typ + typ = TypeReference.toPT onMissing f.typ description = "" } module EnumField = @@ -163,19 +152,20 @@ module Darklang = module Definition = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (d: WrittenTypes.TypeDeclaration.Definition) : ProgramTypes.TypeDeclaration.Definition = match d with | Alias typ -> - let typ = TypeReference.toPT resolver typ - + let typ = TypeReference.toPT onMissing typ ProgramTypes.TypeDeclaration.Definition.Alias typ + | Enum _cases -> "TODO" + | Record fields -> let fields = - Stdlib.List.map fields (fun (f, _) -> RecordField.toPT resolver f) + Stdlib.List.map fields (fun (f, _) -> RecordField.toPT onMissing f) ProgramTypes.TypeDeclaration.Definition.Record fields @@ -184,28 +174,32 @@ module Darklang = ProgramTypes.TypeDeclaration.Definition.Enum cases let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (d: WrittenTypes.TypeDeclaration.TypeDeclaration) : ProgramTypes.TypeDeclaration.TypeDeclaration = - let def = Definition.toPT resolver d.definition + let def = Definition.toPT onMissing d.definition ProgramTypes.TypeDeclaration.TypeDeclaration { typeParams = []; definition = def } - let toUserTypePT - (resolver: NameResolver.NameResolutionSettings) + let toPackageTypePT + (onMissing: NameResolver.OnMissing) + (owner: String) + (modules: List) (d: WrittenTypes.TypeDeclaration.TypeDeclaration) - : ProgramTypes.UserType = - ProgramTypes.UserType + : ProgramTypes.PackageType = + ProgramTypes.PackageType { tlid = gtlid () + id = Stdlib.Uuid.generate () name = - ProgramTypes.FQTypeName.UserProgram - { modules = [] + ProgramTypes.FQTypeName.Package + { owner = owner + modules = modules name = d.name.name version = 0L } description = "" - declaration = toPT resolver d + declaration = toPT onMissing d deprecated = ProgramTypes.Deprecation.NotDeprecated } @@ -252,7 +246,7 @@ module Darklang = let toPT - (resolver: NameResolver.NameResolutionSettings) + (onMissing: NameResolver.OnMissing) (e: WrittenTypes.Expr) : ProgramTypes.Expr = match e with @@ -287,29 +281,29 @@ module Darklang = | EList(_, contents, _, _) -> ProgramTypes.Expr.EList( gid (), - Stdlib.List.map contents (fun (expr, _) -> toPT resolver expr) + Stdlib.List.map contents (fun (expr, _) -> toPT onMissing expr) ) | EDict(_, contents, _, _, _) -> ProgramTypes.Expr.EDict( gid (), - Stdlib.List.map contents (fun (_, k, v) -> (k, toPT resolver v)) + Stdlib.List.map contents (fun (_, k, v) -> (k, toPT onMissing v)) ) | ETuple(_, first, _, second, rest, _, _) -> - let first = toPT resolver first - let second = toPT resolver second - let rest = Stdlib.List.map rest (fun (_, e) -> toPT resolver e) + let first = toPT onMissing first + let second = toPT onMissing second + let rest = Stdlib.List.map rest (fun (_, e) -> toPT onMissing e) ProgramTypes.Expr.ETuple(gid (), first, second, rest) | ERecord(_, typeName, fields, _, _) -> - let typeName = NameResolver.TypeName.resolve resolver [] typeName + let typeName = NameResolver.TypeName.resolve onMissing [] typeName let fields = Stdlib.List.map fields (fun (_, name, typeName) -> let fieldName = name |> Stdlib.Tuple2.second - (fieldName, toPT resolver typeName)) + (fieldName, toPT onMissing typeName)) ProgramTypes.Expr.ERecord(gid (), typeName, fields) @@ -333,20 +327,20 @@ module Darklang = ProgramTypes.Expr.ELet( gid (), LetPattern.toPT pat, - toPT resolver rhs, - toPT resolver body + toPT onMissing rhs, + toPT onMissing body ) | EVariable(_, var) -> ProgramTypes.Expr.EVariable (gid ()) var | EIf(_, cond, thenExpr, elseExpr, _, _, _) -> let elseExpr = - elseExpr |> Stdlib.Option.map (fun es -> Expr.toPT resolver es) + elseExpr |> Stdlib.Option.map (fun es -> Expr.toPT onMissing es) ProgramTypes.Expr.EIf( gid (), - toPT resolver cond, - toPT resolver thenExpr, + toPT onMissing cond, + toPT onMissing thenExpr, elseExpr ) @@ -357,60 +351,64 @@ module Darklang = ProgramTypes.Expr.EInfix( gid (), infix, - toPT resolver left, - toPT resolver right + toPT onMissing left, + toPT onMissing right ) | EFnCall(_, fnName, args, _, _) -> - let fnName = Identifiers.QualifiedFn.toPT resolver fnName + let fnName = Identifiers.QualifiedFn.toPT onMissing fnName - let fnNameExpr = - ProgramTypes.Expr.EFnName(gid (), Stdlib.Result.Result.Ok fnName) + let fnNameExpr = ProgramTypes.Expr.EFnName(gid (), fnName) ProgramTypes.Expr.EApply( gid (), fnNameExpr, [], - Stdlib.List.map args (fun a -> toPT resolver a) + Stdlib.List.map args (fun a -> toPT onMissing a) ) module FunctionDeclaration = module Parameter = - let toUserFnParamPT - (resolver: NameResolver.NameResolutionSettings) + let toPackageFnParamPT + (onMissing: NameResolver.OnMissing) (p: WrittenTypes.FnDeclaration.Parameter) - : ProgramTypes.UserFunction.Parameter = + : ProgramTypes.PackageFn.Parameter = match p with | Unit p -> - ProgramTypes.UserFunction.Parameter + ProgramTypes.PackageFn.Parameter { name = "_" // TODO ok? typ = ProgramTypes.TypeReference.TUnit description = "" } | Normal p -> - ProgramTypes.UserFunction.Parameter + ProgramTypes.PackageFn.Parameter { name = p.name.name - typ = TypeReference.toPT resolver p.typ + typ = TypeReference.toPT onMissing p.typ description = "" } - let toUserFnPT - (resolver: NameResolver.NameResolutionSettings) + let toPackageFnPT + (onMissing: NameResolver.OnMissing) + (owner: String) + (modules: List) (fn: WrittenTypes.FnDeclaration.FnDeclaration) - : ProgramTypes.UserFunction.UserFunction = - ProgramTypes.UserFunction.UserFunction + : ProgramTypes.PackageFn.PackageFn = + ProgramTypes.PackageFn.PackageFn { tlid = gtlid () + id = Stdlib.Uuid.generate () name = - ProgramTypes.FQFnName.UserProgram - { modules = [] + ProgramTypes.FQFnName.Package + { owner = owner + modules = modules name = fn.name.name version = 0L } typeParams = [] parameters = fn.parameters - |> Stdlib.List.map (fun p -> Parameter.toUserFnParamPT resolver p) - returnType = TypeReference.toPT resolver fn.returnType + |> Stdlib.List.map (fun p -> + Parameter.toPackageFnParamPT onMissing p) + returnType = TypeReference.toPT onMissing fn.returnType description = "" deprecated = ProgramTypes.Deprecation.NotDeprecated - body = Expr.toPT resolver fn.body } \ No newline at end of file + body = Expr.toPT onMissing fn.body } \ No newline at end of file diff --git a/packages/darklang/prettyPrinter/programTypes.dark b/packages/darklang/prettyPrinter/programTypes.dark index da4ca7c923..ccd626fdd4 100644 --- a/packages/darklang/prettyPrinter/programTypes.dark +++ b/packages/darklang/prettyPrinter/programTypes.dark @@ -14,6 +14,29 @@ module Darklang = Stdlib.String.join nr.names "." + let packageName + (owner: String) + (modules: List) + (name: String) + (version: Int64) + : String = + let modulesPart = + match modules with + | [] -> "" + | modules -> + let modules = Stdlib.String.join modules "." + $"{modules}." + + let versionPart = + if version == 0L then + "" + else + $"_v{Stdlib.Int64.toString version}" + + match owner with + | "Tests" -> $"{modulesPart}{name}{versionPart}" + | _ -> $"PACKAGE.{owner}.{modulesPart}{name}{versionPart}" + module FQTypeName = module Package = @@ -35,55 +58,7 @@ module Darklang = let fullForReference (p: LanguageTools.ProgramTypes.FQTypeName.Package) : String = - let modulesPart = Stdlib.String.join p.modules "." - let namePart = p.name - - let versionPart = - if p.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString p.version}" - - $"PACKAGE.{p.owner}.{modulesPart}.{namePart}{versionPart}" - - - module UserProgram = - - let atDefinition - // TODO: take in just typ and version - modules should have already been dealt with - (u: LanguageTools.ProgramTypes.FQTypeName.UserProgram) - : String = - match u.modules with - | [] -> - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{namePart}{versionPart}" - | _ -> "(UserTypeName.atDefinition unexpected nonempty u.modules)" - - let fullForReference - (u: LanguageTools.ProgramTypes.FQTypeName.UserProgram) - : String = - let modulesPart = - match u.modules with - | [] -> "" - | modules -> - modules |> Stdlib.String.join "." |> (fun parts -> $"{parts}.") - - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{modulesPart}{namePart}{versionPart}" + packageName p.owner p.modules p.name p.version @@ -92,8 +67,6 @@ module Darklang = : String = match t with | Package p -> PrettyPrinter.ProgramTypes.FQTypeName.Package.atDefinition p - | UserProgram u -> - PrettyPrinter.ProgramTypes.FQTypeName.UserProgram.atDefinition u let fullForReference (t: LanguageTools.ProgramTypes.FQTypeName.FQTypeName) @@ -101,8 +74,6 @@ module Darklang = match t with | Package p -> PrettyPrinter.ProgramTypes.FQTypeName.Package.fullForReference p - | UserProgram u -> - PrettyPrinter.ProgramTypes.FQTypeName.UserProgram.fullForReference u module FQConstantName = @@ -138,55 +109,8 @@ module Darklang = let fullForReference (p: LanguageTools.ProgramTypes.FQConstantName.Package) : String = - let modulesPart = Stdlib.String.join p.modules "." + packageName p.owner p.modules p.name p.version - let namePart = p.name - - let versionPart = - if p.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString p.version}" - - $"PACKAGE.{p.owner}.{modulesPart}.{namePart}{versionPart}" - - - module UserProgram = - let atDefinition - // TODO: take in just typ and version - modules should have already been dealt with - (u: LanguageTools.ProgramTypes.FQConstantName.UserProgram) - : String = - match u.modules with - | [] -> - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{namePart}{versionPart}" - | _ -> "(UserTypeName.atDefinition unexpected nonempty u.modules)" - - let fullForReference - (u: LanguageTools.ProgramTypes.FQConstantName.UserProgram) - : String = - let modulesPart = - match u.modules with - | [] -> "" - | modules -> - modules |> Stdlib.String.join "." |> (fun parts -> $"{parts}.") - - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{modulesPart}{namePart}{versionPart}" let atDefinition @@ -197,8 +121,6 @@ module Darklang = PrettyPrinter.ProgramTypes.FQConstantName.Builtin.fullForReference b | Package p -> PrettyPrinter.ProgramTypes.FQConstantName.Package.atDefinition p - | UserProgram u -> - PrettyPrinter.ProgramTypes.FQConstantName.UserProgram.atDefinition u let fullForReference (t: LanguageTools.ProgramTypes.FQConstantName.FQConstantName) @@ -208,8 +130,6 @@ module Darklang = PrettyPrinter.ProgramTypes.FQConstantName.Builtin.fullForReference b | Package p -> PrettyPrinter.ProgramTypes.FQConstantName.Package.fullForReference p - | UserProgram u -> - PrettyPrinter.ProgramTypes.FQConstantName.UserProgram.fullForReference u module FQFnName = @@ -249,55 +169,7 @@ module Darklang = let fullForReference (p: LanguageTools.ProgramTypes.FQFnName.Package) : String = - let modulesPart = Stdlib.String.join p.modules "." - - let namePart = p.name - - let versionPart = - if p.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString p.version}" - - $"PACKAGE.{p.owner}.{modulesPart}.{namePart}{versionPart}" - - - module UserProgram = - - let atDefinition - // TODO: take in just typ and version - modules should have already been dealt with - (u: LanguageTools.ProgramTypes.FQFnName.UserProgram) - : String = - match u.modules with - | [] -> - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{u.name}{versionPart}" - | _ -> "(UserTypeName.atDefinition unexpected nonempty u.modules)" - - - let fullForReference - (u: LanguageTools.ProgramTypes.FQFnName.UserProgram) - : String = - let modulesPart = - match u.modules with - | [] -> "" - | modules -> - modules |> Stdlib.String.join "." |> (fun parts -> $"{parts}.") - - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{modulesPart}{namePart}{versionPart}" + packageName p.owner p.modules p.name p.version let atDefinition (t: LanguageTools.ProgramTypes.FQFnName.FQFnName) : String = @@ -305,8 +177,6 @@ module Darklang = | Builtin _b -> "why are you trying to print a stdlib type name _definition_?" | Package p -> PrettyPrinter.ProgramTypes.FQFnName.Package.atDefinition p - | UserProgram u -> - PrettyPrinter.ProgramTypes.FQFnName.UserProgram.atDefinition u let fullForReference (t: LanguageTools.ProgramTypes.FQFnName.FQFnName) @@ -316,8 +186,6 @@ module Darklang = PrettyPrinter.ProgramTypes.FQFnName.Builtin.fullForReference b | Package p -> PrettyPrinter.ProgramTypes.FQFnName.Package.fullForReference p - | UserProgram u -> - PrettyPrinter.ProgramTypes.FQFnName.UserProgram.fullForReference u let typeReference (t: LanguageTools.ProgramTypes.TypeReference) : String = @@ -911,10 +779,10 @@ module Darklang = $"{label}: {PrettyPrinter.ProgramTypes.typeReference d.typ}" let enumCase - (d: LanguageTools.ProgramTypes.TypeDeclaration.EnumCase) + (c: LanguageTools.ProgramTypes.TypeDeclaration.EnumCase) : String = - match d.fields with - | [] -> "| " ++ d.name + match c.fields with + | [] -> "| " ++ c.name | fields -> let fieldPart = fields @@ -922,7 +790,7 @@ module Darklang = PrettyPrinter.ProgramTypes.TypeDeclaration.enumField field) |> Stdlib.String.join " * " - $"| {d.name} of {fieldPart}" + $"| {c.name} of {fieldPart}" let customType @@ -985,67 +853,48 @@ module Darklang = $"type {db.name}{versionPart} = {typPart}" - let userType (userType: LanguageTools.ProgramTypes.UserType) : String = - let namePart = - PrettyPrinter.ProgramTypes.FQTypeName.UserProgram.atDefinition - userType.name - let typeParamPart = - match userType.declaration.typeParams with - | [] -> "" - | _ -> - userType.declaration.typeParams - |> Stdlib.List.map (fun typeParam -> $"'{typeParam}") - |> Stdlib.String.join ", " - |> fun parts -> $"<{parts}>" - let defPart = PrettyPrinter.ProgramTypes.customType userType.declaration + // module Toplevel = + // type T = + // | TLHandler of Handler.Handler + // | TLDB of DB - $"type {namePart}{typeParamPart} =\n{PrettyPrinter.indent defPart}" + // let secret (s: Stdlib.Secret.T) : String = + // let versionPart = if s.version == 0 then "" else $"_v{Stdlib.Int64.toString s.version}" - module UserFunction = - let parameter - (p: LanguageTools.ProgramTypes.UserFunction.Parameter) - : String = - // TODO: handle `description` - let typPart = PrettyPrinter.ProgramTypes.typeReference p.typ + // $"let {s.name}{versionPart} = \"*****\"" - $"({p.name}: {typPart})" - let userFunction - (u: LanguageTools.ProgramTypes.UserFunction.UserFunction) - : String = - // TODO: do something with description and deprecated - // TODO: shouldn't there be modules here somewhere? + let packageType (p: LanguageTools.ProgramTypes.PackageType) : String = + // TODO: take care of deprecated and description let namePart = - PrettyPrinter.ProgramTypes.FQFnName.UserProgram.atDefinition u.name - - let typeParamsPart = Stdlib.String.join u.typeParams " " + PrettyPrinter.ProgramTypes.FQTypeName.Package.atDefinition p.name - let paramsPart = - Stdlib.String.join - (Stdlib.List.map u.parameters (fun p -> - PrettyPrinter.ProgramTypes.UserFunction.parameter p)) - " " + let typeParamPart = + match p.declaration.typeParams with + | [] -> "" + | _ -> + p.declaration.typeParams + |> Stdlib.List.map (fun typeParam -> $"'{typeParam}") + |> Stdlib.String.join ", " + |> fun parts -> $"<{parts}>" - let retPart = PrettyPrinter.ProgramTypes.typeReference u.returnType + let defPart = + (PrettyPrinter.ProgramTypes.customType p.declaration) + |> PrettyPrinter.indent - let bodyPart = PrettyPrinter.ProgramTypes.expr u.body - $"let {namePart}{typeParamsPart} {paramsPart}: {retPart} =\n{PrettyPrinter.indent bodyPart}" + $"type {namePart}{typeParamPart} =\n{defPart}" - // module Toplevel = - // type T = - // | TLHandler of Handler.Handler - // | TLDB of DB - // | TLFunction of UserFunction.UserFunction - // | TLType of UserType.T + let packageConstant (p: LanguageTools.ProgramTypes.PackageConstant) : String = + let namePart = + PrettyPrinter.ProgramTypes.FQConstantName.Package.atDefinition p.name - // let secret (s: Stdlib.Secret.T) : String = - // let versionPart = if s.version == 0 then "" else $"_v{Stdlib.Int64.toString s.version}" + let bodyPart = PrettyPrinter.ProgramTypes.constant p.body - // $"let {s.name}{versionPart} = \"*****\"" + $"let {namePart} = {bodyPart}" module PackageFn = @@ -1055,7 +904,8 @@ module Darklang = let packageFn (p: LanguageTools.ProgramTypes.PackageFn.PackageFn) : String = // TODO: handle `deprecated`, `description` - let namePart = PrettyPrinter.ProgramTypes.FnName.Package.atDefinition p.name + let namePart = + PrettyPrinter.ProgramTypes.FQFnName.Package.atDefinition p.name let typeParamPart = match p.typeParams with @@ -1076,34 +926,4 @@ module Darklang = let bodyPart = PrettyPrinter.ProgramTypes.expr p.body - $"let {namePart}{typeParamPart} {paramPart} : {retPart} =\n{PrettyPrinter.indent bodyPart}" - - - let packageType (p: LanguageTools.ProgramTypes.PackageType) : String = - // TODO: take care of deprecated and description - let namePart = - PrettyPrinter.ProgramTypes.FQTypeName.Package.atDefinition p.name - - let typeParamPart = - match p.declaration.typeParams with - | [] -> "" - | _ -> - p.declaration.typeParams - |> Stdlib.List.map (fun typeParam -> $"'{typeParam}") - |> Stdlib.String.join ", " - |> fun parts -> $"<{parts}>" - - let defPart = - (PrettyPrinter.ProgramTypes.customType p.declaration) - |> PrettyPrinter.indent - - $"type {namePart}{typeParamPart} =\n{defPart}" - - - let packageConstant (p: LanguageTools.ProgramTypes.PackageConstant) : String = - let namePart = - PrettyPrinter.ProgramTypes.FQConstantName.Package.atDefinition p.name - - let bodyPart = PrettyPrinter.ProgramTypes.constant p.body - - $"let {namePart} = {bodyPart}" \ No newline at end of file + $"let {namePart}{typeParamPart} {paramPart}: {retPart} =\n{PrettyPrinter.indent bodyPart}" \ No newline at end of file diff --git a/packages/darklang/prettyPrinter/runtimeTypes.dark b/packages/darklang/prettyPrinter/runtimeTypes.dark index e1529df58b..d8927d5e7e 100644 --- a/packages/darklang/prettyPrinter/runtimeTypes.dark +++ b/packages/darklang/prettyPrinter/runtimeTypes.dark @@ -6,46 +6,40 @@ module Darklang = : String = Stdlib.String.join nr.names "." - module FQTypeName = - - let package (p: LanguageTools.RuntimeTypes.FQTypeName.Package) : String = - let modulesPart = Stdlib.String.join p.modules "." - - let namePart = p.name - - let versionPart = - if p.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString p.version}" - $"PACKAGE.{p.owner}.{modulesPart}.{namePart}{versionPart}" + let packageName + (owner: String) + (modules: List) + (name: String) + (version: Int64) + : String = + let modulesPart = + match modules with + | [] -> "" + | modules -> + let modules = Stdlib.String.join modules "." + $"{modules}." + let versionPart = + if version == 0L then + "" + else + $"_v{Stdlib.Int64.toString version}" - let userProgram - (u: LanguageTools.RuntimeTypes.FQTypeName.UserProgram) - : String = - let modulesPart = - match u.modules with - | [] -> "" - | modules -> - modules |> Stdlib.String.join "." |> (fun parts -> $"{parts}.") + match owner with + | "Tests" -> $"{modulesPart}{name}{versionPart}" + | _ -> $"PACKAGE.{owner}.{modulesPart}{name}{versionPart}" - let namePart = u.name - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" + module FQTypeName = - $"{modulesPart}{namePart}{versionPart}" + let package (p: LanguageTools.RuntimeTypes.FQTypeName.Package) : String = + packageName p.owner p.modules p.name p.version // TODO rename to fqtypeName? let typeName (t: LanguageTools.RuntimeTypes.FQTypeName.FQTypeName) : String = match t with | Package p -> FQTypeName.package p - | UserProgram u -> FQTypeName.userProgram u module FQConstantName = @@ -61,36 +55,7 @@ module Darklang = $"{namePart}{versionPart}" let package (p: LanguageTools.RuntimeTypes.FQConstantName.Package) : String = - let modulesPart = Stdlib.String.join p.modules "." - - let namePart = p.name - - let versionPart = - if p.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString p.version}" - - $"PACKAGE.{p.owner}.{modulesPart}.{namePart}{versionPart}" - - let userProgram - (u: LanguageTools.RuntimeTypes.FQConstantName.UserProgram) - : String = - let modulesPart = - match u.modules with - | [] -> "" - | modules -> - modules |> Stdlib.String.join "." |> (fun parts -> $"{parts}.") - - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" - - $"{modulesPart}{namePart}{versionPart}" + packageName p.owner p.modules p.name p.version // TODO rename to fqconstantName? let constantName @@ -99,7 +64,6 @@ module Darklang = match t with | Builtin b -> FQConstantName.builtIn b | Package p -> FQConstantName.package p - | UserProgram u -> FQConstantName.userProgram u module FQFnName = @@ -115,43 +79,14 @@ module Darklang = $"{namePart}{versionPart}" let package (p: LanguageTools.RuntimeTypes.FQFnName.Package) : String = - let modulesPart = Stdlib.String.join p.modules "." - - let namePart = p.name - - let versionPart = - if p.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString p.version}" - - $"PACKAGE.{p.owner}.{modulesPart}.{namePart}{versionPart}" - - let userProgram - (u: LanguageTools.RuntimeTypes.FQFnName.UserProgram) - : String = - let modulesPart = - match u.modules with - | [] -> "" - | modules -> - modules |> Stdlib.String.join "." |> (fun parts -> $"{parts}.") - - let namePart = u.name - - let versionPart = - if u.version == 0L then - "" - else - $"_v{Stdlib.Int64.toString u.version}" + packageName p.owner p.modules p.name p.version - $"{modulesPart}{namePart}{versionPart}" // TODO rename to fqfnName? let fnName (t: LanguageTools.RuntimeTypes.FQFnName.FQFnName) : String = match t with | Builtin b -> FQFnName.builtIn b | Package p -> FQFnName.package p - | UserProgram u -> FQFnName.userProgram u let typeReference (t: LanguageTools.RuntimeTypes.TypeReference) : String = match t with diff --git a/packages/darklang/stdlib/canvas.dark b/packages/darklang/stdlib/canvas.dark index a3b4073e4c..834888a331 100644 --- a/packages/darklang/stdlib/canvas.dark +++ b/packages/darklang/stdlib/canvas.dark @@ -1,7 +1,5 @@ module Darklang = module Canvas = type Program = - { types: List - dbs: List - fns: List + { dbs: List handlers: List } \ No newline at end of file diff --git a/packages/darklang/stdlib/list.dark b/packages/darklang/stdlib/list.dark index df14bc9a72..01f1c5e9ac 100644 --- a/packages/darklang/stdlib/list.dark +++ b/packages/darklang/stdlib/list.dark @@ -479,4 +479,10 @@ module Darklang = Stdlib.Result.Result.Error Stdlib.List.ChunkBySizeError.SizeMustBeGreaterThanZero else - Stdlib.Result.Result.Ok(Stdlib.List.chunkBySizeHelper size list []) \ No newline at end of file + Stdlib.Result.Result.Ok(Stdlib.List.chunkBySizeHelper size list []) + + + let splitLast (l: List<'a>) : Stdlib.Option.Option * 'a> = + match reverse l with + | [] -> Stdlib.Option.Option.None + | head :: tail -> Stdlib.Option.Option.Some((reverse tail, head)) \ No newline at end of file diff --git a/scripts/build/compile b/scripts/build/compile index 523ff8bcb1..f1a048ae97 100755 --- a/scripts/build/compile +++ b/scripts/build/compile @@ -12,6 +12,9 @@ run_tests = False in_ci = os.getenv("CI") == "true" optimize = in_ci +fsharp_thing_to_build = "fsdark.sln" +# sometimes it's handy to only build a specific project +# fsharp_thing_to_build = "src/LocalExec" # Make io unbuffered def flush(fn): @@ -187,7 +190,7 @@ def backend_quick_build(): --no-restore \ --verbosity {verbosity} \ --configuration {configuration} \ - fsdark.sln" + {fsharp_thing_to_build}" result = run_backend(start, build) @@ -209,7 +212,7 @@ def backend_full_build(): /clp:ForceConsoleColor \ --verbosity {verbosity} \ --configuration {configuration} \ - fsdark.sln" + {fsharp_thing_to_build}" result = run_backend(start, build)