Skip to content

Commit c337b93

Browse files
added test for path.app
1 parent b576aa8 commit c337b93

3 files changed

Lines changed: 62 additions & 13 deletions

File tree

tsc/lib/TypeScript/MLIRGen.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4249,12 +4249,14 @@ class MLIRGenImpl
42494249
// cast from optional<T> type
42504250
if (auto leftOptType = leftExpressionValue.getType().dyn_cast_or_null<mlir_ts::OptionalType>())
42514251
{
4252-
leftExpressionValue = cast(loc(leftExpression), leftOptType.getElementType(), leftExpressionValue, genContext);
4252+
leftExpressionValue =
4253+
builder.create<mlir_ts::ValueOp>(loc(leftExpression), leftOptType.getElementType(), leftExpressionValue);
42534254
}
42544255

42554256
if (auto rightOptType = rightExpressionValue.getType().dyn_cast_or_null<mlir_ts::OptionalType>())
42564257
{
4257-
rightExpressionValue = cast(loc(rightExpression), rightOptType.getElementType(), rightExpressionValue, genContext);
4258+
rightExpressionValue =
4259+
builder.create<mlir_ts::ValueOp>(loc(rightExpression), rightOptType.getElementType(), rightExpressionValue);
42584260
}
42594261
}
42604262
}
@@ -4265,8 +4267,10 @@ class MLIRGenImpl
42654267
{
42664268
if (auto rightOptType = rightExpressionValue.getType().dyn_cast_or_null<mlir_ts::OptionalType>())
42674269
{
4268-
leftExpressionValue = cast(loc(leftExpression), leftOptType.getElementType(), leftExpressionValue, genContext);
4269-
rightExpressionValue = cast(loc(rightExpression), rightOptType.getElementType(), rightExpressionValue, genContext);
4270+
leftExpressionValue =
4271+
builder.create<mlir_ts::ValueOp>(loc(leftExpression), leftOptType.getElementType(), leftExpressionValue);
4272+
rightExpressionValue =
4273+
builder.create<mlir_ts::ValueOp>(loc(rightExpression), rightOptType.getElementType(), rightExpressionValue);
42704274
}
42714275
}
42724276
}
@@ -5029,7 +5033,7 @@ class MLIRGenImpl
50295033

50305034
// value if true
50315035

5032-
auto innerFuncRef = cast(location, optFuncRef.getElementType(), funcRefValue, genContext);
5036+
auto innerFuncRef = builder.create<mlir_ts::ValueOp>(location, optFuncRef.getElementType(), funcRefValue);
50335037

50345038
auto hasReturn = false;
50355039
auto value =
@@ -8681,14 +8685,6 @@ class MLIRGenImpl
86818685
return value;
86828686
}
86838687

8684-
if (auto optType = value.getType().dyn_cast<mlir_ts::OptionalType>())
8685-
{
8686-
if (optType.getElementType() == type)
8687-
{
8688-
llvm_unreachable("for getting value from optional - use ValueOpLowering");
8689-
}
8690-
}
8691-
86928688
// class to string
86938689
if (auto stringType = type.dyn_cast_or_null<mlir_ts::StringType>())
86948690
{

tsc/test/tester/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ add_test(NAME test-compile-51-exceptions COMMAND test-runner -llc "${PROJECT_SOU
201201
add_test(NAME test-compile-Grammar_and_types COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/Grammar_and_types.ts")
202202
add_test(NAME test-compile-StackTest COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00stack_test.ts")
203203
add_test(NAME test-compile-Raytrace COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/raytrace.ts")
204+
add_test(NAME test-compile-Path COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/path.ts")
204205
add_test(NAME test-compile-Print-Bug-01 COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/01print-bug.ts")
205206

206207
add_test(NAME test-jit-00-print COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00print.ts")
@@ -338,4 +339,5 @@ endif()
338339
add_test(NAME test-jit-Grammar_and_types COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/Grammar_and_types.ts")
339340
add_test(NAME test-jit-StackTest COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00stack_test.ts")
340341
add_test(NAME test-jit-Raytrace COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/raytrace.ts")
342+
add_test(NAME test-jit-Path COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/path.ts")
341343
add_test(NAME test-jit-Print-Bug-01 COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/01print-bug.ts")

tsc/test/tester/tests/path.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export type Maybe<T> = null | undefined | T;
2+
3+
export interface Path {
4+
readonly prev: Path | undefined;
5+
readonly key: string | number;
6+
readonly typename: string | undefined;
7+
}
8+
9+
/**
10+
* Given a Path and a key, return a new Path containing the new key.
11+
*/
12+
export function addPath(
13+
prev: Readonly<Path> | undefined,
14+
key: string | number,
15+
typename: string | undefined,
16+
): Path {
17+
return { prev, key, typename };
18+
}
19+
20+
/**
21+
* Given a Path, return an Array of the path keys.
22+
*/
23+
export function pathToArray(
24+
path: Maybe<Readonly<Path>>,
25+
): Array<string | number> {
26+
let curr = path;
27+
let flattened = <typeof curr.key[]>[];
28+
while (curr) {
29+
flattened.push(curr.key);
30+
curr = curr.prev;
31+
}
32+
//flattened.reverse();
33+
return flattened;
34+
}
35+
36+
function main() {
37+
let pathArray = pathToArray({
38+
key: "path",
39+
prev: undefined,
40+
typename: undefined,
41+
});
42+
for (let x of pathArray) {
43+
if (typeof x == "string") {
44+
assert(x == "path");
45+
}
46+
47+
print(x);
48+
}
49+
50+
print("done.");
51+
}

0 commit comments

Comments
 (0)