Skip to content

Commit 7e76c79

Browse files
committed
gsoc`24: Add example for explanation
1 parent fc9057c commit 7e76c79

File tree

1 file changed

+87
-3
lines changed

1 file changed

+87
-3
lines changed

content/24/r/final-report.md

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,109 @@ type: docs
1818
![GCCRS Logo](gccrs-logo.png)
1919

2020
### [Rustc Testsuite Adapter for GCC Rust (GCCRS)](https://summerofcode.withgoogle.com/programs/2024/projects/KVAetUOC)
21+
2122
- Organization: [GNU Compiler Collection (GCC)](https://gcc.gnu.org/)
2223
- Mentors: [Arthur Cohen](https://github.com/cohenarthur/), [Pierre Emmanuel Patry](https://github.com/P-E-P/) and [Thomas Schwinge](https://github.com/tschwinge)
2324
- Student: [Muhammad Mahad](https://github.com/mahadmuhammad)
25+
2426
---
2527

2628
## Description:
2729

28-
This project is the follow-up of the previous Google Summer of Code project [Improving user errors & Error Code Support for GCC Rust Frontend](https://summerofcode.withgoogle.com/archive/2023/projects/PZbjvfZl). We have to adapt a copy of the rustc testsuite to make use of the error code framework implemented in gccrs as part of GSoC 2023. We need to develop a test case runner similar to rustc's one, in order to match error codes and line numbers to the output of gccrs. Specifically, we need to ensure that gccrs is emitting the correct error code consistent with rustc-1.49. This project requires investigating the current test framework of gcc/gccrs (dejagnu) and also the official rustc one.
30+
This project is the follow-up of the previous Google Summer of Code project [Improving user errors & Error Code Support for GCC Rust Frontend](https://summerofcode.withgoogle.com/archive/2023/projects/PZbjvfZl). We have to adapt a copy of the rustc testsuite to make use of the error code framework implemented in gccrs as part of GSoC 2023. We need to develop a test case runner similar to rustc's one, in order to match error codes and line numbers to the output of gccrs. Specifically, we need to ensure that gccrs is emitting the correct error code consistent with rustc-1.49. This project requires investigating the current test framework of gcc/gccrs (dejagnu) and also the official rustc one.
2931
The main exact goal of this project is to have access to a tool which enables us to run gccrs on the rustc test cases and assert that we emit the correct error codes/messages w.r.t to their line numbers. Furthermore, the extended deliverable of this project is to integrate this tool in gccrs CI/CD pipeline.
3032

3133
## What was Done:
3234

3335
- Researched the Rust testing framework "[compiletest](https://rustc-dev-guide.rust-lang.org/tests/compiletest.html)" to understand how test cases are organized and Rust processes and executes test cases.
3436
- Learned "Rust" programming language and created a new tool, named [rusttest-to-dg](github.com/Rust-GCC/rusttest-to-dg) to convert the Rust test cases to DejaGnu format.
3537

38+
For gccrs, we only want to check the [ui](https://rustc-dev-guide.rust-lang.org/tests/ui.html) tests — these tests are a collection of general-purpose tests which primarily focus on validating the console output of the compiler.
39+
40+
The general structure of rustc test cases consists of a Rust source file located anywhere in the "tests/ui" directory. For example, [tests/ui/hello.rs](https://github.com/rust-lang/rust/blob/master/tests/ui/hello.rs) is a basic hello-world test. The rust compiler uses a tool called "compiletest" which will test, and compare the compiler output against the expected output which is stored in a .stdout or .stderr file located next to the test. See [output comparison](https://rustc-dev-guide.rust-lang.org/tests/ui.html#output-comparison) for more details.
41+
42+
The errors and warnings in the rust test cases was annotated with comments within the source file.
43+
44+
For explaning, let's take a random [example](https://github.com/rust-lang/rust/blob/master/tests/ui/associated-item/ambiguous-associated-type-with-generics.rs) of a Rust test case:
45+
46+
```rust
47+
trait Trait<A> {}
48+
49+
trait Assoc {
50+
type Ty;
51+
}
52+
53+
impl<A> Assoc for dyn Trait<A> {
54+
type Ty = i32;
55+
}
56+
57+
fn main() {
58+
let _x: <dyn Trait<i32>>::Ty; //~ ERROR ambiguous associated type
59+
}
60+
```
61+
62+
It's [`stderr`](https://github.com/rust-lang/rust/blob/master/tests/ui/associated-item/ambiguous-associated-type-with-generics.stderr) file was:
63+
64+
```
65+
error[E0223]: ambiguous associated type
66+
--> $DIR/ambiguous-associated-type-with-generics.rs:13:13
67+
|
68+
LL | let _x: <dyn Trait<i32>>::Ty;
69+
| ^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<dyn Trait<i32> as Assoc>::Ty`
70+
71+
error: aborting due to 1 previous error
72+
73+
For more information about this error, try `rustc --explain E0223`.
74+
```
75+
76+
The error annotation needs to match with the line of the diagnostic.
77+
The rust compiletest tool uses these methods to match the message with the line
78+
79+
- `~`: Associates the error level and message with the current line
80+
- `~^`: Associates the error level and message with the previous error
81+
annotation line.
82+
Each caret (`^`) that you add adds a line to this, so `~^^^` is three lines
83+
above the error annotation line.
84+
- `~|`: Associates the error level and message with the same line as the
85+
previous comment.
86+
This is more convenient than using multiple carets when there are multiple
87+
messages associated with the same line.
88+
89+
See [Error annotations](https://rustc-dev-guide.rust-lang.org/tests/ui.html#error-annotations) for more.
90+
91+
It's equivalent dejagnu version after passing this to `rusttest-to-dg` tool, we get:
92+
93+
```rust
94+
rusttest-to-dg git:(feat/add-additional-options) ✗ cargo run -- -f test2.rs -e test2.stderr
95+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
96+
Running `target/debug/rusttest-to-dg -f test2.rs -e test2.stderr`
97+
//@ run-rustfix
98+
trait Trait<A> {}
99+
100+
trait Assoc {
101+
type Ty;
102+
}
103+
104+
impl<A> Assoc for dyn Trait<A> {
105+
type Ty = i32;
106+
}
107+
108+
fn main() {
109+
let _x: <dyn Trait<i32>>::Ty; // { dg-error ".E0223." "" { target *-*-* } }
110+
}
111+
112+
```
113+
114+
Note that, we are only adding error codes, not the error messages. We are not comparing error messages, as gccrs and rustc error messages differs in grammatical terms but have same context. We are just making sure, that gccrs and rustc emits same rustc error codes. Therefore, as long as the error code is correct, the regex pattern in [dg-error](https://gcc.gnu.org/onlinedocs/gccint/testsuites/directives-used-within-dejagnu-tests/syntax-and-descriptions-of-test-directives.html#verify-compiler-messages) will pass.
115+
36116
## Contributions Overview:
117+
37118
### Pull Requests:
119+
38120
For a comprehensive overview of the pull requests I've submitted, visit [pull requests page](https://mahadmuhammad.github.io/gsoc/24/r/pulls/).
39121

40122
### Issues:
123+
41124
To delve deeper into the intricacies of the issues I've engaged with, feel free to explore the dedicated [issue page](https://mahadmuhammad.github.io/gsoc/24/r/issues/).
42125

43126
## Work for the future:
@@ -55,6 +138,7 @@ To delve deeper into the intricacies of the issues I've engaged with, feel free
55138

56139
## Acknowledgements:
57140

58-
I am very grateful to the following people who made this project possible and supported me throughout the process. Their expertise, feedback and encouragement were invaluable for me.
141+
I am very grateful to the following people who made this project possible and supported me throughout the process. Their expertise, feedback and encouragement were invaluable for me.
142+
59143
- [Arthur Cohen](https://github.com/cohenarthur/),[Pierre Emmanuel Patry](https://github.com/P-E-P/) and [Thomas Schwinge](https://github.com/tschwinge) for being my amazing mentors and guiding me with their insights and experience.
60-
- And last but not least, [Philip Herron](https://github.com/philberty/) and [Faisal Abbas](https://github.com/abbasfaisal/) for assisting me in my initial contributions.
144+
- And last but not least, [Philip Herron](https://github.com/philberty/) and [Faisal Abbas](https://github.com/abbasfaisal/) for assisting me in my initial contributions.

0 commit comments

Comments
 (0)