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

Fix non-exhaustive switches #1092

Merged
merged 5 commits into from
Aug 7, 2023

Conversation

shonfeder
Copy link
Contributor

@shonfeder shonfeder commented Aug 4, 2023

While working on the second part of #1082 I realized that there are a lot of places
where we had created type checking blind spots due to our use of mutation in
control flow via switches that really require exhaustive analysis of data types
they are operating on. This refactoring pass fixes all the places I could find
readily. This should make it a bit easier to finish #1082 correctly and should
make our code base a bit more maintainable in general.

Please see the addition to our CONTRIBUTING.md in the first commit for a
detailed explanation and rationale.

Also closes #196, tho we will probably need followup to ensure the type is being
used everywhere it should be.

Reviewing

Please review ignoring whitespace. It's a considerably smaller diff that git is reckoning, and the bloat is just from whitespace changes required by restructuring some conditionals.

  • [-] Tests added for any new code
  • Documentation added for any new functionality
  • [-] Entries added to the respective CHANGELOG.md for any new functionality
  • [-] Feature table on README.md updated for any listed functionality

Comment on lines +430 to 449
case 'let':
{
if (transformer.enterLet) {
newExpr = transformer.enterLet(newExpr)
}

const opdef = transformDefinition(transformer, newExpr.opdef)
if (opdef.kind !== 'def') {
// This should only happen if we write a bad transformer. Should never
// be a user facing issue.
throw new Error('Let operator definition transformed into non-operator definition')
}

newExpr.opdef = opdef
newExpr.expr = transformExpression(transformer, newExpr.expr)

if (transformer.exitLet) {
newExpr = transformer.exitLet(newExpr)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was just a formatting change.

Comment on lines -534 to -535
default:
msg = 'Unknown error'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case was redundant b/c it's checked for in the if on line 483.

return entities.length > 1 ? { kind: 'union', entities: entities } : entities[0]
} else {
return { kind: 'concrete', stateVariables: vars }
if (entity.kind == 'union') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this from a switch that just had one branch to a conditional.

Comment on lines +395 to +397
if (!ir.isQuintBuiltin(app)) {
this.applyUserDefined(app)
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only change here was adding a conditional using a type guard to check whether we have a builtin before dispatching the builtins.

@@ -51,49 +52,44 @@ export function compose(table: LookupTable, s1: Substitutions, s2: Substitutions
* given type
*/
export function applySubstitution(table: LookupTable, subs: Substitutions, t: QuintType): QuintType {
let result = t
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Swapping out the mutable assignment for returning computed data.

Copy link
Contributor

@thpani thpani left a comment

Choose a reason for hiding this comment

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

Good find, looks great!

Shon Feder added 5 commits August 7, 2023 14:30
See the accompanying addition to the readme for the motivation and
rationale.
Also adds a type for the builtin operator opcodes.
Apparently one of the hygiene fixes also fixed the tests for union
types (which will be trashing soon) :D
@thpani thpani force-pushed the static-exhaustiveness-checks-on-visitor-switches branch from bab46d9 to db9fbbb Compare August 7, 2023 12:30
@thpani thpani enabled auto-merge August 7, 2023 12:30
@thpani thpani merged commit fd9bcda into main Aug 7, 2023
@thpani thpani deleted the static-exhaustiveness-checks-on-visitor-switches branch August 7, 2023 12:41
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.

Centralize mapping of operators parsed from symbols
2 participants