[Mlir-commits] [mlir] [mlir] Add FileRange location type. (PR #80213)
Bryan Tan
llvmlistbot at llvm.org
Thu Oct 3 11:55:51 PDT 2024
================
@@ -102,6 +102,44 @@ def FileLineColLoc : Builtin_LocationAttr<"FileLineColLoc"> {
let attrName = "builtin.file_line_loc";
}
+//===----------------------------------------------------------------------===//
+// FileRange
+//===----------------------------------------------------------------------===//
+
+def FileRangeLoc : Builtin_LocationAttr<"FileRangeLoc"> {
+ let summary = "A file:line:column to line:column source location range";
+ let description = [{
+ Syntax:
+
+ ```
+ filelinecol-location ::= `range(` string-literal `:` integer-literal `:`
+ integer-literal ` to ` integer-literal `)`
+ ```
+
+ An instance of this location represents a tuple of file, start line number,
+ start column number, end line, and end column number. This represents a range
+ inside a file.
+ }];
+ let parameters = (ins "StringAttr":$filename, "unsigned":$line,
+ "unsigned":$column, "unsigned":$byte_size);
----------------
Technius wrote:
What's the motivation for using line/column for the starting position and then using byte size for the end?
In my understanding, tools that report user-facing diagnostics would want to report line/column information. This would require the tool to query the `SourceMgr` (if one is available) for the line/column of the end position, which could result in incorrect column numbers if there are multibyte characters and no information about the file's text encoding is known. Accurate column number calculations would require the original source files to be available to the tool, which may not always be the case. Wouldn't it be better to also store line/column for the end position, instead computing the length dynamically?
If having 4 integers is a concern, how about using two integers (byte offset and length) instead? This would move the concern of text encodings back to the user-facing tool, which will need to translate the byte offset to starting position and (byte offset + length) to ending position.
https://github.com/llvm/llvm-project/pull/80213
More information about the Mlir-commits
mailing list