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

irinterp: improve semi-concrete interpretation accuracy #47994

Merged
merged 3 commits into from
Dec 27, 2022

Conversation

aviatesk
Copy link
Sponsor Member

Currently semi-concrete interpretation can end up with more inaccurate result than usual abstract interpretation because src.ssavaluetypes are all widened when cached so semi-concrete interpretation can't use extended lattice information of SSAValues. This commit tries to fix it by making CodeInstance keep extended lattice information of SSAValues that are widened and allowing semi-concrete interpretation to override src.ssavaluetypes when it uncompressed src from CodeInstance.

I found there are other chances when semi-concrete interpretation can end up with inaccurate results, but that is unrelated to this and should be fixed separately.

@aviatesk aviatesk requested a review from Keno December 25, 2022 10:05
@aviatesk
Copy link
Sponsor Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@Keno
Copy link
Member

Keno commented Dec 25, 2022

Not really a huge fan of this approach. Can we just stop widening there? That's done for the benefit of codegen, but we've moved both Const and PartialStruct into Core, so codegen could definitely look through those to get to its type information.

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - no performance regressions were detected. A full report can be found here.

@aviatesk aviatesk force-pushed the avi/improve-semi-concrete-accuracy branch from 678e2ad to 67d9dc5 Compare December 25, 2022 23:55
@aviatesk
Copy link
Sponsor Member Author

Can we just stop widening there?

es, I just implemented your suggestion. We may want to switch back to my first approach once our system becomes able to run code produced by an external AbstractInterpreter, which may contain arbitrary lattice elements. However, at the current situation, your approach seems cleaner.

@aviatesk
Copy link
Sponsor Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - no performance regressions were detected. A full report can be found here.

@aviatesk aviatesk force-pushed the avi/improve-semi-concrete-accuracy branch 2 times, most recently from a1d9f21 to cdbab61 Compare December 26, 2022 04:18
@@ -210,7 +210,7 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s)
jl_value_t *val = eval_value(jl_fieldref_noalloc(e, 0), s);
#ifndef JL_NDEBUG
JL_GC_PUSH1(&val);
jl_typeassert(val, jl_fieldref_noalloc(e, 1));
jl_typeassert(val, jl_widen_core_extended_info(jl_fieldref_noalloc(e, 1)));
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

analyzegc complains on this line. Could someone tell me how I can avoid it?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't look at the error message, but I assume the issue is that jl_widen_core_extended_info can return a freshly-allocated result in the Type case, which isn't rooted anywhere. You can fix that by just changing the JL_GC_PUSH1 to JL_GC_PUSH2 above (on some other variable jl_value_t *typ = NULL (note the value at PUSH time matters, it needs to always be a valid pointer or null between the push and the pop)). Then just assign the result of the widening to that variable and it'll be rooted for the call.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Thanks so much for your help! That seems to work.

@aviatesk aviatesk force-pushed the avi/improve-semi-concrete-accuracy branch 2 times, most recently from 523db51 to 0d71680 Compare December 27, 2022 10:58
@aviatesk aviatesk added the kind:don't squash Don't squash merge label Dec 27, 2022
@aviatesk aviatesk force-pushed the avi/improve-semi-concrete-accuracy branch from 0d71680 to 830cdb6 Compare December 27, 2022 11:33
Currently semi-concrete interpretation can end up with more inaccurate
result than usual abstract interpretation because `src.ssavaluetypes`
are all widened when cached so semi-concrete interpretation can't use
extended lattice information of `SSAValue`s. This commit tries to fix it
by making `CodeInstance` keep extended lattice information of `SSAValue`s
that are widened and allowing semi-concrete interpretation to override
`src.ssavaluetypes` when it uncompressed `src` from `CodeInstance`.

I found there are other chances when semi-concrete interpretation can
end up with inaccurate results, but that is unrelated to this and should
be fixed separately.
Currently semi-concrete interpretation can end up with more inaccurate
result than usual abstract interpretation because `src.ssavaluetypes`
are all widened when cached so semi-concrete interpretation can't use
extended lattice information of `SSAValue`s. This commit tries to fix it
by making the codegen system recognize extended lattice information such
as `Const` and `PartialStruct` and not-widening those information from
`src::CodeInfo` when caching.

I found there are other chances when semi-concrete interpretation can
end up with inaccurate results, but that is unrelated to this and should
be fixed separately.
@aviatesk aviatesk force-pushed the avi/improve-semi-concrete-accuracy branch from 830cdb6 to 7ace688 Compare December 27, 2022 11:36
@aviatesk
Copy link
Sponsor Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - no performance regressions were detected. A full report can be found here.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 9, 2023

We primarily used to do this to avoid exploding the precompile caches with garbage data that wastes space and costs GC time permanently. Are we sure this PR has not introduced a regression in that area, since we are recently starting to see test failures from an excess of roots being created (e.g. #48089)?

@aviatesk
Copy link
Sponsor Member Author

aviatesk commented Jan 9, 2023

I haven't checked anything in that area yet. Maybe I should check images size difference first, or is there any other recommended way to check the regression?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 9, 2023

You could instrument ircode.c to make sure there are no new objects getting created and stored as roots

vtjnash added a commit that referenced this pull request Jan 9, 2023
…crete-accuracy"

This reverts commit 03bdf15, reversing
changes made to a9e0545.
vtjnash added a commit that referenced this pull request Jan 10, 2023
…crete-accuracy" (#48194)

This reverts commit 03bdf15, reversing
changes made to a9e0545.

Fixes #48089 regression

That PR causes the runtime to store an undesirable amount of garbage,
to work around a bug in the semi-concrete interpreter failing to
correctly compute the inferred result. That should be fixed in the
semi-concrete interpreter, without bloating the runtime caches with
extraneous information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:don't squash Don't squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants