mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 16:11:45 +03:00
Lazy Diagnostic storage allocation (#10852)
close #10727 Changelog: - add: implement lazy allocation of `DiagnosticStorage` objects - update: compiler phases to make sure they don't allocate redundant `DiagnosticStorage` objects - update: cleanup `DiagnosticStorage` class # Important Notes As a result, all 10MB of redundant `DiagnosticStorage` allocations are gone #### Before ![2024-08-21-170148_2092x171_scrot](https://github.com/user-attachments/assets/c1fd34d5-019d-472f-b523-a5c31b87f454) #### After ![2024-08-21-170058_1693x131_scrot](https://github.com/user-attachments/assets/10d71d81-42b7-4b3c-a49f-ca6267bc6ccf)
This commit is contained in:
parent
582b7f9a2e
commit
3bfe963e32
@ -61,7 +61,7 @@ public final class PrivateConstructorAnalysis implements IRPass {
|
||||
var ctorsCnt = type.members().size();
|
||||
if (!(privateCtorsCnt == ctorsCnt || publicCtorsCnt == ctorsCnt)) {
|
||||
assert type.location().isDefined();
|
||||
return Syntax.apply(
|
||||
return new Syntax(
|
||||
type.location().get(),
|
||||
InconsistentConstructorVisibility$.MODULE$,
|
||||
type.passData(),
|
||||
@ -71,14 +71,14 @@ public final class PrivateConstructorAnalysis implements IRPass {
|
||||
return binding;
|
||||
});
|
||||
return ir.copy(
|
||||
ir.imports(),
|
||||
ir.exports(),
|
||||
ir.copy$default$1(),
|
||||
ir.copy$default$2(),
|
||||
newBindings,
|
||||
ir.isPrivate(),
|
||||
ir.location(),
|
||||
ir.passData(),
|
||||
ir.diagnostics(),
|
||||
ir.id());
|
||||
ir.copy$default$4(),
|
||||
ir.copy$default$5(),
|
||||
ir.copy$default$6(),
|
||||
ir.copy$default$7(),
|
||||
ir.copy$default$8());
|
||||
}
|
||||
|
||||
/** Not supported on a single expression. */
|
||||
|
@ -85,8 +85,7 @@ public final class PrivateModuleAnalysis implements IRPass {
|
||||
ImportExport.apply(
|
||||
resolvedImp.importDef(),
|
||||
new ImportExport.ImportPrivateModule(importedModuleName),
|
||||
ImportExport.apply$default$3(),
|
||||
ImportExport.apply$default$4()));
|
||||
ImportExport.apply$default$3()));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@ -99,8 +98,7 @@ public final class PrivateModuleAnalysis implements IRPass {
|
||||
ImportExport.apply(
|
||||
moduleIr.exports().apply(0),
|
||||
new ImportExport.ExportSymbolsFromPrivateModule(moduleContext.getName().toString()),
|
||||
ImportExport.apply$default$3(),
|
||||
ImportExport.apply$default$4()));
|
||||
ImportExport.apply$default$3()));
|
||||
}
|
||||
|
||||
// Ensure that private modules are not exported
|
||||
@ -116,8 +114,7 @@ public final class PrivateModuleAnalysis implements IRPass {
|
||||
ImportExport.apply(
|
||||
associatedExportIR.get(),
|
||||
new ImportExport.ExportPrivateModule(expModuleRef.getName().toString()),
|
||||
ImportExport.apply$default$3(),
|
||||
ImportExport.apply$default$4()));
|
||||
ImportExport.apply$default$3()));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@ -134,12 +131,12 @@ public final class PrivateModuleAnalysis implements IRPass {
|
||||
return moduleIr.copy(
|
||||
convertedImports,
|
||||
convertedExports,
|
||||
moduleIr.bindings(),
|
||||
moduleIr.isPrivate(),
|
||||
moduleIr.location(),
|
||||
moduleIr.passData(),
|
||||
moduleIr.diagnostics(),
|
||||
moduleIr.id());
|
||||
moduleIr.copy$default$3(),
|
||||
moduleIr.copy$default$4(),
|
||||
moduleIr.copy$default$5(),
|
||||
moduleIr.copy$default$6(),
|
||||
moduleIr.copy$default$7(),
|
||||
moduleIr.copy$default$8());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,14 +72,14 @@ public class PrivateSymbolsAnalysis implements IRPass {
|
||||
ir.bindings()
|
||||
.map(binding -> binding.mapExpressions(expr -> processExpression(expr, bindingsMap)));
|
||||
return ir.copy(
|
||||
ir.imports(),
|
||||
ir.exports(),
|
||||
ir.copy$default$1(),
|
||||
ir.copy$default$2(),
|
||||
newBindings,
|
||||
ir.isPrivate(),
|
||||
ir.location(),
|
||||
ir.passData(),
|
||||
ir.diagnostics(),
|
||||
ir.id());
|
||||
ir.copy$default$4(),
|
||||
ir.copy$default$5(),
|
||||
ir.copy$default$6(),
|
||||
ir.copy$default$7(),
|
||||
ir.copy$default$8());
|
||||
}
|
||||
|
||||
/** Not supported for expressions. */
|
||||
@ -98,11 +98,11 @@ public class PrivateSymbolsAnalysis implements IRPass {
|
||||
yield caseExpr.copy(
|
||||
newScrutinee,
|
||||
newBranches,
|
||||
caseExpr.isNested(),
|
||||
caseExpr.location(),
|
||||
caseExpr.passData(),
|
||||
caseExpr.diagnostics(),
|
||||
caseExpr.id());
|
||||
caseExpr.copy$default$3(),
|
||||
caseExpr.copy$default$4(),
|
||||
caseExpr.copy$default$5(),
|
||||
caseExpr.copy$default$6(),
|
||||
caseExpr.copy$default$7());
|
||||
}
|
||||
case Name name -> processName(name, bindingsMap);
|
||||
default -> expr.mapExpressions(e -> processExpression(e, bindingsMap));
|
||||
@ -116,11 +116,11 @@ public class PrivateSymbolsAnalysis implements IRPass {
|
||||
return branch.copy(
|
||||
newPat,
|
||||
newExpr,
|
||||
branch.terminalBranch(),
|
||||
branch.location(),
|
||||
branch.passData(),
|
||||
branch.diagnostics(),
|
||||
branch.id());
|
||||
branch.copy$default$3(),
|
||||
branch.copy$default$4(),
|
||||
branch.copy$default$5(),
|
||||
branch.copy$default$6(),
|
||||
branch.copy$default$7());
|
||||
}
|
||||
|
||||
private Pattern processCasePattern(Pattern pattern, BindingsMap bindingsMap) {
|
||||
|
@ -78,7 +78,7 @@ public final class TypeInference implements IRPass {
|
||||
protected void encounteredIncompatibleTypes(
|
||||
IR relatedIr, TypeRepresentation expected, TypeRepresentation provided) {
|
||||
relatedIr
|
||||
.diagnostics()
|
||||
.getDiagnostics()
|
||||
.add(
|
||||
new Warning.TypeMismatch(
|
||||
relatedIr.location(), expected.toString(), provided.toString()));
|
||||
@ -88,7 +88,7 @@ public final class TypeInference implements IRPass {
|
||||
protected void encounteredInvocationOfNonFunctionType(
|
||||
IR relatedIr, TypeRepresentation type) {
|
||||
relatedIr
|
||||
.diagnostics()
|
||||
.getDiagnostics()
|
||||
.add(new Warning.NotInvokable(relatedIr.location(), type.toString()));
|
||||
}
|
||||
};
|
||||
|
@ -5,7 +5,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.enso.compiler.PackageRepository;
|
||||
import org.enso.compiler.context.CompilerContext;
|
||||
import org.enso.compiler.core.ir.Diagnostic;
|
||||
import org.enso.compiler.core.ir.DiagnosticStorage;
|
||||
import org.enso.compiler.core.ir.MetadataStorage;
|
||||
import org.enso.compiler.core.ir.Module;
|
||||
@ -14,8 +13,6 @@ import org.enso.compiler.core.ir.expression.errors.ImportExport;
|
||||
import org.enso.compiler.core.ir.module.scope.Export;
|
||||
import org.enso.compiler.data.BindingsMap.ResolvedType;
|
||||
import org.enso.compiler.pass.IRPass;
|
||||
import scala.collection.immutable.Seq;
|
||||
import scala.collection.immutable.Seq$;
|
||||
import scala.jdk.javaapi.CollectionConverters;
|
||||
|
||||
/**
|
||||
@ -224,15 +221,14 @@ public final class ExportSymbolAnalysis {
|
||||
|
||||
private static ImportExport createModuleDoesNotExistError(Export.Module exportIr, String modFQN) {
|
||||
assert modFQN.contains(".");
|
||||
return ImportExport.apply(
|
||||
exportIr, new ImportExport.ModuleDoesNotExist(modFQN), emptyPassData(), emptyDiagnostics());
|
||||
return new ImportExport(exportIr, new ImportExport.ModuleDoesNotExist(modFQN), emptyPassData());
|
||||
}
|
||||
|
||||
private static ImportExport createSymbolDoesNotExistError(
|
||||
Name symbolIr, String symbolName, String modFQN) {
|
||||
assert modFQN.contains(".");
|
||||
assert !symbolName.contains(".");
|
||||
return ImportExport.apply(
|
||||
return new ImportExport(
|
||||
symbolIr,
|
||||
new ImportExport.SymbolDoesNotExist(symbolName, modFQN),
|
||||
emptyPassData(),
|
||||
@ -242,7 +238,7 @@ public final class ExportSymbolAnalysis {
|
||||
private static ImportExport createNoSuchConstructorError(
|
||||
Name symbolIr, String typeName, String consName) {
|
||||
assert !consName.contains(".");
|
||||
return ImportExport.apply(
|
||||
return new ImportExport(
|
||||
symbolIr,
|
||||
new ImportExport.NoSuchConstructor(typeName, consName),
|
||||
emptyPassData(),
|
||||
@ -253,7 +249,7 @@ public final class ExportSymbolAnalysis {
|
||||
Export.Module exportIr, String modFQN, String typeName) {
|
||||
assert modFQN.contains(".");
|
||||
assert !typeName.contains(".");
|
||||
return ImportExport.apply(
|
||||
return new ImportExport(
|
||||
exportIr,
|
||||
new ImportExport.TypeDoesNotExist(typeName, modFQN),
|
||||
emptyPassData(),
|
||||
@ -266,6 +262,6 @@ public final class ExportSymbolAnalysis {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static DiagnosticStorage emptyDiagnostics() {
|
||||
return DiagnosticStorage.apply((Seq<Diagnostic>) Seq$.MODULE$.empty());
|
||||
return new DiagnosticStorage(DiagnosticStorage.$lessinit$greater$default$1());
|
||||
}
|
||||
}
|
||||
|
@ -411,13 +411,13 @@ case object AliasAnalysis extends IRPass {
|
||||
alias.AliasMetadata.ChildScope(graph, currentScope)
|
||||
)
|
||||
)
|
||||
case binding @ Expression.Binding(name, expression, _, _, _) =>
|
||||
case binding @ Expression.Binding(name, expression, _, _) =>
|
||||
if (
|
||||
!parentScope.hasSymbolOccurrenceAs[GraphOccurrence.Def](name.name)
|
||||
) {
|
||||
val isSuspended = expression match {
|
||||
case Expression.Block(_, _, _, isSuspended, _, _) => isSuspended
|
||||
case _ => false
|
||||
case Expression.Block(_, _, _, isSuspended, _) => isSuspended
|
||||
case _ => false
|
||||
}
|
||||
val occurrenceId = graph.nextId()
|
||||
val occurrence =
|
||||
@ -476,7 +476,7 @@ case object AliasAnalysis extends IRPass {
|
||||
parentScope: Scope
|
||||
): Type = {
|
||||
value match {
|
||||
case member @ `type`.Set.Member(label, memberType, value, _, _, _) =>
|
||||
case member @ `type`.Set.Member(label, memberType, value, _, _) =>
|
||||
val memberTypeScope = memberType match {
|
||||
case _: Literal => parentScope
|
||||
case _ => parentScope.addChild()
|
||||
@ -537,8 +537,7 @@ case object AliasAnalysis extends IRPass {
|
||||
): List[DefinitionArgument] = {
|
||||
args.map {
|
||||
case arg @ DefinitionArgument.Specified(
|
||||
selfName @ Name.Self(_, true, _, _),
|
||||
_,
|
||||
selfName @ Name.Self(_, true, _),
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
@ -573,7 +572,6 @@ case object AliasAnalysis extends IRPass {
|
||||
value,
|
||||
suspended,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
val nameOccursInScope =
|
||||
@ -685,7 +683,7 @@ case object AliasAnalysis extends IRPass {
|
||||
graph: Graph,
|
||||
parentScope: Graph.Scope
|
||||
): List[CallArgument] = {
|
||||
args.map { case arg @ CallArgument.Specified(_, expr, _, _, _) =>
|
||||
args.map { case arg @ CallArgument.Specified(_, expr, _, _) =>
|
||||
val currentScope = expr match {
|
||||
case _: Literal => parentScope
|
||||
case _ => parentScope.addChild()
|
||||
|
@ -80,8 +80,8 @@ case object AmbiguousImportsAnalysis extends IRPass {
|
||||
|
||||
/** Analyses ambiguous symbols in the given import.
|
||||
* @param imp current import
|
||||
* @param module current module
|
||||
* @param bindingMap binding map of the current module
|
||||
* @param encounteredSymbols already encountered symbols
|
||||
* @return A list of errors, if any encountered, or an import IR, potentially with some
|
||||
* warnings attached.
|
||||
*/
|
||||
@ -100,7 +100,6 @@ case object AmbiguousImportsAnalysis extends IRPass {
|
||||
_,
|
||||
_,
|
||||
false,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
getImportTargets(moduleImport, bindingMap) match {
|
||||
@ -152,7 +151,6 @@ case object AmbiguousImportsAnalysis extends IRPass {
|
||||
hiddenNames,
|
||||
_,
|
||||
false,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
getImportTargets(moduleImport, bindingMap) match {
|
||||
@ -211,7 +209,6 @@ case object AmbiguousImportsAnalysis extends IRPass {
|
||||
_,
|
||||
_,
|
||||
false,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
val symbolPath = importPath.name
|
||||
@ -235,7 +232,6 @@ case object AmbiguousImportsAnalysis extends IRPass {
|
||||
_,
|
||||
_,
|
||||
false,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
tryAddEncounteredSymbol(
|
||||
@ -250,7 +246,7 @@ case object AmbiguousImportsAnalysis extends IRPass {
|
||||
}
|
||||
|
||||
// Polyglot import
|
||||
case polyImport @ imports.Polyglot(entity, rename, _, _, _) =>
|
||||
case polyImport @ imports.Polyglot(entity, rename, _, _) =>
|
||||
val symbolName = rename.getOrElse(entity.getVisibleName)
|
||||
val symbolPath = entity match {
|
||||
case imports.Polyglot.Java(packageName, className) =>
|
||||
|
@ -69,9 +69,9 @@ case object BindingAnalysis extends IRPass {
|
||||
case method: definition.Method.Explicit =>
|
||||
val ref = method.methodReference
|
||||
ref.typePointer match {
|
||||
case Some(Name.Qualified(List(), _, _, _)) =>
|
||||
case Some(Name.Qualified(List(), _, _)) =>
|
||||
Some(ModuleMethod(ref.methodName.name))
|
||||
case Some(Name.Qualified(List(n), _, _, _)) =>
|
||||
case Some(Name.Qualified(List(n), _, _)) =>
|
||||
val shadowed = definedSumTypes.exists(_.name == n.name)
|
||||
if (!shadowed && n.name == moduleContext.getName().item)
|
||||
Some(ModuleMethod(ref.methodName.name))
|
||||
|
@ -172,7 +172,7 @@ case object CachePreferenceAnalysis extends IRPass {
|
||||
}
|
||||
}
|
||||
|
||||
def analyseSelfCallArgument(
|
||||
private def analyseSelfCallArgument(
|
||||
callArgument: CallArgument,
|
||||
weights: WeightInfo
|
||||
): CallArgument = {
|
||||
@ -198,7 +198,7 @@ case object CachePreferenceAnalysis extends IRPass {
|
||||
weights: WeightInfo
|
||||
): DefinitionArgument = {
|
||||
argument match {
|
||||
case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _, _) =>
|
||||
case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _) =>
|
||||
spec
|
||||
.copy(defaultValue = defValue.map(analyseExpression(_, weights)))
|
||||
.updateMetadata(new MetadataPair(this, weights))
|
||||
|
@ -43,7 +43,7 @@ import scala.collection.mutable
|
||||
*
|
||||
* This pass requires the context to provide:
|
||||
*
|
||||
* - A [[LocalScope]], where relevant.
|
||||
* - A [[org.enso.compiler.context.LocalScope]], where relevant.
|
||||
*
|
||||
* It requires that all members of [[org.enso.compiler.core.ir.IRKind.Primitive]] have been removed
|
||||
* from the IR by the time it runs.
|
||||
@ -166,7 +166,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
method
|
||||
.copy(body = analyseExpression(body, info))
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case tp @ Definition.Type(_, params, members, _, _, _) =>
|
||||
case tp @ Definition.Type(_, params, members, _, _) =>
|
||||
val tpDep = asStatic(tp)
|
||||
val newParams = params.map { param =>
|
||||
val paramDep = asStatic(param)
|
||||
@ -249,7 +249,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
case foreign: Foreign =>
|
||||
foreign.updateMetadata(new MetadataPair(this, info))
|
||||
|
||||
case block @ Expression.Block(expressions, returnValue, _, _, _, _) =>
|
||||
case block @ Expression.Block(expressions, returnValue, _, _, _) =>
|
||||
val retValDep = asStatic(returnValue)
|
||||
val blockDep = asStatic(block)
|
||||
info.dependents.updateAt(retValDep, Set(blockDep))
|
||||
@ -261,7 +261,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
returnValue = analyseExpression(returnValue, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case binding @ Expression.Binding(name, expression, _, _, _) =>
|
||||
case binding @ Expression.Binding(name, expression, _, _) =>
|
||||
val expressionDep = asStatic(expression)
|
||||
val nameDep = asStatic(name)
|
||||
val bindingDep = asStatic(binding)
|
||||
@ -331,7 +331,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
info: DependencyInfo
|
||||
): Application = {
|
||||
application match {
|
||||
case prefix @ Application.Prefix(fn, args, _, _, _, _) =>
|
||||
case prefix @ Application.Prefix(fn, args, _, _, _) =>
|
||||
val fnDep = asStatic(fn)
|
||||
val prefixDep = asStatic(prefix)
|
||||
info.dependents.updateAt(fnDep, Set(prefixDep))
|
||||
@ -348,7 +348,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
arguments = args.map(analyseCallArgument(_, info))
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case force @ Application.Force(target, _, _, _) =>
|
||||
case force @ Application.Force(target, _, _) =>
|
||||
val targetDep = asStatic(target)
|
||||
val forceDep = asStatic(force)
|
||||
info.dependents.updateAt(targetDep, Set(forceDep))
|
||||
@ -357,7 +357,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
force
|
||||
.copy(target = analyseExpression(target, info))
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case vector @ Application.Sequence(items, _, _, _) =>
|
||||
case vector @ Application.Sequence(items, _, _) =>
|
||||
val vectorDep = asStatic(vector)
|
||||
items.foreach(it => {
|
||||
val itemDep = asStatic(it)
|
||||
@ -368,7 +368,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
vector
|
||||
.copy(items = items.map(analyseExpression(_, info)))
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case tSet @ Application.Typeset(expr, _, _, _) =>
|
||||
case tSet @ Application.Typeset(expr, _, _) =>
|
||||
val tSetDep = asStatic(tSet)
|
||||
expr.foreach(exp => {
|
||||
val exprDep = asStatic(exp)
|
||||
@ -394,7 +394,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
*/
|
||||
def analyseType(typ: Type, info: DependencyInfo): Type = {
|
||||
typ match {
|
||||
case asc @ Type.Ascription(typed, signature, _, _, _, _) =>
|
||||
case asc @ Type.Ascription(typed, signature, _, _, _) =>
|
||||
val ascrDep = asStatic(asc)
|
||||
val typedDep = asStatic(typed)
|
||||
val sigDep = asStatic(signature)
|
||||
@ -409,7 +409,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
|
||||
case fun @ Type.Function(args, result, _, _, _) =>
|
||||
case fun @ Type.Function(args, result, _, _) =>
|
||||
val funDep = asStatic(fun)
|
||||
val argDeps = args.map(asStatic)
|
||||
val resDep = asStatic(result)
|
||||
@ -423,7 +423,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
result = analyseExpression(result, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case ctx @ Type.Context(typed, context, _, _, _) =>
|
||||
case ctx @ Type.Context(typed, context, _, _) =>
|
||||
val ctxDep = asStatic(ctx)
|
||||
val typedDep = asStatic(typed)
|
||||
val contextDep = asStatic(context)
|
||||
@ -437,7 +437,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
context = analyseExpression(context, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case err @ Type.Error(typed, error, _, _, _) =>
|
||||
case err @ Type.Error(typed, error, _, _) =>
|
||||
val errDep = asStatic(err)
|
||||
val typedDep = asStatic(typed)
|
||||
val errorDep = asStatic(error)
|
||||
@ -451,7 +451,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
error = analyseExpression(error, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case member @ `type`.Set.Member(_, memberType, value, _, _, _) =>
|
||||
case member @ `type`.Set.Member(_, memberType, value, _, _) =>
|
||||
val memberDep = asStatic(member)
|
||||
val memberTypeDep = asStatic(memberType)
|
||||
val valueDep = asStatic(value)
|
||||
@ -465,7 +465,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
value = analyseExpression(value, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case concat @ `type`.Set.Concat(left, right, _, _, _) =>
|
||||
case concat @ `type`.Set.Concat(left, right, _, _) =>
|
||||
val concatDep = asStatic(concat)
|
||||
val leftDep = asStatic(left)
|
||||
val rightDep = asStatic(right)
|
||||
@ -479,7 +479,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
right = analyseExpression(right, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case eq @ `type`.Set.Equality(left, right, _, _, _) =>
|
||||
case eq @ `type`.Set.Equality(left, right, _, _) =>
|
||||
val eqDep = asStatic(eq)
|
||||
val leftDep = asStatic(left)
|
||||
val rightDep = asStatic(right)
|
||||
@ -491,7 +491,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
left = analyseExpression(left, info),
|
||||
right = analyseExpression(right, info)
|
||||
).updateMetadata(new MetadataPair(this, info))
|
||||
case intersect @ `type`.Set.Intersection(left, right, _, _, _) =>
|
||||
case intersect @ `type`.Set.Intersection(left, right, _, _) =>
|
||||
val intersectDep = asStatic(intersect)
|
||||
val leftDep = asStatic(left)
|
||||
val rightDep = asStatic(right)
|
||||
@ -505,7 +505,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
right = analyseExpression(right, info)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case union @ `type`.Set.Union(operands, _, _, _) =>
|
||||
case union @ `type`.Set.Union(operands, _, _) =>
|
||||
val unionDep = asStatic(union)
|
||||
val opDeps = operands.map(asStatic)
|
||||
opDeps.foreach(info.dependents.updateAt(_, Set(unionDep)))
|
||||
@ -513,7 +513,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
union
|
||||
.copy(operands = operands.map(analyseExpression(_, info)))
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case subsumption @ `type`.Set.Subsumption(left, right, _, _, _) =>
|
||||
case subsumption @ `type`.Set.Subsumption(left, right, _, _) =>
|
||||
val subDep = asStatic(subsumption)
|
||||
val leftDep = asStatic(left)
|
||||
val rightDep = asStatic(right)
|
||||
@ -658,13 +658,13 @@ case object DataflowAnalysis extends IRPass {
|
||||
): Pattern = {
|
||||
val patternDep = asStatic(pattern)
|
||||
pattern match {
|
||||
case named @ Pattern.Name(name, _, _, _) =>
|
||||
case named @ Pattern.Name(name, _, _) =>
|
||||
val nameDep = asStatic(name)
|
||||
info.dependents.updateAt(nameDep, Set(patternDep))
|
||||
info.dependencies.updateAt(patternDep, Set(nameDep))
|
||||
|
||||
named.updateMetadata(new MetadataPair(this, info))
|
||||
case cons @ Pattern.Constructor(constructor, fields, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(constructor, fields, _, _) =>
|
||||
val consDep = asStatic(constructor)
|
||||
info.dependents.updateAt(consDep, Set(patternDep))
|
||||
info.dependencies.updateAt(patternDep, Set(consDep))
|
||||
@ -682,7 +682,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
.updateMetadata(new MetadataPair(this, info))
|
||||
case literal: Pattern.Literal =>
|
||||
literal.updateMetadata(new MetadataPair(this, info))
|
||||
case Pattern.Type(name, tpe, _, _, _) =>
|
||||
case Pattern.Type(name, tpe, _, _) =>
|
||||
val nameDep = asStatic(name)
|
||||
info.dependents.updateAt(nameDep, Set(patternDep))
|
||||
info.dependencies.updateAt(patternDep, Set(nameDep))
|
||||
@ -714,7 +714,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
info: DependencyInfo
|
||||
): DefinitionArgument = {
|
||||
argument match {
|
||||
case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _, _) =>
|
||||
case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _) =>
|
||||
val specDep = asStatic(spec)
|
||||
defValue.foreach(expr => {
|
||||
val exprDep = asStatic(expr)
|
||||
@ -744,7 +744,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
info: DependencyInfo
|
||||
): CallArgument = {
|
||||
argument match {
|
||||
case spec @ CallArgument.Specified(name, value, _, _, _) =>
|
||||
case spec @ CallArgument.Specified(name, value, _, _) =>
|
||||
val specDep = asStatic(spec)
|
||||
val valueDep = asStatic(value)
|
||||
info.dependents.updateAt(valueDep, Set(specDep))
|
||||
|
@ -116,14 +116,14 @@ case object DemandAnalysis extends IRPass {
|
||||
analyseType(typ, isInsideCallArgument)
|
||||
case cse: Case =>
|
||||
analyseCase(cse, isInsideCallArgument)
|
||||
case block @ Expression.Block(expressions, retVal, _, _, _, _) =>
|
||||
case block @ Expression.Block(expressions, retVal, _, _, _) =>
|
||||
block.copy(
|
||||
expressions = expressions.map(x =>
|
||||
analyseExpression(x, isInsideCallArgument = false)
|
||||
),
|
||||
returnValue = analyseExpression(retVal, isInsideCallArgument = false)
|
||||
)
|
||||
case binding @ Expression.Binding(_, expression, _, _, _) =>
|
||||
case binding @ Expression.Binding(_, expression, _, _) =>
|
||||
binding.copy(expression =
|
||||
analyseExpression(
|
||||
expression,
|
||||
@ -219,7 +219,7 @@ case object DemandAnalysis extends IRPass {
|
||||
isInsideCallArgument: Boolean
|
||||
): Application =
|
||||
application match {
|
||||
case pref @ Application.Prefix(fn, args, _, _, _, _) =>
|
||||
case pref @ Application.Prefix(fn, args, _, _, _) =>
|
||||
val newFun = fn match {
|
||||
case n: Name => n
|
||||
case e => analyseExpression(e, isInsideCallArgument = false)
|
||||
@ -228,14 +228,14 @@ case object DemandAnalysis extends IRPass {
|
||||
function = newFun,
|
||||
arguments = args.map(analyseCallArgument)
|
||||
)
|
||||
case force @ Application.Force(target, _, _, _) =>
|
||||
case force @ Application.Force(target, _, _) =>
|
||||
force.copy(target =
|
||||
analyseExpression(
|
||||
target,
|
||||
isInsideCallArgument
|
||||
)
|
||||
)
|
||||
case vec @ Application.Sequence(items, _, _, _) =>
|
||||
case vec @ Application.Sequence(items, _, _) =>
|
||||
vec.copy(items =
|
||||
items.map(
|
||||
analyseExpression(
|
||||
@ -244,7 +244,7 @@ case object DemandAnalysis extends IRPass {
|
||||
)
|
||||
)
|
||||
)
|
||||
case tSet @ Application.Typeset(expr, _, _, _) =>
|
||||
case tSet @ Application.Typeset(expr, _, _) =>
|
||||
tSet.copy(
|
||||
expression =
|
||||
expr.map(analyseExpression(_, isInsideCallArgument = false))
|
||||
@ -266,7 +266,7 @@ case object DemandAnalysis extends IRPass {
|
||||
*/
|
||||
def analyseCallArgument(arg: CallArgument): CallArgument = {
|
||||
arg match {
|
||||
case spec @ CallArgument.Specified(_, expr, _, _, _) =>
|
||||
case spec @ CallArgument.Specified(_, expr, _, _) =>
|
||||
spec.copy(
|
||||
value = analyseExpression(
|
||||
expr,
|
||||
@ -285,7 +285,7 @@ case object DemandAnalysis extends IRPass {
|
||||
arg: DefinitionArgument
|
||||
): DefinitionArgument = {
|
||||
arg match {
|
||||
case spec @ DefinitionArgument.Specified(_, _, default, _, _, _, _) =>
|
||||
case spec @ DefinitionArgument.Specified(_, _, default, _, _, _) =>
|
||||
spec.copy(
|
||||
defaultValue = default.map(x =>
|
||||
analyseExpression(
|
||||
@ -322,7 +322,7 @@ case object DemandAnalysis extends IRPass {
|
||||
isInsideCallArgument: Boolean
|
||||
): Case =
|
||||
cse match {
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
expr.copy(
|
||||
scrutinee = analyseExpression(
|
||||
scrutinee,
|
||||
|
@ -28,7 +28,7 @@ import org.enso.compiler.pass.analyse.alias.AliasMetadata
|
||||
import org.enso.compiler.pass.analyse.alias.graph.{Graph, GraphOccurrence}
|
||||
|
||||
/** This pass attaches [[FramePointer]] as metadata to all the IR elements that already
|
||||
* have [[org.enso.compiler.pass.analyse.alias.Info.Occurrence]] attached.
|
||||
* have [[org.enso.compiler.pass.analyse.alias.AliasMetadata.Occurrence]] attached.
|
||||
* It does not replace the IR elements with errors, it just attaches metadata.
|
||||
*/
|
||||
case object FramePointerAnalysis extends IRPass {
|
||||
@ -112,7 +112,7 @@ case object FramePointerAnalysis extends IRPass {
|
||||
): Unit = {
|
||||
args.foreach { arg =>
|
||||
arg.name match {
|
||||
case Name.Self(loc, synthetic, _, _) if loc.isEmpty && synthetic =>
|
||||
case Name.Self(loc, synthetic, _) if loc.isEmpty && synthetic =>
|
||||
// synthetic self argument has occurrence attached, but there is no Occurence.Def for it.
|
||||
// So we have to handle it specially.
|
||||
updateMeta(arg, new FramePointer(0, 1))
|
||||
@ -146,7 +146,7 @@ case object FramePointerAnalysis extends IRPass {
|
||||
case Function.Lambda(args, body, _, _, _, _) =>
|
||||
processArgumentDefs(args, graph)
|
||||
processExpression(body, graph)
|
||||
case binding @ Expression.Binding(name, expr, _, _, _) =>
|
||||
case binding @ Expression.Binding(name, expr, _, _) =>
|
||||
maybeAttachFramePointer(binding, graph)
|
||||
maybeAttachFramePointer(name, graph)
|
||||
processExpression(expr, graph)
|
||||
@ -204,17 +204,17 @@ case object FramePointerAnalysis extends IRPass {
|
||||
graph: Graph
|
||||
): Unit = {
|
||||
application match {
|
||||
case app @ Application.Prefix(func, arguments, _, _, _, _) =>
|
||||
case app @ Application.Prefix(func, arguments, _, _, _) =>
|
||||
maybeAttachFramePointer(app, graph)
|
||||
processExpression(func, graph)
|
||||
processCallArguments(arguments, graph)
|
||||
case Application.Force(expr, _, _, _) =>
|
||||
case Application.Force(expr, _, _) =>
|
||||
processExpression(expr, graph)
|
||||
case Application.Sequence(items, _, _, _) =>
|
||||
case Application.Sequence(items, _, _) =>
|
||||
items.foreach { item =>
|
||||
processExpression(item, graph)
|
||||
}
|
||||
case Application.Typeset(expr, _, _, _) =>
|
||||
case Application.Typeset(expr, _, _) =>
|
||||
expr.foreach(processExpression(_, graph))
|
||||
case _ =>
|
||||
throw new CompilerError(
|
||||
@ -227,16 +227,15 @@ case object FramePointerAnalysis extends IRPass {
|
||||
arguments: List[CallArgument],
|
||||
graph: Graph
|
||||
): Unit = {
|
||||
arguments.foreach {
|
||||
case arg @ CallArgument.Specified(name, value, _, _, _) =>
|
||||
maybeAttachFramePointer(arg, graph)
|
||||
name.foreach(maybeAttachFramePointer(_, graph))
|
||||
processExpression(value, graph)
|
||||
arguments.foreach { case arg @ CallArgument.Specified(name, value, _, _) =>
|
||||
maybeAttachFramePointer(arg, graph)
|
||||
name.foreach(maybeAttachFramePointer(_, graph))
|
||||
processExpression(value, graph)
|
||||
}
|
||||
}
|
||||
|
||||
/** Attaches [[FramePointerMeta]] metadata to the given `ir` if there is an
|
||||
* appropriate [[Info.Occurrence]] already attached to it.
|
||||
* appropriate [[AliasMetadata.Occurrence]] already attached to it.
|
||||
* @param ir IR to attach the frame pointer metadata to.
|
||||
* @param graph Alias analysis graph
|
||||
* @return Copy of `ir` with attached metadata, or just the `ir` if nothing
|
||||
|
@ -62,7 +62,7 @@ case object GatherDiagnostics extends IRPass {
|
||||
* @return `ir`, with all diagnostics from its subtree associated with it
|
||||
*/
|
||||
private def gatherMetadata(ir: IR): DiagnosticsMeta = {
|
||||
val diagnostics = ir.preorder.collect {
|
||||
val diagnostics = ir.preorder.flatMap {
|
||||
case err: Diagnostic =>
|
||||
List(err)
|
||||
case arg: DefinitionArgument =>
|
||||
@ -71,7 +71,7 @@ case object GatherDiagnostics extends IRPass {
|
||||
.getMetadata(TypeSignatures)
|
||||
.map(_.signature.preorder.collect(collectDiagnostics))
|
||||
.getOrElse(Nil)
|
||||
typeSignatureDiagnostics ++ arg.diagnostics.toList
|
||||
typeSignatureDiagnostics ++ diagnosticsList(arg)
|
||||
case x: definition.Method =>
|
||||
val typeSignatureDiagnostics =
|
||||
x.getMetadata(TypeSignatures)
|
||||
@ -81,16 +81,16 @@ case object GatherDiagnostics extends IRPass {
|
||||
x.getMetadata(GenericAnnotations)
|
||||
.map(_.annotations.flatMap(_.preorder.collect(collectDiagnostics)))
|
||||
.getOrElse(Nil)
|
||||
typeSignatureDiagnostics ++ annotationsDiagnostics ++ x.diagnostics.toList
|
||||
typeSignatureDiagnostics ++ annotationsDiagnostics ++ diagnosticsList(x)
|
||||
case x: Expression =>
|
||||
val typeSignatureDiagnostics =
|
||||
x.getMetadata(TypeSignatures)
|
||||
.map(_.signature.preorder.collect(collectDiagnostics))
|
||||
.getOrElse(Nil)
|
||||
typeSignatureDiagnostics ++ x.diagnostics.toList
|
||||
typeSignatureDiagnostics ++ diagnosticsList(x)
|
||||
case x =>
|
||||
x.diagnostics.toList
|
||||
}.flatten
|
||||
diagnosticsList(x)
|
||||
}
|
||||
DiagnosticsMeta(
|
||||
diagnostics.distinctBy(d => new DiagnosticKeys(d))
|
||||
)
|
||||
@ -100,6 +100,9 @@ case object GatherDiagnostics extends IRPass {
|
||||
case err: Diagnostic => err
|
||||
}
|
||||
|
||||
private def diagnosticsList(ir: IR): List[Diagnostic] =
|
||||
if (ir.diagnostics() eq null) Nil else ir.diagnostics().toList
|
||||
|
||||
final private class DiagnosticKeys(private val diagnostic: Diagnostic) {
|
||||
|
||||
/** Equals is based on type of diagnostic, its location and its diagnostic keys.
|
||||
|
@ -63,7 +63,6 @@ case object ImportSymbolAnalysis extends IRPass {
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
bindingMap.resolvedImports.find(_.importDef == imp) match {
|
||||
@ -96,7 +95,6 @@ case object ImportSymbolAnalysis extends IRPass {
|
||||
_,
|
||||
_,
|
||||
isSynthetic,
|
||||
_,
|
||||
_
|
||||
) if isAll && !isSynthetic =>
|
||||
bindingMap.resolvedImports.find(_.importDef == imp) match {
|
||||
|
@ -100,7 +100,7 @@ case object TailCall extends IRPass {
|
||||
|
||||
/** Performs tail call analysis on a top-level definition in a module.
|
||||
*
|
||||
* @param definition the top-level definition to analyse
|
||||
* @param moduleDefinition the top-level definition to analyse
|
||||
* @return `definition`, annotated with tail call information
|
||||
*/
|
||||
private def analyseModuleBinding(
|
||||
@ -189,14 +189,7 @@ case object TailCall extends IRPass {
|
||||
throw new CompilerError(
|
||||
"Comments should not be present during tail call analysis."
|
||||
)
|
||||
case block @ Expression.Block(
|
||||
expressions,
|
||||
returnValue,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
case block @ Expression.Block(expressions, returnValue, _, _, _) =>
|
||||
block
|
||||
.copy(
|
||||
expressions = expressions.map(
|
||||
@ -207,7 +200,7 @@ case object TailCall extends IRPass {
|
||||
.updateMetadata(
|
||||
new MetadataPair(this, TailPosition.fromBool(isInTailPosition))
|
||||
)
|
||||
case binding @ Expression.Binding(_, expression, _, _, _) =>
|
||||
case binding @ Expression.Binding(_, expression, _, _) =>
|
||||
binding
|
||||
.copy(
|
||||
expression = analyseExpression(expression, isInTailPosition = false)
|
||||
@ -241,7 +234,7 @@ case object TailCall extends IRPass {
|
||||
* or not
|
||||
* @return `literal`, annotated with tail position metdata
|
||||
*/
|
||||
def analyseLiteral(
|
||||
private def analyseLiteral(
|
||||
literal: Literal,
|
||||
isInTailPosition: Boolean
|
||||
): Literal = {
|
||||
@ -262,7 +255,7 @@ case object TailCall extends IRPass {
|
||||
isInTailPosition: Boolean
|
||||
): Application = {
|
||||
application match {
|
||||
case app @ Application.Prefix(fn, args, _, _, _, _) =>
|
||||
case app @ Application.Prefix(fn, args, _, _, _) =>
|
||||
app
|
||||
.copy(
|
||||
function = analyseExpression(fn, isInTailPosition = false),
|
||||
@ -271,7 +264,7 @@ case object TailCall extends IRPass {
|
||||
.updateMetadata(
|
||||
new MetadataPair(this, TailPosition.fromBool(isInTailPosition))
|
||||
)
|
||||
case force @ Application.Force(target, _, _, _) =>
|
||||
case force @ Application.Force(target, _, _) =>
|
||||
force
|
||||
.copy(
|
||||
target = analyseExpression(target, isInTailPosition)
|
||||
@ -279,7 +272,7 @@ case object TailCall extends IRPass {
|
||||
.updateMetadata(
|
||||
new MetadataPair(this, TailPosition.fromBool(isInTailPosition))
|
||||
)
|
||||
case vector @ Application.Sequence(items, _, _, _) =>
|
||||
case vector @ Application.Sequence(items, _, _) =>
|
||||
vector
|
||||
.copy(items =
|
||||
items.map(analyseExpression(_, isInTailPosition = false))
|
||||
@ -287,7 +280,7 @@ case object TailCall extends IRPass {
|
||||
.updateMetadata(
|
||||
new MetadataPair(this, TailPosition.fromBool(isInTailPosition))
|
||||
)
|
||||
case tSet @ Application.Typeset(expr, _, _, _) =>
|
||||
case tSet @ Application.Typeset(expr, _, _) =>
|
||||
tSet
|
||||
.copy(expression =
|
||||
expr.map(analyseExpression(_, isInTailPosition = false))
|
||||
@ -305,9 +298,9 @@ case object TailCall extends IRPass {
|
||||
* @param argument the argument to analyse
|
||||
* @return `argument`, annotated with tail position metadata
|
||||
*/
|
||||
def analyseCallArg(argument: CallArgument): CallArgument = {
|
||||
private def analyseCallArg(argument: CallArgument): CallArgument = {
|
||||
argument match {
|
||||
case arg @ CallArgument.Specified(_, expr, _, _, _) =>
|
||||
case arg @ CallArgument.Specified(_, expr, _, _) =>
|
||||
arg
|
||||
.copy(
|
||||
// Note [Call Argument Tail Position]
|
||||
@ -364,7 +357,7 @@ case object TailCall extends IRPass {
|
||||
*/
|
||||
def analyseCase(caseExpr: Case, isInTailPosition: Boolean): Case = {
|
||||
caseExpr match {
|
||||
case caseExpr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case caseExpr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
caseExpr
|
||||
.copy(
|
||||
scrutinee = analyseExpression(scrutinee, isInTailPosition = false),
|
||||
@ -423,13 +416,13 @@ case object TailCall extends IRPass {
|
||||
pattern: Pattern
|
||||
): Pattern = {
|
||||
pattern match {
|
||||
case namePat @ Pattern.Name(name, _, _, _) =>
|
||||
case namePat @ Pattern.Name(name, _, _) =>
|
||||
namePat
|
||||
.copy(
|
||||
name = analyseName(name, isInTailPosition = false)
|
||||
)
|
||||
.updateMetadata(new MetadataPair(this, TailPosition.NotTail))
|
||||
case cons @ Pattern.Constructor(constructor, fields, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(constructor, fields, _, _) =>
|
||||
cons
|
||||
.copy(
|
||||
constructor = analyseName(constructor, isInTailPosition = false),
|
||||
@ -439,7 +432,7 @@ case object TailCall extends IRPass {
|
||||
case literal: Pattern.Literal =>
|
||||
literal
|
||||
.updateMetadata(new MetadataPair(this, TailPosition.NotTail))
|
||||
case tpePattern @ Pattern.Type(name, tpe, _, _, _) =>
|
||||
case tpePattern @ Pattern.Type(name, tpe, _, _) =>
|
||||
tpePattern
|
||||
.copy(
|
||||
name = analyseName(name, isInTailPosition = false),
|
||||
@ -490,9 +483,11 @@ case object TailCall extends IRPass {
|
||||
* @param arg the argument definition to analyse
|
||||
* @return `arg`, annotated with tail position metadata
|
||||
*/
|
||||
def analyseDefArgument(arg: DefinitionArgument): DefinitionArgument = {
|
||||
private def analyseDefArgument(
|
||||
arg: DefinitionArgument
|
||||
): DefinitionArgument = {
|
||||
arg match {
|
||||
case arg @ DefinitionArgument.Specified(_, _, default, _, _, _, _) =>
|
||||
case arg @ DefinitionArgument.Specified(_, _, default, _, _, _) =>
|
||||
arg
|
||||
.copy(
|
||||
defaultValue = default.map(x =>
|
||||
|
@ -167,7 +167,7 @@ case object ComplexType extends IRPass {
|
||||
): List[Definition] = {
|
||||
var unusedSig: Option[Type.Ascription] = None
|
||||
val sig = lastSignature match {
|
||||
case Some(Type.Ascription(typed, _, _, _, _, _)) =>
|
||||
case Some(Type.Ascription(typed, _, _, _, _)) =>
|
||||
typed match {
|
||||
case literal: Name.Literal =>
|
||||
if (name.name == literal.name) {
|
||||
@ -197,9 +197,9 @@ case object ComplexType extends IRPass {
|
||||
val res = lastSignature
|
||||
lastSignature = Some(sig)
|
||||
res
|
||||
case binding @ Expression.Binding(name, _, _, _, _) =>
|
||||
case binding @ Expression.Binding(name, _, _, _) =>
|
||||
matchSignaturesAndGenerate(name, binding)
|
||||
case funSugar @ Function.Binding(name, _, _, _, _, _, _, _) =>
|
||||
case funSugar @ Function.Binding(name, _, _, _, _, _, _) =>
|
||||
matchSignaturesAndGenerate(name, funSugar)
|
||||
case err: Error => Seq(err)
|
||||
case ann: Name.GenericAnnotation => Seq(ann)
|
||||
@ -248,9 +248,14 @@ case object ComplexType extends IRPass {
|
||||
signature: Option[Type.Ascription]
|
||||
): List[Definition] = {
|
||||
ir match {
|
||||
case Expression.Binding(name, expr, location, passData, diagnostics) =>
|
||||
case expressionBinding @ Expression.Binding(
|
||||
name,
|
||||
expr,
|
||||
location,
|
||||
passData
|
||||
) =>
|
||||
val realExpr = expr match {
|
||||
case b @ Expression.Block(_, _, _, suspended, _, _) if suspended =>
|
||||
case b @ Expression.Block(_, _, _, suspended, _) if suspended =>
|
||||
b.copy(suspended = false)
|
||||
case _ => expr
|
||||
}
|
||||
@ -263,18 +268,17 @@ case object ComplexType extends IRPass {
|
||||
false,
|
||||
location,
|
||||
passData,
|
||||
diagnostics,
|
||||
expressionBinding.diagnosticsCopy,
|
||||
signature
|
||||
)
|
||||
case Function.Binding(
|
||||
case functionBinding @ Function.Binding(
|
||||
name,
|
||||
args,
|
||||
body,
|
||||
isPrivate,
|
||||
location,
|
||||
_,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
) =>
|
||||
genForName(
|
||||
typeName,
|
||||
@ -284,7 +288,7 @@ case object ComplexType extends IRPass {
|
||||
isPrivate,
|
||||
location,
|
||||
passData,
|
||||
diagnostics,
|
||||
functionBinding.diagnosticsCopy,
|
||||
signature
|
||||
)
|
||||
case _ =>
|
||||
@ -324,14 +328,14 @@ case object ComplexType extends IRPass {
|
||||
val newSig =
|
||||
signature.map(sig => sig.copy(typed = methodRef.duplicate()).duplicate())
|
||||
|
||||
val binding = definition.Method.Binding(
|
||||
val binding = new definition.Method.Binding(
|
||||
methodRef.duplicate(),
|
||||
args.map(_.duplicate()),
|
||||
isPrivate,
|
||||
body.duplicate(),
|
||||
location,
|
||||
passData.duplicate,
|
||||
diagnostics.copy
|
||||
diagnostics
|
||||
)
|
||||
|
||||
newSig.toList :+ binding
|
||||
|
@ -95,15 +95,14 @@ case object FunctionBinding extends IRPass {
|
||||
*/
|
||||
def desugarExpression(ir: Expression): Expression = {
|
||||
ir.transformExpressions {
|
||||
case Function.Binding(
|
||||
name,
|
||||
case functionBinding @ Function.Binding(
|
||||
_,
|
||||
args,
|
||||
body,
|
||||
_,
|
||||
location,
|
||||
canBeTCO,
|
||||
passData,
|
||||
diagnostics
|
||||
_
|
||||
) =>
|
||||
if (args.isEmpty) {
|
||||
throw new CompilerError("The arguments list should not be empty.")
|
||||
@ -117,16 +116,16 @@ case object FunctionBinding extends IRPass {
|
||||
.asInstanceOf[Function.Lambda]
|
||||
.copy(canBeTCO = canBeTCO, location = location)
|
||||
|
||||
Expression.Binding(name, lambda, location, passData, diagnostics)
|
||||
new Expression.Binding(functionBinding, lambda)
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs desugaring on a module definition.
|
||||
*
|
||||
* @param definition the module definition to desugar
|
||||
* @param moduleDefinition the module definition to desugar
|
||||
* @return `definition`, with any function definition sugar removed
|
||||
*/
|
||||
def desugarModuleSymbol(
|
||||
private def desugarModuleSymbol(
|
||||
moduleDefinition: Definition
|
||||
): Definition = {
|
||||
moduleDefinition match {
|
||||
@ -150,19 +149,17 @@ case object FunctionBinding extends IRPass {
|
||||
isPrivate,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) if isPrivate && methRef.methodName.name == conversionMethodName =>
|
||||
errors.Conversion(meth, errors.Conversion.DeclaredAsPrivate)
|
||||
|
||||
case meth @ definition.Method.Binding(
|
||||
case methodBinding @ definition.Method.Binding(
|
||||
methRef,
|
||||
args,
|
||||
isPrivate,
|
||||
body,
|
||||
loc,
|
||||
passData,
|
||||
diagnostics
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
val methodName = methRef.methodName.name
|
||||
|
||||
@ -173,17 +170,10 @@ case object FunctionBinding extends IRPass {
|
||||
new Function.Lambda(List(arg), body, None)
|
||||
)
|
||||
|
||||
new definition.Method.Explicit(
|
||||
methRef,
|
||||
newBody,
|
||||
isPrivate,
|
||||
loc,
|
||||
passData,
|
||||
diagnostics
|
||||
)
|
||||
new definition.Method.Explicit(methodBinding, newBody)
|
||||
} else {
|
||||
if (args.isEmpty)
|
||||
errors.Conversion(meth, errors.Conversion.MissingArgs)
|
||||
errors.Conversion(methodBinding, errors.Conversion.MissingArgs)
|
||||
else if (args.head.ascribedType.isEmpty) {
|
||||
errors.Conversion(
|
||||
args.head,
|
||||
@ -271,13 +261,10 @@ case object FunctionBinding extends IRPass {
|
||||
new Function.Lambda(List(arg), body, None)
|
||||
)
|
||||
Right(
|
||||
definition.Method.Conversion(
|
||||
methRef,
|
||||
new definition.Method.Conversion(
|
||||
methodBinding,
|
||||
firstArgumentType,
|
||||
newBody,
|
||||
loc,
|
||||
passData,
|
||||
diagnostics
|
||||
newBody
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import org.enso.compiler.pass.analyse.{
|
||||
TailCall
|
||||
}
|
||||
import org.enso.compiler.pass.lint.UnusedBindings
|
||||
import org.enso.compiler.pass.optimise.{LambdaConsolidate}
|
||||
import org.enso.compiler.pass.optimise.LambdaConsolidate
|
||||
import org.enso.compiler.pass.resolve.{
|
||||
DocumentationComments,
|
||||
IgnoredBindings,
|
||||
@ -137,7 +137,7 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
* @param supply the compiler's fresh name supply
|
||||
* @return `name`, desugared where necessary
|
||||
*/
|
||||
def desugarName(name: Name, supply: FreshNameSupply): Expression = {
|
||||
private def desugarName(name: Name, supply: FreshNameSupply): Expression = {
|
||||
name match {
|
||||
case blank: Name.Blank =>
|
||||
val newName = supply.newName()
|
||||
@ -169,12 +169,12 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
* @param freshNameSupply the compiler's supply of fresh names
|
||||
* @return `application`, with any lambda shorthand arguments desugared
|
||||
*/
|
||||
def desugarApplication(
|
||||
private def desugarApplication(
|
||||
application: Application,
|
||||
freshNameSupply: FreshNameSupply
|
||||
): Expression = {
|
||||
application match {
|
||||
case p @ Application.Prefix(fn, args, _, _, _, _) =>
|
||||
case p @ Application.Prefix(fn, args, _, _, _) =>
|
||||
// Determine which arguments are lambda shorthand
|
||||
val argIsUnderscore = determineLambdaShorthand(args)
|
||||
|
||||
@ -183,7 +183,7 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
args
|
||||
.zip(argIsUnderscore)
|
||||
.map(updateShorthandArg(_, freshNameSupply))
|
||||
.map { case s @ CallArgument.Specified(_, value, _, _, _) =>
|
||||
.map { case s @ CallArgument.Specified(_, value, _, _) =>
|
||||
s.copy(value = desugarExpression(value, freshNameSupply))
|
||||
}
|
||||
|
||||
@ -250,9 +250,9 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
case lam: Function.Lambda => lam.copy(location = p.location)
|
||||
case result => result
|
||||
}
|
||||
case f @ Application.Force(tgt, _, _, _) =>
|
||||
case f @ Application.Force(tgt, _, _) =>
|
||||
f.copy(target = desugarExpression(tgt, freshNameSupply))
|
||||
case vector @ Application.Sequence(items, _, _, _) =>
|
||||
case vector @ Application.Sequence(items, _, _) =>
|
||||
var bindings: List[Name] = List()
|
||||
val newItems = items.map {
|
||||
case blank: Name.Blank =>
|
||||
@ -280,7 +280,7 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
)
|
||||
new Function.Lambda(List(defArg), body, locWithoutId)
|
||||
}
|
||||
case tSet @ Application.Typeset(expr, _, _, _) =>
|
||||
case tSet @ Application.Typeset(expr, _, _) =>
|
||||
tSet.copy(expression = expr.map(desugarExpression(_, freshNameSupply)))
|
||||
case _: Operator =>
|
||||
throw new CompilerError(
|
||||
@ -297,8 +297,10 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
* @return a list containing `true` for a given position if the arg in that
|
||||
* position is lambda shorthand, otherwise `false`
|
||||
*/
|
||||
def determineLambdaShorthand(args: List[CallArgument]): List[Boolean] = {
|
||||
args.map { case CallArgument.Specified(_, value, _, _, _) =>
|
||||
private def determineLambdaShorthand(
|
||||
args: List[CallArgument]
|
||||
): List[Boolean] = {
|
||||
args.map { case CallArgument.Specified(_, value, _, _) =>
|
||||
value match {
|
||||
case _: Name.Blank => true
|
||||
case _ => false
|
||||
@ -314,7 +316,7 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
* @return the above described pair for a given position if the argument in
|
||||
* a given position is shorthand, otherwise [[None]].
|
||||
*/
|
||||
def updateShorthandArg(
|
||||
private def updateShorthandArg(
|
||||
argAndIsShorthand: (CallArgument, Boolean),
|
||||
freshNameSupply: FreshNameSupply
|
||||
): CallArgument = {
|
||||
@ -322,7 +324,7 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
val isShorthand = argAndIsShorthand._2
|
||||
|
||||
arg match {
|
||||
case s @ CallArgument.Specified(_, value, _, _, _) =>
|
||||
case s @ CallArgument.Specified(_, value, _, _) =>
|
||||
if (isShorthand) {
|
||||
val newName = freshNameSupply
|
||||
.newName()
|
||||
@ -345,13 +347,13 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
* @return a corresponding definition argument if `arg` `isShorthand`,
|
||||
* otherwise [[None]]
|
||||
*/
|
||||
def generateDefinitionArg(
|
||||
private def generateDefinitionArg(
|
||||
arg: CallArgument,
|
||||
isShorthand: Boolean
|
||||
): Option[DefinitionArgument] = {
|
||||
if (isShorthand) {
|
||||
arg match {
|
||||
case CallArgument.Specified(_, value, _, passData, diagnostics) =>
|
||||
case specified @ CallArgument.Specified(_, value, _, passData) =>
|
||||
// Note [Safe Casting to Name.Literal]
|
||||
val defArgName =
|
||||
Name.Literal(
|
||||
@ -361,14 +363,14 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
)
|
||||
|
||||
Some(
|
||||
DefinitionArgument.Specified(
|
||||
new DefinitionArgument.Specified(
|
||||
defArgName,
|
||||
None,
|
||||
None,
|
||||
suspended = false,
|
||||
None,
|
||||
passData.duplicate,
|
||||
diagnostics.copy
|
||||
specified.diagnosticsCopy
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -391,7 +393,7 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
* @param freshNameSupply the compiler's supply of fresh names
|
||||
* @return `caseExpr`, with any lambda shorthand desugared
|
||||
*/
|
||||
def desugarCaseExpr(
|
||||
private def desugarCaseExpr(
|
||||
caseExpr: Case.Expr,
|
||||
freshNameSupply: FreshNameSupply
|
||||
): Expression = {
|
||||
@ -400,14 +402,14 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
)
|
||||
|
||||
caseExpr.scrutinee match {
|
||||
case Name.Blank(loc, passData, diagnostics) =>
|
||||
case nameBlank: Name.Blank =>
|
||||
val scrutineeName =
|
||||
freshNameSupply
|
||||
.newName()
|
||||
.copy(
|
||||
location = loc,
|
||||
passData = passData,
|
||||
diagnostics = diagnostics
|
||||
location = nameBlank.location,
|
||||
passData = nameBlank.passData,
|
||||
diagnostics = nameBlank.diagnostics
|
||||
)
|
||||
|
||||
val lambdaArg = DefinitionArgument.Specified(
|
||||
@ -424,11 +426,10 @@ case object LambdaShorthandToLambda extends IRPass {
|
||||
)
|
||||
|
||||
new Function.Lambda(
|
||||
caseExpr,
|
||||
List(lambdaArg),
|
||||
newCaseExpr,
|
||||
caseExpr.location,
|
||||
passData = caseExpr.passData,
|
||||
diagnostics = caseExpr.diagnostics
|
||||
caseExpr.location
|
||||
)
|
||||
case x =>
|
||||
caseExpr.copy(
|
||||
|
@ -155,12 +155,12 @@ case object NestedPatternMatch extends IRPass {
|
||||
* @param freshNameSupply the compiler's supply of fresh names
|
||||
* @return `expr`, with any nested patterns desugared
|
||||
*/
|
||||
def desugarCase(
|
||||
private def desugarCase(
|
||||
expr: Case,
|
||||
freshNameSupply: FreshNameSupply
|
||||
): Expression = {
|
||||
expr match {
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
val scrutineeBindingName = freshNameSupply.newName()
|
||||
val scrutineeExpression = desugarExpression(scrutinee, freshNameSupply)
|
||||
val scrutineeBinding =
|
||||
@ -198,14 +198,14 @@ case object NestedPatternMatch extends IRPass {
|
||||
* @return `branch`, with any nested patterns desugared
|
||||
*/
|
||||
@scala.annotation.tailrec
|
||||
def desugarCaseBranch(
|
||||
private def desugarCaseBranch(
|
||||
branch: Case.Branch,
|
||||
topBranchLocation: Option[IdentifiedLocation],
|
||||
freshNameSupply: FreshNameSupply
|
||||
): Case.Branch = {
|
||||
if (containsNestedPatterns(branch.pattern)) {
|
||||
branch.pattern match {
|
||||
case cons @ Pattern.Constructor(constrName, fields, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(constrName, fields, _, _) =>
|
||||
// Note [Unsafe Getting the Nested Field]
|
||||
val (lastNestedPattern, nestedPosition) =
|
||||
fields.zipWithIndex.findLast { case (pat, _) => isNested(pat) }.get
|
||||
@ -255,7 +255,7 @@ case object NestedPatternMatch extends IRPass {
|
||||
throw new CompilerError(
|
||||
"Type patterns cannot be nested. This should be unreachable."
|
||||
)
|
||||
case Pattern.Documentation(_, _, _, _) =>
|
||||
case Pattern.Documentation(_, _, _) =>
|
||||
throw new CompilerError(
|
||||
"Branch documentation should be desugared at an earlier stage."
|
||||
)
|
||||
@ -295,7 +295,7 @@ case object NestedPatternMatch extends IRPass {
|
||||
* a success
|
||||
* @return a nested case expression of the form above
|
||||
*/
|
||||
def generateNestedCase(
|
||||
private def generateNestedCase(
|
||||
pattern: Pattern,
|
||||
nestedScrutinee: Expression,
|
||||
currentBranchExpr: Expression
|
||||
@ -326,7 +326,7 @@ case object NestedPatternMatch extends IRPass {
|
||||
def containsNestedPatterns(pattern: Pattern): Boolean =
|
||||
pattern match {
|
||||
case _: Pattern.Name => false
|
||||
case Pattern.Constructor(_, fields, _, _, _) =>
|
||||
case Pattern.Constructor(_, fields, _, _) =>
|
||||
fields.exists {
|
||||
case _: Pattern.Constructor => true
|
||||
case _: Pattern.Name => false
|
||||
|
@ -70,18 +70,17 @@ case object OperatorToFunction extends IRPass {
|
||||
ir: Expression,
|
||||
inlineContext: InlineContext
|
||||
): Expression =
|
||||
ir.transformExpressions {
|
||||
case Operator.Binary(l, op, r, loc, passData, diag) =>
|
||||
Application.Prefix(
|
||||
op,
|
||||
List(
|
||||
l.mapExpressions(runExpression(_, inlineContext)),
|
||||
r.mapExpressions(runExpression(_, inlineContext))
|
||||
),
|
||||
hasDefaultsSuspended = false,
|
||||
loc,
|
||||
passData,
|
||||
diag
|
||||
)
|
||||
ir.transformExpressions { case operatorBinary: Operator.Binary =>
|
||||
new Application.Prefix(
|
||||
operatorBinary.operator,
|
||||
List(
|
||||
operatorBinary.left.mapExpressions(runExpression(_, inlineContext)),
|
||||
operatorBinary.right.mapExpressions(runExpression(_, inlineContext))
|
||||
),
|
||||
hasDefaultsSuspended = false,
|
||||
operatorBinary.location,
|
||||
operatorBinary.passData,
|
||||
operatorBinary.diagnostics
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ case object SectionsToBinOp extends IRPass {
|
||||
inlineContext: InlineContext
|
||||
): Expression = {
|
||||
section match {
|
||||
case Section.Left(arg, op, loc, passData, diagnostics) =>
|
||||
case sectionLeft @ Section.Left(arg, op, loc, passData) =>
|
||||
val rightArgName = freshNameSupply.newName()
|
||||
val rightCallArg =
|
||||
CallArgument.Specified(None, rightArgName, None)
|
||||
@ -124,13 +124,13 @@ case object SectionsToBinOp extends IRPass {
|
||||
suspended = false,
|
||||
None
|
||||
)
|
||||
val opCall = Application.Prefix(
|
||||
val opCall = new Application.Prefix(
|
||||
function = op,
|
||||
arguments = List(leftCallArg, rightCallArg),
|
||||
hasDefaultsSuspended = false,
|
||||
location = None,
|
||||
passData,
|
||||
diagnostics
|
||||
passData = passData,
|
||||
diagnostics = sectionLeft.diagnostics
|
||||
)
|
||||
|
||||
val rightLam = new Function.Lambda(
|
||||
@ -144,21 +144,20 @@ case object SectionsToBinOp extends IRPass {
|
||||
rightLam,
|
||||
loc
|
||||
)
|
||||
|
||||
} else {
|
||||
val newArg = arg.mapExpressions(runExpression(_, inlineContext))
|
||||
|
||||
Application.Prefix(
|
||||
new Application.Prefix(
|
||||
function = op,
|
||||
arguments = List(newArg),
|
||||
hasDefaultsSuspended = false,
|
||||
location = loc,
|
||||
passData,
|
||||
diagnostics
|
||||
passData = passData,
|
||||
diagnostics = sectionLeft.diagnostics
|
||||
)
|
||||
}
|
||||
|
||||
case Section.Sides(op, loc, passData, diagnostics) =>
|
||||
case sectionSides @ Section.Sides(op, loc, passData) =>
|
||||
val leftArgName = freshNameSupply.newName()
|
||||
val leftCallArg =
|
||||
CallArgument.Specified(None, leftArgName, None)
|
||||
@ -181,13 +180,13 @@ case object SectionsToBinOp extends IRPass {
|
||||
None
|
||||
)
|
||||
|
||||
val opCall = Application.Prefix(
|
||||
val opCall = new Application.Prefix(
|
||||
function = op,
|
||||
arguments = List(leftCallArg, rightCallArg),
|
||||
hasDefaultsSuspended = false,
|
||||
location = None,
|
||||
passData,
|
||||
diagnostics
|
||||
passData = passData,
|
||||
diagnostics = sectionSides.diagnostics
|
||||
)
|
||||
|
||||
val rightLambda = new Function.Lambda(
|
||||
@ -221,7 +220,7 @@ case object SectionsToBinOp extends IRPass {
|
||||
* The same is true of left sections.
|
||||
*/
|
||||
|
||||
case Section.Right(op, arg, loc, passData, diagnostics) =>
|
||||
case sectionRight @ Section.Right(op, arg, loc, passData) =>
|
||||
val leftArgName = freshNameSupply.newName()
|
||||
val leftCallArg =
|
||||
CallArgument.Specified(None, leftArgName, None)
|
||||
@ -247,13 +246,13 @@ case object SectionsToBinOp extends IRPass {
|
||||
None
|
||||
)
|
||||
|
||||
val opCall = Application.Prefix(
|
||||
val opCall = new Application.Prefix(
|
||||
function = op,
|
||||
arguments = List(leftCallArg, rightCallArg),
|
||||
hasDefaultsSuspended = false,
|
||||
location = None,
|
||||
passData,
|
||||
diagnostics
|
||||
passData = passData,
|
||||
diagnostics = sectionRight.diagnostics
|
||||
)
|
||||
|
||||
val leftLam = new Function.Lambda(
|
||||
@ -270,13 +269,13 @@ case object SectionsToBinOp extends IRPass {
|
||||
} else {
|
||||
val newArg = arg.mapExpressions(runExpression(_, inlineContext))
|
||||
|
||||
val opCall = Application.Prefix(
|
||||
val opCall = new Application.Prefix(
|
||||
function = op,
|
||||
arguments = List(leftCallArg, newArg),
|
||||
hasDefaultsSuspended = false,
|
||||
location = None,
|
||||
passData,
|
||||
diagnostics
|
||||
passData = passData,
|
||||
diagnostics = sectionRight.diagnostics
|
||||
)
|
||||
|
||||
new Function.Lambda(
|
||||
|
@ -42,7 +42,6 @@ case object ModuleNameConflicts extends IRPass {
|
||||
None,
|
||||
None,
|
||||
true,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
Some(mod)
|
||||
|
@ -48,19 +48,17 @@ object NoSelfInStatic extends IRPass {
|
||||
}
|
||||
|
||||
private def transformSelfToError: PartialFunction[Expression, Expression] = {
|
||||
case Name.Self(location, false, passData, diagnostics) =>
|
||||
errors.Syntax(
|
||||
case nameSelf @ Name.Self(location, false, passData) =>
|
||||
new errors.Syntax(
|
||||
location.get,
|
||||
errors.Syntax.InvalidSelfArgUsage,
|
||||
passData,
|
||||
diagnostics
|
||||
nameSelf.diagnostics
|
||||
)
|
||||
}
|
||||
|
||||
/** A method is static if it is either not defined within a type, or if it does not
|
||||
* contain a non-synthetic `self` argument.
|
||||
* @param method
|
||||
* @return
|
||||
*/
|
||||
private def isStaticMethod(
|
||||
method: definition.Method
|
||||
@ -70,8 +68,7 @@ object NoSelfInStatic extends IRPass {
|
||||
): Option[DefinitionArgument] = {
|
||||
arguments.collectFirst {
|
||||
case arg @ DefinitionArgument.Specified(
|
||||
Name.Self(_, false, _, _),
|
||||
_,
|
||||
Name.Self(_, false, _),
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
|
@ -85,7 +85,7 @@ case object ShadowedPatternFields extends IRPass {
|
||||
* @param expression the expression to lint
|
||||
* @return `expression`, with warnings for any shadowed pattern variables
|
||||
*/
|
||||
def lintExpression(
|
||||
private def lintExpression(
|
||||
expression: Expression
|
||||
): Expression = {
|
||||
expression.transformExpressions { case cse: Case =>
|
||||
@ -100,7 +100,7 @@ case object ShadowedPatternFields extends IRPass {
|
||||
*/
|
||||
def lintCase(cse: Case): Case = {
|
||||
cse match {
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
expr.copy(
|
||||
scrutinee = lintExpression(scrutinee),
|
||||
branches = branches.map(lintCaseBranch)
|
||||
@ -139,7 +139,7 @@ case object ShadowedPatternFields extends IRPass {
|
||||
|
||||
def go(pattern: Pattern, seenNames: mutable.Set[String]): Pattern = {
|
||||
pattern match {
|
||||
case named @ Pattern.Name(name, location, _, _) =>
|
||||
case named @ Pattern.Name(name, location, _) =>
|
||||
if (seenNames.contains(name.name)) {
|
||||
val warning = warnings.Shadowed
|
||||
.PatternBinding(name.name, lastSeen(name.name), location)
|
||||
@ -157,7 +157,7 @@ case object ShadowedPatternFields extends IRPass {
|
||||
} else {
|
||||
named
|
||||
}
|
||||
case cons @ Pattern.Constructor(_, fields, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(_, fields, _, _) =>
|
||||
val newFields = fields.reverse.map(go(_, seenNames)).reverse
|
||||
|
||||
cons.copy(
|
||||
@ -165,7 +165,7 @@ case object ShadowedPatternFields extends IRPass {
|
||||
)
|
||||
case literal: Pattern.Literal =>
|
||||
literal
|
||||
case typed @ Pattern.Type(name, _, location, _, _) =>
|
||||
case typed @ Pattern.Type(name, _, location, _) =>
|
||||
if (seenNames.contains(name.name)) {
|
||||
val warning = warnings.Shadowed
|
||||
.PatternBinding(name.name, lastSeen(name.name), location)
|
||||
|
@ -130,7 +130,7 @@ case object UnusedBindings extends IRPass {
|
||||
* @param context the inline context in which linting is taking place
|
||||
* @return `function`, with any lints attached
|
||||
*/
|
||||
def lintFunction(
|
||||
private def lintFunction(
|
||||
function: Function,
|
||||
context: InlineContext
|
||||
): Function = {
|
||||
@ -172,7 +172,7 @@ case object UnusedBindings extends IRPass {
|
||||
* @param context the inline context in which linting is taking place
|
||||
* @return `argument`, with any lints attached
|
||||
*/
|
||||
def lintFunctionArgument(
|
||||
private def lintFunctionArgument(
|
||||
argument: DefinitionArgument,
|
||||
context: InlineContext
|
||||
): DefinitionArgument = {
|
||||
@ -199,11 +199,10 @@ case object UnusedBindings extends IRPass {
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
s
|
||||
case s @ DefinitionArgument.Specified(name, _, default, _, _, _, _) =>
|
||||
case s @ DefinitionArgument.Specified(name, _, default, _, _, _) =>
|
||||
if (!isIgnored && !isUsed) {
|
||||
val nameToReport = name match {
|
||||
case literal: Name.Literal =>
|
||||
@ -225,7 +224,7 @@ case object UnusedBindings extends IRPass {
|
||||
*/
|
||||
def lintCase(cse: Case, context: InlineContext): Case = {
|
||||
cse match {
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
expr.copy(
|
||||
scrutinee = runExpression(scrutinee, context),
|
||||
branches = branches.map(lintCaseBranch(_, context))
|
||||
@ -257,7 +256,7 @@ case object UnusedBindings extends IRPass {
|
||||
*/
|
||||
def lintPattern(pattern: Pattern): Pattern = {
|
||||
pattern match {
|
||||
case n @ Pattern.Name(name, _, _, _) =>
|
||||
case n @ Pattern.Name(name, _, _) =>
|
||||
val isIgnored = name
|
||||
.unsafeGetMetadata(
|
||||
IgnoredBindings,
|
||||
@ -277,7 +276,7 @@ case object UnusedBindings extends IRPass {
|
||||
if (!isIgnored && !isUsed) {
|
||||
n.addDiagnostic(warnings.Unused.PatternBinding(name))
|
||||
} else pattern
|
||||
case cons @ Pattern.Constructor(_, fields, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(_, fields, _, _) =>
|
||||
if (!cons.isDesugared) {
|
||||
throw new CompilerError(
|
||||
"Nested patterns should not be present during linting."
|
||||
@ -287,7 +286,7 @@ case object UnusedBindings extends IRPass {
|
||||
cons.copy(
|
||||
fields = fields.map(lintPattern)
|
||||
)
|
||||
case typed @ Pattern.Type(name, _, _, _, _) =>
|
||||
case typed @ Pattern.Type(name, _, _, _) =>
|
||||
val isIgnored = name
|
||||
.unsafeGetMetadata(
|
||||
IgnoredBindings,
|
||||
|
@ -221,16 +221,16 @@ case object LambdaConsolidate extends IRPass {
|
||||
if (isShadowed) {
|
||||
val restArgs = args.drop(ix + 1)
|
||||
arg match {
|
||||
case spec @ DefinitionArgument.Specified(argName, _, _, _, _, _, _) =>
|
||||
case spec @ DefinitionArgument.Specified(argName, _, _, _, _, _) =>
|
||||
val mShadower = restArgs.collectFirst {
|
||||
case s @ DefinitionArgument.Specified(sName, _, _, _, _, _, _)
|
||||
case s @ DefinitionArgument.Specified(sName, _, _, _, _, _)
|
||||
if sName.name == argName.name =>
|
||||
s
|
||||
}
|
||||
|
||||
val shadower: IR = mShadower.getOrElse(Empty(spec.location))
|
||||
|
||||
spec.diagnostics.add(
|
||||
spec.getDiagnostics.add(
|
||||
warnings.Shadowed
|
||||
.FunctionParam(argName.name, shadower, spec.location)
|
||||
)
|
||||
@ -249,9 +249,9 @@ case object LambdaConsolidate extends IRPass {
|
||||
* @param body the function body to optimise
|
||||
* @return the directly chained lambdas in `body`
|
||||
*/
|
||||
def gatherChainedLambdas(body: Expression): List[Function.Lambda] = {
|
||||
private def gatherChainedLambdas(body: Expression): List[Function.Lambda] = {
|
||||
body match {
|
||||
case Expression.Block(expressions, lam: Function.Lambda, _, _, _, _)
|
||||
case Expression.Block(expressions, lam: Function.Lambda, _, _, _)
|
||||
if expressions.isEmpty =>
|
||||
lam :: gatherChainedLambdas(lam.body)
|
||||
case l @ Function.Lambda(_, body, _, _, _, _) =>
|
||||
@ -271,7 +271,7 @@ case object LambdaConsolidate extends IRPass {
|
||||
* @return `body` and `defaults` with any occurrence of the old name replaced
|
||||
* by the new name
|
||||
*/
|
||||
def replaceUsages(
|
||||
private def replaceUsages(
|
||||
body: Expression,
|
||||
defaults: List[Option[Expression]],
|
||||
argument: DefinitionArgument,
|
||||
@ -296,7 +296,7 @@ case object LambdaConsolidate extends IRPass {
|
||||
* be replaced
|
||||
* @return `expr`, with occurrences of the symbol for `argument` replaced
|
||||
*/
|
||||
def replaceInExpression(
|
||||
private def replaceInExpression(
|
||||
expr: Expression,
|
||||
argument: DefinitionArgument,
|
||||
toReplaceExpressionIds: Set[UUID @Identifier]
|
||||
@ -314,7 +314,7 @@ case object LambdaConsolidate extends IRPass {
|
||||
* replacement
|
||||
* @return `name`, with the symbol replaced by `argument.name`
|
||||
*/
|
||||
def replaceInName(
|
||||
private def replaceInName(
|
||||
name: Name,
|
||||
argument: DefinitionArgument,
|
||||
toReplaceExpressionIds: Set[UUID @Identifier]
|
||||
@ -348,7 +348,7 @@ case object LambdaConsolidate extends IRPass {
|
||||
* @param args the consolidated list of function arguments
|
||||
* @return the set of aliasing identifiers shadowed by `args`
|
||||
*/
|
||||
def getShadowedBindingIds(
|
||||
private def getShadowedBindingIds(
|
||||
args: List[DefinitionArgument]
|
||||
): Set[AliasGraph.Id] = {
|
||||
args
|
||||
@ -376,7 +376,7 @@ case object LambdaConsolidate extends IRPass {
|
||||
* @return the set of usage IR identifiers for each shadowed argument, where
|
||||
* an empty set represents a non-shadowed argument
|
||||
*/
|
||||
def usageIdsForShadowedArgs(
|
||||
private def usageIdsForShadowedArgs(
|
||||
argsWithShadowed: List[(DefinitionArgument, Boolean)]
|
||||
): List[Set[UUID @Identifier]] = {
|
||||
argsWithShadowed.map {
|
||||
@ -447,7 +447,7 @@ case object LambdaConsolidate extends IRPass {
|
||||
* @param usageIdsForShadowed the identifiers for usages of shadowed names
|
||||
* @return `args` and `body`, with any usages of shadowed symbols replaced
|
||||
*/
|
||||
def computeReplacedExpressions(
|
||||
private def computeReplacedExpressions(
|
||||
args: List[DefinitionArgument],
|
||||
body: Expression,
|
||||
usageIdsForShadowed: List[Set[UUID @Identifier]]
|
||||
|
@ -103,7 +103,7 @@ case object UnreachableMatchBranches extends IRPass {
|
||||
* @param expression the expression to optimize
|
||||
* @return `expression` with unreachable case branches removed
|
||||
*/
|
||||
def optimizeExpression(expression: Expression): Expression = {
|
||||
private def optimizeExpression(expression: Expression): Expression = {
|
||||
expression.transformExpressions { case cse: Case =>
|
||||
optimizeCase(cse)
|
||||
}
|
||||
@ -118,9 +118,9 @@ case object UnreachableMatchBranches extends IRPass {
|
||||
* @return `cse` with unreachable branches removed
|
||||
*/
|
||||
//noinspection DuplicatedCode
|
||||
def optimizeCase(cse: Case): Case = {
|
||||
private def optimizeCase(cse: Case): Case = {
|
||||
cse match {
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
val reachableNonCatchAllBranches = branches.takeWhile(!isCatchAll(_))
|
||||
val firstCatchAll = branches.find(isCatchAll)
|
||||
val unreachableBranches =
|
||||
@ -178,7 +178,7 @@ case object UnreachableMatchBranches extends IRPass {
|
||||
* @param branch the branch to check
|
||||
* @return `true` if `branch` is catch-all, otherwise `false`
|
||||
*/
|
||||
def isCatchAll(branch: Case.Branch): Boolean = {
|
||||
private def isCatchAll(branch: Case.Branch): Boolean = {
|
||||
branch.pattern match {
|
||||
case _: Pattern.Name => true
|
||||
case _: Pattern.Constructor => false
|
||||
|
@ -126,10 +126,10 @@ case object DocumentationComments extends IRPass {
|
||||
private def resolveBranches(items: Seq[Case.Branch]): Seq[Case.Branch] = {
|
||||
var lastDoc: Option[String] = None
|
||||
items.flatMap {
|
||||
case Case.Branch(Pattern.Documentation(doc, _, _, _), _, _, _, _, _) =>
|
||||
case Case.Branch(Pattern.Documentation(doc, _, _), _, _, _, _) =>
|
||||
lastDoc = Some(doc)
|
||||
None
|
||||
case branch @ Case.Branch(pattern, expression, _, _, _, _) =>
|
||||
case branch @ Case.Branch(pattern, expression, _, _, _) =>
|
||||
val resolved =
|
||||
branch.copy(
|
||||
pattern = pattern.mapExpressions(resolveExpression),
|
||||
|
@ -72,7 +72,6 @@ case object ExpressionAnnotations extends IRPass {
|
||||
arguments,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
if (isKnownAnnotation(ann.name)) {
|
||||
@ -88,7 +87,7 @@ case object ExpressionAnnotations extends IRPass {
|
||||
case realFun :: args =>
|
||||
val recurFun = doExpression(realFun.value)
|
||||
val (finalFun, preArgs) = recurFun match {
|
||||
case Application.Prefix(nextFun, moreArgs, _, _, _, _) =>
|
||||
case Application.Prefix(nextFun, moreArgs, _, _, _) =>
|
||||
(nextFun, moreArgs)
|
||||
case _ => (recurFun, List())
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ case object FullyQualifiedNames extends IRPass {
|
||||
} else {
|
||||
lit
|
||||
}
|
||||
case app @ Application.Prefix(_, List(_), _, _, _, _) =>
|
||||
case app @ Application.Prefix(_, List(_), _, _, _) =>
|
||||
app.function match {
|
||||
case lit: Name.Literal =>
|
||||
if (lit.isMethod)
|
||||
|
@ -135,7 +135,7 @@ case object IgnoredBindings extends IRPass {
|
||||
* @param supply the compiler's supply of fresh names
|
||||
* @return `binding`, with any ignored bindings desugared
|
||||
*/
|
||||
def resolveBinding(
|
||||
private def resolveBinding(
|
||||
binding: Expression.Binding,
|
||||
supply: FreshNameSupply
|
||||
): Expression.Binding = {
|
||||
@ -203,15 +203,14 @@ case object IgnoredBindings extends IRPass {
|
||||
* @param freshNameSupply the compiler's fresh name supply
|
||||
* @return `arg`, if `isIgnored` is `false`, otherwise `arg` with a new name
|
||||
*/
|
||||
def genNewArg(
|
||||
private def genNewArg(
|
||||
arg: DefinitionArgument,
|
||||
isIgnored: Boolean,
|
||||
freshNameSupply: FreshNameSupply
|
||||
): DefinitionArgument = {
|
||||
arg match {
|
||||
case spec @ DefinitionArgument.Specified(
|
||||
Name.Self(_, _, _, _),
|
||||
_,
|
||||
Name.Self(_, _, _),
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
@ -258,9 +257,9 @@ case object IgnoredBindings extends IRPass {
|
||||
* @param ir the definition argument to check
|
||||
* @return `true` if `ir` represents an ignore, otherwise `false`
|
||||
*/
|
||||
def isIgnoreArg(ir: DefinitionArgument): Boolean = {
|
||||
private def isIgnoreArg(ir: DefinitionArgument): Boolean = {
|
||||
ir match {
|
||||
case DefinitionArgument.Specified(name, _, _, _, _, _, _) =>
|
||||
case DefinitionArgument.Specified(name, _, _, _, _, _) =>
|
||||
isIgnore(name)
|
||||
}
|
||||
}
|
||||
@ -284,9 +283,9 @@ case object IgnoredBindings extends IRPass {
|
||||
* @param supply the compiler's fresh name supply
|
||||
* @return `cse`, with any ignored bindings resolved
|
||||
*/
|
||||
def resolveCase(cse: Case, supply: FreshNameSupply): Case = {
|
||||
private def resolveCase(cse: Case, supply: FreshNameSupply): Case = {
|
||||
cse match {
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _, _) =>
|
||||
case expr @ Case.Expr(scrutinee, branches, _, _, _) =>
|
||||
expr.copy(
|
||||
scrutinee = resolveExpression(scrutinee, supply),
|
||||
branches = branches.map(resolveCaseBranch(_, supply))
|
||||
@ -304,7 +303,7 @@ case object IgnoredBindings extends IRPass {
|
||||
* @param supply the compiler's fresh name supply
|
||||
* @return `branch`, with any ignored bindings resolved
|
||||
*/
|
||||
def resolveCaseBranch(
|
||||
private def resolveCaseBranch(
|
||||
branch: Case.Branch,
|
||||
supply: FreshNameSupply
|
||||
): Case.Branch = {
|
||||
@ -320,12 +319,12 @@ case object IgnoredBindings extends IRPass {
|
||||
* @param supply the compiler's fresh name supply
|
||||
* @return `pattern`, with any ignored bindings resolved
|
||||
*/
|
||||
def resolvePattern(
|
||||
private def resolvePattern(
|
||||
pattern: Pattern,
|
||||
supply: FreshNameSupply
|
||||
): Pattern = {
|
||||
pattern match {
|
||||
case named @ Pattern.Name(name, _, _, _) =>
|
||||
case named @ Pattern.Name(name, _, _) =>
|
||||
if (isIgnore(name)) {
|
||||
val newName = supply
|
||||
.newName(from = Some(name))
|
||||
@ -344,12 +343,12 @@ case object IgnoredBindings extends IRPass {
|
||||
name = setNotIgnored(name)
|
||||
)
|
||||
}
|
||||
case cons @ Pattern.Constructor(_, fields, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(_, fields, _, _) =>
|
||||
cons.copy(
|
||||
fields = fields.map(resolvePattern(_, supply))
|
||||
)
|
||||
case literal: Pattern.Literal => literal
|
||||
case typed @ Pattern.Type(name, _, _, _, _) =>
|
||||
case typed @ Pattern.Type(name, _, _, _) =>
|
||||
if (isIgnore(name)) {
|
||||
val newName = supply
|
||||
.newName(from = Some(name))
|
||||
|
@ -145,8 +145,7 @@ case object MethodDefinitions extends IRPass {
|
||||
case lambda: Function.Lambda =>
|
||||
val newArguments = lambda.arguments match {
|
||||
case (selfArg @ DefinitionArgument.Specified(
|
||||
Name.Self(_, _, _, _),
|
||||
_,
|
||||
Name.Self(_, _, _),
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
|
@ -255,7 +255,7 @@ object Patterns extends IRPass {
|
||||
}
|
||||
case None => consPat.copy(constructor = resolvedName)
|
||||
}
|
||||
case tpePattern @ Pattern.Type(_, tpeName, _, _, _) =>
|
||||
case tpePattern @ Pattern.Type(_, tpeName, _, _) =>
|
||||
val resolution = tpeName match {
|
||||
case qual: Name.Qualified =>
|
||||
val parts = qual.parts.map(_.name)
|
||||
|
@ -212,7 +212,7 @@ case object SuspendedArguments extends IRPass {
|
||||
*/
|
||||
private def resolveExpression(expression: Expression): Expression = {
|
||||
expression.transformExpressions {
|
||||
case bind @ Expression.Binding(_, expr, _, _, _) =>
|
||||
case bind @ Expression.Binding(_, expr, _, _) =>
|
||||
val newExpr = bind.getMetadata(TypeSignatures) match {
|
||||
case Some(Signature(signature, _)) =>
|
||||
expr match {
|
||||
@ -250,8 +250,8 @@ case object SuspendedArguments extends IRPass {
|
||||
*/
|
||||
private def toSegments(signature: Expression): List[Expression] = {
|
||||
signature match {
|
||||
case Type.Function(args, ret, _, _, _) => args :+ ret
|
||||
case _ => List(signature)
|
||||
case Type.Function(args, ret, _, _) => args :+ ret
|
||||
case _ => List(signature)
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,8 +263,8 @@ case object SuspendedArguments extends IRPass {
|
||||
*/
|
||||
def representsSuspended(value: Expression): Boolean = {
|
||||
value match {
|
||||
case Name.Literal("Suspended", _, _, _, _, _) => true
|
||||
case _ => false
|
||||
case Name.Literal("Suspended", _, _, _, _) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ case object TypeFunctions extends IRPass {
|
||||
// === Pass Internals =======================================================
|
||||
|
||||
/** The names of the known typing functions. */
|
||||
val knownTypingFunctions: Set[String] = Set(
|
||||
private val knownTypingFunctions: Set[String] = Set(
|
||||
Type.Ascription.name,
|
||||
Type.Context.name,
|
||||
Type.Error.name,
|
||||
@ -122,9 +122,9 @@ case object TypeFunctions extends IRPass {
|
||||
* @param app the application to perform resolution in
|
||||
* @return `app`, with any typing functions resolved
|
||||
*/
|
||||
def resolveApplication(app: Application): Expression = {
|
||||
private def resolveApplication(app: Application): Expression = {
|
||||
app match {
|
||||
case pre @ Application.Prefix(fn, arguments, _, _, _, _) =>
|
||||
case pre @ Application.Prefix(fn, arguments, _, _, _) =>
|
||||
fn match {
|
||||
case name: Name if name.name == `type`.Set.Union.name =>
|
||||
val members = flattenUnion(app).map(resolveExpression)
|
||||
@ -137,13 +137,13 @@ case object TypeFunctions extends IRPass {
|
||||
arguments = arguments.map(resolveCallArgument)
|
||||
)
|
||||
}
|
||||
case force @ Application.Force(target, _, _, _) =>
|
||||
case force @ Application.Force(target, _, _) =>
|
||||
force.copy(target = resolveExpression(target))
|
||||
case seq @ Application.Sequence(items, _, _, _) =>
|
||||
case seq @ Application.Sequence(items, _, _) =>
|
||||
seq.copy(
|
||||
items = items.map(resolveExpression)
|
||||
)
|
||||
case tSet @ Application.Typeset(expr, _, _, _) =>
|
||||
case tSet @ Application.Typeset(expr, _, _) =>
|
||||
tSet.copy(
|
||||
expression = expr.map(resolveExpression)
|
||||
)
|
||||
@ -154,9 +154,9 @@ case object TypeFunctions extends IRPass {
|
||||
}
|
||||
}
|
||||
|
||||
def flattenUnion(expr: Expression): List[Expression] = {
|
||||
private def flattenUnion(expr: Expression): List[Expression] = {
|
||||
expr match {
|
||||
case Application.Prefix(n: Name, args, _, _, _, _)
|
||||
case Application.Prefix(n: Name, args, _, _, _)
|
||||
if n.name == `type`.Set.Union.name =>
|
||||
args.flatMap(arg => flattenUnion(arg.value))
|
||||
case _ => List(expr)
|
||||
@ -165,10 +165,13 @@ case object TypeFunctions extends IRPass {
|
||||
|
||||
/** Resolves a known typing function to its IR node.
|
||||
*
|
||||
* @param prefix the application to resolve
|
||||
* @param name the typing function name
|
||||
* @param arguments the application arguments
|
||||
* @param location the application location
|
||||
* @param originalIR the application to resolve
|
||||
* @return the IR node representing `prefix`
|
||||
*/
|
||||
def resolveKnownFunction(
|
||||
private def resolveKnownFunction(
|
||||
name: Name,
|
||||
arguments: List[CallArgument],
|
||||
location: Option[IdentifiedLocation],
|
||||
@ -208,9 +211,9 @@ case object TypeFunctions extends IRPass {
|
||||
* @param arg the argument to perform resolution in
|
||||
* @return `arg`, with any call arguments resolved
|
||||
*/
|
||||
def resolveCallArgument(arg: CallArgument): CallArgument = {
|
||||
private def resolveCallArgument(arg: CallArgument): CallArgument = {
|
||||
arg match {
|
||||
case spec @ CallArgument.Specified(_, value, _, _, _) =>
|
||||
case spec @ CallArgument.Specified(_, value, _, _) =>
|
||||
spec.copy(
|
||||
value = resolveExpression(value)
|
||||
)
|
||||
@ -230,9 +233,9 @@ case object TypeFunctions extends IRPass {
|
||||
* @param arg the argument to check
|
||||
* @return `true` if `arg` is valid, otherwise `false`
|
||||
*/
|
||||
def isValidCallArg(arg: CallArgument): Boolean = {
|
||||
private def isValidCallArg(arg: CallArgument): Boolean = {
|
||||
arg match {
|
||||
case CallArgument.Specified(name, _, _, _, _) =>
|
||||
case CallArgument.Specified(name, _, _, _) =>
|
||||
name.isEmpty
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ case object TypeSignatures extends IRPass {
|
||||
case _ =>
|
||||
}
|
||||
val res = lastSignature match {
|
||||
case Some(asc @ Type.Ascription(typed, sig, comment, _, _, _)) =>
|
||||
case Some(asc @ Type.Ascription(typed, sig, comment, _, _)) =>
|
||||
val methodRef = meth.methodReference
|
||||
val newMethodWithDoc = asc
|
||||
.getMetadata(DocumentationComments)
|
||||
@ -223,7 +223,6 @@ case object TypeSignatures extends IRPass {
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
val sig = resolveExpression(ascribedType.duplicate())
|
||||
@ -273,7 +272,7 @@ case object TypeSignatures extends IRPass {
|
||||
case binding: Expression.Binding =>
|
||||
val newBinding = binding.mapExpressions(resolveExpression)
|
||||
val res = lastSignature match {
|
||||
case Some(asc @ Type.Ascription(typed, sig, comment, _, _, _)) =>
|
||||
case Some(asc @ Type.Ascription(typed, sig, comment, _, _)) =>
|
||||
val name = binding.name
|
||||
val newBindingWithDoc = asc
|
||||
.getMetadata(DocumentationComments)
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.phase
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.CompilerContext.Module
|
||||
import org.enso.compiler.core.Implicits.AsMetadata
|
||||
import org.enso.compiler.core.ir.{DiagnosticStorage, MetadataStorage}
|
||||
import org.enso.compiler.core.ir.MetadataStorage
|
||||
import org.enso.compiler.core.ir.module.scope.{Export, Import}
|
||||
import org.enso.compiler.data.BindingsMap
|
||||
import org.enso.compiler.pass.analyse.BindingAnalysis
|
||||
@ -187,7 +187,6 @@ final class ImportResolver(compiler: Compiler) extends ImportResolverForIR {
|
||||
onlyNames,
|
||||
_,
|
||||
isSynthetic,
|
||||
_,
|
||||
_
|
||||
) if !isSynthetic =>
|
||||
val exportsItself = curModName.equals(expName.name)
|
||||
@ -201,8 +200,7 @@ final class ImportResolver(compiler: Compiler) extends ImportResolverForIR {
|
||||
None,
|
||||
location = None,
|
||||
isSynthetic = true,
|
||||
passData = new MetadataStorage(),
|
||||
diagnostics = DiagnosticStorage()
|
||||
passData = new MetadataStorage()
|
||||
)
|
||||
tryResolveImport(module.getIr, syntheticImport) match {
|
||||
case (_, Some(resolvedImp)) =>
|
||||
|
@ -424,7 +424,6 @@ final class EnsureCompiledJob(
|
||||
_,
|
||||
expression.errors.Resolution
|
||||
.ResolverError(BindingsMap.ResolutionNotFound),
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
DataflowAnalysis.DependencyInfo.Type.Static(
|
||||
|
@ -1044,12 +1044,12 @@ public class TypeInferenceTest extends CompilerTest {
|
||||
}
|
||||
|
||||
private List<Diagnostic> getImmediateDiagnostics(IR ir) {
|
||||
return CollectionConverters.asJava(ir.diagnostics().toList());
|
||||
return CollectionConverters.asJava(ir.getDiagnostics().toList());
|
||||
}
|
||||
|
||||
private List<Diagnostic> getDescendantsDiagnostics(IR ir) {
|
||||
return CollectionConverters.asJava(
|
||||
ir.preorder().flatMap((node) -> node.diagnostics().toList()));
|
||||
ir.preorder().flatMap(node -> node.getDiagnostics().toList()));
|
||||
}
|
||||
|
||||
private Method findStaticMethod(Module module, String name) {
|
||||
|
@ -128,9 +128,7 @@ public class ModuleTest {
|
||||
|
||||
assertNull("No IR by default", module.getIr());
|
||||
|
||||
var ir =
|
||||
new org.enso.compiler.core.ir.Module(
|
||||
nil(), nil(), nil(), false, Option.empty(), null, null);
|
||||
var ir = new org.enso.compiler.core.ir.Module(nil(), nil(), nil(), false, Option.empty(), null);
|
||||
compilerContext.updateModule(
|
||||
module,
|
||||
(u) -> {
|
||||
|
@ -3,7 +3,13 @@ package org.enso.compiler.test
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.{EnsoParser, IR, Identifier}
|
||||
import org.enso.compiler.core.Implicits.AsMetadata
|
||||
import org.enso.compiler.core.ir.{DefinitionArgument, Expression, Module, Name}
|
||||
import org.enso.compiler.core.ir.{
|
||||
DefinitionArgument,
|
||||
Diagnostic,
|
||||
Expression,
|
||||
Module,
|
||||
Name
|
||||
}
|
||||
import org.enso.compiler.core.ir.module.scope.Definition
|
||||
import org.enso.compiler.core.ir.module.scope.definition
|
||||
import org.enso.compiler.core.ir.MetadataStorage.MetadataPair
|
||||
@ -82,6 +88,21 @@ trait CompilerRunner {
|
||||
}
|
||||
}
|
||||
|
||||
/** Provides an extensions to work with diagnostic information attached to IR.
|
||||
*
|
||||
* @param ir the IR node
|
||||
*/
|
||||
implicit class DiagnosticStorageExt(ir: IR) {
|
||||
|
||||
/** Get the list of diagnostics attached to the provided IR node without
|
||||
* unnecessary allocations of [[org.enso.compiler.core.ir.DiagnosticStorage]].
|
||||
*
|
||||
* @return the list of attached diagnostics
|
||||
*/
|
||||
def diagnosticsList: List[Diagnostic] =
|
||||
if (ir.diagnostics() eq null) Nil else ir.diagnostics().toList
|
||||
}
|
||||
|
||||
/** Provides an extension method allowing the running of a specified list of
|
||||
* passes on the provided IR.
|
||||
*
|
||||
@ -151,23 +172,23 @@ trait CompilerRunner {
|
||||
*/
|
||||
def asMethod: definition.Method = {
|
||||
new definition.Method.Explicit(
|
||||
Name.MethodReference(
|
||||
Some(
|
||||
Name.Qualified(
|
||||
List(
|
||||
Name
|
||||
.Literal("TestType", isMethod = false, None)
|
||||
),
|
||||
None
|
||||
)
|
||||
definition.Method.Binding(
|
||||
Name.MethodReference(
|
||||
Some(
|
||||
Name.Qualified(
|
||||
List(Name.Literal("TestType", isMethod = false, None)),
|
||||
None
|
||||
)
|
||||
),
|
||||
Name.Literal("testMethod", isMethod = false, None),
|
||||
None
|
||||
),
|
||||
Name
|
||||
.Literal("testMethod", isMethod = false, None),
|
||||
Nil,
|
||||
false,
|
||||
ir,
|
||||
None
|
||||
),
|
||||
ir,
|
||||
false,
|
||||
None
|
||||
ir
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.enso.compiler.test.core.ir
|
||||
|
||||
import org.enso.compiler.core.ir.{Diagnostic, DiagnosticStorage, Empty}
|
||||
import org.enso.compiler.core.ir.expression.errors
|
||||
import org.enso.compiler.core.ir.expression.warnings
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
|
||||
@ -42,115 +41,5 @@ class DiagnosticStorageTest extends CompilerTest {
|
||||
diagnostics.toList should contain(mkDiagnostic("b"))
|
||||
diagnostics.toList should contain(mkDiagnostic("c"))
|
||||
}
|
||||
|
||||
"mapping across the diagnostics to produce a new sequence" in {
|
||||
val diagnostics = new DiagnosticStorage(
|
||||
List(
|
||||
mkDiagnostic("a"),
|
||||
mkDiagnostic("b"),
|
||||
mkDiagnostic("c")
|
||||
)
|
||||
)
|
||||
|
||||
diagnostics.map(d => d.location) shouldEqual Seq(None, None, None)
|
||||
}
|
||||
|
||||
"mapping across the diagnostics in place" in {
|
||||
val diagnostics = new DiagnosticStorage(
|
||||
List(
|
||||
mkDiagnostic("a"),
|
||||
mkDiagnostic("b"),
|
||||
mkDiagnostic("c")
|
||||
)
|
||||
)
|
||||
|
||||
val expectedResult = List(
|
||||
mkDiagnostic("aaa"),
|
||||
mkDiagnostic("aaa"),
|
||||
mkDiagnostic("aaa")
|
||||
)
|
||||
|
||||
diagnostics.mapInPlace {
|
||||
case s: warnings.Shadowed.FunctionParam =>
|
||||
s.copy(shadowedName = "aaa")
|
||||
case x => x
|
||||
}
|
||||
|
||||
diagnostics.toList shouldEqual expectedResult
|
||||
}
|
||||
|
||||
"collecting across the diagnostics to produce a new sequence" in {
|
||||
val err = errors.Syntax(null, errors.Syntax.UnsupportedSyntax("aa"))
|
||||
|
||||
val diagnostics = new DiagnosticStorage(
|
||||
List(
|
||||
mkDiagnostic("a"),
|
||||
mkDiagnostic("b"),
|
||||
mkDiagnostic("c"),
|
||||
err
|
||||
)
|
||||
)
|
||||
|
||||
diagnostics.collect { case e: errors.Syntax =>
|
||||
e
|
||||
} shouldEqual Seq(err)
|
||||
}
|
||||
|
||||
"filtering the diagnostics" in {
|
||||
val diagnostics = new DiagnosticStorage(
|
||||
List(
|
||||
mkDiagnostic("aa"),
|
||||
mkDiagnostic("ba"),
|
||||
mkDiagnostic("cd")
|
||||
)
|
||||
)
|
||||
|
||||
val result = new DiagnosticStorage(
|
||||
List(mkDiagnostic("aa"), mkDiagnostic("ba"))
|
||||
)
|
||||
|
||||
diagnostics.filter {
|
||||
case s: warnings.Shadowed.FunctionParam =>
|
||||
s.shadowedName.contains("a")
|
||||
case _ => false
|
||||
} shouldEqual result
|
||||
}
|
||||
|
||||
"filtering the diagnostics in place" in {
|
||||
val diagnostics = new DiagnosticStorage(
|
||||
List(
|
||||
mkDiagnostic("aa"),
|
||||
mkDiagnostic("ba"),
|
||||
mkDiagnostic("cd")
|
||||
)
|
||||
)
|
||||
|
||||
val result = List(mkDiagnostic("aa"), mkDiagnostic("ba"))
|
||||
|
||||
diagnostics.filterInPlace {
|
||||
case s: warnings.Shadowed.FunctionParam =>
|
||||
s.shadowedName.contains("a")
|
||||
case _ => false
|
||||
}
|
||||
|
||||
diagnostics.toList shouldEqual result
|
||||
}
|
||||
|
||||
"folding over the diagnostics" in {
|
||||
val diagnostics = new DiagnosticStorage(
|
||||
List(
|
||||
mkDiagnostic("a"),
|
||||
mkDiagnostic("b"),
|
||||
mkDiagnostic("cd")
|
||||
)
|
||||
)
|
||||
|
||||
diagnostics.foldLeft("")((str, d) =>
|
||||
d match {
|
||||
case f: warnings.Shadowed.FunctionParam => str + f.shadowedName
|
||||
case _ => str
|
||||
}
|
||||
) shouldEqual "abcd"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ class FramePointerAnalysisTest extends CompilerTest {
|
||||
val syntheticSelfArg = findIRElement[DefinitionArgument.Specified](
|
||||
ir,
|
||||
_.name match {
|
||||
case Name.Self(loc, synthetic, _, _) if loc.isEmpty && synthetic =>
|
||||
case Name.Self(loc, synthetic, _) if loc.isEmpty && synthetic =>
|
||||
true
|
||||
case _ => false
|
||||
}
|
||||
@ -251,7 +251,7 @@ class FramePointerAnalysisTest extends CompilerTest {
|
||||
val syntheticSelfArg = findIRElement[DefinitionArgument.Specified](
|
||||
ir,
|
||||
_.name match {
|
||||
case Name.Self(loc, synthetic, _, _) if loc.isEmpty && synthetic =>
|
||||
case Name.Self(loc, synthetic, _) if loc.isEmpty && synthetic =>
|
||||
true
|
||||
case _ => false
|
||||
}
|
||||
|
@ -94,8 +94,14 @@ class GatherDiagnosticsTest extends CompilerTest {
|
||||
List(),
|
||||
None
|
||||
),
|
||||
new definition.Method.Explicit(method1Ref, lam, false, None),
|
||||
new definition.Method.Explicit(method2Ref, error3, false, None)
|
||||
new definition.Method.Explicit(
|
||||
definition.Method.Binding(method1Ref, Nil, false, lam, None),
|
||||
lam
|
||||
),
|
||||
new definition.Method.Explicit(
|
||||
definition.Method.Binding(method2Ref, Nil, false, error3, None),
|
||||
lam.copy(body = error3)
|
||||
)
|
||||
),
|
||||
false,
|
||||
None
|
||||
|
@ -186,15 +186,11 @@ class TailCallTest extends CompilerTest {
|
||||
.expressions(0)
|
||||
.asInstanceOf[Expression.Binding]
|
||||
.expression
|
||||
.diagnostics
|
||||
.filter(_.isInstanceOf[Warning.WrongTco])
|
||||
.toList
|
||||
.length shouldEqual 1
|
||||
.diagnosticsList
|
||||
.count(_.isInstanceOf[Warning.WrongTco]) shouldEqual 1
|
||||
|
||||
fnBody.returnValue.diagnostics
|
||||
.filter(_.isInstanceOf[Warning.WrongTco])
|
||||
.toList
|
||||
.length shouldEqual 0
|
||||
fnBody.returnValue.diagnosticsList
|
||||
.count(_.isInstanceOf[Warning.WrongTco]) shouldEqual 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,10 +221,8 @@ class TailCallTest extends CompilerTest {
|
||||
.returnValue
|
||||
.asInstanceOf[Application.Prefix]
|
||||
.function
|
||||
.diagnostics
|
||||
.filter(_.isInstanceOf[Warning.WrongTco])
|
||||
.toList
|
||||
.length shouldEqual 0
|
||||
.diagnosticsList
|
||||
.count(_.isInstanceOf[Warning.WrongTco]) shouldEqual 0
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ class GenerateMethodBodiesTest extends CompilerTest {
|
||||
bodyLambda.arguments.size shouldEqual 1
|
||||
val selfArg = bodyLambda.arguments.head.name
|
||||
selfArg shouldEqual Name.Self(location = irBazSndArg.location)
|
||||
resultLambda.diagnostics.collect { case w: Warning =>
|
||||
resultLambda.diagnosticsList.collect { case w: Warning =>
|
||||
w
|
||||
}.head shouldBe an[Warning.WrongSelfParameterPos]
|
||||
}
|
||||
@ -293,7 +293,7 @@ class GenerateMethodBodiesTest extends CompilerTest {
|
||||
val selfArg = resultArgs.head.name
|
||||
selfArg shouldBe a[Name.Self]
|
||||
selfArg.location shouldEqual irMethodAddSelfArg.head.name.location
|
||||
resultLambda.diagnostics.collect { case w: Warning =>
|
||||
resultLambda.diagnosticsList.collect { case w: Warning =>
|
||||
w
|
||||
} shouldBe empty
|
||||
}
|
||||
@ -306,13 +306,13 @@ class GenerateMethodBodiesTest extends CompilerTest {
|
||||
resultArgs.size shouldEqual 1
|
||||
val selfArg = resultArgs(0).name
|
||||
selfArg should not be an[Name.Self]
|
||||
resultLambda.diagnostics.collect { case w: Warning =>
|
||||
resultLambda.diagnosticsList.collect { case w: Warning =>
|
||||
w
|
||||
}.head shouldBe an[Warning.WrongSelfParameterPos]
|
||||
|
||||
val nestedLmabda = resultLambda.body.asInstanceOf[Function.Lambda]
|
||||
nestedLmabda.arguments.size shouldEqual 1
|
||||
nestedLmabda.arguments(0).name shouldBe an[Name.Self]
|
||||
val nestedLambda = resultLambda.body.asInstanceOf[Function.Lambda]
|
||||
nestedLambda.arguments.size shouldEqual 1
|
||||
nestedLambda.arguments(0).name shouldBe an[Name.Self]
|
||||
}
|
||||
}
|
||||
|
||||
@ -363,7 +363,7 @@ class GenerateMethodBodiesTest extends CompilerTest {
|
||||
body.arguments.head.name shouldBe an[Name.Literal]
|
||||
body.arguments.head.name.name shouldBe ConstantsNames.THAT_ARGUMENT
|
||||
|
||||
conversion.body.diagnostics.collect { case w: Warning =>
|
||||
conversion.body.diagnosticsList.collect { case w: Warning =>
|
||||
w
|
||||
}.head shouldBe an[Warning.WrongSelfParameterPos]
|
||||
}
|
||||
@ -381,7 +381,7 @@ class GenerateMethodBodiesTest extends CompilerTest {
|
||||
body.arguments.head.name shouldBe an[Name.Literal]
|
||||
body.arguments.head.name.name shouldBe ConstantsNames.THAT_ARGUMENT
|
||||
|
||||
conversion.body.diagnostics.collect { case w: Warning =>
|
||||
conversion.body.diagnosticsList.collect { case w: Warning =>
|
||||
w
|
||||
}.head shouldBe an[Warning.WrongSelfParameterPos]
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class NoSelfInStaticTests extends CompilerTest {
|
||||
| bar = self.x + self.x
|
||||
|""".stripMargin.preprocessModule.lint
|
||||
val errs = ir.bindings.flatMap(_.preorder).collect {
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _, _) =>
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _) =>
|
||||
err
|
||||
}
|
||||
errs should have size 2
|
||||
@ -68,7 +68,7 @@ class NoSelfInStaticTests extends CompilerTest {
|
||||
|static_method x y = x + y + self.data
|
||||
|""".stripMargin.preprocessModule.lint
|
||||
val errs = ir.bindings.flatMap(_.preorder).collect {
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _, _) =>
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _) =>
|
||||
err
|
||||
}
|
||||
errs should have size 1
|
||||
@ -85,7 +85,7 @@ class NoSelfInStaticTests extends CompilerTest {
|
||||
| nested_method (x + y)
|
||||
|""".stripMargin.preprocessModule.lint
|
||||
val errs = ir.bindings.flatMap(_.preorder).collect {
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _, _) =>
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _) =>
|
||||
err
|
||||
}
|
||||
errs should have size 1
|
||||
@ -103,7 +103,7 @@ class NoSelfInStaticTests extends CompilerTest {
|
||||
| nested_method 42
|
||||
|""".stripMargin.preprocessModule.lint
|
||||
val errs = ir.bindings.flatMap(_.preorder).collect {
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _, _) =>
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _) =>
|
||||
err
|
||||
}
|
||||
errs should be(empty)
|
||||
@ -119,7 +119,7 @@ class NoSelfInStaticTests extends CompilerTest {
|
||||
|My_Type.extension_method = self.value + 1
|
||||
|""".stripMargin.preprocessModule.lint
|
||||
val errs = ir.bindings.flatMap(_.preorder).collect {
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _, _) =>
|
||||
case err @ errors.Syntax(_, errors.Syntax.InvalidSelfArgUsage, _) =>
|
||||
err
|
||||
}
|
||||
errs should have size 1
|
||||
|
@ -73,11 +73,11 @@ class ShadowedPatternFieldsTest extends CompilerTest {
|
||||
}
|
||||
|
||||
"attach a shadowing warning to each shadowed field" in {
|
||||
atLeast(1, pattern.fields.head.diagnostics.toList) shouldBe a[
|
||||
atLeast(1, pattern.fields.head.diagnosticsList) shouldBe a[
|
||||
warnings.Shadowed.PatternBinding
|
||||
]
|
||||
|
||||
val warning = pattern.fields.head.diagnostics.collect {
|
||||
val warning = pattern.fields.head.diagnosticsList.collect {
|
||||
case w: warnings.Shadowed.PatternBinding => w
|
||||
}.head
|
||||
|
||||
|
@ -94,7 +94,7 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|""".stripMargin.preprocessExpression.get.lint
|
||||
.asInstanceOf[Function.Lambda]
|
||||
|
||||
val lintMeta = ir.arguments.head.diagnostics.collect {
|
||||
val lintMeta = ir.arguments.head.diagnosticsList.collect {
|
||||
case u: warnings.Unused.FunctionArgument => u
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|
||||
inside(ir.bindings.head) { case definition: definition.Method.Explicit =>
|
||||
inside(definition.body) { case f: Function.Lambda =>
|
||||
val lintMeta = f.arguments(1).diagnostics.collect {
|
||||
val lintMeta = f.arguments(1).diagnosticsList.collect {
|
||||
case u: warnings.Unused.FunctionArgument => u
|
||||
}
|
||||
|
||||
@ -135,7 +135,7 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|""".stripMargin.preprocessExpression.get.lint
|
||||
.asInstanceOf[Function.Lambda]
|
||||
|
||||
val lintMeta = ir.arguments.head.diagnostics.collect {
|
||||
val lintMeta = ir.arguments.head.diagnosticsList.collect {
|
||||
case u: warnings.Unused => u
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|""".stripMargin.preprocessExpression.get.lint
|
||||
.asInstanceOf[Expression.Binding]
|
||||
|
||||
val lintMeta = ir.diagnostics.collect { case u: warnings.Unused =>
|
||||
val lintMeta = ir.diagnosticsList.collect { case u: warnings.Unused =>
|
||||
u
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|""".stripMargin.preprocessExpression.get.lint
|
||||
.asInstanceOf[Expression.Binding]
|
||||
|
||||
val lintMeta = ir.diagnostics.collect { case u: warnings.Unused =>
|
||||
val lintMeta = ir.diagnosticsList.collect { case u: warnings.Unused =>
|
||||
u
|
||||
}
|
||||
|
||||
@ -192,11 +192,13 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
val field1 = pattern.fields.head.asInstanceOf[Pattern.Name]
|
||||
val field2 = pattern.fields(1).asInstanceOf[Pattern.Name]
|
||||
|
||||
val lintMeta1 = field1.diagnostics.collect { case u: warnings.Unused =>
|
||||
u
|
||||
val lintMeta1 = field1.diagnosticsList.collect {
|
||||
case u: warnings.Unused =>
|
||||
u
|
||||
}
|
||||
val lintMeta2 = field2.diagnostics.collect { case u: warnings.Unused =>
|
||||
u
|
||||
val lintMeta2 = field2.diagnosticsList.collect {
|
||||
case u: warnings.Unused =>
|
||||
u
|
||||
}
|
||||
|
||||
lintMeta1 should not be empty
|
||||
@ -218,7 +220,7 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
|
||||
inside(ir.bindings.head) { case definition: definition.Method.Explicit =>
|
||||
inside(definition.body) { case f: Function.Lambda =>
|
||||
val lintMeta = f.arguments(1).diagnostics.collect {
|
||||
val lintMeta = f.arguments(1).diagnosticsList.collect {
|
||||
case u: warnings.Unused.FunctionArgument => u
|
||||
}
|
||||
|
||||
@ -245,11 +247,13 @@ class UnusedBindingsTest extends CompilerTest with Inside {
|
||||
val field1 = pattern.fields.head.asInstanceOf[Pattern.Name]
|
||||
val field2 = pattern.fields(1).asInstanceOf[Pattern.Name]
|
||||
|
||||
val lintMeta1 = field1.diagnostics.collect { case u: warnings.Unused =>
|
||||
u
|
||||
val lintMeta1 = field1.diagnosticsList.collect {
|
||||
case u: warnings.Unused =>
|
||||
u
|
||||
}
|
||||
val lintMeta2 = field2.diagnostics.collect { case u: warnings.Unused =>
|
||||
u
|
||||
val lintMeta2 = field2.diagnosticsList.collect {
|
||||
case u: warnings.Unused =>
|
||||
u
|
||||
}
|
||||
|
||||
lintMeta2 should not be empty
|
||||
|
@ -205,7 +205,6 @@ class GlobalNamesTest extends CompilerTest {
|
||||
case errors.Resolution(
|
||||
name,
|
||||
_: errors.Resolution.ResolverError,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
name
|
||||
@ -227,7 +226,6 @@ class GlobalNamesTest extends CompilerTest {
|
||||
case errors.Resolution(
|
||||
name,
|
||||
_: errors.Resolution.ResolverError,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
name
|
||||
|
@ -744,7 +744,8 @@ class ImportExportTest
|
||||
val origImport = mainIr.imports(0)
|
||||
val warn = mainIr
|
||||
.imports(1)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warn.size shouldEqual 1
|
||||
warn.head.originalImport shouldEqual origImport
|
||||
@ -768,7 +769,8 @@ class ImportExportTest
|
||||
val origImport = mainIr.imports(0)
|
||||
val warn = mainIr
|
||||
.imports(1)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warn.size shouldEqual 1
|
||||
warn.head.originalImport shouldEqual origImport
|
||||
@ -792,7 +794,8 @@ class ImportExportTest
|
||||
val origImport = mainIr.imports(0)
|
||||
val warn = mainIr
|
||||
.imports(1)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warn.size shouldEqual 1
|
||||
warn.head.originalImport shouldEqual origImport
|
||||
@ -817,7 +820,8 @@ class ImportExportTest
|
||||
val origImport = mainIr.imports(0)
|
||||
val warn = mainIr
|
||||
.imports(1)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warn.size shouldEqual 2
|
||||
warn.foreach(_.originalImport shouldEqual origImport)
|
||||
@ -888,7 +892,8 @@ class ImportExportTest
|
||||
.getIr
|
||||
val warns = mainIr
|
||||
.imports(0)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warns.size shouldEqual 1
|
||||
warns.head.symbolName shouldEqual "A_Type"
|
||||
@ -933,7 +938,8 @@ class ImportExportTest
|
||||
val origImport = mainIr.imports(0)
|
||||
val warns = mainIr
|
||||
.imports(1)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warns.size shouldEqual 1
|
||||
warns.head.symbolName shouldEqual "A_Type"
|
||||
@ -975,7 +981,7 @@ class ImportExportTest
|
||||
mainIr.imports.size shouldEqual 3
|
||||
val origImport = mainIr.imports(0)
|
||||
val allWarns =
|
||||
mainIr.imports.flatMap(_.diagnostics.collect({
|
||||
mainIr.imports.flatMap(_.getDiagnostics.toList.collect({
|
||||
case w: Warning.DuplicatedImport => w
|
||||
}))
|
||||
allWarns.size shouldEqual 2
|
||||
@ -999,7 +1005,7 @@ class ImportExportTest
|
||||
mainIr.imports.size shouldEqual 3
|
||||
val origImport = mainIr.imports(0)
|
||||
val allWarns =
|
||||
mainIr.imports.flatMap(_.diagnostics.collect({
|
||||
mainIr.imports.flatMap(_.getDiagnostics.toList.collect({
|
||||
case w: Warning.DuplicatedImport => w
|
||||
}))
|
||||
allWarns.size shouldEqual 2
|
||||
@ -1022,7 +1028,8 @@ class ImportExportTest
|
||||
mainIr.imports.size shouldEqual 2
|
||||
val warn = mainIr
|
||||
.imports(1)
|
||||
.diagnostics
|
||||
.getDiagnostics
|
||||
.toList
|
||||
.collect({ case w: Warning.DuplicatedImport => w })
|
||||
warn.size shouldEqual 1
|
||||
val arr = Persistance.write(
|
||||
|
@ -90,7 +90,7 @@ trait TypeMatchers {
|
||||
} else {
|
||||
items.lazyZip(t.operands).flatMap(findInequalityWitness).headOption
|
||||
}
|
||||
case (In(typed, context), Type.Context(irTyped, irContext, _, _, _)) =>
|
||||
case (In(typed, context), Type.Context(irTyped, irContext, _, _)) =>
|
||||
findInequalityWitness(typed, irTyped).orElse(
|
||||
findInequalityWitness(context, irContext)
|
||||
)
|
||||
|
@ -100,9 +100,20 @@ public interface IR {
|
||||
@Identifier
|
||||
UUID getId();
|
||||
|
||||
/** Storage for compiler diagnostics related to the IR node. */
|
||||
/**
|
||||
* Get the storage for compiler diagnostics related to the IR node.
|
||||
*
|
||||
* @return the diagnostic storage or {@code null} if not initialized
|
||||
*/
|
||||
DiagnosticStorage diagnostics();
|
||||
|
||||
/**
|
||||
* Initialize and get the storage for compiler diagnostics associated with this IR node.
|
||||
*
|
||||
* @return the diagnostic storage of this node. The result is never {@code null}
|
||||
*/
|
||||
DiagnosticStorage getDiagnostics();
|
||||
|
||||
/**
|
||||
* Creates a deep structural copy of `this`, representing the same structure.
|
||||
*
|
||||
|
@ -104,8 +104,13 @@ final class TreeToIr {
|
||||
methodReference = ex.toError();
|
||||
}
|
||||
var signature = translateType(sig.getType());
|
||||
var ascription = new Type.Ascription(methodReference, signature, Option.empty(),
|
||||
getIdentifiedLocation(sig), meta(), diag());
|
||||
var ascription =
|
||||
new Type.Ascription(
|
||||
methodReference,
|
||||
signature,
|
||||
Option.empty(),
|
||||
getIdentifiedLocation(sig),
|
||||
meta());
|
||||
yield ascription;
|
||||
}
|
||||
case Tree.TypeAnnotated anno -> translateTypeAnnotated(anno);
|
||||
@ -144,8 +149,7 @@ final class TreeToIr {
|
||||
returnValue,
|
||||
combinedLocation,
|
||||
false,
|
||||
meta(),
|
||||
diag()
|
||||
meta()
|
||||
));
|
||||
}
|
||||
};
|
||||
@ -202,15 +206,21 @@ final class TreeToIr {
|
||||
default -> bindings = translateModuleSymbol(expr, bindings);
|
||||
}
|
||||
}
|
||||
yield new Module(imports.reverse(), exports.reverse(), bindings.reverse(), isPrivate,
|
||||
getIdentifiedLocation(module), meta(), DiagnosticStorage.apply(diag));
|
||||
if (diag.isEmpty()) {
|
||||
yield new Module(imports.reverse(), exports.reverse(), bindings.reverse(), isPrivate,
|
||||
getIdentifiedLocation(module), meta(), new DiagnosticStorage(diag));
|
||||
} else {
|
||||
yield new Module(imports.reverse(), exports.reverse(), bindings.reverse(), isPrivate,
|
||||
getIdentifiedLocation(module), meta());
|
||||
}
|
||||
}
|
||||
default -> new Module(
|
||||
nil(), nil(),
|
||||
join(translateSyntaxError(module, new Syntax.UnsupportedSyntax("translateModule")),
|
||||
nil()),
|
||||
false,
|
||||
getIdentifiedLocation(module), meta(), diag()
|
||||
getIdentifiedLocation(module),
|
||||
meta()
|
||||
);
|
||||
};
|
||||
}
|
||||
@ -270,7 +280,7 @@ final class TreeToIr {
|
||||
args,
|
||||
irBody.reverse(),
|
||||
getIdentifiedLocation(inputAst),
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
yield join(type, appendTo);
|
||||
}
|
||||
@ -283,8 +293,7 @@ final class TreeToIr {
|
||||
case Tree.ForeignFunction fn when fn.getBody() instanceof Tree.TextLiteral body -> {
|
||||
var name = fn.getName();
|
||||
var nameLoc = getIdentifiedLocation(name);
|
||||
var methodRef = new Name.MethodReference(Option.empty(), buildName(name), nameLoc, meta(),
|
||||
diag());
|
||||
var methodRef = new Name.MethodReference(Option.empty(), buildName(name), nameLoc, meta());
|
||||
var args = translateArgumentsDefinition(fn.getArgs());
|
||||
var languageName = fn.getLanguage().codeRepr();
|
||||
var language = languageName;
|
||||
@ -294,25 +303,24 @@ final class TreeToIr {
|
||||
yield join(error, appendTo);
|
||||
}
|
||||
var text = buildTextConstant(body, body.getElements());
|
||||
var def = new Foreign.Definition(language, text, getIdentifiedLocation(fn.getBody()),
|
||||
meta(), diag());
|
||||
var def =
|
||||
new Foreign.Definition(language, text, getIdentifiedLocation(fn.getBody()), meta());
|
||||
// Foreign functions are always considered private
|
||||
var binding = new Method.Binding(
|
||||
methodRef, args, true, def, getIdentifiedLocation(inputAst), meta(), diag()
|
||||
);
|
||||
methodRef, args, true, def, getIdentifiedLocation(inputAst), meta());
|
||||
yield join(binding, appendTo);
|
||||
}
|
||||
|
||||
case Tree.AnnotatedBuiltin anno -> {
|
||||
var annotation = new Name.BuiltinAnnotation("@" + anno.getAnnotation().codeRepr(),
|
||||
getIdentifiedLocation(anno), meta(), diag());
|
||||
getIdentifiedLocation(anno), meta());
|
||||
yield translateModuleSymbol(anno.getExpression(), join(annotation, appendTo));
|
||||
}
|
||||
|
||||
case Tree.Annotated anno -> {
|
||||
var annotationArgument = translateExpression(anno.getArgument());
|
||||
var annotation = new Name.GenericAnnotation(anno.getAnnotation().codeRepr(),
|
||||
annotationArgument, getIdentifiedLocation(anno), meta(), diag());
|
||||
annotationArgument, getIdentifiedLocation(anno), meta());
|
||||
yield translateModuleSymbol(anno.getExpression(), join(annotation, appendTo));
|
||||
}
|
||||
|
||||
@ -334,7 +342,7 @@ final class TreeToIr {
|
||||
false,
|
||||
body.setLocation(aLoc),
|
||||
expandToContain(getIdentifiedLocation(a), aLoc),
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
yield join(binding, appendTo);
|
||||
}
|
||||
@ -343,7 +351,7 @@ final class TreeToIr {
|
||||
var methodReference = translateMethodReference(sig.getVariable(), true);
|
||||
var signature = translateType(sig.getType());
|
||||
var ascription = new Type.Ascription(methodReference, signature, Option.empty(),
|
||||
getIdentifiedLocation(sig), meta(), diag());
|
||||
getIdentifiedLocation(sig), meta());
|
||||
yield join(ascription, appendTo);
|
||||
}
|
||||
|
||||
@ -370,7 +378,7 @@ final class TreeToIr {
|
||||
var constructorName = buildName(inputAst, cons.getConstructor());
|
||||
List<DefinitionArgument> args = translateArgumentsDefinition(cons.getArguments());
|
||||
var cAt = getIdentifiedLocation(inputAst);
|
||||
return new Definition.Data(constructorName, args, nil(), isPrivate, cAt, meta(), diag());
|
||||
return new Definition.Data(constructorName, args, nil(), isPrivate, cAt, meta());
|
||||
} catch (SyntaxException ex) {
|
||||
return ex.toError();
|
||||
}
|
||||
@ -465,10 +473,10 @@ final class TreeToIr {
|
||||
yield join(error, appendTo);
|
||||
}
|
||||
var text = buildTextConstant(body, body.getElements());
|
||||
var def = new Foreign.Definition(language, text, getIdentifiedLocation(fn.getBody()),
|
||||
meta(), diag());
|
||||
var binding = new Function.Binding(name, args, def, false, getIdentifiedLocation(fn), true,
|
||||
meta(), diag());
|
||||
var def =
|
||||
new Foreign.Definition(language, text, getIdentifiedLocation(fn.getBody()), meta());
|
||||
var binding =
|
||||
new Function.Binding(name, args, def, false, getIdentifiedLocation(fn), true, meta());
|
||||
yield join(binding, appendTo);
|
||||
}
|
||||
case Tree.Documented doc -> {
|
||||
@ -478,7 +486,7 @@ final class TreeToIr {
|
||||
|
||||
case Tree.AnnotatedBuiltin anno -> {
|
||||
var ir = new Name.BuiltinAnnotation("@" + anno.getAnnotation().codeRepr(),
|
||||
getIdentifiedLocation(anno), meta(), diag());
|
||||
getIdentifiedLocation(anno), meta());
|
||||
var annotation = translateAnnotation(ir, anno.getExpression(), nil());
|
||||
yield join(annotation, appendTo);
|
||||
}
|
||||
@ -486,7 +494,7 @@ final class TreeToIr {
|
||||
case Tree.Annotated anno -> {
|
||||
var annotationArgument = translateExpression(anno.getArgument());
|
||||
var annotation = new Name.GenericAnnotation(anno.getAnnotation().codeRepr(),
|
||||
annotationArgument, getIdentifiedLocation(anno), meta(), diag());
|
||||
annotationArgument, getIdentifiedLocation(anno), meta());
|
||||
yield translateTypeBodyExpression(anno.getExpression(), join(annotation, appendTo));
|
||||
}
|
||||
|
||||
@ -540,8 +548,7 @@ final class TreeToIr {
|
||||
case 1 -> fullQualifiedNames.head();
|
||||
default -> {
|
||||
var name = fullQualifiedNames.head();
|
||||
name = new Name.Literal(name.name(), true, name.location(), Option.empty(), name.passData(),
|
||||
name.diagnostics());
|
||||
name = new Name.Literal(name.name(), true, name.location(), Option.empty(), name.passData());
|
||||
List<Name> tail = (List<Name>) fullQualifiedNames.tail();
|
||||
tail = tail.reverse();
|
||||
final Option<IdentifiedLocation> loc = getIdentifiedLocation(app);
|
||||
@ -549,19 +556,18 @@ final class TreeToIr {
|
||||
if (segments == 2) {
|
||||
arg = tail.head();
|
||||
} else {
|
||||
arg = new Name.Qualified(tail, loc, meta(), diag());
|
||||
arg = new Name.Qualified(tail, loc, meta());
|
||||
}
|
||||
var ca = new CallArgument.Specified(Option.empty(), arg, loc, meta(), diag());
|
||||
var ca = new CallArgument.Specified(Option.empty(), arg, loc, meta());
|
||||
args = join(ca, args);
|
||||
yield name;
|
||||
}
|
||||
};
|
||||
if (in == null) {
|
||||
return new Application.Prefix(type, args, false, getIdentifiedLocation(app), meta(), diag());
|
||||
return new Application.Prefix(type, args, false, getIdentifiedLocation(app), meta());
|
||||
} else {
|
||||
var fn = new CallArgument.Specified(Option.empty(), type, getIdentifiedLocation(app), meta(),
|
||||
diag());
|
||||
return new Operator.Binary(fn, in, args.head(), getIdentifiedLocation(app), meta(), diag());
|
||||
var fn = new CallArgument.Specified(Option.empty(), type, getIdentifiedLocation(app), meta());
|
||||
return new Operator.Binary(fn, in, args.head(), getIdentifiedLocation(app), meta());
|
||||
}
|
||||
}
|
||||
|
||||
@ -577,7 +583,7 @@ final class TreeToIr {
|
||||
var location = new Location(identifiedLocation.end(), identifiedLocation.end());
|
||||
return new IdentifiedLocation(location, identifiedLocation.uuid());
|
||||
});
|
||||
body = new Empty(emptyLocation, meta(), diag());
|
||||
body = new Empty(emptyLocation, meta());
|
||||
}
|
||||
|
||||
String functionName = fn.getName().codeRepr();
|
||||
@ -588,7 +594,7 @@ final class TreeToIr {
|
||||
isPrivate,
|
||||
ascribedBody,
|
||||
loc,
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
return binding;
|
||||
}
|
||||
@ -626,7 +632,7 @@ final class TreeToIr {
|
||||
}
|
||||
|
||||
var ascribedBody = addTypeAscription(functionName, body, returnType, loc);
|
||||
return new Expression.Binding(name, ascribedBody, loc, meta(), diag());
|
||||
return new Expression.Binding(name, ascribedBody, loc, meta());
|
||||
} else {
|
||||
if (body == null) {
|
||||
return translateSyntaxError(fun, Syntax.UnexpectedDeclarationInType$.MODULE$);
|
||||
@ -636,7 +642,7 @@ final class TreeToIr {
|
||||
}
|
||||
|
||||
var ascribedBody = addTypeAscription(functionName, body, returnType, loc);
|
||||
return new Function.Binding(name, args, ascribedBody, isPrivate, loc, true, meta(), diag());
|
||||
return new Function.Binding(name, args, ascribedBody, isPrivate, loc, true, meta());
|
||||
}
|
||||
}
|
||||
|
||||
@ -665,13 +671,12 @@ final class TreeToIr {
|
||||
}
|
||||
|
||||
String comment = "the result of `" + functionName + "`";
|
||||
return new Type.Ascription(body, type, Option.apply(comment), loc, meta(), diag());
|
||||
return new Type.Ascription(body, type, Option.apply(comment), loc, meta());
|
||||
}
|
||||
|
||||
private Type.Ascription translateTypeSignature(Tree sig, Tree type, Expression typeName) {
|
||||
var fn = translateType(type);
|
||||
return new Type.Ascription(typeName, fn, Option.empty(), getIdentifiedLocation(sig), meta(),
|
||||
diag());
|
||||
return new Type.Ascription(typeName, fn, Option.empty(), getIdentifiedLocation(sig), meta());
|
||||
}
|
||||
|
||||
|
||||
@ -704,9 +709,7 @@ final class TreeToIr {
|
||||
}
|
||||
default -> throw translateEntity(sig, "translateMethodReference");
|
||||
}
|
||||
return new Name.MethodReference(type, method,
|
||||
loc, meta(), diag()
|
||||
);
|
||||
return new Name.MethodReference(type, method, loc, meta());
|
||||
}
|
||||
|
||||
private Expression translateCall(Tree ast, boolean isMethod) throws SyntaxException {
|
||||
@ -722,14 +725,14 @@ final class TreeToIr {
|
||||
case Tree.App app -> {
|
||||
var expr = translateExpression(app.getArg(), false);
|
||||
var loc = getIdentifiedLocation(app.getArg());
|
||||
args.add(new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag()));
|
||||
args.add(new CallArgument.Specified(Option.empty(), expr, loc, meta()));
|
||||
tree = app.getFunc();
|
||||
}
|
||||
case Tree.NamedApp app -> {
|
||||
var expr = translateExpression(app.getArg(), false);
|
||||
var loc = getIdentifiedLocation(app.getArg());
|
||||
var id = buildName(app, app.getName());
|
||||
args.add(new CallArgument.Specified(Option.apply(id), expr, loc, meta(), diag()));
|
||||
args.add(new CallArgument.Specified(Option.apply(id), expr, loc, meta()));
|
||||
tree = app.getFunc();
|
||||
}
|
||||
case Tree.OperatorBlockApplication app -> {
|
||||
@ -745,20 +748,17 @@ final class TreeToIr {
|
||||
}
|
||||
var expr = switch (translateExpression(l.getExpression().getExpression(), true)) {
|
||||
case Application.Prefix pref -> {
|
||||
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta(),
|
||||
diag());
|
||||
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta());
|
||||
yield new Application.Prefix(pref.function(), join(arg, pref.arguments()), false,
|
||||
pref.location(), meta(), diag());
|
||||
pref.location(), meta());
|
||||
}
|
||||
case Expression any -> {
|
||||
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta(),
|
||||
diag());
|
||||
yield new Application.Prefix(any, join(arg, nil()), false, any.location(), meta(),
|
||||
diag());
|
||||
var arg = new CallArgument.Specified(Option.empty(), self, self.location(), meta());
|
||||
yield new Application.Prefix(any, join(arg, nil()), false, any.location(), meta());
|
||||
}
|
||||
};
|
||||
var loc = getIdentifiedLocation(l.getExpression().getExpression());
|
||||
args.add(at, new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag()));
|
||||
args.add(at, new CallArgument.Specified(Option.empty(), expr, loc, meta()));
|
||||
self = expr;
|
||||
}
|
||||
return self;
|
||||
@ -775,7 +775,7 @@ final class TreeToIr {
|
||||
if (oprApp.getLhs() != null) {
|
||||
var self = translateExpression(oprApp.getLhs(), isMethod);
|
||||
var loc = getIdentifiedLocation(oprApp.getLhs());
|
||||
args.add(new CallArgument.Specified(Option.empty(), self, loc, meta(), diag()));
|
||||
args.add(new CallArgument.Specified(Option.empty(), self, loc, meta()));
|
||||
}
|
||||
} else if (args.isEmpty()) {
|
||||
return null;
|
||||
@ -788,8 +788,7 @@ final class TreeToIr {
|
||||
func, argsList,
|
||||
hasDefaultsSuspended,
|
||||
getIdentifiedLocation(ast),
|
||||
meta(),
|
||||
diag()
|
||||
meta()
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -802,7 +801,7 @@ final class TreeToIr {
|
||||
case Tree.Group g ->
|
||||
translateOldStyleLambdaArgumentName(g.getBody(), suspended, defaultValue);
|
||||
case Tree.Wildcard wild ->
|
||||
new Name.Blank(getIdentifiedLocation(wild.getToken()), meta(), diag());
|
||||
new Name.Blank(getIdentifiedLocation(wild.getToken()), meta());
|
||||
case Tree.OprApp app when "=".equals(app.getOpr().getRight().codeRepr()) -> {
|
||||
if (defaultValue != null) {
|
||||
defaultValue[0] = translateExpression(app.getRhs(), false);
|
||||
@ -866,7 +865,7 @@ final class TreeToIr {
|
||||
}
|
||||
var body = translateExpression(lambda.getBody(), false);
|
||||
var at = getIdentifiedLocation(lambda);
|
||||
yield new Function.Lambda(args, body, at, true, meta(), diag());
|
||||
yield new Function.Lambda(args, body, at, true, meta());
|
||||
}
|
||||
case Tree.OprApp app -> {
|
||||
var op = app.getOpr().getRight();
|
||||
@ -877,7 +876,7 @@ final class TreeToIr {
|
||||
var errLoc = arr.size() > 1 ? getIdentifiedLocation(arr.get(1)) : at;
|
||||
var err = translateSyntaxError(errLoc.get(), Syntax.UnrecognizedToken$.MODULE$);
|
||||
var name = buildName(app.getLhs());
|
||||
yield new Expression.Binding(name, err, at, meta(), diag());
|
||||
yield new Expression.Binding(name, err, at, meta());
|
||||
} else {
|
||||
yield translateSyntaxError(at.get(), Syntax.UnrecognizedToken$.MODULE$);
|
||||
}
|
||||
@ -911,22 +910,21 @@ final class TreeToIr {
|
||||
Option.apply(defaultValue[0]),
|
||||
isSuspended[0],
|
||||
getIdentifiedLocation(arg),
|
||||
meta(),
|
||||
diag()
|
||||
meta()
|
||||
);
|
||||
List<DefinitionArgument> args = join(arg_, nil());
|
||||
var body = translateExpression(app.getRhs(), false);
|
||||
if (body == null) {
|
||||
body = new Expression.Block(
|
||||
nil(), new Name.Blank(Option.empty(), meta(), diag()),
|
||||
Option.empty(), true, meta(), diag()
|
||||
nil(), new Name.Blank(Option.empty(), meta()),
|
||||
Option.empty(), true, meta()
|
||||
);
|
||||
}
|
||||
var at = expandToContain(switch (body) {
|
||||
case Expression.Block __ -> getIdentifiedLocation(tree, 0, 1, null);
|
||||
default -> getIdentifiedLocation(tree);
|
||||
}, body.location());
|
||||
yield new Function.Lambda(args, body, at, true, meta(), diag());
|
||||
yield new Function.Lambda(args, body, at, true, meta());
|
||||
}
|
||||
default -> {
|
||||
var lhs = unnamedCallArgument(app.getLhs());
|
||||
@ -951,7 +949,7 @@ final class TreeToIr {
|
||||
var loc = getIdentifiedLocation(app);
|
||||
var both = applyOperator(op, lhs, rhs, loc);
|
||||
expr = both;
|
||||
lhs = new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag());
|
||||
lhs = new CallArgument.Specified(Option.empty(), expr, loc, meta());
|
||||
}
|
||||
yield expr;
|
||||
}
|
||||
@ -970,7 +968,8 @@ final class TreeToIr {
|
||||
}
|
||||
yield new Application.Sequence(
|
||||
items.reverse(),
|
||||
getIdentifiedLocation(arr), meta(), diag()
|
||||
getIdentifiedLocation(arr),
|
||||
meta()
|
||||
);
|
||||
}
|
||||
case Tree.Number n -> translateNumber(n);
|
||||
@ -997,12 +996,11 @@ final class TreeToIr {
|
||||
var subexpression = useOrElse(applySkip(body), body);
|
||||
yield translateExpression(subexpression, false);
|
||||
}
|
||||
var fn = new Name.Literal(fullName, true, Option.empty(), Option.empty(), meta(), diag());
|
||||
var fn = new Name.Literal(fullName, true, Option.empty(), Option.empty(), meta());
|
||||
if (!checkArgs(args)) {
|
||||
yield translateSyntaxError(app, Syntax.UnexpectedExpression$.MODULE$);
|
||||
}
|
||||
yield new Application.Prefix(fn, args.reverse(), false, getIdentifiedLocation(tree), meta(),
|
||||
diag());
|
||||
yield new Application.Prefix(fn, args.reverse(), false, getIdentifiedLocation(tree), meta());
|
||||
}
|
||||
case Tree.BodyBlock body -> {
|
||||
var expressions = new java.util.ArrayList<Expression>();
|
||||
@ -1038,7 +1036,7 @@ final class TreeToIr {
|
||||
var id = IdentifiedLocation.create(patched, last.location().get().id());
|
||||
last = last.setLocation(Option.apply(id));
|
||||
}
|
||||
yield new Expression.Block(list, last, locationWithANewLine, false, meta(), diag());
|
||||
yield new Expression.Block(list, last, locationWithANewLine, false, meta());
|
||||
}
|
||||
case Tree.Assignment assign -> {
|
||||
var name = buildNameOrQualifiedName(assign.getPattern());
|
||||
@ -1046,7 +1044,7 @@ final class TreeToIr {
|
||||
if (expr == null) {
|
||||
expr = translateSyntaxError(assign, Syntax.UnexpectedExpression$.MODULE$);
|
||||
}
|
||||
yield new Expression.Binding(name, expr, getIdentifiedLocation(tree), meta(), diag());
|
||||
yield new Expression.Binding(name, expr, getIdentifiedLocation(tree), meta());
|
||||
}
|
||||
case Tree.ArgumentBlockApplication body -> {
|
||||
List<Expression> expressions = nil();
|
||||
@ -1062,10 +1060,10 @@ final class TreeToIr {
|
||||
last = translateExpression(expr, false);
|
||||
}
|
||||
if (last == null) {
|
||||
last = new Name.Blank(Option.empty(), meta(), diag());
|
||||
last = new Name.Blank(Option.empty(), meta());
|
||||
}
|
||||
var block = new Expression.Block(expressions.reverse(), last, getIdentifiedLocation(body),
|
||||
false, meta(), diag());
|
||||
var block =
|
||||
new Expression.Block(expressions.reverse(), last, getIdentifiedLocation(body), false, meta());
|
||||
if (body.getLhs() != null) {
|
||||
var fn = translateExpression(body.getLhs(), isMethod);
|
||||
List<CallArgument> args = nil();
|
||||
@ -1114,11 +1112,13 @@ final class TreeToIr {
|
||||
if (branch.getDocumentation() != null) {
|
||||
var comment = translateComment(cas, branch.getDocumentation());
|
||||
var loc = getIdentifiedLocation(cas);
|
||||
var doc = new Pattern.Documentation(comment.doc(), loc, meta(), diag());
|
||||
var doc = new Pattern.Documentation(comment.doc(), loc, meta());
|
||||
var br = new Case.Branch(
|
||||
doc,
|
||||
new Empty(Option.empty(), meta(), diag()),
|
||||
loc, meta(), diag()
|
||||
new Empty(Option.empty(), meta()),
|
||||
true,
|
||||
loc,
|
||||
meta()
|
||||
);
|
||||
branches = join(br, branches);
|
||||
}
|
||||
@ -1128,12 +1128,13 @@ final class TreeToIr {
|
||||
var br = new Case.Branch(
|
||||
translatePattern(branch.getPattern()),
|
||||
translateExpression(branch.getExpression(), false),
|
||||
getIdentifiedLocation(branch.getExpression()), meta(), diag()
|
||||
true,
|
||||
getIdentifiedLocation(branch.getExpression()), meta()
|
||||
);
|
||||
branches = join(br, branches);
|
||||
}
|
||||
}
|
||||
yield new Case.Expr(expr, branches.reverse(), getIdentifiedLocation(tree), meta(), diag());
|
||||
yield new Case.Expr(expr, branches.reverse(), false, getIdentifiedLocation(tree), meta());
|
||||
}
|
||||
case Tree.Function fun -> {
|
||||
var name = buildName(fun.getName());
|
||||
@ -1156,12 +1157,9 @@ final class TreeToIr {
|
||||
n.copy$default$6()
|
||||
);
|
||||
case Expression expr -> {
|
||||
var negate = new Name.Literal("negate", true, Option.empty(), Option.empty(), meta(),
|
||||
diag());
|
||||
var arg = new CallArgument.Specified(Option.empty(), expr, expr.location(), meta(),
|
||||
diag());
|
||||
yield new Application.Prefix(negate, join(arg, nil()), false, expr.location(), meta(),
|
||||
diag());
|
||||
var negate = new Name.Literal("negate", true, Option.empty(), Option.empty(), meta());
|
||||
var arg = new CallArgument.Specified(Option.empty(), expr, expr.location(), meta());
|
||||
yield new Application.Prefix(negate, join(arg, nil()), false, expr.location(), meta());
|
||||
}
|
||||
case null ->
|
||||
translateSyntaxError(tree, new Syntax.UnsupportedSyntax("Strange unary -"));
|
||||
@ -1172,18 +1170,17 @@ final class TreeToIr {
|
||||
Option.empty(),
|
||||
methodName,
|
||||
methodName.location(),
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
var opName = buildName(Option.empty(), sig.getOperator(), true);
|
||||
var signature = translateTypeCallArgument(sig.getType());
|
||||
yield new Operator.Binary(methodReference, opName, signature, getIdentifiedLocation(sig),
|
||||
meta(), diag());
|
||||
yield new Operator.Binary(methodReference, opName, signature, getIdentifiedLocation(sig), meta());
|
||||
}
|
||||
case Tree.TemplateFunction templ -> translateExpression(templ.getAst(), false);
|
||||
case Tree.Wildcard wild -> new Name.Blank(getIdentifiedLocation(wild), meta(), diag());
|
||||
case Tree.Wildcard wild -> new Name.Blank(getIdentifiedLocation(wild), meta());
|
||||
case Tree.AnnotatedBuiltin anno -> {
|
||||
var ir = new Name.BuiltinAnnotation("@" + anno.getAnnotation().codeRepr(),
|
||||
getIdentifiedLocation(anno), meta(), diag());
|
||||
getIdentifiedLocation(anno), meta());
|
||||
yield translateAnnotation(ir, anno.getExpression(), nil());
|
||||
}
|
||||
// Documentation can be attached to an expression in a few cases, like if someone documents a line of an
|
||||
@ -1193,7 +1190,7 @@ final class TreeToIr {
|
||||
var fn = translateExpression(app.getFunc(), isMethod);
|
||||
var loc = getIdentifiedLocation(app);
|
||||
if (app.getArg() instanceof Tree.SuspendedDefaultArguments) {
|
||||
yield new Application.Prefix(fn, nil(), true, loc, meta(), diag());
|
||||
yield new Application.Prefix(fn, nil(), true, loc, meta());
|
||||
} else {
|
||||
yield fn.setLocation(loc);
|
||||
}
|
||||
@ -1204,7 +1201,7 @@ final class TreeToIr {
|
||||
Option.empty(),
|
||||
methodName,
|
||||
getIdentifiedLocation(autoscopedIdentifier),
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
}
|
||||
case Tree.Private __ -> translateSyntaxError(tree, Syntax.UnexpectedExpression$.MODULE$);
|
||||
@ -1217,23 +1214,23 @@ final class TreeToIr {
|
||||
for (var warning : tree.getWarnings()) {
|
||||
var message = Parser.getWarningMessage(warning);
|
||||
var irWarning = new Warning.Syntax(ir, message);
|
||||
ir.diagnostics().add(irWarning);
|
||||
ir.getDiagnostics().add(irWarning);
|
||||
}
|
||||
}
|
||||
|
||||
private Operator applyOperator(Token.Operator op, CallArgument lhs, CallArgument rhs,
|
||||
Option<IdentifiedLocation> loc) {
|
||||
var name = new Name.Literal(
|
||||
op.codeRepr(), true, getIdentifiedLocation(op), Option.empty(), meta(), diag()
|
||||
op.codeRepr(), true, getIdentifiedLocation(op), Option.empty(), meta()
|
||||
);
|
||||
if (lhs == null && rhs == null) {
|
||||
return new Section.Sides(name, loc, meta(), diag());
|
||||
return new Section.Sides(name, loc, meta());
|
||||
} else if (lhs == null) {
|
||||
return new Section.Right(name, rhs, loc, meta(), diag());
|
||||
return new Section.Right(name, rhs, loc, meta());
|
||||
} else if (rhs == null) {
|
||||
return new Section.Left(lhs, name, loc, meta(), diag());
|
||||
return new Section.Left(lhs, name, loc, meta());
|
||||
} else {
|
||||
return new Operator.Binary(lhs, name, rhs, loc, meta(), diag());
|
||||
return new Operator.Binary(lhs, name, rhs, loc, meta());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1328,8 +1325,7 @@ final class TreeToIr {
|
||||
var literal = translateType(app.getLhs());
|
||||
var body = translateType(app.getRhs());
|
||||
if (body == null) {
|
||||
yield new Syntax(getIdentifiedLocation(app).get(),
|
||||
Syntax.UnexpectedExpression$.MODULE$, meta(), diag());
|
||||
yield new Syntax(getIdentifiedLocation(app).get(), Syntax.UnexpectedExpression$.MODULE$, meta());
|
||||
}
|
||||
var args = switch (body) {
|
||||
case Type.Function fn -> {
|
||||
@ -1338,7 +1334,7 @@ final class TreeToIr {
|
||||
}
|
||||
default -> join(literal, nil());
|
||||
};
|
||||
yield new Type.Function(args, body, Option.empty(), meta(), diag());
|
||||
yield new Type.Function(args, body, Option.empty(), meta());
|
||||
}
|
||||
default -> {
|
||||
var lhs = translateTypeCallArgument(app.getLhs());
|
||||
@ -1347,10 +1343,10 @@ final class TreeToIr {
|
||||
op.codeRepr(), true,
|
||||
getIdentifiedLocation(app),
|
||||
Option.empty(),
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
var loc = getIdentifiedLocation(app);
|
||||
yield new Operator.Binary(lhs, name, rhs, loc, meta(), diag());
|
||||
yield new Operator.Binary(lhs, name, rhs, loc, meta());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1366,13 +1362,14 @@ final class TreeToIr {
|
||||
}
|
||||
yield new Application.Literal.Sequence(
|
||||
items.reverse(),
|
||||
getIdentifiedLocation(arr), meta(), diag()
|
||||
getIdentifiedLocation(arr),
|
||||
meta()
|
||||
);
|
||||
}
|
||||
case Tree.Ident id -> buildName(getIdentifiedLocation(id), id.getToken(), false);
|
||||
case Tree.Group group -> translateType(group.getBody());
|
||||
case Tree.UnaryOprApp un -> translateType(un.getRhs());
|
||||
case Tree.Wildcard wild -> new Name.Blank(getIdentifiedLocation(wild), meta(), diag());
|
||||
case Tree.Wildcard wild -> new Name.Blank(getIdentifiedLocation(wild), meta());
|
||||
case Tree.TypeAnnotated anno -> translateTypeAnnotatedToOperator(anno);
|
||||
default -> translateSyntaxError(tree, new Syntax.UnsupportedSyntax("translateType"));
|
||||
};
|
||||
@ -1384,7 +1381,7 @@ final class TreeToIr {
|
||||
Expression translateTypeAnnotated(Tree.TypeAnnotated anno) {
|
||||
var type = translateType(anno.getType());
|
||||
var expr = translateExpression(anno.getExpression());
|
||||
return new Type.Ascription(expr, type, Option.empty(), getIdentifiedLocation(anno), meta(), diag());
|
||||
return new Type.Ascription(expr, type, Option.empty(), getIdentifiedLocation(anno), meta());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1394,14 +1391,13 @@ final class TreeToIr {
|
||||
var type = translateTypeCallArgument(anno.getType());
|
||||
var expr = translateCallArgument(anno.getExpression());
|
||||
var opName = new Name.Literal(anno.getOperator().codeRepr(), true, Option.empty(),
|
||||
Option.empty(), meta(), diag());
|
||||
Option.empty(), meta());
|
||||
return new Operator.Binary(
|
||||
expr,
|
||||
opName,
|
||||
type,
|
||||
getIdentifiedLocation(anno),
|
||||
meta(), diag()
|
||||
);
|
||||
meta());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -1415,13 +1411,13 @@ final class TreeToIr {
|
||||
}
|
||||
List<CallArgument> allArgs = (List<CallArgument>) pref.arguments().appendedAll(args.reverse());
|
||||
final CallArgument.Specified blockArg = new CallArgument.Specified(Option.empty(), block,
|
||||
block.location(), meta(), diag());
|
||||
block.location(), meta());
|
||||
List<CallArgument> withBlockArgs = (List<CallArgument>) allArgs.appended(blockArg);
|
||||
if (!checkArgs(withBlockArgs)) {
|
||||
return translateSyntaxError(pref.location().get(), Syntax.UnexpectedExpression$.MODULE$);
|
||||
}
|
||||
return new Application.Prefix(pref.function(), withBlockArgs, pref.hasDefaultsSuspended(),
|
||||
pref.location(), meta(), diag());
|
||||
pref.location(), meta());
|
||||
}
|
||||
|
||||
private Application.Prefix translateAnnotation(Name.BuiltinAnnotation ir, Tree expr,
|
||||
@ -1442,7 +1438,7 @@ final class TreeToIr {
|
||||
yield translateAnnotation(ir, null, callArgs);
|
||||
}
|
||||
case null -> {
|
||||
yield new Application.Prefix(ir, callArgs, false, ir.location(), meta(), diag());
|
||||
yield new Application.Prefix(ir, callArgs, false, ir.location(), meta());
|
||||
}
|
||||
default -> {
|
||||
var arg = translateCallArgument(expr);
|
||||
@ -1464,7 +1460,7 @@ final class TreeToIr {
|
||||
var fracPart = ast.getFractionalDigits();
|
||||
String literal = fracPart != null ? intPart.codeRepr() + "." + fracPart.getDigits().codeRepr()
|
||||
: intPart.codeRepr();
|
||||
return new Literal.Number(base, literal, getIdentifiedLocation(ast), meta(), diag());
|
||||
return new Literal.Number(base, literal, getIdentifiedLocation(ast), meta());
|
||||
}
|
||||
|
||||
Literal translateLiteral(Tree.TextLiteral txt) throws SyntaxException {
|
||||
@ -1479,7 +1475,7 @@ final class TreeToIr {
|
||||
}
|
||||
// Splices are not yet supported in the IR.
|
||||
var value = buildTextConstant(txt, txt.getElements());
|
||||
return new Literal.Text(value, getIdentifiedLocation(txt), meta(), diag());
|
||||
return new Literal.Text(value, getIdentifiedLocation(txt), meta());
|
||||
}
|
||||
|
||||
private String buildTextConstant(Tree at, Iterable<TextElement> elements) throws SyntaxException {
|
||||
@ -1517,7 +1513,7 @@ final class TreeToIr {
|
||||
Tree pattern = def.getPattern();
|
||||
Name name = switch (pattern) {
|
||||
case Tree.Wildcard wild ->
|
||||
new Name.Blank(getIdentifiedLocation(wild.getToken()), meta(), diag());
|
||||
new Name.Blank(getIdentifiedLocation(wild.getToken()), meta());
|
||||
case Tree.Ident id -> {
|
||||
Expression identifier = translateIdent(id, false);
|
||||
yield switch (identifier) {
|
||||
@ -1540,8 +1536,7 @@ final class TreeToIr {
|
||||
defaultValue,
|
||||
isSuspended,
|
||||
getIdentifiedLocation(def),
|
||||
meta(),
|
||||
diag()
|
||||
meta()
|
||||
);
|
||||
}
|
||||
|
||||
@ -1557,12 +1552,12 @@ final class TreeToIr {
|
||||
case Tree.NamedApp app -> {
|
||||
var expr = translateExpression(app.getArg(), false);
|
||||
var id = sanitizeName(buildName(app, app.getName()));
|
||||
yield new CallArgument.Specified(Option.apply(id), expr, loc, meta(), diag());
|
||||
yield new CallArgument.Specified(Option.apply(id), expr, loc, meta());
|
||||
}
|
||||
case null -> null;
|
||||
default -> {
|
||||
var expr = translateExpression(arg, false);
|
||||
yield new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag());
|
||||
yield new CallArgument.Specified(Option.empty(), expr, loc, meta());
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1570,7 +1565,7 @@ final class TreeToIr {
|
||||
CallArgument.Specified translateTypeCallArgument(Tree arg) {
|
||||
var loc = getIdentifiedLocation(arg);
|
||||
var expr = translateType(arg);
|
||||
return new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag());
|
||||
return new CallArgument.Specified(Option.empty(), expr, loc, meta());
|
||||
}
|
||||
|
||||
CallArgument.Specified unnamedCallArgument(Tree arg) {
|
||||
@ -1579,7 +1574,7 @@ final class TreeToIr {
|
||||
}
|
||||
var loc = getIdentifiedLocation(arg);
|
||||
var expr = translateExpression(arg);
|
||||
return new CallArgument.Specified(Option.empty(), expr, loc, meta(), diag());
|
||||
return new CallArgument.Specified(Option.empty(), expr, loc, meta());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1601,7 +1596,6 @@ final class TreeToIr {
|
||||
* Translates a pattern in a case expression from its [[AST]] representation into [[IR]].
|
||||
*
|
||||
* @param block the case pattern to translate
|
||||
* @return
|
||||
*/
|
||||
Pattern translatePattern(Tree block) throws SyntaxException {
|
||||
var pattern = maybeManyParensed(block);
|
||||
@ -1611,23 +1605,22 @@ final class TreeToIr {
|
||||
case Tree.Ident id when id.getToken().isTypeOrConstructor() || !fields.isEmpty() -> {
|
||||
yield new Pattern.Constructor(
|
||||
sanitizeName(buildName(id)), fields,
|
||||
getIdentifiedLocation(id), meta(), diag()
|
||||
getIdentifiedLocation(id), meta()
|
||||
);
|
||||
}
|
||||
case Tree.Ident id ->
|
||||
new Pattern.Name(buildName(id), getIdentifiedLocation(id), meta(), diag());
|
||||
new Pattern.Name(buildName(id), getIdentifiedLocation(id), meta());
|
||||
case Tree.OprApp app when isDotOperator(app.getOpr().getRight()) -> {
|
||||
var qualifiedName = buildQualifiedName(app);
|
||||
yield new Pattern.Constructor(
|
||||
qualifiedName, fields, getIdentifiedLocation(app), meta(), diag()
|
||||
qualifiedName, fields, getIdentifiedLocation(app), meta()
|
||||
);
|
||||
}
|
||||
case Tree.Wildcard wild -> translateWildcardPattern(wild);
|
||||
case Tree.TextLiteral lit ->
|
||||
new Pattern.Literal(translateLiteral(lit), getIdentifiedLocation(lit), meta(), diag());
|
||||
new Pattern.Literal(translateLiteral(lit), getIdentifiedLocation(lit), meta());
|
||||
case Tree.Number num ->
|
||||
new Pattern.Literal((Literal) translateNumber(num), getIdentifiedLocation(num), meta(),
|
||||
diag());
|
||||
new Pattern.Literal((Literal) translateNumber(num), getIdentifiedLocation(num), meta());
|
||||
case Tree.UnaryOprApp num when num.getOpr().codeRepr().equals("-") -> {
|
||||
var n = (Literal.Number) translateExpression(num.getRhs());
|
||||
var t = n.copy(
|
||||
@ -1638,13 +1631,12 @@ final class TreeToIr {
|
||||
n.copy$default$5(),
|
||||
n.copy$default$6()
|
||||
);
|
||||
yield new Pattern.Literal(t, getIdentifiedLocation(num), meta(), diag());
|
||||
yield new Pattern.Literal(t, getIdentifiedLocation(num), meta());
|
||||
}
|
||||
case Tree.TypeAnnotated anno -> {
|
||||
var type = buildNameOrQualifiedName(maybeManyParensed(anno.getType()));
|
||||
var expr = buildNameOrQualifiedName(maybeManyParensed(anno.getExpression()));
|
||||
yield new Pattern.Type(expr, type instanceof Name ? (Name) type : null, Option.empty(),
|
||||
meta(), diag());
|
||||
yield new Pattern.Type(expr, type instanceof Name ? (Name) type : null, Option.empty(), meta());
|
||||
}
|
||||
case Tree.Group group -> translatePattern(group.getBody());
|
||||
default -> throw translateEntity(pattern, "translatePattern");
|
||||
@ -1663,8 +1655,8 @@ final class TreeToIr {
|
||||
|
||||
private Pattern.Name translateWildcardPattern(Tree.Wildcard wild) {
|
||||
var at = getIdentifiedLocation(wild);
|
||||
var blank = new Name.Blank(at, meta(), diag());
|
||||
return new Pattern.Name(blank, at, meta(), diag());
|
||||
var blank = new Name.Blank(at, meta());
|
||||
return new Pattern.Name(blank, at, meta());
|
||||
}
|
||||
|
||||
private Name.Qualified buildQualifiedName(Tree t) throws SyntaxException {
|
||||
@ -1673,7 +1665,7 @@ final class TreeToIr {
|
||||
|
||||
private Name.Qualified buildQualifiedName(Tree t, Option<IdentifiedLocation> loc,
|
||||
boolean generateId) throws SyntaxException {
|
||||
return new Name.Qualified(qualifiedNameSegments(t, generateId), loc, meta(), diag());
|
||||
return new Name.Qualified(qualifiedNameSegments(t, generateId), loc, meta());
|
||||
}
|
||||
|
||||
private Name buildNameOrQualifiedName(Tree t) throws SyntaxException {
|
||||
@ -1686,7 +1678,7 @@ final class TreeToIr {
|
||||
if (segments.length() == 1) {
|
||||
return segments.head();
|
||||
} else {
|
||||
return new Name.Qualified(segments, loc, meta(), diag());
|
||||
return new Name.Qualified(segments, loc, meta());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1728,7 +1720,7 @@ final class TreeToIr {
|
||||
return switch (tree) {
|
||||
case Tree.Ident id -> sanitizeName(buildName(id, generateId));
|
||||
case Tree.Wildcard wild ->
|
||||
new Name.Blank(getIdentifiedLocation(wild.getToken(), generateId), meta(), diag());
|
||||
new Name.Blank(getIdentifiedLocation(wild.getToken(), generateId), meta());
|
||||
default -> throw translateEntity(tree, "qualifiedNameSegment");
|
||||
};
|
||||
}
|
||||
@ -1788,8 +1780,7 @@ final class TreeToIr {
|
||||
new Polyglot.Java(pkg.toString(), cls),
|
||||
rename.map(name -> name.name()),
|
||||
getIdentifiedLocation(imp),
|
||||
meta(),
|
||||
diag()
|
||||
meta()
|
||||
);
|
||||
}
|
||||
var isAll = imp.getAll() != null;
|
||||
@ -1813,7 +1804,7 @@ final class TreeToIr {
|
||||
qualifiedName, rename, isAll || onlyNames.isDefined() || hidingNames.isDefined(),
|
||||
onlyNames,
|
||||
hidingNames, getIdentifiedLocation(imp), false,
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
} catch (SyntaxException err) {
|
||||
if (err.where instanceof Invalid invalid) {
|
||||
@ -1877,7 +1868,7 @@ final class TreeToIr {
|
||||
return new Export.Module(
|
||||
qualifiedName, rename, onlyNames,
|
||||
getIdentifiedLocation(exp), false,
|
||||
meta(), diag()
|
||||
meta()
|
||||
);
|
||||
} catch (SyntaxException err) {
|
||||
if (err.where instanceof Invalid invalid) {
|
||||
@ -1896,16 +1887,16 @@ final class TreeToIr {
|
||||
*/
|
||||
Comment.Documentation translateComment(Tree where, DocComment doc) throws SyntaxException {
|
||||
var text = buildTextConstant(where, doc.getElements());
|
||||
return new Comment.Documentation(text, getIdentifiedLocation(where), meta(), diag());
|
||||
return new Comment.Documentation(text, getIdentifiedLocation(where), meta());
|
||||
}
|
||||
|
||||
Syntax translateSyntaxError(Tree where, Syntax.Reason reason) {
|
||||
var at = getIdentifiedLocation(where).get();
|
||||
return new Syntax(at, reason, meta(), diag());
|
||||
return new Syntax(at, reason, meta());
|
||||
}
|
||||
|
||||
Syntax translateSyntaxError(IdentifiedLocation where, Syntax.Reason reason) {
|
||||
return new Syntax(where, reason, meta(), diag());
|
||||
return new Syntax(where, reason, meta());
|
||||
}
|
||||
|
||||
SyntaxException translateEntity(Tree where, String msg) throws SyntaxException {
|
||||
@ -1943,7 +1934,7 @@ final class TreeToIr {
|
||||
|
||||
private Name.Literal buildName(Option<IdentifiedLocation> loc, Token id, boolean isMethod) {
|
||||
final String name = id.codeRepr();
|
||||
return new Name.Literal(name, isMethod, loc, Option.empty(), meta(), diag());
|
||||
return new Name.Literal(name, isMethod, loc, Option.empty(), meta());
|
||||
}
|
||||
|
||||
private Name sanitizeName(Name.Literal id) {
|
||||
@ -2052,10 +2043,6 @@ final class TreeToIr {
|
||||
return new MetadataStorage();
|
||||
}
|
||||
|
||||
private DiagnosticStorage diag() {
|
||||
return DiagnosticStorage.apply(nil());
|
||||
}
|
||||
|
||||
private static int castToInt(long presumablyInt) {
|
||||
int value = (int) presumablyInt;
|
||||
if (value != presumablyInt) {
|
||||
|
@ -467,14 +467,23 @@ public final class IrPersistance {
|
||||
|
||||
@Override
|
||||
protected void writeObject(DiagnosticStorage obj, Output out) throws IOException {
|
||||
out.writeInline(List.class, obj.toList());
|
||||
if (obj == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeInline(List.class, obj.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected DiagnosticStorage readObject(Input in) throws IOException, ClassNotFoundException {
|
||||
var diags = in.readInline(List.class);
|
||||
return new DiagnosticStorage(diags);
|
||||
if (in.readBoolean()) {
|
||||
var diags = in.readInline(List.class);
|
||||
return new DiagnosticStorage(diags);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ object Implicits {
|
||||
* @return [[ir]] with added diagnostics
|
||||
*/
|
||||
def addDiagnostic(diagnostic: Diagnostic): T = {
|
||||
ir.diagnostics.add(diagnostic)
|
||||
ir.getDiagnostics.add(diagnostic)
|
||||
ir
|
||||
}
|
||||
}
|
||||
|
@ -35,20 +35,19 @@ object CallArgument {
|
||||
* A [[CallArgument]] where the `value` is an [[Name.Blank]] is a
|
||||
* representation of a lambda shorthand argument.
|
||||
*
|
||||
* @param name the name of the argument being called, if present
|
||||
* @param value the expression being passed as the argument's value
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param name the name of the argument being called, if present
|
||||
* @param value the expression being passed as the argument's value
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Specified(
|
||||
override val name: Option[Name],
|
||||
override val value: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends CallArgument
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -56,8 +55,6 @@ object CallArgument {
|
||||
* @param name the name of the argument being called, if present
|
||||
* @param value the expression being passed as the argument's value
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param shouldBeSuspended whether or not the argument should be passed
|
||||
* suspended
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param id the identifier for the new node
|
||||
@ -79,14 +76,9 @@ object CallArgument {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Specified(
|
||||
name,
|
||||
value,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
)
|
||||
res.id = id
|
||||
val res = Specified(name, value, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -116,9 +108,8 @@ object CallArgument {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -52,7 +52,6 @@ object DefinitionArgument {
|
||||
* @param suspended whether or not the argument has its execution suspended
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Specified(
|
||||
override val name: Name,
|
||||
@ -60,12 +59,42 @@ object DefinitionArgument {
|
||||
override val defaultValue: Option[Expression],
|
||||
override val suspended: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends DefinitionArgument
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[Specified]] object.
|
||||
*
|
||||
* @param name the name of the argument
|
||||
* @param ascribedType the explicitly ascribed type of the argument, if present
|
||||
* @param defaultValue the default value of the argument, if present
|
||||
* @param suspended whether or not the argument has its execution suspended
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
name: Name,
|
||||
ascribedType: Option[Expression],
|
||||
defaultValue: Option[Expression],
|
||||
suspended: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(
|
||||
name,
|
||||
ascribedType,
|
||||
defaultValue,
|
||||
suspended,
|
||||
location,
|
||||
passData
|
||||
)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param name the name of the argument
|
||||
@ -105,10 +134,10 @@ object DefinitionArgument {
|
||||
defaultValue,
|
||||
suspended,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -148,9 +177,8 @@ object DefinitionArgument {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -24,67 +24,6 @@ final class DiagnosticStorage(initDiagnostics: Seq[Diagnostic] = Seq())
|
||||
diagnostics = newDiagnostics.toList ::: diagnostics
|
||||
}
|
||||
|
||||
/** Applies the function `f` across the diagnostic storage, producing a
|
||||
* result sequence.
|
||||
*
|
||||
* @param f the function to apply
|
||||
* @tparam R the result type of `f`
|
||||
* @return the sequence that results from applying `f` over the storage
|
||||
*/
|
||||
def map[R](f: Diagnostic => R): Seq[R] = {
|
||||
diagnostics.map(f)
|
||||
}
|
||||
|
||||
/** Applies the function `f` across the diagnostic storage in place.
|
||||
*
|
||||
* @param f the function to apply
|
||||
*/
|
||||
def mapInPlace(f: Diagnostic => Diagnostic): Unit = {
|
||||
diagnostics = diagnostics.map(f)
|
||||
}
|
||||
|
||||
/** Performs a collection operation on the diagnostics storage, producing
|
||||
* a new sequence.
|
||||
*
|
||||
* @param pf the partial function to apply
|
||||
* @tparam R the result type of the partial function
|
||||
* @return the result of collecting across the storage with `pf`
|
||||
*/
|
||||
def collect[R](pf: PartialFunction[Diagnostic, R]): Seq[R] = {
|
||||
diagnostics.collect(pf)
|
||||
}
|
||||
|
||||
/** Filters the elements of the diagnostic storage using the predicate.
|
||||
*
|
||||
* @param pred the predicate to filter with
|
||||
* @return a new diagnostic storage instance containing elements matching
|
||||
* `pred`
|
||||
*/
|
||||
def filter(pred: Diagnostic => Boolean): DiagnosticStorage = {
|
||||
new DiagnosticStorage(diagnostics.filter(pred))
|
||||
}
|
||||
|
||||
/** Filters the elements of the diagnostic storage in place using the
|
||||
* predicate.
|
||||
*
|
||||
* @param pred the predicate to filter with
|
||||
*/
|
||||
def filterInPlace(pred: Diagnostic => Boolean): Unit = {
|
||||
diagnostics = diagnostics.filter(pred)
|
||||
}
|
||||
|
||||
/** Performs a left fold over the diagnostic storage to produce a result.
|
||||
*
|
||||
* @param init the starting value
|
||||
* @param op the operator to use to fold
|
||||
* @tparam L the result type of the fold
|
||||
* @return the result of folding over the storage using `op` starting wit
|
||||
* `init`
|
||||
*/
|
||||
def foldLeft[L](init: L)(op: (L, Diagnostic) => L): L = {
|
||||
diagnostics.foldLeft(init)(op)
|
||||
}
|
||||
|
||||
/** Checks two diagnostics storages for equality.
|
||||
*
|
||||
* @param obj the object to check against `this`
|
||||
@ -119,16 +58,6 @@ final class DiagnosticStorage(initDiagnostics: Seq[Diagnostic] = Seq())
|
||||
* @return a shallow copy of this
|
||||
*/
|
||||
def copy: DiagnosticStorage = {
|
||||
DiagnosticStorage(this.diagnostics)
|
||||
new DiagnosticStorage(this.diagnostics)
|
||||
}
|
||||
}
|
||||
object DiagnosticStorage {
|
||||
|
||||
/** Creates a new instance of the diagnostics storage.
|
||||
*
|
||||
* @param initDiagnostics the initial diagnostics to construct it with
|
||||
* @return a new diagnostics storage instance
|
||||
*/
|
||||
def apply(initDiagnostics: Seq[Diagnostic] = Seq()): DiagnosticStorage =
|
||||
new DiagnosticStorage(initDiagnostics)
|
||||
}
|
||||
|
@ -7,17 +7,16 @@ import java.util.UUID
|
||||
|
||||
/** A node representing an empty IR construct that can be used in any place.
|
||||
*
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Empty(
|
||||
override val location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends IR
|
||||
with Expression
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`
|
||||
@ -40,8 +39,9 @@ sealed case class Empty(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Empty(location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Empty(location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -57,9 +57,8 @@ sealed case class Empty(
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -53,17 +53,16 @@ object Expression {
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param suspended whether or not the block is suspended
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Block(
|
||||
expressions: List[Expression],
|
||||
returnValue: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
suspended: Boolean = false,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
suspended: Boolean = false,
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Expression
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -100,10 +99,10 @@ object Expression {
|
||||
returnValue,
|
||||
location,
|
||||
suspended,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -133,9 +132,8 @@ object Expression {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -190,18 +188,27 @@ object Expression {
|
||||
* @param expression the expression being bound to `name`
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Binding(
|
||||
name: Name,
|
||||
expression: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Expression
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[Binding]] object from a [[Function.Binding]].
|
||||
*
|
||||
* @param ir the function binding
|
||||
* @param lambda the body of the function
|
||||
*/
|
||||
def this(ir: Function.Binding, lambda: Function.Lambda) = {
|
||||
this(ir.name, lambda, ir.location, ir.passData)
|
||||
this.diagnostics = ir.diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param name the name being bound to
|
||||
@ -228,8 +235,9 @@ object Expression {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Binding(name, expression, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Binding(name, expression, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -257,9 +265,8 @@ object Expression {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -39,43 +39,56 @@ object Function {
|
||||
* multi-argument lambdas, our internal representation does so to allow for
|
||||
* better optimisation.
|
||||
*
|
||||
* @param arguments the arguments to the lambda
|
||||
* @param arguments the arguments to the lambda
|
||||
* @param bodyReference the body of the lambda, stored as a reference to ensure
|
||||
* laziness of storage
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param canBeTCO whether or not the function can be tail-call optimised
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param canBeTCO whether or not the function can be tail-call optimised
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Lambda(
|
||||
override val arguments: List[DefinitionArgument],
|
||||
bodyReference: Persistance.Reference[Expression],
|
||||
location: Option[IdentifiedLocation],
|
||||
override val canBeTCO: Boolean,
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
passData: MetadataStorage
|
||||
) extends Function
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
def this(
|
||||
arguments: List[DefinitionArgument],
|
||||
body: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
canBeTCO: Boolean = true,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = new DiagnosticStorage()
|
||||
canBeTCO: Boolean = true,
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) = {
|
||||
this(
|
||||
arguments,
|
||||
Persistance.Reference.of(body, true),
|
||||
location,
|
||||
canBeTCO,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
}
|
||||
|
||||
def this(
|
||||
ir: expression.Case.Expr,
|
||||
arguments: List[DefinitionArgument],
|
||||
body: Expression,
|
||||
location: Option[IdentifiedLocation]
|
||||
) = {
|
||||
this(
|
||||
arguments,
|
||||
Persistance.Reference.of(body, true),
|
||||
location,
|
||||
true,
|
||||
ir.passData
|
||||
)
|
||||
diagnostics = ir.diagnostics
|
||||
}
|
||||
|
||||
override lazy val body: Expression = bodyReference.get(classOf[Expression])
|
||||
|
||||
override val isPrivate: Boolean = false
|
||||
@ -115,10 +128,10 @@ object Function {
|
||||
Persistance.Reference.of(body, false),
|
||||
location,
|
||||
canBeTCO,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -148,9 +161,8 @@ object Function {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -195,6 +207,7 @@ object Function {
|
||||
}
|
||||
|
||||
object Lambda {
|
||||
|
||||
def unapply(l: Lambda): Some[
|
||||
(
|
||||
List[DefinitionArgument],
|
||||
@ -226,7 +239,6 @@ object Function {
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param canBeTCO whether or not the function can be tail-call optimised
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Binding(
|
||||
name: Name,
|
||||
@ -235,10 +247,10 @@ object Function {
|
||||
override val isPrivate: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
override val canBeTCO: Boolean = true,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Function
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -284,10 +296,10 @@ object Function {
|
||||
isPrivate,
|
||||
location,
|
||||
canBeTCO,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -323,9 +335,8 @@ object Function {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -0,0 +1,28 @@
|
||||
package org.enso.compiler.core.ir
|
||||
|
||||
import org.enso.compiler.core.IR
|
||||
|
||||
trait LazyDiagnosticStorage { self: IR =>
|
||||
|
||||
private[this] var _diagnostics: DiagnosticStorage = _
|
||||
|
||||
protected def diagnostics_=(diagnostics: DiagnosticStorage): Unit = {
|
||||
assert(_diagnostics eq null)
|
||||
_diagnostics = diagnostics
|
||||
}
|
||||
|
||||
override def diagnostics: DiagnosticStorage = {
|
||||
_diagnostics
|
||||
}
|
||||
|
||||
def diagnosticsCopy: DiagnosticStorage = {
|
||||
if (_diagnostics eq null) _diagnostics else _diagnostics.copy
|
||||
}
|
||||
|
||||
override def getDiagnostics: DiagnosticStorage = {
|
||||
if (_diagnostics eq null) {
|
||||
_diagnostics = new DiagnosticStorage()
|
||||
}
|
||||
_diagnostics
|
||||
}
|
||||
}
|
@ -6,7 +6,8 @@ import org.enso.compiler.core.{IR, Identifier}
|
||||
import java.util.UUID
|
||||
|
||||
trait LazyId { self: IR =>
|
||||
private[this] var _id: UUID @Identifier = null
|
||||
|
||||
private[this] var _id: UUID @Identifier = _
|
||||
|
||||
protected def id: UUID @Identifier = {
|
||||
_id
|
||||
@ -19,7 +20,7 @@ trait LazyId { self: IR =>
|
||||
_id
|
||||
}
|
||||
|
||||
def id_=(id: UUID @Identifier) = {
|
||||
def id_=(id: UUID @Identifier): Unit = {
|
||||
assert(_id == null)
|
||||
_id = id
|
||||
}
|
||||
|
@ -29,19 +29,18 @@ object Literal {
|
||||
|
||||
/** A numeric Enso literal.
|
||||
*
|
||||
* @param base the optional base for the number, expressed in decimal
|
||||
* @param value the textual representation of the numeric literal
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param base the optional base for the number, expressed in decimal
|
||||
* @param value the textual representation of the numeric literal
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Number(
|
||||
base: Option[String],
|
||||
value: String,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Literal
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -70,8 +69,9 @@ object Literal {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Number(base, value, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Number(base, value, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -87,9 +87,8 @@ object Literal {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -167,17 +166,16 @@ object Literal {
|
||||
|
||||
/** A textual Enso literal.
|
||||
*
|
||||
* @param text the text of the literal
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param text the text of the literal
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Text(
|
||||
text: String,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Literal
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -203,8 +201,9 @@ object Literal {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Text(text, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Text(text, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -220,9 +219,8 @@ object Literal {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -11,13 +11,12 @@ import java.util.UUID
|
||||
* Modules may only contain imports and top-level bindings, with no top-level
|
||||
* executable code.
|
||||
*
|
||||
* @param imports the import statements that bring other modules into scope
|
||||
* @param exports the export statements for this module
|
||||
* @param bindings the top-level bindings for this module
|
||||
* @param isPrivate whether or not this module is private (project-private)
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param imports the import statements that bring other modules into scope
|
||||
* @param exports the export statements for this module
|
||||
* @param bindings the top-level bindings for this module
|
||||
* @param isPrivate whether or not this module is private (project-private)
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
final case class Module(
|
||||
imports: List[Import],
|
||||
@ -25,12 +24,35 @@ final case class Module(
|
||||
bindings: List[Definition],
|
||||
isPrivate: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends IR
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a module.
|
||||
*
|
||||
* @param imports the import statements that bring other modules into scope
|
||||
* @param exports the export statements for this module
|
||||
* @param bindings the top-level bindings for this module
|
||||
* @param isPrivate whether or not this module is private (project-private)
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
imports: List[Import],
|
||||
exports: List[Export],
|
||||
bindings: List[Definition],
|
||||
isPrivate: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(imports, exports, bindings, isPrivate, location, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param imports the import statements that bring other modules into scope
|
||||
@ -69,10 +91,10 @@ final case class Module(
|
||||
bindings,
|
||||
isPrivate,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -104,9 +126,8 @@ final case class Module(
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -41,16 +41,15 @@ object Name {
|
||||
* @param methodName the method on `typeName`
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
final case class MethodReference(
|
||||
typePointer: Option[Name],
|
||||
methodName: Name,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
override val name: String = showCode()
|
||||
@ -86,10 +85,10 @@ object Name {
|
||||
typePointer,
|
||||
methodName,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -119,9 +118,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -171,9 +169,7 @@ object Name {
|
||||
*/
|
||||
def isSameReferenceAs(that: MethodReference): Boolean = {
|
||||
val sameTypePointer = typePointer
|
||||
.map(thisTp =>
|
||||
that.typePointer.map(_.name == thisTp.name).getOrElse(false)
|
||||
)
|
||||
.map(thisTp => that.typePointer.exists(_.name == thisTp.name))
|
||||
.getOrElse(that.typePointer.isEmpty)
|
||||
sameTypePointer && (methodName.name == that.methodName.name)
|
||||
}
|
||||
@ -208,19 +204,18 @@ object Name {
|
||||
|
||||
/** A representation of a qualified (multi-part) name.
|
||||
*
|
||||
* @param parts the segments of the name
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param parts the segments of the name
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @return a copy of `this`, updated with the specified values
|
||||
*/
|
||||
final case class Qualified(
|
||||
parts: List[Name],
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
override val name: String = parts.map(_.name).mkString(".")
|
||||
@ -255,14 +250,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Qualified(
|
||||
parts,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
)
|
||||
res.id = id
|
||||
val res = Qualified(parts, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -286,9 +276,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -302,14 +291,13 @@ object Name {
|
||||
*
|
||||
* @param location the source location that the node corresponds to.
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Blank(
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
override val name: String = "_"
|
||||
|
||||
@ -333,8 +321,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Blank(location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Blank(location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -350,9 +339,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -386,10 +374,10 @@ object Name {
|
||||
sealed case class Special(
|
||||
specialName: Special.Ident,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
override val name: String = s"<special::${specialName}>"
|
||||
|
||||
@ -415,8 +403,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Special(specialName, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Special(specialName, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -431,9 +420,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
override def mapExpressions(
|
||||
@ -481,16 +469,15 @@ object Name {
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param originalName the name which this literal has replaced, if any
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Literal(
|
||||
override val name: String,
|
||||
override val isMethod: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
originalName: Option[Name] = None,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
originalName: Option[Name] = None,
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -522,9 +509,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Literal(name, isMethod, location, originalName, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Literal(name, isMethod, location, originalName, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -540,9 +527,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -599,15 +585,14 @@ object Name {
|
||||
* @param name the annotation text of the name
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class BuiltinAnnotation(
|
||||
override val name: String,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Annotation
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -633,8 +618,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = BuiltinAnnotation(name, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = BuiltinAnnotation(name, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -650,9 +636,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -688,19 +673,18 @@ object Name {
|
||||
|
||||
/** Common annotations of form `@name expression`.
|
||||
*
|
||||
* @param name the annotation text of the name
|
||||
* @param expression the annotation expression
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param name the annotation text of the name
|
||||
* @param expression the annotation expression
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class GenericAnnotation(
|
||||
override val name: String,
|
||||
expression: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Annotation
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -730,8 +714,9 @@ object Name {
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
GenericAnnotation(name, expression, location, passData, diagnostics)
|
||||
res.id = id
|
||||
GenericAnnotation(name, expression, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -747,9 +732,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -787,17 +771,35 @@ object Name {
|
||||
|
||||
/** A representation of the name `self`, used to refer to the current type.
|
||||
*
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param synthetic the flag indicating that the name was generated
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Self(
|
||||
location: Option[IdentifiedLocation],
|
||||
synthetic: Boolean = false,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
synthetic: Boolean = false,
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[Self]] object.
|
||||
*
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param synthetic the flag indicating that the name was generated
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
location: Option[IdentifiedLocation],
|
||||
synthetic: Boolean,
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(location, synthetic, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
override val name: String = ConstantsNames.SELF_ARGUMENT
|
||||
|
||||
/** Creates a copy of `self`.
|
||||
@ -822,8 +824,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Self(location, synthetic, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Self(location, synthetic, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -839,9 +842,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -874,16 +876,31 @@ object Name {
|
||||
|
||||
/** A representation of the name `Self`, used to refer to the current type.
|
||||
*
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class SelfType(
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Name
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[SelfType]] object.
|
||||
*
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(location, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
override val name: String = ConstantsNames.SELF_TYPE_ARGUMENT
|
||||
|
||||
/** Creates a copy of `Self`.
|
||||
@ -906,8 +923,9 @@ object Name {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = SelfType(location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = SelfType(location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -923,9 +941,8 @@ object Name {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -35,17 +35,16 @@ object Pattern {
|
||||
* As a result they can be used to represent a catch all pattern (e.g.
|
||||
* `_ -> ...` or `a -> ...`).
|
||||
*
|
||||
* @param name the name that constitutes the pattern
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with the node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param name the name that constitutes the pattern
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with the node
|
||||
*/
|
||||
sealed case class Name(
|
||||
name: IRName,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Pattern
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -71,8 +70,9 @@ object Pattern {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Name(name, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Name(name, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -94,9 +94,8 @@ object Pattern {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -138,15 +137,14 @@ object Pattern {
|
||||
* @param fields the asserted fields of the constructor
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Constructor(
|
||||
constructor: IRName,
|
||||
fields: List[Pattern],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Pattern
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -175,9 +173,9 @@ object Pattern {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Constructor(constructor, fields, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Constructor(constructor, fields, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -207,9 +205,8 @@ object Pattern {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** Checks if the constructor pattern has been desugared.
|
||||
@ -238,7 +235,7 @@ object Pattern {
|
||||
*
|
||||
* @return the fields from `this`
|
||||
*/
|
||||
def fieldsAsNamed: List[Option[Pattern.Name]] = {
|
||||
private def fieldsAsNamed: List[Option[Pattern.Name]] = {
|
||||
fields.map {
|
||||
case f: Name => Some(f)
|
||||
case _ => None
|
||||
@ -296,17 +293,16 @@ object Pattern {
|
||||
*
|
||||
* A literal pattern matches on constants.
|
||||
*
|
||||
* @param literal the literal representing the pattern
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with the node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param literal the literal representing the pattern
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with the node
|
||||
*/
|
||||
sealed case class Literal(
|
||||
literal: IRLiteral,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Pattern
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -332,8 +328,9 @@ object Pattern {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Literal(literal, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Literal(literal, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -355,9 +352,8 @@ object Pattern {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -395,21 +391,20 @@ object Pattern {
|
||||
* A type pattern matches on types. Type pattern is composed of two parts:
|
||||
* - a single identifier (e.g. `a` or `_`)
|
||||
* - a (potentially fully qualified) type name
|
||||
* E.g., `a : Foo -> ...` or `_ : Bar -> ...``
|
||||
* E.g., `a : Foo -> ...` or `_ : Bar -> ...`
|
||||
*
|
||||
* @param name the name of the bound variable, or wildcard
|
||||
* @param tpe the name of the type to match on
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with the node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param name the name of the bound variable, or wildcard
|
||||
* @param tpe the name of the type to match on
|
||||
* @param location the source location for this IR node
|
||||
* @param passData any pass metadata associated with the node
|
||||
*/
|
||||
sealed case class Type(
|
||||
name: IRName,
|
||||
tpe: IRName,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Pattern
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -438,8 +433,9 @@ object Pattern {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Type(name, tpe, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Type(name, tpe, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -467,9 +463,8 @@ object Pattern {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -511,17 +506,16 @@ object Pattern {
|
||||
* created with its pattern being an instance of this Doc and expression
|
||||
* being empty.
|
||||
*
|
||||
* @param doc the documentation entity
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param doc the documentation entity
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
final case class Documentation(
|
||||
doc: String,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Pattern
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -559,8 +553,9 @@ object Pattern {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Documentation(doc, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Documentation(doc, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -577,9 +572,8 @@ object Pattern {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -37,9 +37,9 @@ object Type {
|
||||
args: List[Expression],
|
||||
result: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Type
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
def copy(
|
||||
@ -58,8 +58,9 @@ object Type {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Function(args, result, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Function(args, result, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -89,9 +90,8 @@ object Type {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -133,18 +133,17 @@ object Type {
|
||||
* @param comment a comment that may be used to add context to the type error
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Ascription(
|
||||
typed: Expression,
|
||||
signature: Expression,
|
||||
comment: Option[String],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Type
|
||||
with module.scope.Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -176,9 +175,9 @@ object Type {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Ascription(typed, signature, comment, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Ascription(typed, signature, comment, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -206,9 +205,8 @@ object Type {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -255,16 +253,15 @@ object Type {
|
||||
* @param context the context being ascribed to `typed`
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Context(
|
||||
typed: Expression,
|
||||
context: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Type
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates ac opy of `this`.
|
||||
@ -293,8 +290,9 @@ object Type {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Context(typed, context, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Context(typed, context, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -322,9 +320,8 @@ object Type {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -364,20 +361,19 @@ object Type {
|
||||
|
||||
/** Represents the ascription of an error context to an expression.
|
||||
*
|
||||
* @param typed the expression being ascribed an error context
|
||||
* @param error the error being ascribed
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param typed the expression being ascribed an error context
|
||||
* @param error the error being ascribed
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Error(
|
||||
typed: Expression,
|
||||
error: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Type
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -406,8 +402,9 @@ object Type {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Error(typed, error, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Error(typed, error, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -435,9 +432,8 @@ object Type {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -14,25 +14,52 @@ object Application {
|
||||
|
||||
/** A standard prefix function application.
|
||||
*
|
||||
* @param function the function being called
|
||||
* @param arguments the arguments to the function being called
|
||||
* @param function the function being called
|
||||
* @param arguments the arguments to the function being called
|
||||
* @param hasDefaultsSuspended whether the function application has any
|
||||
* argument defaults in `function` suspended
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* argument defaults in `function` suspended
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Prefix(
|
||||
function: Expression,
|
||||
arguments: List[CallArgument],
|
||||
hasDefaultsSuspended: Boolean,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Application
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a prefix application.
|
||||
*
|
||||
* @param function the function being called
|
||||
* @param arguments the arguments to the function being called
|
||||
* @param hasDefaultsSuspended whether the function application has any
|
||||
* argument defaults in `function` suspended
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
function: Expression,
|
||||
arguments: List[CallArgument],
|
||||
hasDefaultsSuspended: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(
|
||||
function,
|
||||
arguments,
|
||||
hasDefaultsSuspended,
|
||||
location,
|
||||
passData
|
||||
)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param function the function being called
|
||||
@ -69,10 +96,10 @@ object Application {
|
||||
arguments,
|
||||
hasDefaultsSuspended,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -102,9 +129,8 @@ object Application {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -145,18 +171,17 @@ object Application {
|
||||
|
||||
/** A representation of a term that is explicitly forced.
|
||||
*
|
||||
* @param target the expression being forced
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param target the expression being forced
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Force(
|
||||
target: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Application
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -182,8 +207,9 @@ object Application {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Force(target, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Force(target, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -205,9 +231,8 @@ object Application {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -265,18 +290,17 @@ object Application {
|
||||
*
|
||||
* These are necessary as they delimit pattern contexts.
|
||||
*
|
||||
* @param expression the expression of the typeset body
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param expression the expression of the typeset body
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Typeset(
|
||||
expression: Option[Expression],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Literal
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
override def mapExpressions(
|
||||
@ -307,9 +331,9 @@ object Application {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Typeset(expression, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Typeset(expression, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -333,9 +357,8 @@ object Application {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -370,18 +393,17 @@ object Application {
|
||||
|
||||
/** A representation of a vector literal.
|
||||
*
|
||||
* @param items the items being put in the vector
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param items the items being put in the vector
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Sequence(
|
||||
items: List[Expression],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Literal
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
override def mapExpressions(
|
||||
@ -412,9 +434,9 @@ object Application {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Sequence(items, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Sequence(items, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -438,9 +460,8 @@ object Application {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -31,34 +31,23 @@ object Case {
|
||||
|
||||
/** The main body of the Enso case expression.
|
||||
*
|
||||
* @param scrutinee the expression whose value is being matched on
|
||||
* @param branches the branches of the case expression
|
||||
* @param isNested if true, the flag indicates that the expr represents a desugared nested case
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param scrutinee the expression whose value is being matched on
|
||||
* @param branches the branches of the case expression
|
||||
* @param isNested if true, the flag indicates that the expr represents a desugared nested case
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Expr(
|
||||
scrutinee: Expression,
|
||||
branches: Seq[Branch],
|
||||
isNested: Boolean,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Case
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
def this(
|
||||
scrutinee: Expression,
|
||||
branches: Seq[Branch],
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(scrutinee, branches, false, location, passData, diagnostics)
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param scrutinee the expression whose value is being matched on
|
||||
@ -88,9 +77,9 @@ object Case {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Expr(scrutinee, branches, isNested, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Expr(scrutinee, branches, isNested, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -121,9 +110,8 @@ object Case {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -169,29 +157,6 @@ object Case {
|
||||
}
|
||||
}
|
||||
|
||||
object Expr {
|
||||
def apply(
|
||||
scrutinee: Expression,
|
||||
branches: Seq[Branch],
|
||||
location: Option[IdentifiedLocation]
|
||||
): Expr =
|
||||
apply(
|
||||
scrutinee,
|
||||
branches,
|
||||
location,
|
||||
new MetadataStorage(),
|
||||
new DiagnosticStorage()
|
||||
)
|
||||
|
||||
def apply(
|
||||
scrutinee: Expression,
|
||||
branches: Seq[Branch],
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
): Expr = new Expr(scrutinee, branches, location, passData, diagnostics)
|
||||
}
|
||||
|
||||
/** A branch in a case statement.
|
||||
*
|
||||
* @param pattern the pattern that attempts to match against the scrutinee
|
||||
@ -199,29 +164,18 @@ object Case {
|
||||
* @param terminalBranch the flag indicating whether the branch represents the final pattern to be checked
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Branch(
|
||||
pattern: Pattern,
|
||||
expression: Expression,
|
||||
terminalBranch: Boolean,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Case
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
def this(
|
||||
pattern: Pattern,
|
||||
expression: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(pattern, expression, true, location, passData, diagnostics)
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param pattern the pattern that attempts to match against the scrutinee
|
||||
@ -250,16 +204,15 @@ object Case {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Branch(
|
||||
pattern,
|
||||
expression,
|
||||
terminalBranch,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -288,9 +241,8 @@ object Case {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -332,28 +284,4 @@ object Case {
|
||||
s"${pattern.showCode(indent)} -> $bodyStr"
|
||||
}
|
||||
}
|
||||
|
||||
object Branch {
|
||||
def apply(
|
||||
pattern: Pattern,
|
||||
expression: Expression,
|
||||
location: Option[IdentifiedLocation]
|
||||
): Branch =
|
||||
apply(
|
||||
pattern,
|
||||
expression,
|
||||
location,
|
||||
new MetadataStorage(),
|
||||
new DiagnosticStorage()
|
||||
)
|
||||
|
||||
def apply(
|
||||
pattern: Pattern,
|
||||
expression: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
): Branch =
|
||||
new Branch(pattern, expression, location, passData, diagnostics)
|
||||
}
|
||||
}
|
||||
|
@ -33,15 +33,14 @@ object Comment {
|
||||
* @param doc the documentation entity
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Documentation(
|
||||
doc: String,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Comment
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -67,9 +66,9 @@ object Comment {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Documentation(doc, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Documentation(doc, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -85,9 +84,8 @@ object Comment {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -31,17 +31,16 @@ object Error {
|
||||
|
||||
/** A representation of an invalid piece of IR.
|
||||
*
|
||||
* @param ir the IR that is invalid
|
||||
* @param passData any annotations from compiler passes
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param ir the IR that is invalid
|
||||
* @param passData any annotations from compiler passes
|
||||
*/
|
||||
sealed case class InvalidIR(
|
||||
ir: IR,
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Error
|
||||
with Diagnostic.Kind.Static
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -64,9 +63,9 @@ object Error {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = InvalidIR(ir, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = InvalidIR(ir, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -87,9 +86,8 @@ object Error {
|
||||
),
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -37,16 +37,15 @@ object Foreign {
|
||||
* @param code the code written in `lang`
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Definition(
|
||||
lang: String,
|
||||
code: String,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Foreign
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -75,9 +74,9 @@ object Foreign {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Definition(lang, code, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Definition(lang, code, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -93,9 +92,8 @@ object Foreign {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -35,17 +35,16 @@ object Operator {
|
||||
* @param right the right operand to `operator`
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Binary(
|
||||
left: CallArgument,
|
||||
operator: Name,
|
||||
right: CallArgument,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Operator
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -77,10 +76,9 @@ object Operator {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res =
|
||||
Binary(left, operator, right, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Binary(left, operator, right, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -114,9 +112,8 @@ object Operator {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -30,20 +30,19 @@ object Section {
|
||||
|
||||
/** Represents a left operator section of the form `(arg op)`.
|
||||
*
|
||||
* @param arg the argument (on the left of the operator)
|
||||
* @param operator the operator
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param arg the argument (on the left of the operator)
|
||||
* @param operator the operator
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Left(
|
||||
arg: CallArgument,
|
||||
operator: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Section
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -72,9 +71,9 @@ object Section {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Left(arg, operator, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Left(arg, operator, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -103,9 +102,8 @@ object Section {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -144,18 +142,17 @@ object Section {
|
||||
|
||||
/** Represents a sides operator section of the form `(op)`
|
||||
*
|
||||
* @param operator the operator
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param operator the operator
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Sides(
|
||||
operator: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Section
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -181,8 +178,9 @@ object Section {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Sides(operator, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Sides(operator, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -205,9 +203,8 @@ object Section {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -243,20 +240,19 @@ object Section {
|
||||
|
||||
/** Represents a right operator section of the form `(op arg)`
|
||||
*
|
||||
* @param operator the operator
|
||||
* @param arg the argument (on the right of the operator)
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param operator the operator
|
||||
* @param arg the argument (on the right of the operator)
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Right(
|
||||
operator: Name,
|
||||
arg: CallArgument,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Section
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -285,9 +281,9 @@ object Section {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Right(operator, arg, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Right(operator, arg, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -316,9 +312,8 @@ object Section {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -11,18 +11,18 @@ import java.util.UUID
|
||||
* @param storedIr the IR that contains the error
|
||||
* @param reason the explanation for the error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler dianostics for this node
|
||||
*/
|
||||
sealed case class Conversion(
|
||||
storedIr: IR,
|
||||
reason: Conversion.Reason,
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Error
|
||||
with Diagnostic.Kind.Interactive
|
||||
with IRKind.Primitive
|
||||
with Name
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
override val name: String = "conversion_error"
|
||||
|
||||
override def mapExpressions(
|
||||
@ -59,9 +59,9 @@ sealed case class Conversion(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Conversion(storedIr, reason, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Conversion(storedIr, reason, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -82,9 +82,8 @@ sealed case class Conversion(
|
||||
),
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -10,23 +10,39 @@ import scala.annotation.unused
|
||||
|
||||
/** An erroneous import or export statement.
|
||||
*
|
||||
* @param ir the original statement
|
||||
* @param reason the reason it's erroneous
|
||||
* @param passData the pass data
|
||||
* @param diagnostics the attached diagnostics
|
||||
* @param ir the original statement
|
||||
* @param reason the reason it's erroneous
|
||||
* @param passData the pass data
|
||||
*/
|
||||
sealed case class ImportExport(
|
||||
ir: IR,
|
||||
reason: ImportExport.Reason,
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Error
|
||||
with Diagnostic.Kind.Interactive
|
||||
with org.enso.compiler.core.ir.module.scope.Import
|
||||
with org.enso.compiler.core.ir.module.scope.Export
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create an erroneous import or export statement.
|
||||
*
|
||||
* @param ir the original statement
|
||||
* @param reason the reason it's erroneous
|
||||
* @param passData the pass data
|
||||
* @param diagnostics the attached diagnostics
|
||||
*/
|
||||
def this(
|
||||
ir: IR,
|
||||
reason: ImportExport.Reason,
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(ir, reason, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param ir the original IR
|
||||
@ -50,9 +66,9 @@ sealed case class ImportExport(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = ImportExport(ir, reason, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = ImportExport(ir, reason, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -67,9 +83,8 @@ sealed case class ImportExport(
|
||||
copy(
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -115,8 +130,7 @@ sealed case class ImportExport(
|
||||
|
||||
object ImportExport {
|
||||
|
||||
/** A reason for a statement being erroneous.
|
||||
*/
|
||||
/** A reason for a statement being erroneous. */
|
||||
sealed trait Reason {
|
||||
|
||||
/** @param source Location of the original import/export IR.
|
||||
|
@ -11,18 +11,35 @@ import java.util.UUID
|
||||
* @param originalPattern pattern that resulted in the error
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @return a copy of `this`, updated with the specified values
|
||||
*/
|
||||
sealed case class Pattern(
|
||||
originalPattern: org.enso.compiler.core.ir.Pattern,
|
||||
reason: Pattern.Reason,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Error
|
||||
with Diagnostic.Kind.Interactive
|
||||
with org.enso.compiler.core.ir.Pattern
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[Pattern]] object.
|
||||
*
|
||||
* @param originalPattern pattern that resulted in the error
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
originalPattern: org.enso.compiler.core.ir.Pattern,
|
||||
reason: Pattern.Reason,
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(originalPattern, reason, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
override def mapExpressions(
|
||||
fn: java.util.function.Function[Expression, Expression]
|
||||
): Pattern =
|
||||
@ -54,9 +71,9 @@ sealed case class Pattern(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Pattern(originalPattern, reason, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Pattern(originalPattern, reason, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -78,12 +95,11 @@ sealed case class Pattern(
|
||||
),
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
override def message(source: (IdentifiedLocation => String)): String =
|
||||
override def message(source: IdentifiedLocation => String): String =
|
||||
reason.explain
|
||||
|
||||
override def diagnosticKeys(): Array[Any] = Array(reason)
|
||||
@ -99,8 +115,7 @@ sealed case class Pattern(
|
||||
|
||||
object Pattern {
|
||||
|
||||
/** A representation of the reason the pattern is erroneous.
|
||||
*/
|
||||
/** A representation of the reason the pattern is erroneous. */
|
||||
sealed trait Reason {
|
||||
|
||||
/** Provides a human-readable explanation of the error.
|
||||
|
@ -34,17 +34,16 @@ object Redefined {
|
||||
/** An error representing the redefinition or incorrect positioning of
|
||||
* the `self` argument to methods.
|
||||
*
|
||||
* @param location the source location of the error
|
||||
* @param passData the pass metadata for this node
|
||||
* @param diagnostics compiler diagnostics associated with the node
|
||||
* @param location the source location of the error
|
||||
* @param passData the pass metadata for this node
|
||||
*/
|
||||
sealed case class SelfArg(
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `self`.
|
||||
@ -67,9 +66,9 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = SelfArg(location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = SelfArg(location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -85,9 +84,8 @@ object Redefined {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -124,18 +122,17 @@ object Redefined {
|
||||
* @param location the location in the source to which this error
|
||||
* corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
* @param diagnostics any diagnostics associated with this error.
|
||||
*/
|
||||
sealed case class Conversion(
|
||||
targetType: Option[Name],
|
||||
sourceType: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with module.scope.Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -166,10 +163,9 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res =
|
||||
Conversion(targetType, sourceType, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Conversion(targetType, sourceType, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -200,9 +196,8 @@ object Redefined {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -254,23 +249,21 @@ object Redefined {
|
||||
/** An error representing the redefinition of a method in a given module.
|
||||
* This is also known as a method overload.
|
||||
*
|
||||
* @param typeName the name of the type the method was being redefined on
|
||||
* @param methodName the method name being redefined on `atomName`
|
||||
* @param location the location in the source to which this error
|
||||
* corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
* @param diagnostics any diagnostics associated with this error.
|
||||
* @param typeName the name of the type the method was being redefined on
|
||||
* @param methodName the method name being redefined on `atomName`
|
||||
* @param location the location in the source to which this error corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
*/
|
||||
sealed case class Method(
|
||||
typeName: Option[Name],
|
||||
methodName: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with module.scope.Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -300,10 +293,9 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res =
|
||||
Method(typeName, methodName, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Method(typeName, methodName, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -334,9 +326,8 @@ object Redefined {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -388,23 +379,21 @@ object Redefined {
|
||||
* when the module defines a method with the same name as an atom.
|
||||
* This is also known as a name clash.
|
||||
*
|
||||
* @param atomName the name of the atom that clashes with the method
|
||||
* @param methodName the method name being redefined in the module
|
||||
* @param location the location in the source to which this error
|
||||
* corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
* @param diagnostics any diagnostics associated with this error.
|
||||
* @param atomName the name of the atom that clashes with the method
|
||||
* @param methodName the method name being redefined in the module
|
||||
* @param location the location in the source to which this error corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
*/
|
||||
sealed case class MethodClashWithAtom(
|
||||
atomName: Name,
|
||||
methodName: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with module.scope.Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -434,15 +423,14 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = MethodClashWithAtom(
|
||||
atomName,
|
||||
methodName,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -471,9 +459,8 @@ object Redefined {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -519,21 +506,19 @@ object Redefined {
|
||||
|
||||
/** An error representing the redefinition of an atom in a given module.
|
||||
*
|
||||
* @param typeName the name of the atom being redefined
|
||||
* @param location the location in the source to which this error
|
||||
* corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
* @param diagnostics any diagnostics associated with this error.
|
||||
* @param typeName the name of the atom being redefined
|
||||
* @param location the location in the source to which this error corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
*/
|
||||
sealed case class Type(
|
||||
typeName: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with module.scope.Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -561,10 +546,9 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res =
|
||||
Type(typeName, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Type(typeName, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -586,9 +570,8 @@ object Redefined {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -633,17 +616,16 @@ object Redefined {
|
||||
* @param location the location in the source to which this error
|
||||
* corresponds
|
||||
* @param passData the pass metadata for the error
|
||||
* @param diagnostics any diagnostics associated with this error.
|
||||
*/
|
||||
sealed case class Arg(
|
||||
name: Name,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with module.scope.Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -671,10 +653,9 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res =
|
||||
Arg(name, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Arg(name, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -696,9 +677,8 @@ object Redefined {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -744,15 +724,14 @@ object Redefined {
|
||||
*
|
||||
* @param invalidBinding the invalid binding
|
||||
* @param passData the pass metadata for the error
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Binding(
|
||||
invalidBinding: Expression.Binding,
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Redefined
|
||||
with Diagnostic.Kind.Interactive
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -775,9 +754,9 @@ object Redefined {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Binding(invalidBinding, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Binding(invalidBinding, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -799,9 +778,8 @@ object Redefined {
|
||||
),
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -11,18 +11,35 @@ import java.util.UUID
|
||||
* @param originalName the original name that could not be resolved
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Resolution(
|
||||
originalName: Name,
|
||||
reason: Resolution.Reason,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Error
|
||||
with Diagnostic.Kind.Interactive
|
||||
with IRKind.Primitive
|
||||
with Name
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[Resolution]] object.
|
||||
*
|
||||
* @param originalName the original name that could not be resolved
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
originalName: Name,
|
||||
reason: Resolution.Reason,
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(originalName, reason, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
override val name: String = originalName.name
|
||||
|
||||
override def mapExpressions(
|
||||
@ -58,9 +75,9 @@ sealed case class Resolution(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Resolution(originalName, reason, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Resolution(originalName, reason, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -82,9 +99,8 @@ sealed case class Resolution(
|
||||
),
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -110,8 +126,7 @@ sealed case class Resolution(
|
||||
|
||||
object Resolution {
|
||||
|
||||
/** A representation of a symbol resolution error.
|
||||
*/
|
||||
/** A representation of a symbol resolution error. */
|
||||
sealed trait Reason {
|
||||
def explain(originalName: Name): String
|
||||
}
|
||||
|
@ -10,24 +10,40 @@ import scala.annotation.unused
|
||||
|
||||
/** A representation of an Enso syntax error.
|
||||
*
|
||||
* @param at the error location
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param at the error location
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Syntax(
|
||||
at: IdentifiedLocation,
|
||||
reason: Syntax.Reason,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Error
|
||||
with Diagnostic.Kind.Interactive
|
||||
with module.scope.Definition
|
||||
with module.scope.Export
|
||||
with module.scope.Import
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a syntax error.
|
||||
*
|
||||
* @param at the error location
|
||||
* @param reason the cause of this error
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
at: IdentifiedLocation,
|
||||
reason: Syntax.Reason,
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(at, reason, passData)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param ast the error location
|
||||
@ -51,8 +67,9 @@ sealed case class Syntax(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Syntax(at, reason, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Syntax(at, reason, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -67,9 +84,8 @@ sealed case class Syntax(
|
||||
copy(
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -117,12 +133,10 @@ sealed case class Syntax(
|
||||
|
||||
object Syntax {
|
||||
|
||||
/** A common type for all syntax errors expected by the language.
|
||||
*/
|
||||
/** A common type for all syntax errors expected by the language. */
|
||||
sealed trait Reason {
|
||||
|
||||
/** @return a human-readable description of the error.
|
||||
*/
|
||||
/** @return a human-readable description of the error. */
|
||||
def explanation: String
|
||||
}
|
||||
|
||||
|
@ -46,17 +46,16 @@ object Unexpected {
|
||||
/** An error representing a type signature not associated with a
|
||||
* binding of some kind.
|
||||
*
|
||||
* @param ir the erroneous signature
|
||||
* @param passData any pass metadata associated with this node
|
||||
* @param diagnostics any compiler diagnostics for this node
|
||||
* @param ir the erroneous signature
|
||||
* @param passData any pass metadata associated with this node
|
||||
*/
|
||||
sealed case class TypeSignature(
|
||||
override val ir: IR,
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Unexpected
|
||||
with IRKind.Primitive
|
||||
with org.enso.compiler.core.ir.module.scope.Definition
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
override val entity: String = "type signature"
|
||||
|
||||
@ -80,9 +79,9 @@ object Unexpected {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = TypeSignature(ir, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = TypeSignature(ir, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -113,9 +112,8 @@ object Unexpected {
|
||||
),
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -7,6 +7,7 @@ import org.enso.compiler.core.ir.{
|
||||
Expression,
|
||||
IRKind,
|
||||
IdentifiedLocation,
|
||||
LazyDiagnosticStorage,
|
||||
LazyId,
|
||||
MetadataStorage,
|
||||
Name
|
||||
@ -47,21 +48,20 @@ object Definition {
|
||||
* types logic through the runtime and implement statics – the whole
|
||||
* notion of desugaring complex type definitions becomes obsolete then.
|
||||
*
|
||||
* @param name the name of the union
|
||||
* @param members the members of this union
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param name the name of the union
|
||||
* @param members the members of this union
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Type(
|
||||
name: Name,
|
||||
params: List[DefinitionArgument],
|
||||
members: List[Data],
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Definition
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
def copy(
|
||||
@ -82,9 +82,9 @@ object Definition {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Type(name, params, members, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Type(name, params, members, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -114,9 +114,8 @@ object Definition {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -167,7 +166,6 @@ object Definition {
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param isPrivate If the constructor is private (project-private).
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Data(
|
||||
name: Name,
|
||||
@ -175,10 +173,10 @@ object Definition {
|
||||
annotations: List[Name.GenericAnnotation],
|
||||
isPrivate: Boolean = false,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends IR
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -218,10 +216,10 @@ object Definition {
|
||||
annotations,
|
||||
isPrivate,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -251,9 +249,8 @@ object Definition {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -299,22 +296,21 @@ object Definition {
|
||||
/** The definition of a complex type definition that may contain
|
||||
* multiple atom and method definitions.
|
||||
*
|
||||
* @param name the name of the complex type
|
||||
* @param arguments the (type) arguments to the complex type
|
||||
* @param body the body of the complex type
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param name the name of the complex type
|
||||
* @param arguments the (type) arguments to the complex type
|
||||
* @param body the body of the complex type
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class SugaredType(
|
||||
name: Name,
|
||||
arguments: List[DefinitionArgument],
|
||||
body: List[IR],
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Definition
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -351,10 +347,10 @@ object Definition {
|
||||
arguments,
|
||||
body,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -392,9 +388,8 @@ object Definition {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -8,6 +8,7 @@ import org.enso.compiler.core.ir.{
|
||||
Expression,
|
||||
IRKind,
|
||||
IdentifiedLocation,
|
||||
LazyDiagnosticStorage,
|
||||
LazyId,
|
||||
MetadataStorage,
|
||||
Name
|
||||
@ -45,19 +46,18 @@ object Export {
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param isSynthetic is this export compiler-generated
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Module(
|
||||
name: Name.Qualified,
|
||||
rename: Option[Name.Literal],
|
||||
onlyNames: Option[List[Name.Literal]],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
isSynthetic: Boolean = false,
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
isSynthetic: Boolean = false,
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends IR
|
||||
with IRKind.Primitive
|
||||
with Export
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -92,17 +92,16 @@ object Export {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Module(
|
||||
name,
|
||||
rename,
|
||||
onlyNames,
|
||||
location,
|
||||
isSynthetic,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -118,9 +117,8 @@ object Export {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -8,6 +8,7 @@ import org.enso.compiler.core.ir.{
|
||||
Expression,
|
||||
IRKind,
|
||||
IdentifiedLocation,
|
||||
LazyDiagnosticStorage,
|
||||
LazyId,
|
||||
MetadataStorage,
|
||||
Name
|
||||
@ -47,7 +48,6 @@ object Import {
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param isSynthetic is this import compiler-generated
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Module(
|
||||
name: Name.Qualified,
|
||||
@ -56,11 +56,11 @@ object Import {
|
||||
onlyNames: Option[List[Name.Literal]],
|
||||
hiddenNames: Option[List[Name.Literal]],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
isSynthetic: Boolean = false,
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
isSynthetic: Boolean = false,
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Import
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -109,10 +109,10 @@ object Import {
|
||||
hiddenNames,
|
||||
location,
|
||||
isSynthetic,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -144,9 +144,8 @@ object Import {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -49,38 +49,36 @@ object Method {
|
||||
* @param isStaticWrapperForInstanceMethod true if this method represents a static wrapper for instance method, false otherwise
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Explicit(
|
||||
methodReference: Name.MethodReference,
|
||||
bodyReference: Persistance.Reference[Expression],
|
||||
isStatic: Boolean,
|
||||
isPrivate: Boolean,
|
||||
override val isPrivate: Boolean,
|
||||
isStaticWrapperForInstanceMethod: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage
|
||||
) extends Method
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
def this(
|
||||
methodReference: Name.MethodReference,
|
||||
body: Expression,
|
||||
isPrivate: Boolean,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage = new MetadataStorage(),
|
||||
diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
) = {
|
||||
|
||||
/** Create an [[Explicit]] object from [[Method.Binding]].
|
||||
*
|
||||
* @param ir the method binding IR
|
||||
* @param body the method body expression
|
||||
*/
|
||||
def this(ir: Method.Binding, body: Expression) = {
|
||||
this(
|
||||
methodReference,
|
||||
ir.methodReference,
|
||||
Persistance.Reference.of(body, false),
|
||||
Explicit.computeIsStatic(body),
|
||||
isPrivate,
|
||||
ir.isPrivate,
|
||||
Explicit.computeIsStaticWrapperForInstanceMethod(body),
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
);
|
||||
ir.location,
|
||||
ir.passData
|
||||
)
|
||||
diagnostics = ir.diagnostics
|
||||
}
|
||||
|
||||
lazy val body: Expression = bodyReference.get(classOf[Expression])
|
||||
@ -128,10 +126,10 @@ object Method {
|
||||
isPrivate,
|
||||
isStaticWrapperForInstanceMethod,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -160,10 +158,8 @@ object Method {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy
|
||||
else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -211,6 +207,7 @@ object Method {
|
||||
}
|
||||
|
||||
object Explicit {
|
||||
|
||||
def unapply(m: Explicit): Option[
|
||||
(
|
||||
Name.MethodReference,
|
||||
@ -254,7 +251,6 @@ object Method {
|
||||
* @param body the body of the method
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Binding(
|
||||
override val methodReference: Name.MethodReference,
|
||||
@ -262,12 +258,43 @@ object Method {
|
||||
isPrivate: Boolean,
|
||||
override val body: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Method
|
||||
with IRKind.Sugar
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a [[Binding]] object.
|
||||
*
|
||||
* @param methodReference a reference to the method being defined
|
||||
* @param arguments the arguments to the method
|
||||
* @param isPrivate if the method is declared as private (project-private).
|
||||
* i.e. with prepended `private` keyword.
|
||||
* @param body the body of the method
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics the compiler diagnostics
|
||||
*/
|
||||
def this(
|
||||
methodReference: Name.MethodReference,
|
||||
arguments: List[DefinitionArgument],
|
||||
isPrivate: Boolean,
|
||||
body: Expression,
|
||||
location: Option[IdentifiedLocation],
|
||||
passData: MetadataStorage,
|
||||
diagnostics: DiagnosticStorage
|
||||
) = {
|
||||
this(
|
||||
methodReference,
|
||||
arguments,
|
||||
isPrivate,
|
||||
body,
|
||||
location,
|
||||
passData
|
||||
)
|
||||
this.diagnostics = diagnostics
|
||||
}
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param methodReference a reference to the method being defined
|
||||
@ -305,10 +332,10 @@ object Method {
|
||||
isPrivate,
|
||||
body,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -344,10 +371,8 @@ object Method {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy
|
||||
else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -408,19 +433,33 @@ object Method {
|
||||
* @param body the body of the method
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Conversion(
|
||||
override val methodReference: Name.MethodReference,
|
||||
sourceTypeName: Expression,
|
||||
override val body: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Method
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Create a conversion method from [[Method.Binding]].
|
||||
*
|
||||
* @param ir the method binding IR
|
||||
* @param sourceTypeName the type of the source value for this conversion
|
||||
* @param body the body of the method
|
||||
*/
|
||||
def this(
|
||||
ir: Method.Binding,
|
||||
sourceTypeName: Expression,
|
||||
body: Expression
|
||||
) = {
|
||||
this(ir.methodReference, sourceTypeName, body, ir.location, ir.passData)
|
||||
diagnostics = ir.diagnostics
|
||||
}
|
||||
|
||||
// Conversion methods cannot be private for now
|
||||
override val isPrivate: Boolean = false
|
||||
|
||||
@ -455,16 +494,15 @@ object Method {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
|
||||
val res = Conversion(
|
||||
methodReference,
|
||||
sourceTypeName,
|
||||
body,
|
||||
location,
|
||||
passData,
|
||||
diagnostics
|
||||
passData
|
||||
)
|
||||
res.id = id
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -498,10 +536,8 @@ object Method {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy
|
||||
else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import org.enso.compiler.core.ir.{
|
||||
Expression,
|
||||
IRKind,
|
||||
IdentifiedLocation,
|
||||
LazyDiagnosticStorage,
|
||||
LazyId,
|
||||
MetadataStorage
|
||||
}
|
||||
@ -16,21 +17,19 @@ import java.util.UUID
|
||||
|
||||
/** An import of a polyglot class.
|
||||
*
|
||||
* @param entity language-specific information on the imported entity
|
||||
* @param rename the name this object should be visible under in the
|
||||
* importing scope
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param entity language-specific information on the imported entity
|
||||
* @param rename the name this object should be visible under in the importing scope
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Polyglot(
|
||||
entity: Polyglot.Entity,
|
||||
rename: Option[String],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Import
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -60,9 +59,9 @@ sealed case class Polyglot(
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Polyglot(entity, rename, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Polyglot(entity, rename, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -78,9 +77,8 @@ sealed case class Polyglot(
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -32,22 +32,21 @@ object Set {
|
||||
|
||||
/** The representation of a typeset member.
|
||||
*
|
||||
* @param label the member's label, if given
|
||||
* @param memberType the member's type, if given
|
||||
* @param value the member's value, if given
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param label the member's label, if given
|
||||
* @param memberType the member's type, if given
|
||||
* @param value the member's value, if given
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Member(
|
||||
label: Name,
|
||||
memberType: Expression,
|
||||
value: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Set
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -79,9 +78,9 @@ object Set {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res =
|
||||
Member(label, memberType, value, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Member(label, memberType, value, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -116,9 +115,8 @@ object Set {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -167,20 +165,19 @@ object Set {
|
||||
|
||||
/** The typeset subsumption judgement `<:`.
|
||||
*
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Subsumption(
|
||||
left: Expression,
|
||||
right: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Set
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -209,8 +206,9 @@ object Set {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Subsumption(left, right, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Subsumption(left, right, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -238,9 +236,8 @@ object Set {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -281,20 +278,19 @@ object Set {
|
||||
|
||||
/** The typeset equality judgement `~`.
|
||||
*
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Equality(
|
||||
left: Expression,
|
||||
right: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Set
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -323,8 +319,9 @@ object Set {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Equality(left, right, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Equality(left, right, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -352,9 +349,8 @@ object Set {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -399,16 +395,15 @@ object Set {
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Concat(
|
||||
left: Expression,
|
||||
right: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Set
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -437,8 +432,9 @@ object Set {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Concat(left, right, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Concat(left, right, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -466,9 +462,8 @@ object Set {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -508,24 +503,22 @@ object Set {
|
||||
|
||||
/** The typeset union operator `|`.
|
||||
*
|
||||
* @param operands the operands
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param operands the operands
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Union(
|
||||
operands: List[Expression],
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Set
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
*
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param operands the list of expressions
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
@ -546,8 +539,9 @@ object Set {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Union(operands, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Union(operands, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -571,9 +565,8 @@ object Set {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -612,20 +605,19 @@ object Set {
|
||||
|
||||
/** The typeset intersection operator `&`.
|
||||
*
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
* @param left the left operand
|
||||
* @param right the right operand
|
||||
* @param location the source location that the node corresponds to
|
||||
* @param passData the pass metadata associated with this node
|
||||
*/
|
||||
sealed case class Intersection(
|
||||
left: Expression,
|
||||
right: Expression,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = new MetadataStorage(),
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
override val passData: MetadataStorage = new MetadataStorage()
|
||||
) extends Set
|
||||
with IRKind.Primitive
|
||||
with LazyDiagnosticStorage
|
||||
with LazyId {
|
||||
|
||||
/** Creates a copy of `this`.
|
||||
@ -654,8 +646,9 @@ object Set {
|
||||
|| diagnostics != this.diagnostics
|
||||
|| id != this.id
|
||||
) {
|
||||
val res = Intersection(left, right, location, passData, diagnostics)
|
||||
res.id = id
|
||||
val res = Intersection(left, right, location, passData)
|
||||
res.diagnostics = diagnostics
|
||||
res.id = id
|
||||
res
|
||||
} else this
|
||||
}
|
||||
@ -683,9 +676,8 @@ object Set {
|
||||
location = if (keepLocations) location else None,
|
||||
passData =
|
||||
if (keepMetadata) passData.duplicate else new MetadataStorage(),
|
||||
diagnostics =
|
||||
if (keepDiagnostics) diagnostics.copy else DiagnosticStorage(),
|
||||
id = if (keepIdentifiers) id else null
|
||||
diagnostics = if (keepDiagnostics) diagnosticsCopy else null,
|
||||
id = if (keepIdentifiers) id else null
|
||||
)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -9,7 +9,6 @@ import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import org.enso.compiler.core.ir.DiagnosticStorage;
|
||||
import org.enso.compiler.core.ir.IdentifiedLocation;
|
||||
import org.enso.compiler.core.ir.Location;
|
||||
import org.enso.compiler.core.ir.MetadataStorage;
|
||||
@ -288,8 +287,7 @@ public class IrPersistanceTest {
|
||||
@Test
|
||||
public void serializeModule() throws Exception {
|
||||
var meta = new MetadataStorage();
|
||||
var diag = new DiagnosticStorage(nil());
|
||||
var m = new Module(nil(), nil(), nil(), true, Option.empty(), meta, diag);
|
||||
var m = new Module(nil(), nil(), nil(), true, Option.empty(), meta);
|
||||
|
||||
var out = serde(Module.class, m, -1);
|
||||
|
||||
|
@ -71,7 +71,6 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
params,
|
||||
List(),
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
val tpe =
|
||||
@ -83,7 +82,6 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
params,
|
||||
members,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
val tpe =
|
||||
@ -95,7 +93,6 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
annotations,
|
||||
isPrivate,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) if !isPrivate =>
|
||||
buildAtomConstructor(
|
||||
@ -123,7 +120,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
|
||||
case m @ definition.Method
|
||||
.Explicit(
|
||||
Name.MethodReference(typePtr, methodName, _, _, _),
|
||||
Name.MethodReference(typePtr, methodName, _, _),
|
||||
Function.Lambda(args, body, _, _, _, _),
|
||||
_,
|
||||
_,
|
||||
@ -162,11 +159,10 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
|
||||
case conversionMeth @ definition.Method
|
||||
.Conversion(
|
||||
Name.MethodReference(typePtr, _, _, _, _),
|
||||
Name.MethodReference(typePtr, _, _, _),
|
||||
_,
|
||||
Function.Lambda(args, body, _, _, _, _),
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) if !conversionMeth.isPrivate =>
|
||||
val selfType = typePtr.flatMap { typePointer =>
|
||||
@ -187,7 +183,6 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
name,
|
||||
Function.Lambda(args, body, _, _, _, _),
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) if name.location.isDefined =>
|
||||
val typeSignature = ir.getMetadata(TypeSignatures)
|
||||
@ -206,7 +201,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
)
|
||||
go(tree += Tree.Node(function, subforest), scope)
|
||||
|
||||
case Expression.Binding(name, expr, _, _, _)
|
||||
case Expression.Binding(name, expr, _, _)
|
||||
if name.location.isDefined =>
|
||||
val typeSignature = ir.getMetadata(TypeSignatures)
|
||||
val local = buildLocal(
|
||||
@ -571,7 +566,6 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
defaultValue,
|
||||
suspended,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) +: vtail =>
|
||||
if (isStatic) {
|
||||
@ -770,7 +764,7 @@ final class SuggestionBuilder[A: IndexedSource](
|
||||
*/
|
||||
private def buildDefaultValue(expr: IR): String =
|
||||
expr match {
|
||||
case Application.Prefix(name, path, _, _, _, _) =>
|
||||
case Application.Prefix(name, path, _, _, _) =>
|
||||
path.map(_.value.showCode()).mkString(".") + "." + name.showCode()
|
||||
case other => other.showCode()
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ class IrToTruffle(
|
||||
|
||||
private def registerPolyglotImports(module: Module): Unit =
|
||||
module.imports.foreach {
|
||||
case poly @ imports.Polyglot(i: imports.Polyglot.Java, _, _, _, _) =>
|
||||
case poly @ imports.Polyglot(i: imports.Polyglot.Java, _, _, _) =>
|
||||
var hostSymbol = context.lookupJavaClass(i.getJavaName)
|
||||
if (hostSymbol == null) {
|
||||
val err = Text.create(
|
||||
@ -1296,7 +1296,7 @@ class IrToTruffle(
|
||||
"Comments should not be present during codegen."
|
||||
)
|
||||
case err: Error => processError(err)
|
||||
case Foreign.Definition(_, _, _, _, _) =>
|
||||
case Foreign.Definition(_, _, _, _) =>
|
||||
throw new CompilerError(
|
||||
s"Foreign expressions not yet implemented: $ir."
|
||||
)
|
||||
@ -1410,7 +1410,7 @@ class IrToTruffle(
|
||||
subjectToInstrumentation: Boolean
|
||||
): RuntimeExpression =
|
||||
caseExpr match {
|
||||
case Case.Expr(scrutinee, branches, isNested, location, _, _) =>
|
||||
case Case.Expr(scrutinee, branches, isNested, location, _) =>
|
||||
val scrutineeNode = this.run(scrutinee, subjectToInstrumentation)
|
||||
|
||||
val maybeCases = branches.map(processCaseBranch)
|
||||
@ -1473,7 +1473,7 @@ class IrToTruffle(
|
||||
)
|
||||
|
||||
branch.pattern match {
|
||||
case named @ Pattern.Name(_, _, _, _) =>
|
||||
case named: Pattern.Name =>
|
||||
val arg = List(genArgFromMatchField(named))
|
||||
|
||||
val branchCodeNode = childProcessor.processFunctionBody(
|
||||
@ -1486,7 +1486,7 @@ class IrToTruffle(
|
||||
CatchAllBranchNode.build(branchCodeNode.getCallTarget, true)
|
||||
|
||||
Right(branchNode)
|
||||
case cons @ Pattern.Constructor(constructor, _, _, _, _) =>
|
||||
case cons @ Pattern.Constructor(constructor, _, _, _) =>
|
||||
if (!cons.isDesugared) {
|
||||
throw new CompilerError(
|
||||
"Nested patterns desugaring must have taken place by the " +
|
||||
@ -1705,7 +1705,7 @@ class IrToTruffle(
|
||||
)
|
||||
)
|
||||
}
|
||||
case Pattern.Type(varName, tpeName, location, _, _) =>
|
||||
case Pattern.Type(varName, tpeName, location, _) =>
|
||||
tpeName.getMetadata(Patterns) match {
|
||||
case None =>
|
||||
Left(BadPatternMatch.NonVisibleType(tpeName.name))
|
||||
@ -1720,7 +1720,7 @@ class IrToTruffle(
|
||||
) match {
|
||||
case Some(tpe) =>
|
||||
val argOfType = List(
|
||||
DefinitionArgument.Specified(
|
||||
new DefinitionArgument.Specified(
|
||||
varName,
|
||||
None,
|
||||
None,
|
||||
@ -1754,7 +1754,7 @@ class IrToTruffle(
|
||||
asScope(mod.unsafeAsModule()).getPolyglotSymbol(symbol.name)
|
||||
if (polySymbol != null) {
|
||||
val argOfType = List(
|
||||
DefinitionArgument.Specified(
|
||||
new DefinitionArgument.Specified(
|
||||
varName,
|
||||
None,
|
||||
None,
|
||||
@ -1792,7 +1792,6 @@ class IrToTruffle(
|
||||
case errors.Pattern(
|
||||
_,
|
||||
errors.Pattern.WrongArity(name, expected, actual),
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
Left(BadPatternMatch.WrongArgCount(name, expected, actual))
|
||||
@ -1814,8 +1813,8 @@ class IrToTruffle(
|
||||
* @param name the pattern field to generate from
|
||||
* @return `name` as a function definition argument.
|
||||
*/
|
||||
def genArgFromMatchField(name: Pattern.Name): DefinitionArgument = {
|
||||
DefinitionArgument.Specified(
|
||||
private def genArgFromMatchField(name: Pattern.Name): DefinitionArgument = {
|
||||
new DefinitionArgument.Specified(
|
||||
name.name,
|
||||
None,
|
||||
None,
|
||||
@ -1909,13 +1908,12 @@ class IrToTruffle(
|
||||
resolver.resolveName(literalName, fpMeta)
|
||||
case Name.MethodReference(
|
||||
None,
|
||||
Name.Literal(nameStr, _, _, _, _, _),
|
||||
_,
|
||||
Name.Literal(nameStr, _, _, _, _),
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
DynamicSymbolNode.buildUnresolvedConstructor(nameStr)
|
||||
case Name.Self(location, _, passData, _) =>
|
||||
case Name.Self(location, _, passData) =>
|
||||
processName(
|
||||
Name.Literal(
|
||||
ConstantsNames.SELF_ARGUMENT,
|
||||
@ -1932,7 +1930,7 @@ class IrToTruffle(
|
||||
"a Self occurence must be resolved"
|
||||
).target
|
||||
)
|
||||
case Name.Special(name, _, _, _) =>
|
||||
case Name.Special(name, _, _) =>
|
||||
val fun = name match {
|
||||
case Special.NewRef => context.getBuiltins.special().getNewRef
|
||||
case Special.ReadRef => context.getBuiltins.special().getReadRef
|
||||
@ -2061,14 +2059,14 @@ class IrToTruffle(
|
||||
@throws[CompilerError]
|
||||
private def processLiteral(literal: Literal): RuntimeExpression =
|
||||
literal match {
|
||||
case lit @ Literal.Number(_, _, location, _, _) =>
|
||||
case lit: Literal.Number =>
|
||||
val node = lit.numericValue match {
|
||||
case l: Long => LiteralNode.build(l)
|
||||
case d: Double => LiteralNode.build(d)
|
||||
case b: BigInteger => LiteralNode.build(b)
|
||||
}
|
||||
setLocation(node, location)
|
||||
case Literal.Text(text, location, _, _) =>
|
||||
setLocation(node, lit.location)
|
||||
case Literal.Text(text, location, _) =>
|
||||
setLocation(LiteralNode.build(text), location)
|
||||
}
|
||||
|
||||
@ -2088,7 +2086,7 @@ class IrToTruffle(
|
||||
*/
|
||||
private def processError(error: Error): RuntimeExpression = {
|
||||
val payload: Atom = error match {
|
||||
case Error.InvalidIR(_, _, _) =>
|
||||
case Error.InvalidIR(_, _) =>
|
||||
throw new CompilerError("Unexpected Invalid IR during codegen.")
|
||||
case err: errors.Syntax =>
|
||||
context.getBuiltins
|
||||
@ -2189,7 +2187,7 @@ class IrToTruffle(
|
||||
val (argSlotIdxs, _, argExpressions) = slots
|
||||
|
||||
val bodyExpr = body match {
|
||||
case Foreign.Definition(lang, code, _, _, _) =>
|
||||
case Foreign.Definition(lang, code, _, _) =>
|
||||
buildForeignBody(
|
||||
lang,
|
||||
body.location,
|
||||
@ -2346,16 +2344,16 @@ class IrToTruffle(
|
||||
subjectToInstrumentation: Boolean
|
||||
): RuntimeExpression =
|
||||
application match {
|
||||
case Application.Prefix(fn, Nil, true, _, _, _) =>
|
||||
case Application.Prefix(fn, Nil, true, _, _) =>
|
||||
run(fn, subjectToInstrumentation)
|
||||
case app: Application.Prefix =>
|
||||
processApplicationWithArgs(app, subjectToInstrumentation)
|
||||
case Application.Force(expr, location, _, _) =>
|
||||
case Application.Force(expr, location, _) =>
|
||||
setLocation(
|
||||
ForceNode.build(this.run(expr, subjectToInstrumentation)),
|
||||
location
|
||||
)
|
||||
case Application.Sequence(items, location, _, _) =>
|
||||
case Application.Sequence(items, location, _) =>
|
||||
val itemNodes = items.map(run(_, subjectToInstrumentation)).toArray
|
||||
setLocation(SequenceLiteralNode.build(itemNodes), location)
|
||||
case _: Application.Typeset =>
|
||||
@ -2386,7 +2384,7 @@ class IrToTruffle(
|
||||
application: Application.Prefix,
|
||||
subjectToInstrumentation: Boolean
|
||||
): RuntimeExpression = {
|
||||
val Application.Prefix(fn, args, hasDefaultsSuspended, loc, _, _) =
|
||||
val Application.Prefix(fn, args, hasDefaultsSuspended, loc, _) =
|
||||
application
|
||||
val callArgFactory =
|
||||
new CallArgumentProcessor(scope, scopeName, currentVarName)
|
||||
@ -2448,13 +2446,7 @@ class IrToTruffle(
|
||||
subjectToInstrumentation: Boolean
|
||||
): callable.argument.CallArgument =
|
||||
arg match {
|
||||
case CallArgument.Specified(
|
||||
name,
|
||||
value,
|
||||
_,
|
||||
_,
|
||||
_
|
||||
) =>
|
||||
case CallArgument.Specified(name, value, _, _) =>
|
||||
def scopeInfo() = {
|
||||
arg
|
||||
.unsafeGetMetadata(
|
||||
|
Loading…
Reference in New Issue
Block a user