Class Resolver
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classVisitor that converts aAst.From,Ast.ExistsorAst.ForalltoCore.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 Core.Expprivate final Environmentprivate final NameGeneratorprivate final Map<String, Pair<Core.IdPat, List<Core.IdPat>>> private 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, Map<String, Pair<Core.IdPat, List<Core.IdPat>>> resolvedOverloads, Environment env, @Nullable Session session, @Nullable Core.Exp current) -
Method Summary
Modifier and TypeMethodDescription(package private) static voidprivate Core.ExpflattenLet(List<Ast.Decl> decls, Ast.Exp exp) private Core.NamedPatgetIdPat(Ast.Id id, Core.NamedPat coreId) Converts an Id that is a reference to a variable into an IdPat that represents its declaration.private @Nullable Core.IdPatgetOverload(Core.IdPat pat) 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 static Resolver.ResolvedDeclresolveOverDecl(Ast.OverDecl ignoredDecl, List<Binding> ignoredBindings) private Resolver.ResolvedValDeclresolveValDecl(Ast.ValDecl valDecl, List<Binding> bindings) 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 Core.ExptoCore(Ast.Current ignoredCurrent) private DataTypetoCore(Ast.DatatypeBind bind) toCore(Ast.DatatypeDecl datatypeDecl) private Core.Expprivate Core.Fnprivate Core.Idprivate Core.Caseprivate Core.ApplytoCore(Ast.InfixCall call) private Core.Expprivate Core.ExptoCore(Ast.ListExp list) private Core.Matchprivate Core.ExptoCore(Ast.Ordinal ordinal) private Core.Patprivate Core.PatConverts a pattern to Core, reusing an existingCore.IdPatifinst.private Core.Patprivate Core.PatConverts a pattern to Core.(package private) Core.Expprivate Core.TupletoCore(Ast.Record record) private Core.RecordSelectortoCore(Ast.RecordSelector recordSelector) private Core.TupletoCore(Ast.ValDecl valDecl) toCore(TypeSystem typeSystem, Ast.OverDecl overDecl) Converts anAst.OverDeclto a CoreCore.OverDecl.private Core.ExptoCoreFromEq(Ast.Exp exp) Translates "x" in "from e = x".private Core.ExptoCoreImplies(Ast.Exp a0, Ast.Exp a1) Translate "p implies q" as "(not p) orelse q".private Core.IdPatConverts an id in a declaration to Core.(package private) static ObjectvalueOf(Environment env, Core.Exp exp) private ResolverwithCurrent(Core.Exp current) 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
-
current
-
resolvedOverloads
-
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, Map<String, Pair<Core.IdPat, List<Core.IdPat>>> resolvedOverloads, Environment env, @Nullable Session session, @Nullable Core.Exp current)
-
-
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. -
withCurrent
-
toCore
-
toCore
Converts anAst.OverDeclto a CoreCore.OverDecl. -
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.
-
getOverload
-
toCore
-
resolve
-
resolveDatatypeDecl
private Resolver.ResolvedDatatypeDecl resolveDatatypeDecl(Ast.DatatypeDecl decl, List<Binding> bindings) -
resolveOverDecl
private static Resolver.ResolvedDecl resolveOverDecl(Ast.OverDecl ignoredDecl, List<Binding> ignoredBindings) -
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
-
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
-
toCoreImplies
Translate "p implies q" as "(not p) orelse q". -
toBuiltIn
-
toCore
-
toCore
-
toCore
-
toCore
-
flattenLet
-
flatten
-
toCore
-
toCore
Converts a pattern to Core, reusing an existingCore.IdPatifinst. -
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
-