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
2 changes: 2 additions & 0 deletions docs/MLIRGen-refactoring-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Benefits: parallel builds (this single TU dominates incremental build time), sma

Mechanically safest path: keep `MLIRGenImpl` as-is, move method *bodies* out with no signature changes, verify with the existing test suite after each batch.

*Status: in progress.* First slice landed: the class moved out of MLIRGen.cpp's anonymous namespace into `typescript::mlirgen` in a private header `lib/TypeScript/MLIRGenImpl.h` (bodies still inline; each subsequent slice replaces a family's inline bodies with declarations and moves the definitions to a new TU). `MLIRGenCast.cpp` is the first satellite: the contiguous cast family (`selectFieldsValues` … `createBoundMethodFromExtensionMethod`, 29 methods) defined out-of-line. Enabling fixes: `GenContext`/`PassResult`/`ValueOrLogicalResult` in `MLIRGenContext.h` were in an anonymous namespace **in a header** (each TU got distinct types — worked only because there was one TU); they now live in `namespace typescript`. `ts::print(Node)` in `dump.h` was a non-inline header definition — now `inline`. The TU-static `compileOptionsPtr` stays in MLIRGen.cpp behind a new `setCompileOptions()` so inline code never references a TU-local. Remaining units to peel off per the table above; header hygiene (§8) comes after the last one.

## 2. Kill the dangling-`FuncOp` hazard in the symbol maps

`functionMap` (per-namespace `llvm::StringMap<mlir_ts::FuncOp>`) and `GenericFunctionInfo::funcOp` cache **raw op handles**. Discovery passes create ops and then erase them (`clearTempModule`, and until recently `theModule.getBody()->clear()`), so any cached handle from a discarded pass dangles. Today the code survives because consumers only read the *type* early — but this is exactly what made the nested-import bug subtle.
Expand Down
6 changes: 4 additions & 2 deletions tslang/include/TypeScript/MLIRLogic/MLIRGenContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ using llvm::SmallVector;
using llvm::StringRef;
using llvm::Twine;

namespace
// These types are shared across the MLIRGen translation units (see MLIRGenImpl.h),
// so they need external linkage — an anonymous namespace would give each TU its own type.
namespace typescript
{

struct PassResult
Expand Down Expand Up @@ -213,6 +215,6 @@ struct ValueOrLogicalResult
}
};

} // namespace
} // namespace typescript

#endif // MLIR_TYPESCRIPT_MLIRGENCONTEXT_H_
3 changes: 2 additions & 1 deletion tslang/lib/TypeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ add_mlir_dialect_library(MLIRTypeScript
AsyncDialectTranslation.cpp
DiagnosticHelper.cpp
MLIRGen.cpp
LowerToAffineLoops.cpp
MLIRGenCast.cpp
LowerToAffineLoops.cpp
LowerToLLVM.cpp
RelocateConstantPass.cpp
GCPass.cpp
Expand Down
Loading
Loading