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

Make applyDebug's free variable check take the context into account #2624

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

leonschoorl
Copy link
Member

Fixes #2623

Still TODO:

  • Write a changelog entry (see changelog/README.md)
  • Check copyright notices are up to date in edited files

Copy link
Member

@martijnbastiaan martijnbastiaan left a comment

Choose a reason for hiding this comment

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

LGTM in general! Reformat of comment + question about it in the comments.

Comment on lines +276 to +282
-- Since [Give evaluator acces to inscope let-bindings #2571](https://github.com/clash-lang/clash-compiler/pull/2571)
-- the evaluator can rewrite expressions using let bindings from the 'TransformContext',
-- these bindings may reference other things bound in the context which weren't
-- in the expression before, and in doing so introduces new free variables and
-- fails this check for new free variables.
-- To prevent this we filter out all variables from bound in the context.
-- But only during a caseCon transformation, to not weaken this check unnecessarily.
Copy link
Member

@martijnbastiaan martijnbastiaan Jan 2, 2024

Choose a reason for hiding this comment

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

Suggested change
-- Since [Give evaluator acces to inscope let-bindings #2571](https://github.com/clash-lang/clash-compiler/pull/2571)
-- the evaluator can rewrite expressions using let bindings from the 'TransformContext',
-- these bindings may reference other things bound in the context which weren't
-- in the expression before, and in doing so introduces new free variables and
-- fails this check for new free variables.
-- To prevent this we filter out all variables from bound in the context.
-- But only during a caseCon transformation, to not weaken this check unnecessarily.
-- Since [Give evaluator acces to inscope let-bindings #2571](https://github.com/clash-lang/clash-compiler/pull/2571)
-- the evaluator can rewrite expressions using let bindings from the 'TransformContext'.
-- These bindings may reference other things bound in the context which weren't
-- in the expression before, and in doing so introduces new free variables. Consequently,
-- this fails a check that prevents new free variables from being introduced -
-- as this is a bug in all other cases. To prevent this we filter out all
-- variables from bound in the context. We only do this during a 'caseCon' transformation,
-- to not weaken this check unnecessarily.

I've reformatted / broke up sentences to make it easier to read.

I'm not sure about this though:

We only do this during a 'caseCon' transformation,
to not weaken this check unnecessarily.

Is this because the evaluator is only called in caseCon? In any case, I think we should defend why we think we only need to do it for caseCon in the note.

Copy link
Member

Choose a reason for hiding this comment

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

@christiaanb maybe you could comment on this?

Copy link
Member

Choose a reason for hiding this comment

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

The evaluator is called in multiple places, including caseCon. But as @leonschoorl points out, the "introduce free variables" check is quite useful to catch bugs in the Clash compiler, so we want to leave it enabled in as many places as possible. So it's only disabled in caseCon as we have a confirmed "false positive" for that transformation.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, this sounds like: we're aware this is an issue, and we're going to wait until another transformation calling the evaluator is going to blow up..

What we should do is check the other transformations calling the evaluator, check whether they suffer from the same issue, and add a comment explaining why we do (not) need a similar approach as introduced in this PR.

@martijnbastiaan martijnbastiaan enabled auto-merge (squash) February 27, 2024 08:44
@martijnbastiaan martijnbastiaan merged commit 0aa341a into master Feb 27, 2024
12 checks passed
@martijnbastiaan martijnbastiaan deleted the fix-FV-check branch February 27, 2024 10:23
mergify bot pushed a commit that referenced this pull request Feb 27, 2024
martijnbastiaan pushed a commit that referenced this pull request Feb 27, 2024
…2624) (#2681)

Fixes #2623

(cherry picked from commit 0aa341a)

Co-authored-by: Leon Schoorl <leon@qbaylogic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

caseCon introduces free variables because of evaluator changes
3 participants