hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Exception: class_alias with non-literal parameters is not allowed when WholeProgram optimizations are turned on

Open raulp opened this issue 13 years ago • 33 comments

after installing from deb packages on ubuntu, i was trying to compile a list of php files in my folder. I've got:

Exception: class_alias with non-literal parameters is not allowed when WholeProgram optimizations are turned on\n hphp failed

Any clue what i might do ?

raulp avatar Jul 19 '13 20:07 raulp

WholeProgram optimizations rely on being able to determine certain things about types when doing global analysis. Using class_alias() with non-literal parameters makes it very difficult to prove certain things about types during analysis. There are some trivial cases where in theory WholeProgram optimization could make it work, for example:

function my_class_alias($x,$y) { class_alias($x,$y); } my_class_alias('Foo', 'Bar');

In the example above, WholeProgram optimization could in theory see what literal strings are ultimately getting passed into class_alias(). However, in the general case it is not always possible to reliably determine what literal strings get passed to class_alias(), since the strings could come from some external source like a database, or the strings could be computed using some Turing-complete logic, etc.

The short answer: you should either turn off WholeProgram optimization for you program, or find a way to change your program to avoid using non-literal parameters with class_alias().

paroski avatar Jul 19 '13 20:07 paroski

Hey Paroski Not sure if you're familiar, but i'm trying to move laravel ( which is a php framework ) to HipHop. So far, all i did was installing HipHop ( apt-get install ). Then, i wanted to add all the php files with something like: hhvm --hphp -k 1 -o /tmp/app/ --input-list /tmp/files.list -l 1

Then, i got that error ( which now i understand what it means - not sure if i can change that though ) and lots of file not found ( Unable to stat file ... ), which is weird, as those files paths are not in /tmp/files.list. Do you know why i get those too ?

Thanks !

raulp avatar Jul 19 '13 21:07 raulp

I believe those "unable to stat file" statements can be ignored.

Since you don't control this code, the best suggestion is not to use WholeProgram mode. (Add -v WholeProgram=false to the commandline.)

scannell avatar Jul 19 '13 21:07 scannell

Even stranger now :) /home/sgolemon/dev/hiphop-php/hphp/compiler/expression/simple_variable.cpp:87: bool HPHP::SimpleVariable::couldBeAliased() const: assertion m_sym' failed. /home/sgolemon/dev/hiphop-php/hphp/compiler/expression/simple_variable.cpp:87: bool HPHP::SimpleVariable::couldBeAliased() const: assertionm_sym' failed. hphp failed

Thanks guys for helping me with this.

Btw, just to be sure, the steps are like i said ?

  1. install
  2. hhvm --hphp ...
  3. hhvm -m daemon --config .... ?

raulp avatar Jul 19 '13 21:07 raulp

@raulp, can you give us a small piece of code that reproduces the assertion so we can investigate that further?

scannell avatar Jul 19 '13 21:07 scannell

scannell, what exactly should i give you ? It does not say on what file :)

Here's what you can do: try to add https://github.com/laravel/laravel this to HipHop. I guess that kind of what i have. A Laravel installation with some custom things. Or you can install it on your server, it's very easy, 2 command lines

raulp avatar Jul 19 '13 21:07 raulp

@raulp, I have a repro on the AliasLoader from laravel. I'll follow up.

scannell avatar Jul 19 '13 21:07 scannell

Thanks man ! Really appreciate it !

raulp avatar Jul 19 '13 21:07 raulp

@scannell , whenever you have some updates, please do let me know :) the Laravel community will appreciate it. And if we can find a way to make it work, i know lots of ppl that will use it in their systems.

Thanks again !

raulp avatar Jul 22 '13 17:07 raulp

@raulp, internally we don't use WholeProgram = false very often so we don't test that much with it. I know you don't really care to use it besides that class_alias doesn't work in WholeProgram mode because it invalidates some optimization assumptions we are making.

As a workaround in the meantime, if you temporarily remove AliasLoader::load function (are you using this part of laravel in your application?) from the laravel source, does what you are trying to do work for you?

scannell avatar Jul 22 '13 18:07 scannell

Also, @raulp, curious: what is your use case for repo construction? (Our gut is that not many people outside Facebook are using this so we're wondering.)

scannell avatar Jul 22 '13 18:07 scannell

@scannell i think Laravel uses the AliasLoader in the core. So finding where that is used can be a problem. But, when i tried to use WholeProgram ( set it to false ), i still got errors. Are they related ? The error was

/home/sgolemon/dev/hiphop-php/hphp/compiler/expression/simple_variable.cpp:87: bool HPHP::SimpleVariable::couldBeAliased() const: assertionm_sym' failed. hphp failed

raulp avatar Jul 22 '13 18:07 raulp

@scannell can you detail that please ( repo construction ) ... not sure what you mean by that.

raulp avatar Jul 22 '13 18:07 raulp

What I mean is that we normally run with WholeProgram = true when we construct a bytecode repository. We don't use class_alias internally so it does not cause issues. We don't run often with WholeProgram = false so it is very possible there are bugs (like that assertion.)

class_alias not working with WholeProgram = true is expected for the reasons we stated; the assertion is not.

My question on repo construction is this: one does not have to precompile the PHP code into a bytecode repository using hhvm --hphp in order to run PHP code on HHVM, so I was just wondering why you were doing so instead of just running with the repo being populated at runtime as your PHP code is parsed and executed. If you need to use something with class_alias, I believe you'll be able to do so as long as you don't run in repository mode with a pre-compiled repository. Does that make sense?

scannell avatar Jul 22 '13 18:07 scannell

@scannell , thanks for all the info. I've got the idea with the class_alias and WholeProgram. I'll try to get with the creator and see if we can change that later on.

Hmm, about the second part, that's who i've read everywhere that i have to get up and running. Maybe i did it all wrong ? Can you tell me the exact steps to get a Laravel default app running on HipHop ? And my question will be ... if i'm not pre-compiling the code, is it worth it to run it with HipHop ?

raulp avatar Jul 22 '13 18:07 raulp

It is most likely still worth it. One just incurs the overhead of parsing and repo construction the first time a unit of PHP code is executed. Subsequent runs will execute from the repo. One can save a bit of time parsing ahead of time but assuming your application is a long-running server application it will be a bit slower to warm up but then will execute from the dynamically built repository.

Per the high-level instructions at https://github.com/facebook/hiphop-php, you should just be able to run a script with hhvm <scriptname> and server mode with something like sudo hhvm -m server and then making the appropriate web requests. The precompilation step is optional. (I am guessing a lot of what you read pertains to the former HPHPC days when were compiling PHP to C++; this is no longer required.)

Hope this helps!

scannell avatar Jul 22 '13 18:07 scannell

@scannell yeah, most of the docs are based on HPHPc. Ok, i'll try to give it a shot without compiling ( i think i've tried, but i had an error with empty repository, and every request failed ) I did create a hhvm config file like here: http://www.hiphop-php.com/wp/?p=113 , but maybe i missed something I'm gonna try again !

raulp avatar Jul 22 '13 18:07 raulp

laravel works on trunk

ptarjan avatar Dec 07 '13 00:12 ptarjan

I suspect it still doesn't work with WholeProgram mode enabled -- because @jdelong wasn't entirely sure what we could do here even -- but I'd suggest just not using RepoAuthoritative mode if one has to include this code (or removing it from one's local laravel installation if need be -- even if we allowed it during compilation, calling class_alias would break things badly, or we'd have to make significant changes to how WholeProgram mode works.) What is unfortunate is we haven't really spent much time running hhvm --hphp not in WholeProgram mode but it's unlikely to be something we're going to spend time on any time in the next year.

scannell avatar Dec 07 '13 00:12 scannell

Yeah it doesn't work in RepoAuthoritative mode (and likely won't), because it breaks assumptions needed for static analysis.

With RepoAuthoritative=false it should work though.

jdelong avatar Dec 07 '13 00:12 jdelong