Package net.hydromatic.morel.compile
Class TypeResolver
java.lang.Object
net.hydromatic.morel.compile.TypeResolver
Resolves the type of an expression.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA type environment that consists of a type environment plus one binding.private static classEmpty substitution.(package private) static enumEmpty type environment.(package private) static classVisitor that expands progressive types if they are used in field references.private static classWorkspace for converting types to keys.private static classSubstitution that adds one (type, variable) assignment to a parent substitution.static classResult of validating a declaration.private static classSubstitution.private static classPair consisting of a term and a variable.(package private) static interfaceType environment.private classContains aTypeResolver.TypeEnvand adds to it by callingTypeResolver.TypeEnv.bind(String, Function).static classError while deducing type. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<Unifier.Variable, Unifier.Action> (package private) static final String(package private) static final Stringprivate final Map<AstNode, Unifier.Term> private final PairList<Unifier.Variable, PrimitiveType> (package private) static final StringA field of this name indicates that a record type is progressive.(package private) static final Stringprivate final List<TypeResolver.TermVariable> (package private) static final Stringprivate final TypeSystemprivate final Unifier -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static TypeResolver.TypeEnvbindAll(TypeResolver.TypeEnv env, Map<Ast.IdPat, Unifier.Term> termMap) private static voidcheckNoUnresolvedFieldRefs(Ast.Decl decl, TypeMap typeMap) Checks that there are no field references "x.y" or "#y x" where "x" has an unresolved type.private voiddeduceDatatypeBindType(Ast.DatatypeBind datatypeBind, SortedMap<String, Type.Key> tyCons) private Ast.DecldeduceDataTypeDeclType(TypeResolver.TypeEnv env, Ast.DatatypeDecl datatypeDecl, Map<Ast.IdPat, Unifier.Term> termMap) private Ast.DecldeduceDeclType(TypeResolver.TypeEnv env, Ast.Decl node, Map<Ast.IdPat, Unifier.Term> termMap) deduceMatchListType(TypeResolver.TypeEnv env, List<Ast.Match> matchList, NavigableSet<String> labelNames, Unifier.Variable argVariable, Unifier.Variable resultVariable) private Ast.MatchdeduceMatchType(TypeResolver.TypeEnv env, Ast.Match match, Map<Ast.IdPat, Unifier.Term> termMap, Unifier.Variable argVariable, Unifier.Variable resultVariable) private Ast.PatdeducePatType(TypeResolver.TypeEnv env, Ast.Pat pat, Map<Ast.IdPat, Unifier.Term> termMap, NavigableSet<String> labelNames, Unifier.Variable v) Derives a type term for a pattern, collecting the names of pattern variables.private Ast.RecordSelectordeduceRecordSelectorType(TypeResolver.TypeEnv env, Unifier.Variable vResult, Unifier.Variable vArg, Ast.RecordSelector recordSelector) private Pair<TypeResolver.TypeEnv, Unifier.Variable> deduceStepType(TypeResolver.TypeEnv env, Ast.FromStep step, Unifier.Variable v, TypeResolver.TypeEnv env2, Map<Ast.Id, Unifier.Variable> fieldVars, List<Ast.FromStep> fromSteps) static TypeResolver.ResolveddeduceType(Environment env, Ast.Decl decl, TypeSystem typeSystem) Deduces the datatype of a declaration.private Ast.ExpdeduceType(TypeResolver.TypeEnv env, Ast.Exp node, Unifier.Variable v) private TypeResolver.ResolveddeduceType_(Environment env, Ast.Decl decl) private AstNodededuceValBindType(TypeResolver.TypeEnv env, Ast.ValBind valBind, Map<Ast.IdPat, Unifier.Term> termMap, Unifier.Variable v, Unifier.Variable vPat) private Ast.DecldeduceValDeclType(TypeResolver.TypeEnv env, Ast.ValDecl valDecl, Map<Ast.IdPat, Unifier.Term> termMap) private voidequiv(Unifier.Term term, Unifier.Term term2) private voidequiv(Unifier.Term term, Unifier.Variable atom) fieldList(Unifier.Sequence sequence) private Unifier.TermfieldRecord(Map<Ast.Id, Unifier.Variable> fieldVars) private static voidforEachUnresolvedField(Ast.Decl decl, TypeMap typeMap, Consumer<Ast.Apply> consumer) private static Ast.ExpConverts a list of variable names to a variable or tuple.private Ast.Expinfix(TypeResolver.TypeEnv env, Ast.InfixCall call, Unifier.Variable v) Registers an infix operator.private Ast.Expinfix(TypeResolver.TypeEnv env, Ast.InfixCall call, Unifier.Variable v, Type type) Registers an infix operator whose type is a given type.private Ast.PatpatTuple(TypeResolver.TypeEnv env, List<Ast.Pat> patList) Converts a list of patterns to a singleton pattern or tuple pattern.private Ast.Expprefix(TypeResolver.TypeEnv env, Ast.PrefixCall call, Unifier.Variable v) Registers a prefix operator.private Unifier.Termrecord(NavigableMap<String, ? extends Unifier.Term> labelTypes) private <E extends AstNode>
Ereg(E node, Unifier.Variable variable, Unifier.Term term) private Unifier.TermtoTerm(PrimitiveType type) private Unifier.TermtoTerm(Type type, TypeResolver.Subst subst) private List<Unifier.Term> toTerms(Iterable<? extends Type> types, TypeResolver.Subst subst) static TypetoType(Ast.Type type, TypeSystem typeSystem) Converts a type AST to a type.static Type.KeyConverts a type AST to a type key.private Ast.ValBindtoValBind(TypeResolver.TypeEnv env, Ast.FunBind funBind) private Ast.ValDecltoValDecl(TypeResolver.TypeEnv env, Ast.FunDecl funDecl) Converts a function declaration to a value declaration.private Unifier.Termtuple(List<Unifier.Term> types) private voidvalidateGroup(Ast.Group group) Validates aGroup.
-
Field Details
-
typeSystem
-
unifier
-
terms
-
map
-
actionMap
-
preferredTypes
-
TUPLE_TY_CON
- See Also:
-
LIST_TY_CON
- See Also:
-
RECORD_TY_CON
- See Also:
-
FN_TY_CON
- See Also:
-
PROGRESSIVE_LABEL
A field of this name indicates that a record type is progressive.- See Also:
-
-
Constructor Details
-
TypeResolver
-
-
Method Details
-
deduceType
public static TypeResolver.Resolved deduceType(Environment env, Ast.Decl decl, TypeSystem typeSystem) Deduces the datatype of a declaration. -
toType
Converts a type AST to a type. -
toTypeKey
Converts a type AST to a type key. -
deduceType_
-
checkNoUnresolvedFieldRefs
Checks that there are no field references "x.y" or "#y x" where "x" has an unresolved type. Throws if there are unresolved field references. -
forEachUnresolvedField
-
reg
-
deduceType
-
deduceStepType
private Pair<TypeResolver.TypeEnv,Unifier.Variable> deduceStepType(TypeResolver.TypeEnv env, Ast.FromStep step, Unifier.Variable v, TypeResolver.TypeEnv env2, Map<Ast.Id, Unifier.Variable> fieldVars, List<Ast.FromStep> fromSteps) -
validateGroup
Validates aGroup. Throws if there are duplicate names among the keys and aggregates. -
fieldRecord
-
tuple
-
deduceRecordSelectorType
private Ast.RecordSelector deduceRecordSelectorType(TypeResolver.TypeEnv env, Unifier.Variable vResult, Unifier.Variable vArg, Ast.RecordSelector recordSelector) -
fieldList
-
deduceMatchType
private Ast.Match deduceMatchType(TypeResolver.TypeEnv env, Ast.Match match, Map<Ast.IdPat, Unifier.Term> termMap, Unifier.Variable argVariable, Unifier.Variable resultVariable) -
deduceValBindType
private AstNode deduceValBindType(TypeResolver.TypeEnv env, Ast.ValBind valBind, Map<Ast.IdPat, Unifier.Term> termMap, Unifier.Variable v, Unifier.Variable vPat) -
bindAll
private static TypeResolver.TypeEnv bindAll(TypeResolver.TypeEnv env, Map<Ast.IdPat, Unifier.Term> termMap) -
deduceDeclType
private Ast.Decl deduceDeclType(TypeResolver.TypeEnv env, Ast.Decl node, Map<Ast.IdPat, Unifier.Term> termMap) -
deduceDataTypeDeclType
private Ast.Decl deduceDataTypeDeclType(TypeResolver.TypeEnv env, Ast.DatatypeDecl datatypeDecl, Map<Ast.IdPat, Unifier.Term> termMap) -
deduceValDeclType
private Ast.Decl deduceValDeclType(TypeResolver.TypeEnv env, Ast.ValDecl valDecl, Map<Ast.IdPat, Unifier.Term> termMap) -
deduceDatatypeBindType
private void deduceDatatypeBindType(Ast.DatatypeBind datatypeBind, SortedMap<String, Type.Key> tyCons) -
toValDecl
Converts a function declaration to a value declaration. In other words,funis syntactic sugar, and this is the de-sugaring machine.For example,
fun inc x = x + 1becomesval rec inc = fn x => x + 1.If there are multiple arguments, there is one
fnfor each argument:fun sum x y = x + ybecomesval rec sum = fn x => fn y => x + y.If there are multiple clauses, we generate
case:fun gcd a 0 = a | gcd a b = gcd b (a mod b)becomesval rec gcd = fn x => fn y => case (x, y) of (a, 0) => a | (a, b) = gcd b (a mod b). -
toValBind
-
idTuple
-
patTuple
Converts a list of patterns to a singleton pattern or tuple pattern. -
infix
Registers an infix operator whose type is a given type. -
infix
Registers an infix operator. -
prefix
Registers a prefix operator. -
equiv
-
equiv
-
toTerms
-
toTerm
-
toTerm
-