Class Resolver
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classVisitor that convertsAst.FromtoCore.Fromby handling each subtype ofAst.FromStepcallingFromBuilderappropriately.private static enumHelper for initialization.(package private) static classPattern and expression.(package private) static classVisitor that finds all references to unbound variables in an expression.(package private) static classResolved datatype declaration.static classResolved declaration.(package private) classResolved value declaration. -
Field Summary
FieldsModifier and TypeFieldDescriptionMap fromBuiltIn, toOp; the reverse ofOP_BUILT_IN_MAP, and needed when we convert an optimized expression back to human-readable Morel code.private final Environmentprivate final NameGeneratorprivate final @Nullable Session(package private) final TypeMapprivate final Map<Pair<Core.NamedPat, Type>, Core.NamedPat> Contains variable declarations whose type at the point they are used is different (more specific) than in their declaration. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateResolver(TypeMap typeMap, NameGenerator nameGenerator, Map<Pair<Core.NamedPat, Type>, Core.NamedPat> variantIdMap, Environment env, @Nullable Session session) -
Method Summary
Modifier and TypeMethodDescription(package private) static voidprivate Core.ExpflattenLet(List<Ast.Decl> decls, Ast.Exp exp) private Core.NamedPatConverts an Id that is a reference to a variable into an IdPat that represents its declaration.static Resolverof(TypeMap typeMap, Environment env, @Nullable Session session) Creates a root Resolver.private booleanreferences(List<Resolver.PatExp> patExps) Returns whether any of the expressions inexpsreferences and of the variables defined inpats.private Resolver.ResolvedDeclprivate Resolver.ResolvedDatatypeDeclresolveDatatypeDecl(Ast.DatatypeDecl decl, List<Binding> bindings) private Resolver.ResolvedValDeclresolveValDecl(Ast.ValDecl valDecl, List<Binding> bindings) private static booleanAn actual type subsumes an expected type if it is equal or if progressive record types have been expanded.private BuiltInprivate Core.AggregatetoCore(Ast.Aggregate aggregate, Collection<? extends Core.IdPat> groupKeys) private Core.Applyprivate Core.Caseprivate DataTypetoCore(Ast.DatatypeBind bind) toCore(Ast.DatatypeDecl datatypeDecl) private Core.Expprivate Core.Fn(package private) Core.Expprivate Core.Idprivate Core.Caseprivate Core.ApplytoCore(Ast.InfixCall call) private Core.Expprivate Core.ExptoCore(Ast.ListExp list) private Core.Matchprivate Core.OrderItemtoCore(Ast.OrderItem orderItem) private Core.Patprivate Core.Patprivate Core.PatConverts a pattern to Core.private Core.TupletoCore(Ast.Record record) private Core.RecordSelectortoCore(Ast.RecordSelector recordSelector) private Core.TupletoCore(Ast.ValDecl valDecl) private Core.ExptoCoreFromEq(Ast.Exp exp) Translates "x" in "from e = x".private Core.IdPatConverts an id in a declaration to Core.(package private) static ObjectvalueOf(Environment env, Core.Exp exp) final ResolverBinds a Resolver to an environment that consists of the current environment plus some bindings.withEnv(Environment env) Binds a Resolver to a new environment.
-
Field Details
-
OP_BUILT_IN_MAP
-
BUILT_IN_OP_MAP
Map fromBuiltIn, toOp; the reverse ofOP_BUILT_IN_MAP, and needed when we convert an optimized expression back to human-readable Morel code. -
typeMap
-
nameGenerator
-
env
-
session
-
variantIdMap
Contains variable declarations whose type at the point they are used is different (more specific) than in their declaration.For example, the infix operator "op +" has type "α * α →" in the base environment, but at point of use might instead be "int * int → int". This map will contain a new
Core.IdPatfor all points that use it with that second type. Effectively, it is a phantom declaration, in aletthat doesn't exist. Without this shared declaration, all points have their own distinctCore.IdPat, which theAnalyzerwill think is used just once.
-
-
Constructor Details
-
Resolver
private Resolver(TypeMap typeMap, NameGenerator nameGenerator, Map<Pair<Core.NamedPat, Type>, Core.NamedPat> variantIdMap, Environment env, @Nullable Session session)
-
-
Method Details
-
of
Creates a root Resolver. -
withEnv
Binds a Resolver to a new environment. -
withEnv
Binds a Resolver to an environment that consists of the current environment plus some bindings. -
toCore
-
toCore
Converts a simpleAst.ValDecl, of the formval v = e, to a CoreCore.ValDecl.Declarations such as
val (x, y) = (1, 2)andval emp :: rest = empsare considered complex, and are not handled by this method.Likewise recursive declarations.
-
toCore
-
resolve
-
resolveDatatypeDecl
private Resolver.ResolvedDatatypeDecl resolveDatatypeDecl(Ast.DatatypeDecl decl, List<Binding> bindings) -
resolveValDecl
-
references
Returns whether any of the expressions inexpsreferences and of the variables defined inpats.This method is used to decide whether it is safe to convert a recursive declaration into a non-recursive one.
-
toCore
-
toCore
-
toCore
-
toCorePat
Converts an id in a declaration to Core. -
getIdPat
Converts an Id that is a reference to a variable into an IdPat that represents its declaration. -
toCore
-
toCore
-
toCore
-
toCoreFromEq
Translates "x" in "from e = x". Desugar to the same as if they had written "from e in [x]". -
toCore
-
valueOf
-
toCore
-
toCore
-
toBuiltIn
-
toCore
-
toCore
-
toCore
-
toCore
-
flattenLet
-
flatten
-
toCore
-
toCore
-
toCore
Converts a pattern to Core.Expands a pattern if it is a record pattern that has an ellipsis or if the arguments are not in the same order as the labels in the type.
-
toCore
-
toCore
-
subsumes
An actual type subsumes an expected type if it is equal or if progressive record types have been expanded. -
toCore
-
toCore
-