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
16 changes: 15 additions & 1 deletion tslang/lib/TypeScript/MLIRGenCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2199,11 +2199,25 @@ namespace mlirgen
mlir::OpBuilder::InsertionGuard guard(builder);

// compiler glue with no source to step through, as INSTANCEOF_NONE_NAME's
auto noLocation = mlir::UnknownLoc::get(builder.getContext());
mlir::Location noLocation = mlir::UnknownLoc::get(builder.getContext());
auto funcOp = mlir_ts::FuncOp::create(noLocation, thunkName, thunkType);
funcOp.setPrivate();
funcOp->setAttr("internal_linkage", builder.getUnitAttr());

// ...but with --di a function of its own to the debugger, as the catch copy thunk is
// (mlirGenCatchCopyThunk): its call into the callee needs a location, or LLVM rejects the
// module ("inlinable function call in a function with a DISubprogram location must have a
// debug location"). A subprogram for the thunk at the place that first needs it, the body
// scoped under it.
DITableScopeT debugFuncScope(debugScope);
if (compileOptions.generateDebugInfo)
{
MLIRDebugInfoHelper mdi(builder, debugScope);
auto plainLocation = stripMetadata(location);
funcOp->setLoc(mdi.getSubprogram(plainLocation, thunkName, thunkName, plainLocation));
noLocation = locFuseWithScope(plainLocation);
}

auto &entryBlock = *funcOp.addEntryBlock();
builder.setInsertionPointToStart(&entryBlock);

Expand Down
8 changes: 8 additions & 0 deletions tslang/lib/TypeScript/MLIRGenImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7927,6 +7927,14 @@ class MLIRGenImpl
{
return mlir::failure();
}

// a copy in each module that checks, its own: the default library has one as well, and two
// public ones were a duplicate symbol where nothing optimized one away (a debug build's link)
if (auto funcOp = theModule.lookupSymbol<mlir_ts::FuncOp>(funcName))
{
funcOp.setPrivate();
funcOp->setAttr("internal_linkage", builder.getUnitAttr());
}
}

auto funcResult = resolveIdentifier(location, funcName, genContext);
Expand Down
8 changes: 8 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2913,6 +2913,14 @@ add_test(NAME test-compile-debug-info-opt
-DTESTS_DIR=${PROJECT_SOURCE_DIR}/test/tester/tests
-P ${CMAKE_CURRENT_SOURCE_DIR}/debug-info-opt.cmake)

# Debug info without optimisation, for the functions the compiler makes itself - see
# debug-info-glue.cmake.
add_test(NAME test-compile-debug-info-glue
COMMAND ${CMAKE_COMMAND}
-DTSLANG=$<TARGET_FILE:tslang>
-DTESTS_DIR=${PROJECT_SOURCE_DIR}/test/tester/tests
-P ${CMAKE_CURRENT_SOURCE_DIR}/debug-info-glue.cmake)

# A throw under the JIT without TypeScriptRuntime (which test-runner always passes), under every
# model but gc - see jit-throw-without-runtime.cmake. Windows only: the symbol is MSVC's type_info vtable.
if (WIN32)
Expand Down
56 changes: 56 additions & 0 deletions tslang/test/tester/debug-info-glue.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Emits LLVM IR WITH debug info and no optimisation, as a debug build compiles (`--di --opt_level=0`),
# under every memory model, for programs that make functions of the compiler's own: glue with no source
# of its own, which still has to come out with a debug location on everything that calls.
#
# `test-runner` in a release build compiles with `--opt` and no `--di`, so it never sees these; the
# release workflow's debug default library does. A function taking fewer parameters than its function
# type is called through a thunk (fewerParametersThunk), made with no location: with `--di` it got a
# subprogram while its call had none, and LLVM rejected the module - "inlinable function call in a
# function with a DISubprogram location must have a debug location". Array callbacks take the
# element's index too, so `a.every((v) => ...)` made one in every debug program that used them.
#
# A compile, not a run, for the same reason as debug-info-rc.cmake: the failure was a module that
# would not come out.

if(NOT DEFINED TSLANG OR NOT DEFINED TESTS_DIR)
message(FATAL_ERROR "TSLANG and TESTS_DIR are both required")
endif()

set(files
# a named function and an arrow given as a function type with more parameters
00function_fewer_parameters.ts
# an arrow that captures, bound over its captures to the thunk
00closure_fewer_parameters.ts)

set(failures "")
set(count 0)
foreach(model gc rc none own)
foreach(name ${files})
execute_process(
COMMAND "${TSLANG}" --emit=llvm --di --opt_level=0 -mm=${model} --no-default-lib
"${TESTS_DIR}/${name}" -o=${name}.${model}.ll
OUTPUT_QUIET
ERROR_VARIABLE diagnostics
RESULT_VARIABLE status)

if(NOT status EQUAL 0)
# the first error, not a warning printed ahead of it
if(diagnostics MATCHES "[^\n]*error:[^\n]*")
set(first_line "${CMAKE_MATCH_0}")
else()
string(REGEX REPLACE "\n.*" "" first_line "${diagnostics}")
endif()
list(APPEND failures " ${name} -mm=${model}: exit ${status}: ${first_line}")
endif()

file(REMOVE "${name}.${model}.ll")
math(EXPR count "${count} + 1")
endforeach()
endforeach()

if(failures)
string(REPLACE ";" "\n" report "${failures}")
message(FATAL_ERROR "debug info without optimisation failed:\n${report}")
endif()

message(STATUS "debug info without optimisation: ${count} compile(s) emitted")
Loading