Explorer: Reduce prelude path when printing source location (#3080)

The Prelude path can be very long, which can make the `SourceLocation`'s
`Print(...)` method output unnecessarily verbose. This PR modifies the
`SourceLocation`'s `Print()` method to just print the **filename** and
**line number** for prelude.
This commit is contained in:
Prabhat Sachdeva
2023-08-09 17:57:07 +00:00
committed by GitHub
parent 927375f9c6
commit 2f70c7d8bb
13 changed files with 19 additions and 13 deletions
+7 -1
View File
@@ -48,14 +48,20 @@ class SourceLocation {
auto file_kind() const -> FileKind { return file_kind_; }
void Print(llvm::raw_ostream& out) const {
out << filename_ << ":" << line_num_;
if (file_kind_ == FileKind::Prelude) {
out << llvm::StringRef(filename_).rsplit("/").second << ":" << line_num_;
} else {
out << filename_ << ":" << line_num_;
}
}
auto ToString() const -> std::string {
std::string result;
llvm::raw_string_ostream out(result);
Print(out);
return result;
}
LLVM_DUMP_METHOD void Dump() const { Print(llvm::errs()); }
private:
+1 -1
View File
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: "HALLO WELT"
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: "HALLO WELT"
package ExplorerTest api;
+1 -1
View File
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: "Fail"
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: "Fail"
package ExplorerTest api;
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Deallocating a derived class from base class pointer requires a virtual destructor
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Deallocating a derived class from base class pointer requires a virtual destructor
package ExplorerTest api;
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Integer overflow
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Integer overflow
package ExplorerTest api;
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Integer overflow
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Integer overflow
package ExplorerTest api;
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Integer overflow
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Integer overflow
package ExplorerTest api;
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Integer overflow
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Integer overflow
package ExplorerTest api;
+1 -1
View File
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: "Attempted to unwrap empty Optional"
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: "Attempted to unwrap empty Optional"
package ExplorerTest api;
+1 -1
View File
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Rand inputs must be ordered for a non-empty range: 0 must be less than 0
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Rand inputs must be ordered for a non-empty range: 0 must be less than 0
package ExplorerTest api;
+1 -1
View File
@@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// CHECK:STDERR: RUNTIME ERROR: /explorer/data/prelude.carbon:{{\d+}}: Rand inputs must be ordered for a non-empty range: 1 must be less than -1
// CHECK:STDERR: RUNTIME ERROR: prelude.carbon:{{\d+}}: Rand inputs must be ordered for a non-empty range: 1 must be less than -1
package ExplorerTest api;
+1 -1
View File
@@ -15,7 +15,7 @@ fn Main() -> i32 {
// ARGS: --trace_file=- --trace_phase=all --trace_file_context=all %s
// NOAUTOUPDATE
// SET-CHECK-SUBSET
// CHECK:STDOUT: *** declaring `interface As` ({{.*}}/explorer/data/prelude.carbon:14)
// CHECK:STDOUT: *** declaring `interface As` (prelude.carbon:14)
// CHECK:STDOUT: *** declaring function `Main` (context_all.carbon:11)
// CHECK:STDOUT: interface As {
// CHECK:STDOUT: fn Main ()-> i32 {
+1 -1
View File
@@ -15,5 +15,5 @@ fn Main() -> i32 {
// ARGS: --trace_file=- --trace_phase=all --trace_file_context=prelude %s
// NOAUTOUPDATE
// SET-CHECK-SUBSET
// CHECK:STDOUT: *** declaring `interface As` ({{.*}}/explorer/data/prelude.carbon:14)
// CHECK:STDOUT: *** declaring `interface As` (prelude.carbon:14)
// CHECK:STDOUT: interface As {