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

fix: Kind for CMPLX and ArrayConstructor doesn't work #3670

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

Pranavchiku
Copy link
Contributor

Fixes #3601

@Pranavchiku Pranavchiku marked this pull request as ready for review March 19, 2024 04:56
@@ -5129,6 +5129,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
Vec<ASR::expr_t*> args; args.reserve(al, 1);
args.push_back(al, arg);
array->m_args[i] = ASRUtils::expr_value(ASRUtils::EXPR(create_func(al, loc, args, diag)));
ASR::Array_t* arr_type = ASR::down_cast<ASR::Array_t>(array->m_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, it seems like kind is being treated as an elemental intrinsic function.

While in the documentation, kind is actually an "Inquiry function" (screenshot from page 384, J3/18-007r1):
Screenshot 2024-03-19 at 11 38 34 AM.

So here, kind([real :: 1, 2, 3, 4]) would act on the array element-wise, which isn't what kind is supposed to do though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay then this will be a design change, that can be done in another PR?

Copy link
Contributor

@gxyd gxyd Mar 19, 2024

Choose a reason for hiding this comment

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

Okay then this will be a design change, that can be done in another PR?

That sounds like a good way. Can I re-think implications of the added code on other element-wise intrinsic functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we just need to find an elemental intrinsic that takes real and returns integer.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought of floor and ceiling, but seems like they raise an error on array constructor input (a bug).

Copy link
Contributor

Choose a reason for hiding this comment

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

I created a bug report here: #3673 for issues with floor, ceiling etc.

I do agree that these changes look good, I'm happy with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for that, I'll check why it fails and try to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Pranavchiku , don't worry, I'm already working on that.

@gxyd
Copy link
Contributor

gxyd commented Mar 19, 2024

I think the above solution works for kind for complex object, but not for an array constructor.

@Pranavchiku
Copy link
Contributor Author

The example maybe wrong, we can put X[real::1] that returns integer and can reproduce intrinsics_190.

Copy link
Contributor

@gxyd gxyd left a comment

Choose a reason for hiding this comment

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

I'm happy with the changes, if you could ensure that it doesn't actually close the issue #3601, as the constructor issue isn't handled in this.

@@ -5129,6 +5129,9 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
Vec<ASR::expr_t*> args; args.reserve(al, 1);
args.push_back(al, arg);
array->m_args[i] = ASRUtils::expr_value(ASRUtils::EXPR(create_func(al, loc, args, diag)));
ASR::Array_t* arr_type = ASR::down_cast<ASR::Array_t>(array->m_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

I created a bug report here: #3673 for issues with floor, ceiling etc.

I do agree that these changes look good, I'm happy with it.

integration_tests/intrinsics_191.f90 Show resolved Hide resolved
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

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

I think this PR is fine. @Pranavchiku if you are ok with it, you can merge it.

@Pranavchiku Pranavchiku merged commit f9d65a0 into lfortran:main Mar 19, 2024
21 checks passed
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.

Kind for CMPLX and ArrayConstructor doesn't work
3 participants