diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index f6fbe707..04e09578 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -162,6 +162,19 @@ jobs: .\build.bat release shell: pwsh + - name: Test Default Library + continue-on-error: false + working-directory: ${{github.workspace}}/TypeScriptCompilerDefaultLib + env: + TOOL_PATH: ${{github.workspace}}/__build/tslang/msbuild/x64/release/bin + GC_LIB_PATH: ${{github.workspace}}/__build/gc/msbuild/x64/release/${{ env.BUILD_TYPE }} + LLVM_LIB_PATH: ${{github.workspace}}/3rdParty/llvm/x64/release/lib + TSLANG_LIB_PATH: ${{github.workspace}}/__build/tslang/msbuild/x64/release/lib + run: | + .\tests.ps1 + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + shell: pwsh + - name: Create Zip of Windows Asset working-directory: ${{github.workspace}}/__build run: Get-ChildItem -Path .\tslang\msbuild\x64\release\bin\tslang.exe, .\tslang\msbuild\x64\release\bin\TypeScriptRuntime.dll, .\gc\msbuild\x64\release\${{ env.BUILD_TYPE }}\gc.lib, .\tslang\msbuild\x64\release\lib\TypeScriptAsyncRuntime.lib, ..\3rdParty\llvm\x64\release\lib\LLVMSupport.lib, ..\3rdParty\llvm\x64\release\bin\wasm-ld.exe, ..\TypeScriptCompilerDefaultLib\__build\release\* | Compress-Archive -DestinationPath ..\tslang.zip @@ -332,6 +345,17 @@ jobs: TSLANG_LIB_PATH: ${{github.workspace}}/__build/tslang/ninja/release/lib run: chmod +x ./build.sh ./scripts/*.sh; ./build.sh release + - name: Test Default Library + continue-on-error: false + working-directory: ${{github.workspace}}/TypeScriptCompilerDefaultLib + shell: sh + env: + TOOL_PATH: ${{github.workspace}}/__build/tslang/ninja/release/bin + GC_LIB_PATH: ${{github.workspace}}/__build/gc/ninja/release + LLVM_LIB_PATH: ${{github.workspace}}/3rdParty/llvm/release/lib + TSLANG_LIB_PATH: ${{github.workspace}}/__build/tslang/ninja/release/lib + run: chmod +x ./tests.sh; ./tests.sh + - name: Create Tar.GZ of Linux Asset working-directory: ${{github.workspace}}/__build shell: sh diff --git a/tag.bat b/tag.bat index 888d4a70..85f68390 100644 --- a/tag.bat +++ b/tag.bat @@ -1,2 +1,2 @@ -git tag -a v0.0-pre-alpha77 -m "pre alpha v0.0-77" +git tag -a v0.0-pre-alpha78 -m "pre alpha v0.0-78" git push origin --tags diff --git a/tag_del.bat b/tag_del.bat index c377cf5d..190fcbad 100644 --- a/tag_del.bat +++ b/tag_del.bat @@ -1,2 +1,2 @@ -git push --delete origin v0.0-pre-alpha77 -git tag -d v0.0-pre-alpha77 +git push --delete origin v0.0-pre-alpha78 +git tag -d v0.0-pre-alpha78 diff --git a/tslang.code-workspace b/tslang.code-workspace index b7fc55a0..808a715a 100644 --- a/tslang.code-workspace +++ b/tslang.code-workspace @@ -182,6 +182,7 @@ "npm.autoDetect": "off", "[html]": { "editor.defaultFormatter": "vscode.html-language-features" - } + }, + "powershell.cwd": "TypeScript Compiler Source (Lib)" } } \ No newline at end of file diff --git a/tslang/include/TypeScript/TypeScriptOps.td b/tslang/include/TypeScript/TypeScriptOps.td index 241dea6b..34cd85b6 100644 --- a/tslang/include/TypeScript/TypeScriptOps.td +++ b/tslang/include/TypeScript/TypeScriptOps.td @@ -17,6 +17,11 @@ include "mlir/Interfaces/SideEffectInterfaces.td" include "mlir/Interfaces/CastInterfaces.td" include "mlir/Interfaces/LoopLikeInterface.td" +// info: +// Commutative - it actually represents. MLIR's Commutative trait tells canonicalizers/CSE "operand order doesn't matter, +// feel free to reorder to canonicalize/match commuted forms" — that's true for +, *, &, |, ^, but definitely false +// for -, /, %, **, and the shifts. + //===----------------------------------------------------------------------===// // TypeScript op definitions //===----------------------------------------------------------------------===// @@ -474,7 +479,7 @@ def TypeScript_IsNaNOp : TypeScript_Op<"isNaN"> { let results = (outs TypeScript_Boolean:$res); } -def TypeScript_TypeOfOp : TypeScript_Op<"TypeOf"> { +def TypeScript_TypeOfOp : TypeScript_Op<"TypeOf", [Pure]> { let summary = "name of type"; let description = [{ name of type @@ -484,7 +489,7 @@ def TypeScript_TypeOfOp : TypeScript_Op<"TypeOf"> { let results = (outs TypeScript_String:$typeOf); } -def TypeScript_TypeOfAnyOp : TypeScript_Op<"TypeOfAny"> { +def TypeScript_TypeOfAnyOp : TypeScript_Op<"TypeOfAny", [Pure]> { let summary = "name of type from any"; let description = [{ name of type from any @@ -494,7 +499,7 @@ def TypeScript_TypeOfAnyOp : TypeScript_Op<"TypeOfAny"> { let results = (outs TypeScript_String:$typeOf); } -def TypeScript_SizeOfOp : TypeScript_Op<"SizeOf"> { +def TypeScript_SizeOfOp : TypeScript_Op<"SizeOf", [Pure]> { let summary = "size of type"; let description = [{ size of type @@ -1003,7 +1008,10 @@ def TypeScript_ParamDefaultValueOp : TypeScript_Op<"DefaultValue", [Pure, Return let builders = [OpBuilder<(ins), [{ /* nothing to do */ }]>]; } -def TypeScript_OptionalOp : TypeScript_Op<"Optional", +// Not Pure: lowering (ValueOptionalOpLowering/OptionalOpLowering) routes through +// CastLogicHelper::cast(), the generic dispatcher that can call ch.MemoryAlloc via +// castToAny/castToArrayType depending on the boxed type - see TypeScript_CreateUnionInstanceOp. +def TypeScript_OptionalOp : TypeScript_Op<"Optional", [TypesMatchWith<"type of 'value' matches element type of 'optional'", "res", "in", "cast($_self).getElementType()">]> { @@ -1072,7 +1080,10 @@ def TypeScript_DefaultOp : TypeScript_Op<"Default"> { let results = (outs AnyType:$res); } -def TypeScript_OptionalValueOp : TypeScript_Op<"OptionalValue", +// Not Pure: lowering (ValueOptionalOpLowering) routes through CastLogicHelper::cast(), the +// generic dispatcher that can call ch.MemoryAlloc via castToAny/castToArrayType depending on +// the boxed type - see TypeScript_CreateUnionInstanceOp. +def TypeScript_OptionalValueOp : TypeScript_Op<"OptionalValue", [TypesMatchWith<"type of 'value' matches element type of 'optional'", "res", "in", "cast($_self).getElementType()">]> { @@ -1084,7 +1095,7 @@ def TypeScript_OptionalValueOp : TypeScript_Op<"OptionalValue", let results = (outs TypeScript_AnyOptional:$res); } -def TypeScript_OptionalUndefOp : TypeScript_Op<"OptionalUndef"> { +def TypeScript_OptionalUndefOp : TypeScript_Op<"OptionalUndef", [Pure]> { let description = [{ Example: ts.optional_undef : ts.optional @@ -1093,7 +1104,7 @@ def TypeScript_OptionalUndefOp : TypeScript_Op<"OptionalUndef"> { let results = (outs TypeScript_AnyOptional:$res); } -def TypeScript_HasValueOp : TypeScript_Op<"HasValue"> { +def TypeScript_HasValueOp : TypeScript_Op<"HasValue", [Pure]> { let description = [{ Example: ts.has_value %v : ts.optional to bool @@ -1102,8 +1113,8 @@ def TypeScript_HasValueOp : TypeScript_Op<"HasValue"> { let results = (outs TypeScript_Boolean:$res); } -def TypeScript_ValueOp : TypeScript_Op<"Value", - [TypesMatchWith<"type of 'value' matches element type of 'optional'", +def TypeScript_ValueOp : TypeScript_Op<"Value", + [Pure, TypesMatchWith<"type of 'value' matches element type of 'optional'", "in", "res", "cast($_self).getElementType()">]> { let description = [{ @@ -1113,11 +1124,11 @@ def TypeScript_ValueOp : TypeScript_Op<"Value", let arguments = (ins TypeScript_AnyOptional:$in); let results = (outs AnyType:$res); - let hasCanonicalizer = 1; + let hasCanonicalizer = 1; } -def TypeScript_ValueOrDefaultOp : TypeScript_Op<"ValueOrDefault", - [TypesMatchWith<"type of 'value' matches element type of 'optional'", +def TypeScript_ValueOrDefaultOp : TypeScript_Op<"ValueOrDefault", + [Pure, TypesMatchWith<"type of 'value' matches element type of 'optional'", "in", "res", "cast($_self).getElementType()">]> { let description = [{ @@ -1369,7 +1380,7 @@ def TypeScript_CreateBoundFunctionOp : TypeScript_Op<"CreateBoundFunction"> { } -def TypeScript_GetThisOp : TypeScript_Op<"GetThis"> { +def TypeScript_GetThisOp : TypeScript_Op<"GetThis", [Pure]> { let description = [{ ```mlir %2 = ts.get_this %1 : !ts.ref @@ -1384,9 +1395,12 @@ def TypeScript_GetThisOp : TypeScript_Op<"GetThis"> { TypeScript_AnyRefLike:$result ); - + } +// Not Pure: lowering (GetMethodOpLowering) calls CastLogicHelper::cast(), the generic +// dispatcher that can call ch.MemoryAlloc via castToAny/castToArrayType depending on the +// operand's runtime type - see TypeScript_CreateUnionInstanceOp. def TypeScript_GetMethodOp : TypeScript_Op<"GetMethod"> { let description = [{ ```mlir @@ -1405,13 +1419,10 @@ def TypeScript_GetMethodOp : TypeScript_Op<"GetMethod"> { } -def TypeScript_ArithmeticUnaryOp : TypeScript_Op<"ArithmeticUnary"> { - let description = [{ - ```mlir - %2 = ts.arithmetic_unary 1, %1 : f32 - ``` - }]; - +// Shared shape for the opCode+operand1->AnyType family of unary operators. Purity differs +// per op (prefix/postfix carry increment/decrement side effects), so traits stay per-def. +class TypeScript_UnaryOpBase traits = []> : + TypeScript_Op { let arguments = (ins I32Attr:$opCode, AnyType:$operand1 @@ -1420,86 +1431,66 @@ def TypeScript_ArithmeticUnaryOp : TypeScript_Op<"ArithmeticUnary"> { let results = (outs AnyType:$result ); +} - +def TypeScript_ArithmeticUnaryOp : TypeScript_UnaryOpBase<"ArithmeticUnary", [Pure]> { + let description = [{ + ```mlir + %2 = ts.arithmetic_unary 1, %1 : f32 + ``` + }]; } -def TypeScript_PrefixUnaryOp : TypeScript_Op<"PrefixUnary"> { +def TypeScript_PrefixUnaryOp : TypeScript_UnaryOpBase<"PrefixUnary"> { let description = [{ ```mlir %2 = ts.prefix_unary 1, %1 : f32 ``` }]; - - let arguments = (ins - I32Attr:$opCode, - AnyType:$operand1 - ); - - let results = (outs - AnyType:$result - ); - - } -def TypeScript_PostfixUnaryOp : TypeScript_Op<"PostfixUnary"> { +def TypeScript_PostfixUnaryOp : TypeScript_UnaryOpBase<"PostfixUnary"> { let description = [{ ```mlir %2 = ts.postfix_unary 1, %1 : f32 ``` }]; +} +// Shared opCode+operand1+operand2 arguments for the binary operator family. Result types +// differ (AnyType vs TypeScript_Boolean), so only the argument list is factored. +class TypeScript_BinaryOpArgsBase traits = []> : + TypeScript_Op { let arguments = (ins I32Attr:$opCode, - AnyType:$operand1 - ); - - let results = (outs - AnyType:$result + AnyType:$operand1, + AnyType:$operand2 ); - - } -def TypeScript_ArithmeticBinaryOp : TypeScript_Op<"ArithmeticBinary"> { +def TypeScript_ArithmeticBinaryOp : TypeScript_BinaryOpArgsBase<"ArithmeticBinary", [Pure]> { let description = [{ ```mlir %2 = ts.arithmetic_binary 1, %0, %1 : f32 ``` }]; - let arguments = (ins - I32Attr:$opCode, - AnyType:$operand1, - AnyType:$operand2 - ); - let results = (outs AnyType:$result ); - - } -def TypeScript_LogicalBinaryOp : TypeScript_Op<"LogicalBinary"> { +def TypeScript_LogicalBinaryOp : TypeScript_BinaryOpArgsBase<"LogicalBinary"> { let description = [{ ```mlir %2 = ts.logical_binary 1, %0, %1 : ts.boolean ``` }]; - let arguments = (ins - I32Attr:$opCode, - AnyType:$operand1, - AnyType:$operand2 - ); - let results = (outs TypeScript_Boolean:$result ); - let hasCanonicalizer = 1; } @@ -1747,14 +1738,19 @@ def TypeScript_IfOp : TypeScript_Op<"If", let hasCanonicalizer = 1; } -def TypeScript_ResultOp : TypeScript_Op<"Result", [Pure, ReturnLike, Terminator, - ParentOneOf<["IfOp", "DoWhileOp", "WhileOp", "ForOp", "TryOp", "OptionalValueOrDefaultOp"]>]> { - let summary = "loop yield and termination operation"; - +// Shared shape for region-yield terminators: a Variadic operand list plus the +// argument-less builder used when a region has no yielded values. +class TypeScript_YieldOpBase parents> : + TypeScript_Op]> { let arguments = (ins Variadic:$results); let builders = [OpBuilder<(ins), [{ /* nothing to do */ }]>]; } +def TypeScript_ResultOp : TypeScript_YieldOpBase<"Result", + ["IfOp", "DoWhileOp", "WhileOp", "ForOp", "TryOp", "OptionalValueOrDefaultOp"]> { + let summary = "loop yield and termination operation"; +} + def TypeScript_WhileOp : TypeScript_Op<"While", [ LoopLikeOpInterface, @@ -2139,12 +2135,8 @@ def TypeScript_GlobalOp : TypeScript_Op<"Global", }]; } -def TypeScript_GlobalResultOp : TypeScript_Op<"GlobalResult", [Pure, ReturnLike, Terminator, - ParentOneOf<["GlobalOp"]>]> { +def TypeScript_GlobalResultOp : TypeScript_YieldOpBase<"GlobalResult", ["GlobalOp"]> { let summary = "global init yield and termination operation"; - - let arguments = (ins Variadic:$results); - let builders = [OpBuilder<(ins), [{ /* nothing to do */ }]>]; } def TypeScript_GlobalConstructorOp : TypeScript_Op<"GlobalConstructor"> { @@ -2193,12 +2185,8 @@ def TypeScript_BodyInternalOp : TypeScript_Op<"BodyInternal", }]; } -def TypeScript_BodyResultInternalOp : TypeScript_Op<"BodyResultInternal", [Pure, ReturnLike, Terminator, - ParentOneOf<["typescript::BodyInternalOp"]>]> { +def TypeScript_BodyResultInternalOp : TypeScript_YieldOpBase<"BodyResultInternal", ["typescript::BodyInternalOp"]> { let summary = "termination operation"; - - let arguments = (ins Variadic:$results); - let builders = [OpBuilder<(ins), [{ /* nothing to do */ }]>]; } def TypeScript_ArrayPushOp : TypeScript_Op<"ArrayPush", [ @@ -2283,44 +2271,33 @@ def TypeScript_CharToStringOp : TypeScript_Op<"CharToString"> { let results = (outs TypeScript_String:$result); } -def TypeScript_LoadSaveOp : TypeScript_Op<"LoadSave", [AllTypesMatch<["dst", "src"]>]> { - let arguments = (ins Arg:$dst, Arg:$src); - let results = (outs ); - +// Shared getSource()/getTarget() accessors for ops with a MemWrite $dst and MemRead $src. +class TypeScript_MemCopyLikeOpBase traits = []> : + TypeScript_Op], traits)> { let extraClassDeclaration = [{ Value getSource() { return getSrc(); } Value getTarget() { return getDst(); } }]; } -def TypeScript_CopyStructOp : TypeScript_Op<"CopyStruct", [AllTypesMatch<["dst", "src"]>]> { +def TypeScript_LoadSaveOp : TypeScript_MemCopyLikeOpBase<"LoadSave"> { let arguments = (ins Arg:$dst, Arg:$src); let results = (outs ); +} - let extraClassDeclaration = [{ - Value getSource() { return getSrc(); } - Value getTarget() { return getDst(); } - }]; +def TypeScript_CopyStructOp : TypeScript_MemCopyLikeOpBase<"CopyStruct"> { + let arguments = (ins Arg:$dst, Arg:$src); + let results = (outs ); } -def TypeScript_MemoryCopyOp : TypeScript_Op<"MemoryCopy", [AllTypesMatch<["dst", "src"]>]> { +def TypeScript_MemoryCopyOp : TypeScript_MemCopyLikeOpBase<"MemoryCopy"> { let arguments = (ins Arg:$dst, Arg:$src, Index:$count); let results = (outs ); - - let extraClassDeclaration = [{ - Value getSource() { return getSrc(); } - Value getTarget() { return getDst(); } - }]; } -def TypeScript_MemoryMoveOp : TypeScript_Op<"MemoryMove", [AllTypesMatch<["dst", "src"]>]> { +def TypeScript_MemoryMoveOp : TypeScript_MemCopyLikeOpBase<"MemoryMove"> { let arguments = (ins Arg:$dst, Arg:$src, Index:$count); let results = (outs ); - - let extraClassDeclaration = [{ - Value getSource() { return getSrc(); } - Value getTarget() { return getDst(); } - }]; } def TypeScript_DebuggerOp : TypeScript_Op<"Debugger"> { diff --git a/tslang/tslang/tslang.cpp b/tslang/tslang/tslang.cpp index b453e577..a6937285 100644 --- a/tslang/tslang/tslang.cpp +++ b/tslang/tslang/tslang.cpp @@ -321,7 +321,6 @@ int main(int argc, char **argv) // If we aren't dumping the AST, then we are compiling with/to MLIR. mlir::DialectRegistry registry; - //mlir::func::registerAllExtensions(registry); registerAllExtensions(registry); mlir::MLIRContext mlirContext(registry);