Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
ASDAlexander77 committed Oct 22, 2024
1 parent 35e0fb5 commit cafd73c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
59 changes: 57 additions & 2 deletions tsc/include/TypeScript/MLIRLogic/MLIRTypeHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,67 @@ class MLIRTypeHelper
startParamRes + ShouldThisParamBeIgnored(resFuncType, inFuncType) ? 1 : 0);
}

bool isBoolType(mlir::Type type) {
if (type.isa<mlir_ts::BooleanType>() || type.isa<mlir_ts::TypePredicateType>()) return true;
return type.isa<mlir::IntegerType>() && type.getIntOrFloatBitWidth() == 1;
}

bool isAnyOrUnknownOrObjectType(mlir::Type type) {
return type.isa<mlir_ts::AnyType>() || type.isa<mlir_ts::UnknownType>() || type.isa<mlir_ts::ObjectType>();
}

// TODO: add types such as opt, reference, array as they may have nested types Is which is not equal
// TODO: add travel logic and match only simple types
bool canMatch(mlir::Location location, mlir::Type left, mlir::Type right) {
if (left == right) return true;
llvm::StringMap<std::pair<ts::TypeParameterDOM::TypePtr,mlir::Type>> typeParamsWithArgs{};
return extendsType(location, left, right, typeParamsWithArgs) == ExtendsResult::True;

left = stripLiteralType(left);
right = stripLiteralType(right);

if (left == right) return true;

if (isBoolType(left) && isBoolType(right)) return true;

if (isAnyOrUnknownOrObjectType(left) && isAnyOrUnknownOrObjectType(right)) return true;

// opts
auto leftOpt = left.dyn_cast<mlir_ts::OptionalType>();
auto rightOpt = right.dyn_cast<mlir_ts::OptionalType>();
if (leftOpt && rightOpt)
{
return canMatch(location, leftOpt.getElementType(), rightOpt.getElementType());
}

// array
auto leftArray = left.dyn_cast<mlir_ts::ArrayType>();
auto rightArray = right.dyn_cast<mlir_ts::ArrayType>();
if (leftArray && rightArray)
{
return canMatch(location, leftArray.getElementType(), rightArray.getElementType());
}

// funcs
if (isAnyFunctionType(left) && isAnyFunctionType(right)) {
return TestFunctionTypesMatchWithObjectMethods(location, left, right).result == MatchResultType::Match;
}

auto leftClass = left.dyn_cast<mlir_ts::ClassType>();
auto rightClass = right.dyn_cast<mlir_ts::ClassType>();
if (leftClass && rightClass)
{
llvm::StringMap<std::pair<ts::TypeParameterDOM::TypePtr,mlir::Type>> typeParamsWithArgs;
return extendsType(location, rightClass, leftClass, typeParamsWithArgs) == ExtendsResult::True;
}

auto leftInteface = left.dyn_cast<mlir_ts::InterfaceType>();
auto rightInteface = right.dyn_cast<mlir_ts::InterfaceType>();
if (leftInteface && rightInteface)
{
llvm::StringMap<std::pair<ts::TypeParameterDOM::TypePtr,mlir::Type>> typeParamsWithArgs;
return extendsType(location, leftInteface, rightInteface, typeParamsWithArgs) == ExtendsResult::True;
}

return false;
}

MatchResult TestFunctionTypesMatchWithObjectMethods(mlir::Location location, mlir_ts::FunctionType inFuncType, mlir_ts::FunctionType resFuncType,
Expand Down
20 changes: 10 additions & 10 deletions tsc/lib/TypeScript/MLIRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18704,19 +18704,19 @@ genContext);

if (mlir::failed(mth.canCastTupleToInterface(location, tupleType.cast<mlir_ts::TupleType>(), interfaceInfo)))
{
SmallVector<mlir_ts::FieldInfo> fields;
if (mlir::failed(interfaceInfo->getTupleTypeFields(fields, builder.getContext())))
{
return mlir::Value();
}
// SmallVector<mlir_ts::FieldInfo> fields;
// if (mlir::failed(interfaceInfo->getTupleTypeFields(fields, builder.getContext())))
// {
// return mlir::Value();
// }

auto newInterfaceTupleType = getTupleType(fields);
CAST(inEffective, location, newInterfaceTupleType, inEffective, genContext);
tupleType = newInterfaceTupleType;
// auto newInterfaceTupleType = getTupleType(fields);
// CAST(inEffective, location, newInterfaceTupleType, inEffective, genContext);
// tupleType = newInterfaceTupleType;

// TODO: you can create new Tuple with set of data, as tuple can be object with 'this' and internal values which needed to run commands
// by stipping important members of Tuple you break integrity of the code(program)
//llvm_unreachable("can't be casted");
llvm_unreachable("can't be casted");
//return mlir::Value();
}

Expand Down Expand Up @@ -18746,7 +18746,7 @@ genContext);

LLVM_DEBUG(llvm::dbgs() << "\n!!"
<< "@ created interface:" << createdInterfaceVTableForObject << "\n";);

return V(builder.create<mlir_ts::NewInterfaceOp>(location,
mlir::TypeRange{interfaceInfo->interfaceType}, in, createdInterfaceVTableForObject));
}
Expand Down

0 comments on commit cafd73c

Please sign in to comment.