Skip to content

Fix #5521: prefix not checked in realizability check #5522

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

Merged
merged 3 commits into from
Dec 2, 2018

Conversation

abeln
Copy link
Contributor

@abeln abeln commented Nov 26, 2018

We were forgetting to check the prefix in the uncached case.

We were forgetting to check the prefix in the uncached case.
@abeln abeln requested a review from Blaisorblade November 28, 2018 22:13
@abeln
Copy link
Contributor Author

abeln commented Nov 28, 2018

@Blaisorblade do you have time to take a look? Guillaume mentioned on gitter that you were looking at CheckRealizable.

@Blaisorblade
Copy link
Contributor

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

Copy link
Contributor

@Blaisorblade Blaisorblade left a comment

Choose a reason for hiding this comment

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

Kudos for the find! See comment; a further (oneliner) change is probably needed.

r
val r1 = if (r == Realizable) {
sym.setFlag(Stable)
realizability(tp.prefix)
Copy link
Contributor

Choose a reason for hiding this comment

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

I looked at this time ago in #4036, I should look more closely, and I'm in a rush, but here are some initial comments.

I agree this is a bug and this change should give the correct behavior; but this change risks being pretty computationally expensive (possible fix below). This can duplicate recursive calls, and that risks causing exponential slowdowns. Triggering it might require a chain of final lazy vals or be impossible, but it's more robust to not duplicate calls.

If isLateInitialized(sym), this calls realizability(tp.prefix) again, and that can be too expensive. Caching only affects symbols, but we don't cache realizability on whole types; tp could not even be a TermRef and fall through boundsRealizability(tp).andAlso(memberRealizability(tp)).

I asked dottybot for a performance test. But maybe one could just reorganize the logic.
Looking at #4036 (which is where I "studied" this), I propose to add to your change the following:

-else if (!isLateInitialized(sym)) realizability(tp.prefix)
+else if (!isLateInitialized(sym)) Realizable

because in this branch we can certainly mark the symbol as stable (that PR also achieves this goal, though in a hackier way). If that works, this PR can go in with that fix.

Optional requests

Here's a couple of bonus requests one could fix here as well — if they are non-trivial, feel free to defer them. I should probably do these changes myself and PR them, I'm in a rush right now.

On performance: https://github.com/lampepfl/dotty/pull/4036/files#diff-0535d82f8f57a2204d6452bae575efc9 might be a useful test here (if it doesn't cause a stack overflow).

On error reporting, I think one could cherry-pick from #4036 the following:

-realizability(tp.prefix)
+realizability(tp.prefix).mapError(r => new ProblemInUnderlying(tp.prefix, r))

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/5522/ to see the changes.

Benchmarks is based on merging with master (f66225c)

This change also caches stability for the affected code path.
@Blaisorblade Blaisorblade dismissed their stale review November 29, 2018 23:15

Addressed myself

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Nov 29, 2018

@abeln To move things along I did the necessary changes myself — basic tests pass locally, let's see what the CI says. I've stuck to changes that really belong here to avoid scope creep.
EDIT: let me know what you think and if you want to do another pass, but otherwise we should be able to merge this.

@Blaisorblade
Copy link
Contributor

test performance please

@Blaisorblade Blaisorblade assigned Blaisorblade and unassigned abeln Dec 2, 2018
@dottybot
Copy link
Member

dottybot commented Dec 2, 2018

performance test scheduled: 1 job(s) in queue, 1 running.

@Blaisorblade
Copy link
Contributor

Martin wrote:

If you are comfortable with #5522, yes please go ahead and merge it. Maybe run a performance test again, to be sure.

so doing that.

@dottybot
Copy link
Member

dottybot commented Dec 2, 2018

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/5522/ to see the changes.

Benchmarks is based on merging with master (5d1efe3)

@Blaisorblade Blaisorblade merged commit e1ba839 into scala:master Dec 2, 2018
@abeln
Copy link
Contributor Author

abeln commented Dec 4, 2018

@Blaisorblade thanks for doing this, and sorry I didn't get to it myself! I got busy trying to get the flow-sensitive type inference to work for the null project (still working on it).

@abeln abeln deleted the prefix branch December 4, 2018 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants