Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to print dataclasses and tuples in REPL #2785

Merged
merged 2 commits into from
Jul 27, 2024

Conversation

Vipul-Cariappa
Copy link
Contributor

Example:

>>> x: tuple[i32, f64] = (2, 2.4)
>>> x
(2, 2.400000)
>>> (2, 2.4, "LPython")
(2, 2.400000, "LPython")
>>> @dataclass
... class MyClass:
...   x: bool
...   y: i32
...   z: str
...
>>> MyClass(True, 12, "LPython")
MyClass(x=True, y=12, z="LPython")

r = e.evaluate2("c4");
CHECK(r.ok);
CHECK(r.result.type == PythonCompiler::EvalResult::struct_type);
CHECK(e.aggregate_type_to_string(r.result) == "MyClass4(i_1=True, i_8=2, i_16=3, i_32=4, i_64=5)");
Copy link
Contributor Author

@Vipul-Cariappa Vipul-Cariappa Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line fails on Windows. (1639)

Commenting this one line and running the test does not seg fault in my local machine.

@Vipul-Cariappa
Copy link
Contributor Author

On further investigation, it looks like when we get the offset of each member field of the struct from LLVM, it returns a random value (reference:

size_t offset = dl.getStructLayout((llvm::StructType*)type)->getElementOffset(i);
offsets.push_back(al, offset);
).

I am printing out the offsets, and just before it seg faults the offset values are random and high.

(lp16) C:\Users\vipul\Documents\Workspace\lpython\build16>ctest --rerun-failed --output-on-failure
Test project C:/Users/vipul/Documents/Workspace/lpython/build16
    Start 2: test_lpython
1/1 Test #2: test_lpython .....................***Failed    0.68 sec
[doctest] doctest version is "2.4.8"
[doctest] run with "--help" for options
0 0 0 0 0 0 0 0 0 0
0
4
8
0
4
8
0
4
8
0
4
8
0
4
0
4
8
0
4
8
16
0
4
8
16
24
0
2
8
0
0
0
8
0
8
16
0
10376344761626795937
2841615990688
140698833649665
140375097361
===============================================================================
C:\Users\vipul\Documents\Workspace\lpython\src\lpython\tests\test_llvm.cpp(1556):
TEST CASE:  PythonCompiler classes

C:\Users\vipul\Documents\Workspace\lpython\src\lpython\tests\test_llvm.cpp(1556): FATAL ERROR: test case CRASHED: SIGSEGV - Segmentation violation signal

===============================================================================
[doctest] test cases:  55 |  54 passed | 1 failed | 17 skipped
[doctest] assertions: 488 | 488 passed | 0 failed |
[doctest] Status: FAILURE!


0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.69 sec

The following tests FAILED:
          2 - test_lpython (Failed)
Errors while running CTest

Is this a bug in LLVM?

cc @Shaikh-Ubaid @certik

@Shaikh-Ubaid
Copy link
Collaborator

Shaikh-Ubaid commented Jul 23, 2024

I am printing out the offsets, and just before it seg faults the offset values are random and high.

Could you please share the test code and the offset printing modification you used here?

Is this a bug in LLVM?

Which LLVM version are you currently using? Could you please check with other LLVM versions?

@Vipul-Cariappa
Copy link
Contributor Author

I have tested it with both LLVM 11 and 16. It fails similarly in both.

Code used to debug:
debugging_segfault_windows.patch

You can uncomment if (___flag) { std::cout << m->str() << std::endl; }, if you want to see the LLVM IR.

@Vipul-Cariappa Vipul-Cariappa marked this pull request as ready for review July 27, 2024 03:52
@Vipul-Cariappa
Copy link
Contributor Author

@Shaikh-Ubaid, please have a look at the PR. I believe it is ready to be merged. I have commented out the failing test and opened an issue #2793.

Copy link
Collaborator

@Shaikh-Ubaid Shaikh-Ubaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for this!

@Shaikh-Ubaid Shaikh-Ubaid merged commit 42f385f into lcompilers:main Jul 27, 2024
15 checks passed
@Vipul-Cariappa Vipul-Cariappa deleted the REPL-class-print branch July 27, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants