-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
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) | ||
} | ||
} |
There was a problem hiding this comment.
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.
default: | ||
msg = 'Unknown error' |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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.
if (!ir.isQuintBuiltin(app)) { | ||
this.applyUserDefined(app) | ||
} else { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
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
bab46d9
to
db9fbbb
Compare
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 adetailed 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.
CHANGELOG.md
for any new functionalityREADME.md
updated for any listed functionality