UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

43 lines 2.02 kB
"use strict"; /* ---------------------------------------------------------------------------------- * Copyright 2022 Informal Systems * Licensed under the Apache License, Version 2.0. * See LICENSE in the project root for license information. * --------------------------------------------------------------------------------- */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeInferrer = void 0; const IRVisitor_1 = require("../ir/IRVisitor"); const constraintGenerator_1 = require("./constraintGenerator"); const constraintSolver_1 = require("./constraintSolver"); const simplification_1 = require("./simplification"); const lodash_1 = require("lodash"); class TypeInferrer extends constraintGenerator_1.ConstraintGeneratorVisitor { constructor(table, types) { super(constraintSolver_1.solveConstraint, table, types); } /** * Infers a type for each expression in a list of QuintDeclarations. If there * are missing types in the type map, there will be at least one error. * * @param declarations: the list of QuintDeclarations to infer types for * * @returns a map from expression ids to their type schemes and a map from expression * ids to the corresponding error for any problematic expressions. */ inferTypes(declarations) { const typeIdsBefore = Array.from(this.types.keys()); // Resolve all type applications used in expressions in the lookup table declarations.forEach(decl => { (0, IRVisitor_1.walkDeclaration)(this, decl); }); const typeIdsAfter = Array.from(this.types.keys()); const newTypeIds = (0, lodash_1.difference)(typeIdsAfter, typeIdsBefore); // Simplify all new types newTypeIds.forEach(id => { this.types.set(id, (0, simplification_1.simplify)(this.types.get(id))); }); return [this.errors, this.types]; } } exports.TypeInferrer = TypeInferrer; //# sourceMappingURL=inferrer.js.map