Skip to content

Commit

Permalink
Remove TypeMap.nodeTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
julianhyde committed Dec 24, 2023
1 parent 9cba23e commit c8b13e2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 29 deletions.
8 changes: 0 additions & 8 deletions src/main/java/net/hydromatic/morel/compile/Resolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,6 @@ Object valueOf(Core.Exp exp) {
final Core.Id id = (Core.Id) exp;
Binding binding = env.getOpt(id.idPat);
if (binding != null) {
if (binding.value == Codes.SYS_FILE) { // TODO: is this 'if' still used
// We can't evaluate, because we don't have an EvalEnv. But we
// can go straight to the Session.
if (session == null) {
return null;
}
return session.file.get();
}
return binding.value;
}
}
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/net/hydromatic/morel/compile/TypeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package net.hydromatic.morel.compile;

import net.hydromatic.morel.ast.Ast;
import net.hydromatic.morel.ast.AstNode;
import net.hydromatic.morel.type.ProgressiveRecordType;
import net.hydromatic.morel.type.RecordType;
Expand Down Expand Up @@ -57,13 +56,6 @@ public class TypeMap {
* sufficient. */
private final Map<String, TypeVar> typeVars = new HashMap<>();

/** Types for nodes that have been refined using progressive types.
*
* <p>For example, after type deduction "file.data" has type "{...}" but
* after expansion that type has become type "{scott: {...}, wordle: {...}}".
* We want to use that expanded type for the rest of preparation. */
private final Map<AstNode, Type> nodeTypes = new HashMap<>(); // TODO remove?

TypeMap(TypeSystem typeSystem, Map<AstNode, Unifier.Term> nodeTypeTerms,
Unifier.Substitution substitution) {
this.typeSystem = requireNonNull(typeSystem);
Expand Down Expand Up @@ -91,18 +83,12 @@ Type termToType(Unifier.Term term) {

/** Returns the type of an AST node. */
public Type getType(AstNode node) {
if (nodeTypes.containsKey(node)) {
return nodeTypes.get(node);
}
final Unifier.Term term = requireNonNull(nodeTypeTerms.get(node));
return termToType(term);
}

/** Returns the type of an AST node, or null if no type is known. */
public @Nullable Type getTypeOpt(AstNode node) {
if (nodeTypes.containsKey(node)) {
return nodeTypes.get(node);
}
final Unifier.Term term = nodeTypeTerms.get(node);
return term == null ? null : termToType(term);
}
Expand Down Expand Up @@ -130,10 +116,6 @@ public boolean hasType(AstNode node) {
return nodeTypeTerms.containsKey(node);
}

public void overrideType(Ast.Exp exp, Type type) {
nodeTypes.put(exp, type);
}

/** Visitor that converts type terms into actual types. */
private static class TermToTypeConverter
implements Unifier.TermVisitor<Type> {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/hydromatic/morel/compile/TypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,9 @@ private static boolean isProgressive(Type type) {
typedValue.discoverField(typeSystem, selector.name);
final RecordLikeType type =
(RecordLikeType) typedValue.typeKey().toType(typeSystem);
// TODO do we need overrideType?
typeMap.overrideType(exp, type.argNameTypes().get(selector.name));
int i =
ImmutableList.copyOf(type.argNameTypes().keySet())
.indexOf(selector.name); // subtract 1 for $dummy; TODO
.indexOf(selector.name);
if (i >= 0) { // TODO: add a method TypedValue.fieldValue(name)
@SuppressWarnings("unchecked")
final List<Codes.TypedValue> list = typedValue.valueAs(List.class);
Expand Down

0 comments on commit c8b13e2

Please sign in to comment.