[code-reflection] Integrated: 8324789: Add line number information to code models
Paul Sandoz
psandoz at openjdk.org
Thu Apr 25 20:26:54 UTC 2024
On Wed, 17 Apr 2024 20:24:49 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
> 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=...
This pull request has now been integrated.
Changeset: 9f35792f
Author: Paul Sandoz <psandoz at openjdk.org>
URL: https://git.openjdk.org/babylon/commit/9f35792fc834a9c89d3f7a13547e3f0a75178c01
Stats: 496 lines in 14 files changed: 454 ins; 9 del; 33 mod
8324789: Add line number information to code models
Reviewed-by: mcimadamore
-------------
PR: https://git.openjdk.org/babylon/pull/54
More information about the babylon-dev
mailing list