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

'this' cannot be returned inside a method when 'internal-call-transformation' is enabled #1956

Closed
JellyBrick opened this issue Oct 6, 2019 · 6 comments
Labels
bug

Comments

@JellyBrick
Copy link
Contributor

@JellyBrick JellyBrick commented Oct 6, 2019

Code

    public function stretch(int axis, float distance) -> <AxisAlignedBB>
    {
        ...
        return this;
    }

axisalignedbb.zep

void zep_Pocketmine_Math_AxisAlignedBB_stretch_zephir_internal_call(int ht, zval *return_value, zval *this_ptr, int return_value_used, zval *axis_param_ext, zval *distance_param_ext) {
        ...
        RETURN_THISW();

}

axisalignedbb.zep.c

Error log

/RapidPM/ext/pocketmine/math/axisalignedbb.zep.c: In function ‘zep_Pocketmine_Math_AxisAlignedBB_stretch_zephir_internal_call’:
/phpdir/include/php/Zend/zend_compile.h:560:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^~~~~~~~~~~~
/phpdir/include/php/Zend/zend_API.h:602:17: note: in definition of macro ‘ZVAL_ZVA ’
   zval *__zv = (zv);      \
                 ^~
/phpdir/include/php/Zend/zend_API.h:649:40: note: in expansion of macro ‘RETVAL_ZVAL’
 #define RETURN_ZVAL(zv, copy, dtor)  { RETVAL_ZVAL(zv, copy, dtor); return; }
                                        ^~~~~~~~~~~
./kernel/main.h:147:2: note: in expansion of macro ‘RETURN_ZVAL’
  RETURN_ZVAL(getThis(), 1, 0);
  ^~~~~~~~~~~
/phpdir/include/php/Zend/zend_API.h:363:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/phpdir/include/php/Zend/zend_API.h:363:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
./kernel/main.h:147:14: note: in expansion of macro ‘getThis’
  RETURN_ZVAL(getThis(), 1, 0);
              ^~~~~~~
/RapidPM/ext/pocketmine/math/axisalignedbb.zep.c:2525:2: note: in expansion of macro ‘RETURN_THISW’
  RETURN_THISW();
  ^~~~~~~~~~~~
@sergeyklay sergeyklay added the bug label Oct 6, 2019
@andrewdalpino

This comment has been minimized.

Copy link

@andrewdalpino andrewdalpino commented Oct 30, 2019

I am also having this problem with internal-call-transformation: true with version 0.12.10 as well as dev-development

Here is my compile-errors.log

In file included from /mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/columnvector.zep.c:14:0:
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/columnvector.zep.c: In function ‘zep_Tensor_ColumnVector_m_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/columnvector.zep.c:1663:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/usr/include/php/20170718/Zend/zend_compile.h:530:26: note: each undeclared identifier is reported only once for each function it appears in
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/columnvector.zep.c:1663:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
make: *** [tensor/columnvector.lo] Error 1
make: *** Waiting for unfinished jobs....
In file included from /mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:14:0:
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_size_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9105:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/usr/include/php/20170718/Zend/zend_compile.h:530:26: note: each undeclared identifier is reported only once for each function it appears in
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9105:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_n_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9131:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_asArray_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9144:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "a");
                ^~~~~~~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_count_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:15848:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
make: *** [tensor/vector.lo] Error 1
In file included from /mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:14:0:
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_size_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9105:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/usr/include/php/20170718/Zend/zend_compile.h:530:26: note: each undeclared identifier is reported only once for each function it appears in
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9105:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_n_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9131:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_asArray_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:9144:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "a");
                ^~~~~~~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c: In function ‘zep_Tensor_Vector_count_zephir_internal_call’:
/usr/include/php/20170718/Zend/zend_compile.h:530:26: error: ‘execute_data’ undeclared (first use in this function); did you mean ‘execute_ex’?
 #define EX(element)    ((execute_data)->element)
                          ^
./kernel/main.h:164:39: note: in definition of macro ‘RETURN_MEMBER’
  zephir_return_property(return_value, object, SL(member_name)); \
                                       ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:27: note: in expansion of macro ‘Z_TYPE’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                           ^~~~~~
/usr/include/php/20170718/Zend/zend_API.h:379:34: note: in expansion of macro ‘EX’
 #define getThis()       ((Z_TYPE(EX(This)) == IS_OBJECT) ? &EX(This) : NULL)
                                  ^~
/mnt/c/Users/Andrew/Workspace/Rubix/Tensor/ext/tensor/vector.zep.c:15848:16: note: in expansion of macro ‘getThis’
  RETURN_MEMBER(getThis(), "n");
                ^~~~~~~
make: *** [tensor/vector.lo] Error 1

Source file https://github.com/RubixML/Tensor/blob/master/tensor/columnvector.zep

Generated code ...

/**
 * Return the number of rows in the vector.
 *
 * @return int
 */
void zep_Tensor_ColumnVector_m_zephir_internal_call(int ht, zval *return_value, zval *this_ptr, int return_value_used) {

	

	RETURN_MEMBER(getThis(), "n");

}
@sergeyklay

This comment has been minimized.

Copy link
Member

@sergeyklay sergeyklay commented Oct 30, 2019

@dreamsxin Could you please take a look

@dreamsxin

This comment has been minimized.

Copy link
Member

@dreamsxin dreamsxin commented Oct 30, 2019

@sergeyklay
Change c code, add INTERNAL_FUNCTION_PARAMETERS and INTERNAL_FUNCTION_PARAM_PASSTHRU
define

void zep_xxx_zephir_internal_call(..., INTERNAL_FUNCTION_PARAMETERS) {
        ...
}

call

zep_xxx_zephir_internal_call(..., INTERNAL_FUNCTION_PARAM_PASSTHRU);
@dreamsxin

This comment has been minimized.

Copy link
Member

@dreamsxin dreamsxin commented Oct 30, 2019

#define INTERNAL_FUNCTION_PARAMETERS zend_execute_data *execute_data, zval *return_value
#define INTERNAL_FUNCTION_PARAM_PASSTHRU execute_data, return_value
@andrewdalpino

This comment has been minimized.

Copy link

@andrewdalpino andrewdalpino commented Oct 31, 2019

Thanks for taking a look fellas! @sergeyklay @dreamsxin

I was able to get about an 80% speedup in Rubix ML just by porting the Tensor library over to Zephir

I'm hoping we can increase that with this optimization and eventually get to CPU/GPU multithreading by calling BLAS routines from C (see openBLAS)

Keep up the good work

dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 1, 2019
sergeyklay added a commit to dreamsxin/zephir that referenced this issue Nov 1, 2019
sergeyklay added a commit to dreamsxin/zephir that referenced this issue Nov 1, 2019
@dreamsxin dreamsxin referenced this issue Nov 1, 2019
3 of 3 tasks complete
@sergeyklay sergeyklay closed this in 4f49f36 Nov 1, 2019
sergeyklay added a commit that referenced this issue Nov 1, 2019
Fix #1956
@sergeyklay

This comment has been minimized.

Copy link
Member

@sergeyklay sergeyklay commented Nov 1, 2019

Fixed in the development branch. Feel free to open a new issue if the problem appears again. Thank you for contributing.

sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
sergeyklay added a commit that referenced this issue Nov 2, 2019
dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
dreamsxin added a commit to dreamsxin/zephir that referenced this issue Nov 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.