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
Improve Exceptions support #65
Conversation
d8d748e
to
8cdd8d7
Compare
The code may be rough in some places, but it's ready for the review. |
php-src tests are failing due to the fact that KPHP now resolves the classes used in Right now we're missing
|
d73c6e4
to
bc6a194
Compare
Some extra generated code diff is expected now: since |
a7b3614
to
df4e06f
Compare
0c10c1f
to
5d49e6a
Compare
Tested exception tracking with Also compared the passes execution time. |
5d49e6a
to
691c275
Compare
Ready for review. |
ac70886
to
fcc74c0
Compare
2b4100b
to
a7bdd88
Compare
Add __FILE__ and __LINE__ arguments to the Exception-derived construction call in the PreprocessException pass instead of doing it in the lexer. The problem with lexer is that it tries to know about the Exception class and adds these arguments too early. If Exception class can be extended, then we don't know whether a `new T()` expression constructs an exception class. The PreprocessException has class data info, so it can perform this operation with more accuracy. We also change the Exception class constructor signature so it's compatible with the PHP version. It doesn't accept the file and line arguments now; to set these fields, a new builtin function is added that is inserted by the compiler. This transformation can be described as: new T(args...) => __exception_set_location(new T(args...), __FILE__, __LINE__) Where __exception_set_location() call returns the modified exception. This patch does not add missing Exception-related features, but it makes it's needed to make the work in that direction possible.
Connect the graph like this: e1 catch1 \ / e2 -- catch_list_start -- catch2 / \ eN catchN Instead of this: catch1 / e1 -- catch2 \ catchN catch1 / e2 -- catch2 \ catchN catch1 / eN -- catch2 \ catchN
PHP does the same thing.
CurException is now Throwable as it can be either Exception or Error.
- use unordered sets for kphp-test-throws - use dedicated op instead of __set_exception_location()
216753d
to
179b79c
Compare
68164d5
to
b7edab4
Compare
Compiler memory consumption comparison:
Notes:
catch
clauses pertry
block\Throwable
interface;\Exception
now implements\Throwable
\Error
class that implements\Throwable
+ SPL Exception classesnew Exception(...)
=>__exception_set_location(new Exception(...), __FILE__, __LINE__)
and an instance cast of exception var if it's notThrowable
finally
on purpose--
Enabled exceptions inheritance.
updated CFG and other passes so they handle the program flow correctly
codegen generates 2 new cases for the try/catch ops.
If exception class has derived classes, is_a() is used;
If exception class has no derived classes, hash comparison is used;
When the code catches \Exception class, same codegen is used.
Exceptions in CFG propagate like this: if try block catches
all exceptions, we consider that nothing propagates.
Otherwise, we consider all exceptions that can be created inside try block do propagate.
We may do exceptions tracking here as well, but it doesn't affect
the code generation right now.
--
Added
PreprocessException
pass.Add
__FILE__
and__LINE__
arguments to the Exception-derivedconstruction call in the PreprocessException pass instead of
doing it in the lexer.
The problem with lexer is that it tries to know about the
Exception class and adds these arguments too early.
If Exception class can be extended, then we don't know
whether a
new T()
expression constructs an exception class.The PreprocessException has class data info, so it can
perform this operation with more accuracy.
We also change the Exception class constructor signature so
it's compatible with the PHP version. It doesn't accept the
file and line arguments now; to set these fields, a new builtin function
is added that is inserted by the compiler.
This transformation can be described as:
Where __exception_set_location() call returns the modified exception.
This patch does not add missing Exception-related features,
but it makes it's needed to make the work in that direction possible.