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
1 change: 1 addition & 0 deletions docs/whats-new.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# What's new

- Stepping through a program built with `--di` stops once at each statement: the line table had a row for each expression and a column for each, and now has one row for a statement, so a debugger no longer goes back and forth over a statement written on several lines or back to a variable's declaration to release it at the end of its scope. A function is left at its closing brace (not at its first line), a constructor steps through its fields' initializers before its own statements, a callback written in a call keeps its own lines, and the compiler's own functions (a class's `.new` and `.instanceOf`, a cast's thunk, the reference counting routines) have no source line, so a debugger steps over them. Under CodeView the line table has no columns, as clang leaves them out: the Microsoft debuggers handle start columns without end columns badly. A default library built before this keeps its columns until it is rebuilt. The default library's generics made in the program (`Array.sort`, `join`) are shown in the library's file, not at lines of the program's past its end, and the code the compiler makes from TypeScript of its own (`Math.max`, printing an array, casting from `any`) is at no line of the program's; the functions a debugger steps over have no first line to stop at either
- A function of the program named as a function of the default library is the program's own: `function sleep(ms: number): string` beside the library's generic `sleep` compiles and is called (it took the library's type, "can't find return variable"), a program's `__is_any` or a generic function of that name is called instead of the library's, and one named as a function the library declares keeps the signature it is written with. The library's own code, its generics made in the program included (a `Map`'s hashing, `toSpliced`), still calls the library's
- **JSX** runs as it is: with no factory named, an element is a call of the default library's `h`, which makes a `JsxElement` (its tag, attributes and children) that prints and turns into a string as HTML (`print(<p class="x">a &lt; b</p>)` prints `<p class="x">a &lt; b</p>`). A tag that is a function is a component, called with the attributes and the children; `<>...</>` is a `Fragment`. tsc's default, `React.createElement`, is used only when named. When a statement fails with an error of its own, the "failed statement" error that followed it is no longer printed, and the error of a JSX factory that can't be found is shorter. Needs the default library of the same release
- A mixed array literal is typed as tsc types it: an array of the union of its elements' types, `[1, "a"]` a `(s32 | string)[]` and `[3, { a: 4 }]` a `(s32 | { a: s32 })[]` (they were tuples), so it can grow and takes either member. It stays a tuple where the context asks for one: destructured (`const [n, s] = [1, "a"]`, `[x, y] = [y, x]`), given to a tuple parameter or a generic one inferred as a tuple, or pushed into an array of tuples. Code that indexes such a literal as a tuple (`[1, [2, 2]][1][1]`, which tsc refuses too) needs a tuple type (`const t: [number, number[]] = ...`). A union of primitives and object shapes (`number | { a: number }`) can be cast and printed: each member is told apart by its tag, and `print([3, { a: 4 }])` prints `[ 3, { a: 4 } ]`
Expand Down
7 changes: 7 additions & 0 deletions tslang/include/TypeScript/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
// routine of the base (OwnershipRoutineLogic) compares an object's vtable with each subclass's and
// releases the fields of the class it is, not only the base's (rc and own).
#define CLASS_BASES_ATTR_NAME "ts.class_bases"
// On the module, under --di: the statements of each file, as {file: [line, column, end line, end column, barrier]...}
// - where a debugger stops (DebugStepLocationsPass, which removes it). A barrier is a function's body.
#define DEBUG_STATEMENTS_ATTR_NAME "ts.debug_statements"
// The file the locations of code made from the compiler's own TypeScript (a helper's source, a library's
// printed declarations - parsePartialStatements) are in: their positions are in that text, not in any file.
// No line of it is a debugger's (DebugStepLocationsPass).
#define HELPER_SOURCE_FILE_NAME "<tslang>"
// The classes the module knows (its own and those it imports or declares) whose objects can't say which class they
// are: a @cpp class (a C++ vtable), a @value or a static one (no RTTI). A union of classes is stored as the object's
// pointer alone, the class asked of the object (`.instanceOf`), unless one of these is among them (user ruling
Expand Down
24 changes: 18 additions & 6 deletions tslang/include/TypeScript/MLIRLogic/MLIRDebugInfoHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ class MLIRDebugInfoHelper
|| isa<mlir::LLVM::DIModuleAttr>(scope));
}

mlir::Location getSubprogram(mlir::Location functionLocation, StringRef functionName, StringRef linkageName, mlir::Location functionBlockLocation) {
// glue: compiler glue with no source to step through (a thunk). LocalToUnit - it is internal - marks it for
// DebugStepLocationsPass, which leaves it no line, so a debugger steps over it (the LLVM dialect has no
// DIFlagArtificial for a subprogram).
mlir::Location getSubprogram(mlir::Location functionLocation, StringRef functionName, StringRef linkageName, mlir::Location functionBlockLocation, bool glue = false) {

if (auto compileUnitAttr = dyn_cast_or_null<mlir::LLVM::DICompileUnitAttr>(debugScope.lookup(CU_DEBUG_SCOPE)))
{
Expand Down Expand Up @@ -184,6 +187,11 @@ class MLIRDebugInfoHelper
subprogramFlags = subprogramFlags | mlir::LLVM::DISubprogramFlags::Optimized;
}

if (glue)
{
subprogramFlags = subprogramFlags | mlir::LLVM::DISubprogramFlags::LocalToUnit;
}

// add return types
auto type = mlir::LLVM::DISubroutineTypeAttr::get(builder.getContext(), llvm::dwarf::DW_CC_normal, {/*Add Types here*/});

Expand Down Expand Up @@ -214,13 +222,17 @@ class MLIRDebugInfoHelper
{
if (auto scopeAttr = dyn_cast_or_null<mlir::LLVM::DIScopeAttr>(debugScope.lookup(DEBUG_SCOPE)))
{
auto [scopeLine, scopeColumn] = LocationHelper::getLineAndColumn(blockLocation);
// the block's own file, as a function's: a default library's generic made in the program is in the
// library's file, and a debugger showed the lines in its blocks as the program's
LocationHelper lh(builder.getContext());
auto [blockFile, scopeLineAndColumn] = lh.getLineAndColumnAndFile(blockLocation);
auto [scopeLine, scopeColumn] = scopeLineAndColumn;

auto lexicalBlockAttr =
auto lexicalBlockAttr =
mlir::LLVM::DILexicalBlockAttr::get(
builder.getContext(),
scopeAttr,
fileAttr,
builder.getContext(),
scopeAttr,
blockFile ? blockFile : fileAttr,
scopeLine,
scopeColumn);

Expand Down
3 changes: 3 additions & 0 deletions tslang/include/TypeScript/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ std::unique_ptr<mlir::Pass> createProcessHeapPass();
/// location of its own takes the call's, and one outside any function (a string literal's global)
/// the location it was written at. Schedule before it, under --di --opt.
std::unique_ptr<mlir::Pass> createInlinedLocationPass();
/// Under --di, ahead of DIScopeForLLVMFuncOpPass: a debugger stops once at each statement, not at every
/// expression, and steps over compiler glue (DEBUG_STATEMENTS_ATTR_NAME holds the statements).
std::unique_ptr<mlir::Pass> createDebugStepLocationsPass(const CompileOptions &, bool optimized);
/// MemAlloc Pass to replace ts_malloc, ts_realloc, ts_free
std::unique_ptr<mlir::Pass> createMemAllocPass(CompileOptions&);

Expand Down
1 change: 1 addition & 0 deletions tslang/lib/TypeScript/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ add_mlir_dialect_library(MLIRTypeScript
GCPass.cpp
ProcessHeapPass.cpp
InlinedLocationPass.cpp
DebugStepLocationsPass.cpp
AsyncTargetWidthPass.cpp
ObjDumper.cpp
LibraryDeclarations.cpp
Expand Down
Loading
Loading