Skip to content

Commit

Permalink
Merge pull request #1483 from informalsystems/gabriela/type-simp-perf…
Browse files Browse the repository at this point in the history
…ormance-fix

Simplify only new types to improve performance on incremental analysis
  • Loading branch information
bugarela authored Aug 21, 2024
2 parents 26733f0 + 727431c commit 89db9d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
### Changed

- Performance of incrementally checking types (i.e. in REPL) was improved (#1483).

### Deprecated
### Removed
### Fixed
Expand Down
14 changes: 12 additions & 2 deletions quint/src/types/inferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TypeScheme } from './base'
import { ConstraintGeneratorVisitor } from './constraintGenerator'
import { solveConstraint } from './constraintSolver'
import { simplify } from './simplification'
import { difference } from 'lodash'

export type TypeInferenceResult = [Map<bigint, ErrorTree>, Map<bigint, TypeScheme>]

Expand All @@ -39,11 +40,20 @@ export class TypeInferrer extends ConstraintGeneratorVisitor {
* ids to the corresponding error for any problematic expressions.
*/
inferTypes(declarations: QuintDeclaration[]): TypeInferenceResult {
const typeIdsBefore = Array.from(this.types.keys())

// Resolve all type applications used in expressions in the lookup table
declarations.forEach(decl => {
walkDeclaration(this, decl)
})
const simplifiedTypes = new Map([...this.types.entries()].map(([id, t]) => [id, simplify(t)]))
return [this.errors, simplifiedTypes]

const typeIdsAfter = Array.from(this.types.keys())
const newTypeIds = difference(typeIdsAfter, typeIdsBefore)
// Simplify all new types
newTypeIds.forEach(id => {
this.types.set(id, simplify(this.types.get(id)!))
})

return [this.errors, this.types]
}
}

0 comments on commit 89db9d7

Please sign in to comment.