Skip to content

Conversation

Oshanath
Copy link
Contributor

@Oshanath Oshanath commented Mar 29, 2022

  • Created the function make_ImplicitCast_t_value() in ASRUtils that will create an implicit cast node and calculate the value attribute if possible. If not possible, function is identical to make_ImplicitCast_t().

  • Replaced the make_ImplicitCast_t() calls in implicitcast_helper() with make_ImplicitCast_t_value().

  • Uncommented test case in integration_tests/test_complex.py now passes. (Does not pass in the main branch)

  • Made the function make_ImplicitCast_t_value() non-inline since it will be large.

  • IntegerToReal cast fails test cases in integration_tests/test_builtin_pow.py. When both arguments of the pow() are integer and right arg is negative, IntegerToReal cast node gets created with a constantReal_t as the argument.

  • IntegerToInteger cast fails test cases in integration_tests/test_types_01.py.

  • So both of the above casts along with IntegerToLogical remain unimplemented for now.

Fixes #294

@certik
Copy link
Contributor

certik commented Mar 30, 2022

Yes, this is exactly how to do it, thanks for submitting the PR! I have to review the details of the new function carefully, but overall this is what I had in mind. I'll review it carefully hopefully tomorrow.

@@ -11,7 +11,7 @@ def test_real_imag():
b = x.imag
assert abs(a - 2) < eps
# TODO: below test should work
# assert abs(b - 3) < eps
assert abs(b - 3) < eps
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some more tests may be? For better coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have any tips as to how I can write some tests to check whether an implicit cast node has a compile time value?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think value calculation will happen while visiting ImplicitCast node. So, adding tests which will require implicit cast should do the job. Like, c = a + b where a, b and c all are of different types.

@czgdp1807
Copy link
Collaborator

Why is this PR closed?

@certik
Copy link
Contributor

certik commented Apr 13, 2022

I don't know. I just reviewed PR #319 which seems to be the successor of this one.

This pull request was closed.
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.

Create a function to automatically compute the value member for an expr node
3 participants