Skip to content

Commit

Permalink
Merge pull request #1872 from usethesource/no-more-uuid-for-type-para…
Browse files Browse the repository at this point in the history
…meters

fixing the superfluous generation of enormous amounts of temporary tuple types with UUIDs for type parameter names.
  • Loading branch information
jurgenvinju authored Oct 13, 2023
2 parents a1c42cf + 976b864 commit 1e66c8b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public boolean next() {

if (dynMatchType.isOpen()) {
// type parameter hygiene required (consider self-application of a function like `&T id(&T v) = v`)
dynMatchType = AbstractFunction.renameType(dynMatchType, new HashMap<>());
dynMatchType = AbstractFunction.renameType(dynMatchType, new HashMap<>(), ctx.getCurrentAST().getLocation());
}

if (!declaredType.match(dynMatchType, dynBindings)) {
Expand All @@ -134,7 +134,7 @@ public boolean next() {
Type dynType = subject.getValue().getType();
if (dynType.isOpen()) {
// type parameter hygiene required (consider self-application of a function like `&T id(&T v) = v`)
dynType = AbstractFunction.renameType(dynType, new HashMap<>());
dynType = AbstractFunction.renameType(dynType, new HashMap<>(), ctx.getCurrentAST().getLocation());
}

if (!dynType.isSubtypeOf(declaredType.instantiate(ctx.getCurrentEnvt().getDynamicTypeBindings()))) {
Expand Down
10 changes: 5 additions & 5 deletions src/org/rascalmpl/interpreter/result/AbstractFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;

import org.rascalmpl.ast.AbstractAST;
import org.rascalmpl.ast.Expression;
import org.rascalmpl.ast.FunctionDeclaration;
Expand All @@ -45,6 +43,7 @@
import io.usethesource.vallang.IConstructor;
import io.usethesource.vallang.IExternalValue;
import io.usethesource.vallang.IListWriter;
import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.IWithKeywordParameters;
Expand Down Expand Up @@ -347,8 +346,9 @@ protected Type bindTypeParameters(Type actualStaticTypes, IValue[] actuals, Type
if (actualStaticTypes.isOpen()) {
// we have to make the environment hygenic now, because the caller scope
// may have the same type variable names as the current scope
actualStaticTypes = renameType(actualStaticTypes, renamings);
actualStaticTypes = renameType(actualStaticTypes, renamings, env.getLocation());
}


Map<Type, Type> staticBindings = new HashMap<Type, Type>();

Expand Down Expand Up @@ -394,13 +394,13 @@ protected static Type unrenameType(Map<Type, Type> renamings, Type resultType) {
return resultType;
}

public static Type renameType(Type actualTypes, Map<Type, Type> renamings) {
public static Type renameType(Type actualTypes, Map<Type, Type> renamings, ISourceLocation uniquePrefix) {
actualTypes.match(TypeFactory.getInstance().voidType(), renamings);

// rename all the bound type parameters
for (Entry<Type,Type> entry : renamings.entrySet()) {
Type key = entry.getKey();
renamings.put(key, TypeFactory.getInstance().parameterType(key.getName() + ":" + UUID.randomUUID().toString(), key.getBound()));
renamings.put(key, TypeFactory.getInstance().parameterType(key.getName() + ":" + uniquePrefix, key.getBound()));
}
actualTypes = actualTypes.instantiate(renamings);
return actualTypes;
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/interpreter/result/NamedFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected void checkReturnTypeIsNotVoid(List<Expression> formals, IValue[] actua
Map<Type, Type> bindings = new HashMap<>();

for (int i = 0; i < actuals.length; i++) {
formals.get(i).typeOf(declarationEnvironment, getEval(), false).match(renameType(actuals[i].getType(), renamings), bindings);
formals.get(i).typeOf(declarationEnvironment, getEval(), false).match(renameType(actuals[i].getType(), renamings, ctx.getCurrentAST().getLocation()), bindings);
}

if (!getReturnType().isBottom() && getReturnType().instantiate(bindings).isBottom()) {
Expand Down
1 change: 0 additions & 1 deletion src/org/rascalmpl/interpreter/result/RascalFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ private List<Statement> cloneBody() {
return getAst().clone(body);
}


private String computeIndexedLabel(int pos, AbstractAST ast) {
return ast.accept(new NullASTVisitor<String>() {
@Override
Expand Down
3 changes: 2 additions & 1 deletion src/org/rascalmpl/values/RascalFunctionValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public IFunction loadParsers(ISourceLocation saveLocation, IBool allowAmbiguity,
tf.tupleType(rtf.reifiedType(parameterType), tf.valueType(), tf.sourceLocationType()),
tf.tupleEmpty());

@SuppressWarnings({"unchecked"})
final Class<IGTD<IConstructor, ITree, ISourceLocation>> parser
= (Class<IGTD<IConstructor, ITree, ISourceLocation>>) ctx.getEvaluator()
.__getJavaBridge().loadClass(URIResolverRegistry.getInstance().getInputStream(saveLocation));
Expand All @@ -329,7 +330,7 @@ public IFunction loadParser(IValue reifiedGrammar, ISourceLocation saveLocation,
tf.tupleType(tf.valueType(), tf.sourceLocationType()),
tf.tupleEmpty());


@SuppressWarnings({"unchecked"})
final Class<IGTD<IConstructor, ITree, ISourceLocation>> parser
= (Class<IGTD<IConstructor, ITree, ISourceLocation>>) ctx.getEvaluator()
.__getJavaBridge().loadClass(URIResolverRegistry.getInstance().getInputStream(saveLocation));
Expand Down

0 comments on commit 1e66c8b

Please sign in to comment.