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

New timing for generating refinement constraints #316

Open
d367wang opened this issue Mar 30, 2021 · 0 comments
Open

New timing for generating refinement constraints #316

d367wang opened this issue Mar 30, 2021 · 0 comments

Comments

@d367wang
Copy link

d367wang commented Mar 30, 2021

Originally the refinement constraints (i.e. equality constraint of form "refinement var == rhs value"), are created in InferenceVisitor.commonAssignmentCheck. This leads to the hack of overriding the LHS type with the refinement value in the dataflow transfer function, which is misleading.

To avoid hacking, PR #314 change the timing for refinement constraint generation when the LHS is declared type, from InferenceVisitor.commonAssignmentCheck to InferenceTransfer.visitAssignment. In other word, we create equality constraint once a new refinement variable is created.

The benefit of this change is that the type inference and type checking are unified in one single type rule:
LHS <: RHS.

Another benefit is that for posfix-increment/decrement expression specifically, it saves the work of caching the pre-state of increment/decrement and retrieving it when creating constraints. The logic becomes concise and straightforward for x++:
refinement constraints are naturally created along with the dataflow analysis so that no caching-retrieving is needed.

PR #314 doesn't handle the cases when LHS is type variable or wildcard, since type refinement in CFI is still unsound. We will finally handle this in the same way as above.

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

No branches or pull requests

1 participant