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

Certain method calls fail when called from static context and compiled with "internal-call-transformation": true #2005

Closed
andrewdalpino opened this issue Nov 9, 2019 · 5 comments
Labels
bug

Comments

@andrewdalpino
Copy link

@andrewdalpino andrewdalpino commented Nov 9, 2019

I get the following errors when running this test with the extension compiled with internal-call-transformation: true. The errors go away if we disable the optimization.

1) Tensor\Tests\MatrixTest::test_inverse
RuntimeException: Trying to call method m on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:403

2) Tensor\Tests\MatrixTest::test_det
RuntimeException: Trying to call method m on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:417

3) Tensor\Tests\MatrixTest::test_rank
RuntimeException: Trying to call method m on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:458

4) Tensor\Tests\MatrixTest::test_full_rank
RuntimeException: Trying to call method m on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:465

5) Tensor\Tests\MatrixTest::test_ref
RuntimeException: Trying to call method m on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:511

6) Tensor\Tests\MatrixTest::test_rref
RuntimeException: Trying to call method m on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:525

7) Tensor\Tests\MatrixTest::test_lu_decomposition
RuntimeException: Trying to call method issquare on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:539

8) Tensor\Tests\MatrixTest::test_cholesky
RuntimeException: Trying to call method issquare on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:571

9) Tensor\Tests\MatrixTest::test_solve
RuntimeException: Trying to call method issquare on a non-object

/mnt/c/Users/User/Workspace/Rubix/Tensor/tests/MatrixTest.php:608

At first glance, it appears that we can't access methods on objects from another class' static context. This is similar to #2000 but different.

I traced the calls back to the matrix decomposition objects here. They all use static factories. Here is an excerpt from the LU decomposition where one of the errors is being thrown. It's a similar case for each of the other decompositions.

/**
     * Factory method to decompose a matrix.
     *
     * @param \Tensor\Matrix a
     * @return self
     */
    public static function decompose(const <Matrix> a) -> <Lu>
    {
        if !a->isSquare() {
            throw new RuntimeException("Cannot decompose a non square matrix.");
        }

        // ...
    }

There also seems to be the issue that methods being overloaded by a child class are not being called (the parent method is called instead.) This may or may not be related to this issue - and again, only when compiled with internal-call-transformation: true.

@sergeyklay sergeyklay added the bug label Nov 10, 2019
@sergeyklay

This comment has been minimized.

Copy link
Member

@sergeyklay sergeyklay commented Nov 14, 2019

@dreamsxin Could you please take a look?

@dreamsxin

This comment has been minimized.

Copy link
Member

@dreamsxin dreamsxin commented Nov 14, 2019

Because ZEPHIR_STATIC_CALL_INTERNAL_METHOD_P use ZEPHIR_SET_THIS_EXPLICIT_NULL.
I will try replace current_execute_data

dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 14, 2019
@dreamsxin dreamsxin mentioned this issue Nov 14, 2019
1 of 3 tasks complete
@dreamsxin

This comment has been minimized.

Copy link
Member

@dreamsxin dreamsxin commented Nov 14, 2019

Please test again, There's another mistake:
PHP Warning: array_reduce() expects parameter 2 to be a valid callback, non-static method Tensor\Matrix::implodeRow() cannot be called statically

    public function __toString() -> string
    {
        return trim(array_reduce(this->a, ["Tensor\\Matrix", "implodeRow"], ""));
    }
sergeyklay added a commit that referenced this issue Nov 15, 2019
@andrewdalpino

This comment has been minimized.

Copy link
Author

@andrewdalpino andrewdalpino commented Nov 16, 2019

Hi @dreamsxin it looks like the 900bd5f commit to the development branch fixes the primary issue. The issue of overriding parent methods still exists so that probably a separate issue.

Thank you for pointing out the error with __toString() (I had forgotten about that). Changing the implodeRow() method to static seems to work, however, it may be good to note that this is unnecessary in PHP. I'm not sure the behavior that Zephir intends.

Thanks again for your great work guys

@sergeyklay

This comment has been minimized.

Copy link
Member

@sergeyklay sergeyklay commented Nov 17, 2019

Closing, this is fixed. Lets follow up in separate issue with the overriding parent methods.

@andrewdalpino Could you please open a new issue with problem description and code to reproduce?

@sergeyklay sergeyklay closed this Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.