Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions tslang/include/TypeScript/MLIRLogic/MLIRGenContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,45 +149,45 @@ struct GenContext
return stopProcess || rootContext && rootContext->stopProcess;
}

bool allowPartialResolve;
bool dummyRun;
bool allowConstEval;
bool allocateVarsInContextThis;
bool allocateVarsOutsideOfOperation;
bool allocateUsingVarsOutsideOfOperation;
bool forceDiscover;
bool discoverParamsOnly;
bool insertIntoParentScope;
mlir::Operation *currentOperation;
bool allowPartialResolve = false;
bool dummyRun = false;
bool allowConstEval = false;
bool allocateVarsInContextThis = false;
bool allocateVarsOutsideOfOperation = false;
bool allocateUsingVarsOutsideOfOperation = false;
bool forceDiscover = false;
bool discoverParamsOnly = false;
bool insertIntoParentScope = false;
mlir::Operation *currentOperation = nullptr;
mlir_ts::FuncOp funcOp;
FunctionPrototypeDOM::TypePtr funcProto;
llvm::StringMap<ts::VariableDeclarationDOM::TypePtr> *capturedVars;
llvm::SmallVector<ts::VariableDeclarationDOM::TypePtr> *usingVars;
llvm::StringMap<ts::VariableDeclarationDOM::TypePtr> *capturedVars = nullptr;
llvm::SmallVector<ts::VariableDeclarationDOM::TypePtr> *usingVars = nullptr;
mlir::Type thisType;
mlir_ts::ClassType thisClassType;
mlir::Type receiverFuncType;
mlir::Type receiverType;
mlir::StringRef receiverName;
bool isGlobalVarReceiver;
PassResult *passResult;
mlir::SmallVector<mlir::Block *> *cleanUps;
mlir::SmallVector<mlir::Operation *> *cleanUpOps;
bool isGlobalVarReceiver = false;
PassResult *passResult = nullptr;
mlir::SmallVector<mlir::Block *> *cleanUps = nullptr;
mlir::SmallVector<mlir::Operation *> *cleanUpOps = nullptr;
NodeArray<Statement> generatedStatements;
llvm::StringMap<mlir::Type> typeAliasMap;
llvm::StringMap<std::pair<TypeParameterDOM::TypePtr, mlir::Type>> typeParamsWithArgs;
ArrayRef<mlir::Value> callOperands;
int *state;
bool disableSpreadParams;
const GenContext* parentBlockContext;
const GenContext* rootContext;
bool isLoop;
int *state = nullptr;
bool disableSpreadParams = false;
const GenContext* parentBlockContext = nullptr;
const GenContext* rootContext = nullptr;
bool isLoop = false;
std::string loopLabel;
bool stopProcess;
mlir::SmallVector<std::unique_ptr<mlir::Diagnostic>> *postponedMessages;
bool specialization;
bool stopProcess = false;
mlir::SmallVector<std::unique_ptr<mlir::Diagnostic>> *postponedMessages = nullptr;
bool specialization = false;
// TODO: special hack to detect initializing specialized class and see that generic methods are not initialized at the same time
bool instantiateSpecializedFunction;
llvm::StringMap<std::pair<TypeParameterDOM::TypePtr, mlir::Type>> *inferTypes;
bool instantiateSpecializedFunction = false;
llvm::StringMap<std::pair<TypeParameterDOM::TypePtr, mlir::Type>> *inferTypes = nullptr;
};

struct ValueOrLogicalResult
Expand Down
79 changes: 31 additions & 48 deletions tslang/lib/TypeScript/MLIRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@ class MLIRGenImpl
const_cast<llvm::SourceMgr &>(sourceMgr).setIncludeDirs(includeDirs);
}

// RAII scope switching the current source file and file name (used for locations and debug info).
class SourceFileScope
{
public:
SourceFileScope(MLIRGenImpl &mlirGenImpl, ts::SourceFile newSourceFile, llvm::StringRef newFileName)
: sourceFileGuard(mlirGenImpl.sourceFile, newSourceFile),
fileNameGuard(mlirGenImpl.mainSourceFileName, newFileName)
{
}

// interns the file name from the source file's wide file name
SourceFileScope(MLIRGenImpl &mlirGenImpl, ts::SourceFile newSourceFile)
: SourceFileScope(mlirGenImpl, newSourceFile,
llvm::StringRef(convertWideToUTF8(newSourceFile->fileName)).copy(mlirGenImpl.stringAllocator))
{
}

private:
MLIRValueGuard<ts::SourceFile> sourceFileGuard;
MLIRValueGuard<llvm::StringRef> fileNameGuard;
};

mlir::LogicalResult report(SourceFile module, const std::vector<SourceFile> &includeFiles)
{
// output diag info
Expand Down Expand Up @@ -748,12 +770,7 @@ class MLIRGenImpl

for (auto includeFile : includeFiles)
{
MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
auto fileNameUtf8 = convertWideToUTF8(includeFile->fileName);
mainSourceFileName = StringRef(fileNameUtf8).copy(stringAllocator);

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = includeFile;
SourceFileScope sourceFileScope(*this, includeFile);

if (failed(mlirGen(includeFile->statements, genContextPartial)))
{
Expand Down Expand Up @@ -830,12 +847,7 @@ class MLIRGenImpl

for (auto includeFile : includeFiles)
{
MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
auto fileNameUtf8 = convertWideToUTF8(includeFile->fileName);
mainSourceFileName = StringRef(fileNameUtf8).copy(stringAllocator);;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = includeFile;
SourceFileScope sourceFileScope(*this, includeFile);

if (failed(mlirGen(includeFile->statements, genContext)))
{
Expand Down Expand Up @@ -983,12 +995,7 @@ class MLIRGenImpl
}

// we need to override filename to track it in DBG info
MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
auto fileNameUtf8 = convertWideToUTF8(importSource->fileName);
mainSourceFileName = StringRef(fileNameUtf8).copy(stringAllocator);

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = importSource;
SourceFileScope sourceFileScope(*this, importSource);

if (mlir::succeeded(mlirDiscoverAllDependencies(importSource, importIncludeFiles)) &&
mlir::succeeded(mlirCodeGenModule(importSource, importIncludeFiles, false, false)))
Expand Down Expand Up @@ -2219,11 +2226,7 @@ class MLIRGenImpl
MLIRNamespaceGuard nsGuard(currentNamespace);
currentNamespace = functionGenericTypeInfo->elementNamespace;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = functionGenericTypeInfo->sourceFile;

MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
mainSourceFileName = functionGenericTypeInfo->fileName;
SourceFileScope sourceFileScope(*this, functionGenericTypeInfo->sourceFile, functionGenericTypeInfo->fileName);

return instantiateSpecializedFunctionTypeHelper(location, functionGenericTypeInfo->functionDeclaration,
recieverType, discoverReturnType, genContext);
Expand Down Expand Up @@ -2315,11 +2318,7 @@ class MLIRGenImpl
MLIRNamespaceGuard nsGuard(currentNamespace);
currentNamespace = functionGenericTypeInfo->elementNamespace;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = functionGenericTypeInfo->sourceFile;

MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
mainSourceFileName = functionGenericTypeInfo->fileName;
SourceFileScope sourceFileScope(*this, functionGenericTypeInfo->sourceFile, functionGenericTypeInfo->fileName);

auto [result, specFuncOp, specFuncName, isGeneric] =
mlirGenFunctionLikeDeclaration(functionGenericTypeInfo->functionDeclaration, funcGenContext);
Expand Down Expand Up @@ -2669,11 +2668,7 @@ class MLIRGenImpl
MLIRNamespaceGuard ng(currentNamespace);
currentNamespace = functionGenericTypeInfo->elementNamespace;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = functionGenericTypeInfo->sourceFile;

MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
mainSourceFileName = functionGenericTypeInfo->fileName;
SourceFileScope sourceFileScope(*this, functionGenericTypeInfo->sourceFile, functionGenericTypeInfo->fileName);

auto anyNamedGenericType = IsGeneric::False;

Expand Down Expand Up @@ -2900,11 +2895,7 @@ class MLIRGenImpl
MLIRNamespaceGuard ng(currentNamespace);
currentNamespace = genericClassInfo->elementNamespace;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = genericClassInfo->sourceFile;

MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
mainSourceFileName = genericClassInfo->fileName;
SourceFileScope sourceFileScope(*this, genericClassInfo->sourceFile, genericClassInfo->fileName);

GenContext genericTypeGenContext(genContext);
genericTypeGenContext.instantiateSpecializedFunction = false;
Expand Down Expand Up @@ -2970,11 +2961,7 @@ class MLIRGenImpl
MLIRNamespaceGuard ng(currentNamespace);
currentNamespace = genericClassInfo->elementNamespace;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = genericClassInfo->sourceFile;

MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
mainSourceFileName = genericClassInfo->fileName;
SourceFileScope sourceFileScope(*this, genericClassInfo->sourceFile, genericClassInfo->fileName);

GenContext genericTypeGenContext(genContext);
genericTypeGenContext.instantiateSpecializedFunction = false;
Expand Down Expand Up @@ -3044,11 +3031,7 @@ class MLIRGenImpl
MLIRNamespaceGuard ng(currentNamespace);
currentNamespace = genericInterfaceInfo->elementNamespace;

MLIRValueGuard<ts::SourceFile> vgSourceFile(sourceFile);
sourceFile = genericInterfaceInfo->sourceFile;

MLIRValueGuard<llvm::StringRef> vgFileName(mainSourceFileName);
mainSourceFileName = genericInterfaceInfo->fileName;
SourceFileScope sourceFileScope(*this, genericInterfaceInfo->sourceFile, genericInterfaceInfo->fileName);

GenContext genericTypeGenContext(genContext);
auto typeParams = genericInterfaceInfo->typeParams;
Expand Down
Loading