[code-reflection] RFR: 8324789: Add line number information to code models [v2]
Paul Sandoz
psandoz at openjdk.org
Tue Apr 23 23:15:06 UTC 2024
> Enable operations to have originating source location information, specifically source reference, line and column information.
>
> The location information may be set (one or more times) on an operation while it is unbound. Once it is bound, when it is a member of a block and that block is bound, it can no longer be set. Copying an operation will also copy the location. This enables preservation when transforming, especially for lowering.
>
> The compiler generates location information from a tree node, and sets it on the associated operation(s). For the operations associated with a reflected method (FuncOp) or quoted lambda expression (LambdaOp or ClosureOp) the source reference (a URI) is added to the location, whereas for all other operations the source reference is absent.
>
> Example:
>
>
> @CodeReflection // 47
> static int f(int n) { // 48
> int sum = 0; // 49
> for (int i = 0; i < n; i++) { // 50
> sum += i; // 51
> } // 52
> return sum; // 53
> } // 54
>
>
> Model:
>
>
> func @"f" @loc="47:5:file:///Users/sandoz/Projects/jdk/test/babylon-test/src/test/java/T.java" (%0 : int)int -> {
> %1 : Var<int> = var %0 @"n" @loc="47:5";
> %2 : int = constant @"0" @loc="49:19";
> %3 : Var<int> = var %2 @"sum" @loc="49:9";
> java.for @loc="50:9"
> ()Var<int> -> {
> %4 : int = constant @"0" @loc="50:22";
> %5 : Var<int> = var %4 @"i" @loc="50:14";
> yield %5 @loc="50:9";
> }
> (%6 : Var<int>)boolean -> {
> %7 : int = var.load %6 @loc="50:25";
> %8 : int = var.load %1 @loc="50:29";
> %9 : boolean = lt %7 %8 @loc="50:25";
> yield %9 @loc="50:9";
> }
> (%10 : Var<int>)void -> {
> %11 : int = var.load %10 @loc="50:32";
> %12 : int = constant @"1" @loc="50:32";
> %13 : int = add %11 %12 @loc="50:32";
> var.store %10 %13 @loc="50:32";
> yield @loc="50:9";
> }
> (%14 : Var<int>)void -> {
> %15 : int = var.load %3 @loc="51:13";
> %16 : int = var.load %14 @loc="51:20";
> %17 : int = add %15 %16 @loc="51:13";
> var.store %3 %17 @loc="51:13";
> java.continue @loc="50:9";
> };
> %18 : int = var.load %3 @loc="53:16";
> return %18 @loc=...
Paul Sandoz has updated the pull request incrementally with one additional commit since the last revision:
Cleanup
-------------
Changes:
- all: https://git.openjdk.org/babylon/pull/54/files
- new: https://git.openjdk.org/babylon/pull/54/files/f4ce2cef..5784587c
Webrevs:
- full: https://webrevs.openjdk.org/?repo=babylon&pr=54&range=01
- incr: https://webrevs.openjdk.org/?repo=babylon&pr=54&range=00-01
Stats: 3 lines in 2 files changed: 0 ins; 2 del; 1 mod
Patch: https://git.openjdk.org/babylon/pull/54.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/54/head:pull/54
PR: https://git.openjdk.org/babylon/pull/54
More information about the babylon-dev
mailing list