HaxeFoundation / HaxeFoundation/haxe
[jvm] Request for implementation of JSR-45 Source Maps to allow for debugging with IDEs and JDB
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
The JVM supports source maps to allow for other languages to leverage the [Java Platform Debugger Architecture (JPDA)](https://docs.oracle.com/javase/8/docs/technotes/guides/jpda/index.html). JPDA is how IDEs such as Eclipse and IntelliJ, along with the CLI tool JDB debug JVM languages . JSR-45 details the SourceDebugExtension and specifies the structure of non-java source maps. Kotlin use JSR-45 for debugging and Scala is working on implementing JSR-45 as well: https://github.com/scala/scala/pull/9121
Scala contributors have a good discussion about the changes needed for implementing JSR-45 for languages that compile directly to JVM Bytecode. This can be found on their forums [here](https://contributors.scala-lang.org/t/improving-the-scala-debugging-experience/4264
)
Some addition Kotlin implementation information:
[SMAP.kt](https://github.com/JetBrains/kotlin/blob/29b23e79f32791e456a5b4a453277f0f0b3e984d/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SMAP.kt) is used in [ClassCodegen.kt](https://github.com/JetBrains/kotlin/blob/8bfcef415e7d63ed5f9a40b5b3f4eb125a2c4bdb/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ClassCodegen.kt ) and [FunctionCodegen.kt](https://github.com/JetBrains/kotlin/blob/8999fd88b1ad6b2424a36c002365e90110c564ff/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/FunctionCodegen.kt)
Test data that Kotlin uses for their source maps can be found [here](https://github.com/JetBrains/kotlin/tree/0ebb39a26eaf5f4aff9003e551e2fffd3c93c6ef/compiler/testData/codegen/boxInline/smap)
The JSR-45 spec can be downloaded here:
https://download.oracle.com/otndocs/jcp/dsol-1.0-fr-spec-oth-JSpec/
Below is a simple example copied from the spec that uses Java as an intermediary step:
# Example
The example below shows how the process described above would apply to a tiny JSP program.
## Input Source
The input consists of two JSP files, the first is Hello.jsp:
```jsp
Hello Example
<%@ include file="greeting.jsp" %>
```
The second JSP file is the included file greeting.jsp:
```jsp
Hello There!
Goodbye on <%= new Date() %>
```
## Language Processor
When a JSP compiler (the language-processor) compiles these files it will produce two outputs - a Java programming language source file and a SMAP-file. The generated Java programming language source file is HelloServlet.java:
```java
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Hello.jsp:1
out.println("");
// Hello.jsp:2
out.println("");
// Hello.jsp:3
out.println("Hello Example");
// Hello.jsp:4
out.println("");
// Hello.jsp:5
out.println("");
// greeting.jsp:1
out.println("Hello There!
");
// greeting.jsp:2
out.println("Goodbye on " + new Date());
// Hello.jsp:7
out.println("");
// Hello.jsp:8
out.println("");
}
}
```
The generated SMAP-file is HelloServlet.java.smap:
```
SMAP
HelloServlet.java
JSP
*S JSP
*F
1 Hello.jsp
2 greeting.jsp
*L
1#1,5:10,2
1#2,2:20,2
7#1,2:24,2
*E
```
A couple things are interesting to note about this SMAP -- the user has chosen to make JSP the default stratum (perhaps by a command line option) and even though there are ten lines of input source and 29 lines of generated source, only three LineInfo lines describe the transformation: the first and last are for the lines before and after the include (respectively) and the middle is for the included file greeting.jsp.
The three LineInfo lines describe these mappings:
```
1#1,5:10,2
Hello.jsp: line 1 -> HelloServlet.java: lines 10, 11
line 2 -> lines 12, 13
line 3 -> lines 14, 15
line 4 -> lines 16, 17
line 5 -> lines 18, 19
1#2,2:20,2
greeting.jsp: line 1 -> HelloServlet.java: lines 20, 21
line 2 -> lines 22, 23
7#1,2:24,2
Hello.jsp: line 7 -> HelloServlet.java: lines 24, 25
line 8 -> lines 26, 27
```
Contributor guide
Research direction
Start with the JSR-45 specification and the linked Kotlin SMAP.kt, ClassCodegen.kt, and FunctionCodegen.kt implementations, then review Kotlin's compiler/testData/codegen/boxInline/smap examples. Identify the Haxe JVM compiler entry point for class generation, which the issue does not name. Done means JVM output carries JSR-45 source-map metadata that IDEs and JDB can use for debugging.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100