Repository navigation
Extend Location manger to handle multi-file import errors - #1297
Conversation
d2a6959 to
1cdd5aa
Compare
b460712 to
f3187ba
Compare
| from test_mod import i, test | ||
| print(test(5.0)) | ||
| print(i) |
There was a problem hiding this comment.
Works beautifully!
Here is the output:
$ lpython tests/errors/test__c.py --show-asr
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/test_mod/test__a.py:3:1
|
3 | i: Const[i32] = 1.23
| ^ ^^^^ type mismatch ('i32' and 'f64')
semantic error: The module `test__a` cannot be loaded
--> tests/errors/test_mod/__init__.py:1:1
|
1 | from .test__a import i, test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
semantic error: The module `__init__` cannot be loaded
--> tests/errors/test__c.py:1:1
|
1 | from test_mod import i, test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).Now, I'm working on addressing the @certik comments and simplifying things.
certik
left a comment
There was a problem hiding this comment.
Otherwise I think this is a very good progress, thanks!
| } else { | ||
| throw LCompilersException("Error format not supported."); | ||
| } | ||
| lm.files.pop_back(); |
There was a problem hiding this comment.
This seems to be using the files from the end of the stack, but I don't think that's a correct assumptions. The locations in a given error message can point to any file.
There was a problem hiding this comment.
I agree, I faced this situation while passing the wrong argument for the function
5f53ad2 to
4ff2228
Compare
|
This PR is ready, kindly review and provide the feedback! $ lpython tests/errors/test_import_02.py --show-asr
note: The module `test_import_01` cannot be loaded
--> tests/errors/test_import_02.py:1:1
|
1 | from test_import_01 import X
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
note: The module `__init__` cannot be loaded
--> tests/errors/test_import_01.py:2:1
|
2 | from test_import import test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
note: The module `test_import_1` cannot be loaded
--> tests/errors/test_import/__init__.py:1:1
|
1 | from .test_import_1 import test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
semantic error: Type mismatch in procedure call; the types must be compatible
--> tests/errors/test_import_01.py:4:22
|
4 | X: Const[f64] = test(5.0)
| ^^^ type mismatch (passed argument type is f64 but required type is i32)
--> tests/errors/test_import/test_import_1.py:3:13
|
3 | def test(x: i32) -> i32:
| ^^^ type mismatch (passed argument type is f64 but required type is i32)
Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed).Test 2: lpython tests/errors/test_import_01.py --show-asr
note: The module `__init__` cannot be loaded
--> tests/errors/test_import_01.py:2:1
|
2 | from test_import import test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
note: The module `test_import_1` cannot be loaded
--> tests/errors/test_import/__init__.py:1:1
|
1 | from .test_import_1 import test
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
semantic error: Type mismatch in procedure call; the types must be compatible
--> tests/errors/test_import_01.py:4:22
|
4 | X: Const[f64] = test(5.0)
| ^^^ type mismatch (passed argument type is f64 but required type is i32)
--> tests/errors/test_import/test_import_1.py:3:13
|
3 | def test(x: i32) -> i32:
| ^^^ type mismatch (passed argument type is f64 but required type is i32)
Note: if any of the above error or warning messages are not clear or are lacking
context please report it to us (we consider that a bug that needs to be fixed). |
We continue the location of the imported file, i.e., if the new file is imported then the location starts from the size of the previous file. Here are the contents of the filename and file_ends now: tests/errors/test_import_01.py
tests/errors/test_import/__init__.py
tests/errors/test_import/test_import_1.py
86
118
192 |
|
The CI is getting an error: Looks like you need to update some code in |
|
I think this is roughly correct. Try to get the CI all passing and I'll review very carefully. |
Yup! I fixed everything. Currently, working on the |
4ff2228 to
934c910
Compare
|
I fixed it, this is ready for review. |
ba23349 to
0396bea
Compare
| ifs.read(&bytes[0], filesize); | ||
|
|
||
| text = std::string(&bytes[0], filesize); | ||
| text.erase( std::remove(text.begin(), text.end(), '\r'), text.end() ); |
There was a problem hiding this comment.
This fixes the failure in the windows. I don't know whether this is the correct fix.
There was a problem hiding this comment.
The good news is that, this almost fixed the run_tests issue in the Windows.
Ie., Now, we can do python run_tests.py.
The only left out part to fix is to stop the printing this Creating library *.lib and object *.exp in the runtime
There was a problem hiding this comment.
We can just filter it from the output on Windows. Do you want to submit a PR?
There was a problem hiding this comment.
Ok, this will slow down every file read.
Ideally we handle this in the tokenizer, which we have to extend to handle \r properly.
Why does this change have to be here? What in this PR requires this change?
There was a problem hiding this comment.
a65de92 to
1b4213a
Compare
| auto parsing_end = std::chrono::high_resolution_clock::now(); | ||
| times.push_back(std::make_pair("Parsing", std::chrono::duration<double, std::milli>(parsing_end - parsing_start).count())); | ||
| std::cerr << diagnostics.render(input, lm, compiler_options); | ||
| // std::cerr << diagnostics.render(lm, compiler_options); |
There was a problem hiding this comment.
I think the errors have to be rendered here:
| // std::cerr << diagnostics.render(lm, compiler_options); | |
| std::cerr << diagnostics.render(lm, compiler_options); |
| @@ -0,0 +1,3 @@ | |||
| from test_import_01 import X | |||
|
|
|||
| print(X) | |||
There was a problem hiding this comment.
I think these new tests are not registered in tests.toml?
There was a problem hiding this comment.
Here, are the current outputs, I just replaced the note with warning (it highlights with yellow):
$
warning: The module 'test_import/test_import_2' cannot be loaded
--> tests/errors/test_import_02.py:1:1
|
1 | from test_import.test_import_2 import X
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ imported here
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/test_import/test_import_2.py:3:1
|
3 | X: Const[i32] = 1.23
| ^ ^^^^ type mismatch ('i32' and 'f64')
$
semantic error: Type mismatch in procedure call; the types must be compatible
--> tests/errors/test_import_01.py:4:22
|
4 | X: Const[f64] = test(5.0)
| ^^^ type mismatch (passed argument type is f64 but required type is i32)
--> tests/errors/test_import/test_import_1.py:3:13
|
3 | def test(x: i32) -> i32:
| ^^^ type mismatch (passed argument type is f64 but required type is i32)|
@Thirumalai-Shaktivel great job. I think this is almost ready. I reviewed every change and I only noticed the issues that I posted above in comments. Let's address them, after which I think this is ready. |
| std::ofstream out("input.txt"); | ||
| out << input; | ||
| LocationManager::FileLocations fl; | ||
| fl.in_filename = "input.txt"; | ||
| lm.get_newlines(input, fl.in_newlines); |
There was a problem hiding this comment.
Here we write the input contents into the input.txt.
In the content "One line text\n": the \n is replaced with \r\n. So, the ctests fail, as \r is added up in the windows. I think, we either remove \r or handle this test_error_rendering separately for windows.
Error:
( semantic error: Error with label no message
--> input.txt:1:5
|
1 | One line text
| ^^^^
== semantic error: Error with label no message
--> input.txt:1:5
|
1 | One line text
| ^^^^
There was a problem hiding this comment.
I figured out, how to fix this...
15c6153 to
f8adb68
Compare
f8adb68 to
36df81e
Compare
| << reset << std::endl; | ||
| std::string line = s0.source_code[0]; | ||
| std::replace(std::begin(line), std::end(line), '\t', ' '); | ||
| line.erase(std::remove(line.begin(), line.end(), '\r'), line.end()); |
There was a problem hiding this comment.
We currently, use this to fix the \r issue in the error_rendering.
|
@Thirumalai-Shaktivel do you want to finish this? Just resolve the conflicts and rebase / merge and this should be good to go. |
- Add a new struct FileLocation to store multi- file information. - Add a new vector to store all the file ends. - Now, the error file can be determined using the error location, see the comments under `file_ends` for more details. - Use the index to retrieve all the information like filename, newlines, etc.
…p file. And initialize all the Location information
Store the input into the input.txt. Later use this to render the errors.
36df81e to
4e1e032
Compare
|
I just rebased this on top of sync. |
czgdp1807
left a comment
There was a problem hiding this comment.
Mind applying libasr/ changes to LFortran's libasr. Reason being this is a very significant change so we should check if it works for LFortran as well. Doing this at the time of next sync will not allow us to test it properly for LFortran. How much time will it take to just apply the libasr/ changes and run the existing tests of LFortran to make sure we are not getting any errors there?
|
Yup, After merging this PR, I had the same plan to submit a PR to LFortran as well. |
|
No worries, I will do it on your behalf tomorrow. |
|
Seems like we need to fix lfortran/lfortran#1026 before getting both the PRs into @Thirumalai-Shaktivel I have given you push access to my LFortran fork. Please feel free to update lfortran/lfortran#1026 and fix the bugs in it. Then we will merge both the PRs. Thanks. |
|
Thanks, for opening the PR. I'm working on it. |
certik
left a comment
There was a problem hiding this comment.
This looks good to me.
@czgdp1807 do you want to first upgrade LFortran before we merge, in lfortran/lfortran#1026?
Yes. I would strongly recommend doing so because the changes of |
|
Yup, I will complete this by today. |
|
I reviewed and this looks good, I merged both LFortran and LPython PRs. |
|
Thank you. |
Fixes: #1218