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

Don't use typecheck rule for non FOIs in refine imports plugin #2995

Merged
merged 1 commit into from Jul 21, 2022

Conversation

wz1000
Copy link
Collaborator

@wz1000 wz1000 commented Jun 28, 2022

Also add an assertion to check that we never use non-FOI rules

Fixes #2962

@wz1000 wz1000 requested a review from pepeiborra as a code owner June 28, 2022 08:34
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

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

LGTM!

-- We should only call the typecheck rule for files of interest.
-- Keeping typechecked modules in memory for other files is
-- very expensive.
assert (foi /= NotFOI) $ typeCheckRuleDefinition hsc pm
Copy link
Contributor

Choose a reason for hiding this comment

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

I have this assertion locally and it often fails for me but not necessarily in bad ways, just seems there is a race?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you get a call stack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you close a file while a typecheck has been queued, then on restart that typecheck will be executed, but the assertion will fail because it is not an FOI any longer.

I think this is harmless because it should be garbage collected soon after?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds like a good reason to make it just a warning :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but I think the false positive rate can be very high to the point of being annoying. Maybe we should just silently log it, with a message that explains this caveat and asks for a bug report.

Something to effect of "Warning: Typecheck executed for file that is not currently open. This is harmless if this file was recently open and has now been closed. If not, please report a bug."

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you close a file while a typecheck has been queued,

Can the check be moved to the code that schedules the typecheck?

-- We should only call the typecheck rule for files of interest.
-- Keeping typechecked modules in memory for other files is
-- very expensive.
assert (foi /= NotFOI) $ typeCheckRuleDefinition hsc pm
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is pretty aggressive, right? It'll throw, and presumably crash HLS? Couldn't we just log the occurrence?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Assertions are disabled by -O. So this assert won't trigger for users, and I doubt it will even trigger in CI

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, then I think we should definitely log too! I would like to know if this is happening in general usage as well. A warning log would be fine.

@michaelpj
Copy link
Collaborator

Ah, the same mysterious ghcide windows failure that I was getting! That makes me feel much better that it's not actually my fault 😂 Would be nice if we had any idea what's going on there though.

@michaelpj
Copy link
Collaborator

@wz1000 add a log and I think we can merge this?

@wz1000 wz1000 force-pushed the wip/foi-no-typecheck branch 2 times, most recently from b710651 to a3d45f4 Compare July 20, 2022 17:50
Also add an assertion to check that we never use non-FOI rules

Fixes #2962
@wz1000 wz1000 merged commit c045857 into master Jul 21, 2022
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.

refineImports plugin causes excessive memory use
5 participants