From eb2c37685dae7d08dd243b1251e5ec3f12043c07 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 12 Oct 2023 21:29:03 +0200 Subject: [PATCH 1/2] fixing the superfluous generation of enormous amounts of temporary tuple types with UUIDs for type parameter names. --- .../interpreter/matching/TypedVariablePattern.java | 4 ++-- .../rascalmpl/interpreter/result/AbstractFunction.java | 9 ++++----- src/org/rascalmpl/interpreter/result/NamedFunction.java | 2 +- src/org/rascalmpl/interpreter/result/RascalFunction.java | 1 - src/org/rascalmpl/values/RascalFunctionValueFactory.java | 3 ++- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java b/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java index ef64cf610df..6e3ccdb6c26 100644 --- a/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java +++ b/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java @@ -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<>(), Integer.toString(ctx.getCurrentAST().getLocation().getOffset())); } if (!declaredType.match(dynMatchType, dynBindings)) { @@ -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<>(), Integer.toString(ctx.getCurrentAST().getLocation().getOffset())); } if (!dynType.isSubtypeOf(declaredType.instantiate(ctx.getCurrentEnvt().getDynamicTypeBindings()))) { diff --git a/src/org/rascalmpl/interpreter/result/AbstractFunction.java b/src/org/rascalmpl/interpreter/result/AbstractFunction.java index 7a453732d21..c68b5beccda 100644 --- a/src/org/rascalmpl/interpreter/result/AbstractFunction.java +++ b/src/org/rascalmpl/interpreter/result/AbstractFunction.java @@ -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; @@ -347,8 +345,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, Integer.toString(env.getLocation().getOffset())); } + Map staticBindings = new HashMap(); @@ -394,13 +393,13 @@ protected static Type unrenameType(Map renamings, Type resultType) { return resultType; } - public static Type renameType(Type actualTypes, Map renamings) { + public static Type renameType(Type actualTypes, Map renamings, String uniquePrefix) { actualTypes.match(TypeFactory.getInstance().voidType(), renamings); // rename all the bound type parameters for (Entry 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; diff --git a/src/org/rascalmpl/interpreter/result/NamedFunction.java b/src/org/rascalmpl/interpreter/result/NamedFunction.java index d6f48776587..9523c20c6a1 100644 --- a/src/org/rascalmpl/interpreter/result/NamedFunction.java +++ b/src/org/rascalmpl/interpreter/result/NamedFunction.java @@ -164,7 +164,7 @@ protected void checkReturnTypeIsNotVoid(List formals, IValue[] actua Map 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, Integer.toString(ctx.getCurrentAST().getLocation().getOffset())), bindings); } if (!getReturnType().isBottom() && getReturnType().instantiate(bindings).isBottom()) { diff --git a/src/org/rascalmpl/interpreter/result/RascalFunction.java b/src/org/rascalmpl/interpreter/result/RascalFunction.java index 390142ec8e7..7eabbc774e7 100644 --- a/src/org/rascalmpl/interpreter/result/RascalFunction.java +++ b/src/org/rascalmpl/interpreter/result/RascalFunction.java @@ -128,7 +128,6 @@ private List cloneBody() { return getAst().clone(body); } - private String computeIndexedLabel(int pos, AbstractAST ast) { return ast.accept(new NullASTVisitor() { @Override diff --git a/src/org/rascalmpl/values/RascalFunctionValueFactory.java b/src/org/rascalmpl/values/RascalFunctionValueFactory.java index 5f462421c07..9e496b66c46 100644 --- a/src/org/rascalmpl/values/RascalFunctionValueFactory.java +++ b/src/org/rascalmpl/values/RascalFunctionValueFactory.java @@ -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> parser = (Class>) ctx.getEvaluator() .__getJavaBridge().loadClass(URIResolverRegistry.getInstance().getInputStream(saveLocation)); @@ -329,7 +330,7 @@ public IFunction loadParser(IValue reifiedGrammar, ISourceLocation saveLocation, tf.tupleType(tf.valueType(), tf.sourceLocationType()), tf.tupleEmpty()); - + @SuppressWarnings({"unchecked"}) final Class> parser = (Class>) ctx.getEvaluator() .__getJavaBridge().loadClass(URIResolverRegistry.getInstance().getInputStream(saveLocation)); From 976b8648653150278e1ad029d477a58a447112c9 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Fri, 13 Oct 2023 10:20:59 +0200 Subject: [PATCH 2/2] more specific ids --- .../rascalmpl/interpreter/matching/TypedVariablePattern.java | 4 ++-- src/org/rascalmpl/interpreter/result/AbstractFunction.java | 5 +++-- src/org/rascalmpl/interpreter/result/NamedFunction.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java b/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java index 6e3ccdb6c26..e94a28eddaa 100644 --- a/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java +++ b/src/org/rascalmpl/interpreter/matching/TypedVariablePattern.java @@ -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<>(), Integer.toString(ctx.getCurrentAST().getLocation().getOffset())); + dynMatchType = AbstractFunction.renameType(dynMatchType, new HashMap<>(), ctx.getCurrentAST().getLocation()); } if (!declaredType.match(dynMatchType, dynBindings)) { @@ -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<>(), Integer.toString(ctx.getCurrentAST().getLocation().getOffset())); + dynType = AbstractFunction.renameType(dynType, new HashMap<>(), ctx.getCurrentAST().getLocation()); } if (!dynType.isSubtypeOf(declaredType.instantiate(ctx.getCurrentEnvt().getDynamicTypeBindings()))) { diff --git a/src/org/rascalmpl/interpreter/result/AbstractFunction.java b/src/org/rascalmpl/interpreter/result/AbstractFunction.java index c68b5beccda..a0a29e38fc2 100644 --- a/src/org/rascalmpl/interpreter/result/AbstractFunction.java +++ b/src/org/rascalmpl/interpreter/result/AbstractFunction.java @@ -43,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; @@ -345,7 +346,7 @@ 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, Integer.toString(env.getLocation().getOffset())); + actualStaticTypes = renameType(actualStaticTypes, renamings, env.getLocation()); } @@ -393,7 +394,7 @@ protected static Type unrenameType(Map renamings, Type resultType) { return resultType; } - public static Type renameType(Type actualTypes, Map renamings, String uniquePrefix) { + public static Type renameType(Type actualTypes, Map renamings, ISourceLocation uniquePrefix) { actualTypes.match(TypeFactory.getInstance().voidType(), renamings); // rename all the bound type parameters diff --git a/src/org/rascalmpl/interpreter/result/NamedFunction.java b/src/org/rascalmpl/interpreter/result/NamedFunction.java index 9523c20c6a1..4323f410129 100644 --- a/src/org/rascalmpl/interpreter/result/NamedFunction.java +++ b/src/org/rascalmpl/interpreter/result/NamedFunction.java @@ -164,7 +164,7 @@ protected void checkReturnTypeIsNotVoid(List formals, IValue[] actua Map bindings = new HashMap<>(); for (int i = 0; i < actuals.length; i++) { - formals.get(i).typeOf(declarationEnvironment, getEval(), false).match(renameType(actuals[i].getType(), renamings, Integer.toString(ctx.getCurrentAST().getLocation().getOffset())), 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()) {