diff --git a/engine/runtime-compiler/src/main/java/org/enso/compiler/pass/resolve/MethodDefinitions.java b/engine/runtime-compiler/src/main/java/org/enso/compiler/pass/resolve/MethodDefinitions.java index 3264faf4610f..69ed314447b0 100644 --- a/engine/runtime-compiler/src/main/java/org/enso/compiler/pass/resolve/MethodDefinitions.java +++ b/engine/runtime-compiler/src/main/java/org/enso/compiler/pass/resolve/MethodDefinitions.java @@ -253,7 +253,7 @@ private static Expression addTypeAscriptionToSelfArgument(Expression methodBody) if (firstArg instanceof DefinitionArgument.Specified selfArg && selfArg.name() instanceof Name.Self) { var selfType = new Name.SelfType(selfArg.identifiedLocation(), new MetadataStorage()); - var newSelfArg = selfArg.copyWithAscribedType(selfType); + var newSelfArg = selfArg.copyWithAscribedType(Option.apply(selfType)); return lambdaWithNewSelfArg(lambda, newSelfArg); } else { throw new CompilerError( diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AliasAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AliasAnalysis.scala index cac5fa37c8e2..b021ca0c0afa 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AliasAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AliasAnalysis.scala @@ -500,6 +500,13 @@ case object AliasAnalysis extends IRPass { } } + private def isSyntheticSelf(name: Name): Boolean = { + name match { + case Name.Self(_, true, _) => true + case _ => false + } + } + /** Performs alias analysis on the argument definitions for a function. * * Care is taken during this analysis to ensure that spurious resolutions do @@ -519,18 +526,11 @@ case object AliasAnalysis extends IRPass { builder: GraphBuilder ): List[DefinitionArgument] = { args.map { - case arg @ DefinitionArgument.Specified( - selfName @ Name.Self(_, true, _), - _, - _, - _, - _, - _ - ) => + case arg: DefinitionArgument.Specified if isSyntheticSelf(arg.name) => // Synthetic `self` must not be added to the scope, but it has to be added as a // definition for frame index metadata val definition = builder.newDef( - selfName.name, + arg.name.name, arg.getId(), arg.getExternalId ) @@ -542,18 +542,14 @@ case object AliasAnalysis extends IRPass { alias.AliasMetadata.Occurrence(builder.toGraph(), definition.id) ) ) - .copy( - ascribedType = arg.ascribedType.map(analyseExpression(_, builder)) + .copyWithAscribedType( + arg.ascribedType.map(analyseExpression(_, builder)) ) - case arg @ DefinitionArgument.Specified( - name, - _, - value, - suspended, - _, - _ - ) => + case arg: DefinitionArgument.Specified => + val name = arg.name + val value = arg.defaultValue + val suspended = arg.suspended val nameOccursInScope = builder.findDef( name.name @@ -574,8 +570,8 @@ case object AliasAnalysis extends IRPass { arg .copy( - defaultValue = newDefault, - ascribedType = arg.ascribedType.map(analyseExpression(_, builder)) + newDefault, + arg.ascribedType.map(analyseExpression(_, builder)) ) .updateMetadata( new MetadataPair( @@ -585,8 +581,8 @@ case object AliasAnalysis extends IRPass { ) } else { arg - .copy( - ascribedType = Some(Redefined.Arg(name, arg.identifiedLocation)) + .copyWithAscribedType( + Some(Redefined.Arg(name, arg.identifiedLocation)) ) .updateMetadata( new MetadataPair( @@ -617,13 +613,13 @@ case object AliasAnalysis extends IRPass { arguments = analyseCallArguments(app.arguments, builder) ) case app: Application.Force => - app.copy(target = analyseExpression(app.target, builder)) + app.copyWithTarget(analyseExpression(app.target, builder)) case app: Application.Sequence => - app.copy(items = app.items.map(analyseExpression(_, builder))) + app.copyWithItems(app.items.map(analyseExpression(_, builder))) case tSet: Application.Typeset => val newScope = builder.addChild() tSet - .copy(expression = + .copyWithExpression( tSet.expression.map(analyseExpression(_, newScope)) ) .updateMetadata( @@ -659,7 +655,7 @@ case object AliasAnalysis extends IRPass { case _ => builder.addChild() } arg - .copy(value = analyseExpression(arg.value, currentScope)) + .copy(analyseExpression(arg.value, currentScope)) .updateMetadata( new MetadataPair( this, diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AutomaticParallelism.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AutomaticParallelism.scala index cea100c4c60b..c275255b63c9 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AutomaticParallelism.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AutomaticParallelism.scala @@ -302,11 +302,9 @@ object AutomaticParallelism extends IRPass { Expression .Binding( _, - Application.Prefix( + new Application.Prefix( Name.Special(Name.Special.NewRef, null), - List(), - false, - null + List() ), null ) @@ -319,7 +317,7 @@ object AutomaticParallelism extends IRPass { val blockBody = exprs.map(_.ir).flatMap { case bind: Expression.Binding => - val refWrite = Application.Prefix( + val refWrite = new Application.Prefix( Name.Special(Name.Special.WriteRef, null), List( new CallArgument.Specified( @@ -334,14 +332,12 @@ object AutomaticParallelism extends IRPass { true, null ) - ), - false, - null + ) ) List(bind, refWrite) case other => List(other) } - val spawn = Application.Prefix( + val spawn = new Application.Prefix( Name.Special(Name.Special.RunThread, null), List( new CallArgument.Specified( @@ -350,9 +346,7 @@ object AutomaticParallelism extends IRPass { true, null ) - ), - false, - null + ) ) Expression .Binding(freshNameSupply.newName(), spawn, null) @@ -362,13 +356,11 @@ object AutomaticParallelism extends IRPass { } val threadJoins = threadSpawns.map { bind => - Application.Prefix( + new Application.Prefix( Name.Special(Name.Special.JoinThread, null), List( new CallArgument.Specified(None, bind.name.duplicate(), true, null) - ), - false, - null + ) ) } @@ -376,11 +368,9 @@ object AutomaticParallelism extends IRPass { Expression .Binding( name.duplicate(), - Application.Prefix( + new Application.Prefix( Name.Special(Name.Special.ReadRef, null), - List(new CallArgument.Specified(None, ref.duplicate(), true, null)), - false, - null + List(new CallArgument.Specified(None, ref.duplicate(), true, null)) ), null ) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala index ebf7da9b87b5..91a56358ff3d 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/CachePreferenceAnalysis.scala @@ -151,7 +151,7 @@ case object CachePreferenceAnalysis extends IRPass { app.arguments match { case self :: rest => val newSelf = analyseSelfCallArgument(self, weights) - app.copy(arguments = newSelf :: rest) + app.copyWithArguments(newSelf :: rest) case _ => app } @@ -170,7 +170,7 @@ case object CachePreferenceAnalysis extends IRPass { .foreach(weights.update(_, CachePreferences.Kind.SELF_ARGUMENT)) callArgument match { case arg: Specified => - arg.copy(value = + arg.copy( analyseExpression(arg.value, weights) .updateMetadata(new MetadataPair(this, weights)) ) @@ -188,9 +188,12 @@ case object CachePreferenceAnalysis extends IRPass { weights: WeightInfo ): DefinitionArgument = { argument match { - case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _) => + case spec: DefinitionArgument.Specified => + val defValue = spec.defaultValue spec - .copy(defaultValue = defValue.map(analyseExpression(_, weights))) + .copyWithDefaultValue( + defValue.map(analyseExpression(_, weights)) + ) .updateMetadata(new MetadataPair(this, weights)) } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DataflowAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DataflowAnalysis.scala index eaac79498341..fba9ccbd01b8 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DataflowAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DataflowAnalysis.scala @@ -332,12 +332,12 @@ case object DataflowAnalysis extends IRPass { info: DependencyInfo ): Application = { application match { - case prefix @ Application.Prefix(fn, args, _, _, _) => - val fnDep = asStatic(fn) + case prefix: Application.Prefix => + val fnDep = asStatic(prefix.function) val prefixDep = asStatic(prefix) info.dependents.updateAt(fnDep, Set(prefixDep)) info.dependencies.updateAt(prefixDep, Set(fnDep)) - args.foreach(arg => { + prefix.arguments.foreach(arg => { val argDep = asStatic(arg) info.dependents.updateAt(argDep, Set(prefixDep)) info.dependencies.updateAt(prefixDep, Set(argDep)) @@ -345,40 +345,40 @@ case object DataflowAnalysis extends IRPass { prefix .copy( - function = analyseExpression(fn, info), - arguments = args.map(analyseCallArgument(_, info)) + function = analyseExpression(prefix.function, info), + arguments = prefix.arguments.map(analyseCallArgument(_, info)) ) .updateMetadata(new MetadataPair(this, info)) - case force @ Application.Force(target, _, _) => - val targetDep = asStatic(target) + case force: Application.Force => + val targetDep = asStatic(force.target) val forceDep = asStatic(force) info.dependents.updateAt(targetDep, Set(forceDep)) info.dependencies.updateAt(forceDep, Set(targetDep)) force - .copy(target = analyseExpression(target, info)) + .copyWithTarget(analyseExpression(force.target, info)) .updateMetadata(new MetadataPair(this, info)) - case vector @ Application.Sequence(items, _, _) => + case vector: Application.Sequence => val vectorDep = asStatic(vector) - items.foreach(it => { + vector.items.foreach(it => { val itemDep = asStatic(it) info.dependents.updateAt(itemDep, Set(vectorDep)) info.dependencies.updateAt(vectorDep, Set(itemDep)) }) vector - .copy(items = items.map(analyseExpression(_, info))) + .copyWithItems(vector.items.map(analyseExpression(_, info))) .updateMetadata(new MetadataPair(this, info)) - case tSet @ Application.Typeset(expr, _, _) => + case tSet: Application.Typeset => val tSetDep = asStatic(tSet) - expr.foreach(exp => { + tSet.expression.foreach(exp => { val exprDep = asStatic(exp) info.dependents.updateAt(exprDep, Set(tSetDep)) info.dependencies.updateAt(tSetDep, Set(exprDep)) }) tSet - .copy(expression = expr.map(analyseExpression(_, info))) + .copyWithExpression(tSet.expression.map(analyseExpression(_, info))) .updateMetadata(new MetadataPair(this, info)) case _: Operator => throw new CompilerError("Unexpected operator during Dataflow Analysis.") @@ -715,8 +715,9 @@ case object DataflowAnalysis extends IRPass { info: DependencyInfo ): DefinitionArgument = { argument match { - case spec @ DefinitionArgument.Specified(_, _, defValue, _, _, _) => - val specDep = asStatic(spec) + case spec: DefinitionArgument.Specified => + val defValue = spec.defaultValue + val specDep = asStatic(spec) defValue.foreach(expr => { val exprDep = asStatic(expr) info.dependents.updateAt(exprDep, Set(specDep)) @@ -724,8 +725,8 @@ case object DataflowAnalysis extends IRPass { }) spec - .copy( - defaultValue = defValue.map(analyseExpression(_, info)) + .copyWithDefaultValue( + defValue.map(analyseExpression(_, info)) ) .updateMetadata(new MetadataPair(this, info)) } @@ -758,7 +759,7 @@ case object DataflowAnalysis extends IRPass { spec .copy( - value = analyseExpression(spec.value, info) + analyseExpression(spec.value, info) ) .updateMetadata(new MetadataPair(this, info)) } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DemandAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DemandAnalysis.scala index 7d7f9d0ec854..c51791cbdf14 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DemandAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DemandAnalysis.scala @@ -10,6 +10,7 @@ import org.enso.compiler.core.ir.{ Function, IdentifiedLocation, Literal, + MetadataStorage, Module, Name, Type @@ -189,7 +190,11 @@ case object DemandAnalysis extends IRPass { val newNameLocation = name.location.map(l => new IdentifiedLocation(l.location())) val newName = lit.copy(location = newNameLocation) - Application.Force(newName, name.identifiedLocation()) + new Application.Force( + newName, + name.identifiedLocation(), + new MetadataStorage() + ) case _ => name } } @@ -218,35 +223,36 @@ case object DemandAnalysis extends IRPass { isInsideCallArgument: Boolean ): Application = application match { - case pref @ Application.Prefix(fn, args, _, _, _) => - val newFun = fn match { + case pref: Application.Prefix => + val newFun = pref.function match { case n: Name => n case e => analyseExpression(e, isInsideCallArgument = false) } pref.copy( function = newFun, - arguments = args.map(analyseCallArgument) + arguments = pref.arguments.map(analyseCallArgument) ) - case force @ Application.Force(target, _, _) => - force.copy(target = + case force: Application.Force => + force.copyWithTarget( analyseExpression( - target, + force.target, isInsideCallArgument ) ) - case vec @ Application.Sequence(items, _, _) => - vec.copy(items = - items.map( + case vec: Application.Sequence => + vec.copyWithItems( + vec.items.map( analyseExpression( _, isInsideCallArgument = false ) ) ) - case tSet @ Application.Typeset(expr, _, _) => - tSet.copy( - expression = - expr.map(analyseExpression(_, isInsideCallArgument = false)) + case tSet: Application.Typeset => + tSet.copyWithExpression( + tSet.expression.map( + analyseExpression(_, isInsideCallArgument = false) + ) ) case _: Operator => throw new CompilerError( @@ -267,7 +273,7 @@ case object DemandAnalysis extends IRPass { arg match { case arg: CallArgument.Specified => arg.copy( - value = analyseExpression( + analyseExpression( arg.value, isInsideCallArgument = true ) @@ -284,9 +290,10 @@ case object DemandAnalysis extends IRPass { arg: DefinitionArgument ): DefinitionArgument = { arg match { - case spec @ DefinitionArgument.Specified(_, _, default, _, _, _) => - spec.copy( - defaultValue = default.map(x => + case spec: DefinitionArgument.Specified => + val default = spec.defaultValue + spec.copyWithDefaultValue( + default.map(x => analyseExpression( x, isInsideCallArgument = false diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala index 5923095164f8..706993c3225f 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala @@ -219,18 +219,18 @@ case object FramePointerAnalysis extends IRPass { graph: Graph ): Unit = { application match { - case app @ Application.Prefix(func, arguments, _, _, _) => + case app: Application.Prefix => maybeAttachFramePointer(app, graph) - processExpression(func, graph) - processCallArguments(arguments, graph) - case Application.Force(expr, _, _) => - processExpression(expr, graph) - case Application.Sequence(items, _, _) => - items.foreach { item => + processExpression(app.function, graph) + processCallArguments(app.arguments, graph) + case force: Application.Force => + processExpression(force.target, graph) + case seq: Application.Sequence => + seq.items.foreach { item => processExpression(item, graph) } - case Application.Typeset(expr, _, _) => - expr.foreach(processExpression(_, graph)) + case tSet: Application.Typeset => + tSet.expression.foreach(processExpression(_, graph)) case _ => throw new CompilerError( "Unexpected type of Application: " + application diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/ComplexType.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/ComplexType.scala index 3869b49851b0..63236dc7e597 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/ComplexType.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/ComplexType.scala @@ -333,7 +333,7 @@ case object ComplexType extends IRPass { val binding = new definition.Method.Binding( methodRef.duplicate(), - args.map(_.duplicate()), + args.map(_.duplicate(true, true, true, false)), isPrivate, body.duplicate(), identifiedLocation, diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/GenerateMethodBodies.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/GenerateMethodBodies.scala index b949bd457cdc..4d803f037ee8 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/GenerateMethodBodies.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/GenerateMethodBodies.scala @@ -265,7 +265,7 @@ case object GenerateMethodBodies extends IRPass { * @return the `self` argument */ private def genSyntheticSelf(): DefinitionArgument.Specified = { - DefinitionArgument.Specified( + new DefinitionArgument.Specified( Name.Self(identifiedLocation = null, synthetic = true), None, defaultValue = None, diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/LambdaShorthandToLambdaMini.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/LambdaShorthandToLambdaMini.scala index 14bbc4926434..d93cc19df277 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/LambdaShorthandToLambdaMini.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/LambdaShorthandToLambdaMini.scala @@ -32,17 +32,17 @@ class LambdaShorthandToLambdaMini( private def shouldSkipBlanks(parent: IR): Boolean = { parent match { - case Application.Prefix(fn, args, _, _, _) => - val hasBlankArg = args.exists { + case app: Application.Prefix => + val hasBlankArg = app.arguments.exists { case arg: CallArgument.Specified if arg.value.isInstanceOf[Name.Blank] => true case _ => false } - val hasBlankFn = fn.isInstanceOf[Name.Blank] + val hasBlankFn = app.function.isInstanceOf[Name.Blank] hasBlankArg || hasBlankFn - case Application.Sequence(items, _, _) => - val hasBlankItem = items.exists { + case seq: Application.Sequence => + val hasBlankItem = seq.items.exists { case _: Name.Blank => true case _ => false } @@ -76,16 +76,16 @@ class LambdaShorthandToLambdaMini( new Function.Lambda( List( - DefinitionArgument.Specified( - name = Name.Literal( + new DefinitionArgument.Specified( + Name.Literal( newName.name, isMethod = false, null ), - ascribedType = None, - defaultValue = None, - suspended = false, - identifiedLocation = null + None, + None, + false, + null ) ), newName, @@ -104,13 +104,13 @@ class LambdaShorthandToLambdaMini( application: Application ): Expression = { application match { - case p @ Application.Prefix(fn, args, _, _, _) => + case p: Application.Prefix => // Determine which arguments are lambda shorthand - val argIsUnderscore = determineLambdaShorthand(args) + val argIsUnderscore = determineLambdaShorthand(p.arguments) // Generate a new name for the arg value for each shorthand arg val updatedArgs = - args + p.arguments .zip(argIsUnderscore) .map(updateShorthandArg) @@ -123,19 +123,19 @@ class LambdaShorthandToLambdaMini( } // Determine whether or not the function itself is shorthand - val functionIsShorthand = fn.isInstanceOf[Name.Blank] + val functionIsShorthand = p.function.isInstanceOf[Name.Blank] val (updatedFn, updatedName) = if (functionIsShorthand) { val newFn = freshNameSupply .newName() .copy( - location = fn.location, - passData = fn.passData, - diagnostics = fn.diagnostics + location = p.function.location, + passData = p.function.passData, + diagnostics = p.function.diagnostics ) val newName = newFn.name (newFn, Some(newName)) } else { - (fn, None) + (p.function, None) } val processedApp = p.copy( @@ -154,17 +154,13 @@ class LambdaShorthandToLambdaMini( val resultExpr = if (functionIsShorthand) { new Function.Lambda( List( - DefinitionArgument.Specified( + new DefinitionArgument.Specified( Name .Literal( updatedName.get, isMethod = false, - fn.location.orNull - ), - None, - None, - suspended = false, - null + p.function.location.orNull + ) ) ), appResult, @@ -177,9 +173,9 @@ class LambdaShorthandToLambdaMini( case result => result } - case vector @ Application.Sequence(items, _, _) => + case vector: Application.Sequence => var bindings: List[Name] = List() - val newItems = items.map { + val newItems = vector.items.map { case blank: Name.Blank => val name = freshNameSupply .newName() @@ -192,17 +188,11 @@ class LambdaShorthandToLambdaMini( name case it => it } - val newVec = vector.copy(newItems) + val newVec = vector.copyWithItems(newItems) val locWithoutId = newVec.location.map(l => new IdentifiedLocation(l.location())) bindings.foldLeft(newVec: Expression) { (body, bindingName) => - val defArg = DefinitionArgument.Specified( - bindingName, - ascribedType = None, - defaultValue = None, - suspended = false, - identifiedLocation = null - ) + val defArg = new DefinitionArgument.Specified(bindingName) new Function.Lambda(List(defArg), body, locWithoutId.orNull) } @@ -329,7 +319,7 @@ class LambdaShorthandToLambdaMini( diagnostics = nameBlank.diagnostics ) - val lambdaArg = DefinitionArgument.Specified( + val lambdaArg = new DefinitionArgument.Specified( scrutineeName.copy(id = null), None, None, diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/NoSelfInStatic.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/NoSelfInStatic.scala index 28afef2d4e4f..9b48b3bf97d2 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/NoSelfInStatic.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/NoSelfInStatic.scala @@ -57,6 +57,13 @@ object NoSelfInStatic extends IRPass { ) } + private def isSelfName(name: Name): Boolean = { + name match { + case self: Name.Self => !self.synthetic + case _ => false + } + } + /** A method is static if it is either not defined within a type, or if it does not * contain a non-synthetic `self` argument. */ @@ -67,14 +74,7 @@ object NoSelfInStatic extends IRPass { arguments: List[DefinitionArgument] ): Option[DefinitionArgument] = { arguments.collectFirst { - case arg @ DefinitionArgument.Specified( - Name.Self(_, false, _), - _, - _, - _, - _, - _ - ) => + case arg: DefinitionArgument.Specified if isSelfName(arg.name) => arg } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/UnusedBindings.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/UnusedBindings.scala index 21b9df88ba5b..1b27dafa757e 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/UnusedBindings.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/lint/UnusedBindings.scala @@ -194,23 +194,18 @@ case object UnusedBindings extends IRPass { val isUsed = aliasInfo.graph.linksFor(aliasInfo.id).nonEmpty argument match { - case s @ DefinitionArgument.Specified( - _: Name.Self, - _, - _, - _, - _, - _ - ) => + case s: DefinitionArgument.Specified if s.name.isInstanceOf[Name.Self] => s - case s @ DefinitionArgument.Specified(name, _, default, _, _, _) => + case s: DefinitionArgument.Specified => + val name = s.name + val default = s.defaultValue if (!isIgnored && !isUsed) { val nameToReport = name match { case literal: Name.Literal => literal.originalName.getOrElse(literal) case _ => name } - s.copy( + s.copyWithDefaultValue( defaultValue = default.map(runExpression(_, context)) ).addDiagnostic(warnings.Unused.FunctionArgument(nameToReport)) } else s diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/optimise/LambdaConsolidate.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/optimise/LambdaConsolidate.scala index 6b32d472bc16..8145ccb85ca9 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/optimise/LambdaConsolidate.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/optimise/LambdaConsolidate.scala @@ -219,10 +219,11 @@ case object LambdaConsolidate extends IRPass { if (isShadowed) { val restArgs = args.drop(ix + 1) arg match { - case spec @ DefinitionArgument.Specified(argName, _, _, _, _, _) => + case spec: DefinitionArgument.Specified => + val argName = spec.name val mShadower = restArgs.collectFirst { - case s @ DefinitionArgument.Specified(sName, _, _, _, _, _) - if sName.name == argName.name => + case s: DefinitionArgument.Specified + if s.name.name == argName.name => s } @@ -404,6 +405,7 @@ case object LambdaConsolidate extends IRPass { } else Set[UUID @Identifier]() usageIds + case _ => Set[UUID @Identifier]() } } @@ -434,7 +436,8 @@ case object LambdaConsolidate extends IRPass { ) } else oldName - spec.copy(name = newName) + spec.withName(newName) + case (arg, _) => arg } } @@ -467,7 +470,8 @@ case object LambdaConsolidate extends IRPass { val processedArgList = args.zip(newDefaults).map { case (spec: DefinitionArgument.Specified, default) => - spec.copy(defaultValue = default) + spec.copyWithDefaultValue(default) + case (arg, _) => arg } (processedArgList, newBody) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/ExpressionAnnotations.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/ExpressionAnnotations.scala index b36ff90edfaa..88a74216dcd3 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/ExpressionAnnotations.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/ExpressionAnnotations.scala @@ -67,15 +67,11 @@ case object ExpressionAnnotations extends IRPass { ir: Expression ): Expression = ir.transformExpressions { - case app @ Application.Prefix( - ann: Name.BuiltinAnnotation, - arguments, - _, - _, - _ - ) => + case app: Application.Prefix + if app.function.isInstanceOf[Name.BuiltinAnnotation] => + val ann = app.function.asInstanceOf[Name.BuiltinAnnotation] if (isKnownAnnotation(ann.name)) { - arguments match { + app.arguments match { case List() => errors.Resolution( ann, @@ -87,8 +83,8 @@ case object ExpressionAnnotations extends IRPass { case realFun :: args => val recurFun = doExpression(realFun.value) val (finalFun, preArgs) = recurFun match { - case Application.Prefix(nextFun, moreArgs, _, _, _) => - (nextFun, moreArgs) + case app: Application.Prefix => + (app.function, app.arguments) case _ => (recurFun, List()) } val recurArgs = args.map(_.mapExpressions(doExpression)) @@ -99,7 +95,7 @@ case object ExpressionAnnotations extends IRPass { } else { val err = errors.Resolution(ann, errors.Resolution.UnknownAnnotation) - app.copy(function = err) + app.copyWithFunction(err) } case ann: Name.BuiltinAnnotation => if (isKnownAnnotation(ann.name)) { diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyAppliedFunctionUses.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyAppliedFunctionUses.scala index 810ae404fe72..3b191c1c8874 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyAppliedFunctionUses.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyAppliedFunctionUses.scala @@ -52,13 +52,16 @@ object FullyAppliedFunctionUses extends IRPass { private def doExpression(expr: Expression): Expression = { expr.transformExpressions { case app: Application.Prefix => - app.copy(arguments = app.arguments.map(_.mapExpressions(doExpression))) + app.copyWithArguments(app.arguments.map(_.mapExpressions(doExpression))) case name: Name.Literal => val meta = name.getMetadata(GlobalNames) meta match { case Some(Resolution(ResolvedConstructor(_, cons))) if cons.allFieldsDefaulted && cons.arity > 0 => - Application.Prefix(name, List(), false, identifiedLocation = null); + new Application.Prefix( + name, + List() + ); case _ => name } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyQualifiedNames.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyQualifiedNames.scala index fb1bf1f0bcbe..48b8a075d641 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyQualifiedNames.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/FullyQualifiedNames.scala @@ -260,7 +260,7 @@ case object FullyQualifiedNames extends IRPass { } else { lit } - case app @ Application.Prefix(_, List(_), _, _, _) => + case app: Application.Prefix if app.arguments.nonEmpty => app.function match { case lit: Name.Literal => if (lit.isMethod) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala index 34c0f94b43be..932464684bde 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala @@ -7,6 +7,7 @@ import org.enso.compiler.core.ir.{ CallArgument, DefinitionArgument, Expression, + MetadataStorage, Module, Name, Type @@ -221,7 +222,7 @@ case object GlobalNames extends IRPass { name = resolvedModuleMethod.method.name, location = None ) - val app = Application.Prefix( + val app = new Application.Prefix( fun, List( new CallArgument.Specified( @@ -232,7 +233,8 @@ case object GlobalNames extends IRPass { ) ), hasDefaultsSuspended = false, - lit.identifiedLocation + lit.identifiedLocation, + new MetadataStorage() ) fun .getMetadata(ExpressionAnnotations) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/IgnoredBindings.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/IgnoredBindings.scala index 32a4277e794e..8a11203f1e57 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/IgnoredBindings.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/IgnoredBindings.scala @@ -210,17 +210,11 @@ case object IgnoredBindings extends IRPass { freshNameSupply: FreshNameSupply ): DefinitionArgument = { arg match { - case spec @ DefinitionArgument.Specified( - Name.Self(_, _, _), - _, - _, - _, - _, - _ - ) => + case spec: DefinitionArgument.Specified + if spec.name.isInstanceOf[Name.Self] => // Note [Ignored `this` Argument] spec - .copy(defaultValue = + .copyWithDefaultValue( spec.defaultValue.map(resolveExpression(_, freshNameSupply)) ) .updateMetadata(new MetadataPair(this, State.Ignored)) @@ -244,9 +238,8 @@ case object IgnoredBindings extends IRPass { } else { setNotIgnored( spec - .copy( - defaultValue = - spec.defaultValue.map(resolveExpression(_, freshNameSupply)) + .copyWithDefaultValue( + spec.defaultValue.map(resolveExpression(_, freshNameSupply)) ) ) } @@ -260,8 +253,8 @@ case object IgnoredBindings extends IRPass { */ private def isIgnoreArg(ir: DefinitionArgument): Boolean = { ir match { - case DefinitionArgument.Specified(name, _, _, _, _, _) => - isIgnore(name) + case spec: DefinitionArgument.Specified => + isIgnore(spec.name) } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/SuspendedArguments.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/SuspendedArguments.scala index e5f50d37b0f4..9c5cbce43d1b 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/SuspendedArguments.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/SuspendedArguments.scala @@ -283,8 +283,8 @@ case object SuspendedArguments extends IRPass { arg match { case spec: DefinitionArgument.Specified => if (representsSuspended(typ) || spec.suspended) { - spec.copy(suspended = true) - } else spec.copy(suspended = false) + spec.copyWithSuspended(true) + } else spec.copyWithSuspended(false) } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeFunctions.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeFunctions.scala index a1c47cec7f6e..f268e585084e 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeFunctions.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeFunctions.scala @@ -125,8 +125,8 @@ case object TypeFunctions extends IRPass { */ private def resolveApplication(app: Application): Expression = { app match { - case pre @ Application.Prefix(fn, arguments, _, _, _) => - fn match { + case pre: Application.Prefix => + pre.function match { case name: Name if name.name == `type`.Set.Union.name => val members = flattenUnion(app).map(resolveExpression) `type`.Set.Union(members, app.identifiedLocation()) @@ -139,19 +139,19 @@ case object TypeFunctions extends IRPass { ) case _ => pre.copy( - function = resolveExpression(fn), - arguments = arguments.map(resolveCallArgument) + function = resolveExpression(pre.function), + arguments = pre.arguments.map(resolveCallArgument) ) } - case force @ Application.Force(target, _, _) => - force.copy(target = resolveExpression(target)) - case seq @ Application.Sequence(items, _, _) => - seq.copy( - items = items.map(resolveExpression) + case force: Application.Force => + force.copyWithTarget(resolveExpression(force.target)) + case seq: Application.Sequence => + seq.copyWithItems( + seq.items.map(resolveExpression) ) - case tSet @ Application.Typeset(expr, _, _) => - tSet.copy( - expression = expr.map(resolveExpression) + case tSet: Application.Typeset => + tSet.copyWithExpression( + tSet.expression.map(resolveExpression) ) case _: Operator => throw new CompilerError( @@ -162,9 +162,10 @@ case object TypeFunctions extends IRPass { private def flattenUnion(expr: Expression): List[Expression] = { expr match { - case Application.Prefix(n: Name, args, _, _, _) - if n.name == `type`.Set.Union.name => - args.flatMap(arg => flattenUnion(arg.value)) + case app: Application.Prefix + if app.function.isInstanceOf[Name] && + app.function.asInstanceOf[Name].name == `type`.Set.Union.name => + app.arguments.flatMap(arg => flattenUnion(arg.value)) case _ => List(expr) } } @@ -221,7 +222,7 @@ case object TypeFunctions extends IRPass { arg match { case spec: CallArgument.Specified => spec.copy( - value = resolveExpression(spec.value) + resolveExpression(spec.value) ) } } diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala index 7dbad5295476..e2d497ef3493 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/TypeSignatures.scala @@ -224,20 +224,15 @@ case object TypeSignatures extends IRPass { argument: DefinitionArgument ): DefinitionArgument = argument match { - case specified @ DefinitionArgument.Specified( - _, - Some(ascribedType), - _, - _, - _, - _ - ) => - val sig = resolveExpression(ascribedType.duplicate()) - specified.copy( - name = specified.name.updateMetadata( + case specified: DefinitionArgument.Specified + if specified.ascribedType.isDefined => + val ascribedType = specified.ascribedType.get + val sig = resolveExpression(ascribedType.duplicate()) + specified.copyWithNameAndAscribedType( + specified.name.updateMetadata( new MetadataPair(this, Signature(sig)) ), - ascribedType = Some( + Some( ascribedType.updateMetadata(new MetadataPair(this, Signature(sig))) ) ) diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/refactoring/IRUtils.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/refactoring/IRUtils.scala index a319085cbdf3..ea31d61db4a8 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/refactoring/IRUtils.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/refactoring/IRUtils.scala @@ -130,8 +130,10 @@ trait IRUtils { usages <- findDynamicUsages(ir, node.name) } yield { usages.collect { - case Application.Prefix(function: Name.Literal, args, _, _, _) - if function.name == node.name => + case app: Application.Prefix + if app.function.isInstanceOf[Name.Literal] && + app.function.asInstanceOf[Name.Literal].name == node.name => + val function = app.function.asInstanceOf[Name.Literal] function.getMetadata(MethodCalls) match { case Some(resolution) => resolution.target match { @@ -142,7 +144,7 @@ trait IRUtils { None } case None => - args.headOption match { + app.arguments.headOption match { case Some(arg) if arg.isSynthetic => Some(function) case _ => diff --git a/engine/runtime-instrument-common/src/test/scala/org/enso/compiler/test/context/ChangesetBuilderTest.scala b/engine/runtime-instrument-common/src/test/scala/org/enso/compiler/test/context/ChangesetBuilderTest.scala index 389deeae9190..0adf063745ae 100644 --- a/engine/runtime-instrument-common/src/test/scala/org/enso/compiler/test/context/ChangesetBuilderTest.scala +++ b/engine/runtime-instrument-common/src/test/scala/org/enso/compiler/test/context/ChangesetBuilderTest.scala @@ -37,7 +37,8 @@ class ChangesetBuilderTest .get .asInstanceOf[Expression.Binding] val rhs = ir.expression.asInstanceOf[Application.Prefix] - val two = rhs.arguments(1).asInstanceOf[CallArgument.Specified].value + val two = + rhs.arguments.apply(1).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( two.getId @@ -53,7 +54,8 @@ class ChangesetBuilderTest .get .asInstanceOf[Expression.Binding] val rhs = ir.expression.asInstanceOf[Application.Prefix] - val two = rhs.arguments(1).asInstanceOf[CallArgument.Specified].value + val two = + rhs.arguments.apply(1).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( two.getId @@ -69,7 +71,8 @@ class ChangesetBuilderTest .get .asInstanceOf[Expression.Binding] val rhs = ir.expression.asInstanceOf[Application.Prefix] - val two = rhs.arguments(1).asInstanceOf[CallArgument.Specified].value + val two = + rhs.arguments.apply(1).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( two.getId @@ -116,7 +119,8 @@ class ChangesetBuilderTest .asInstanceOf[Expression.Binding] val rhs = ir.expression.asInstanceOf[Application.Prefix] val plus = rhs.function - val two = rhs.arguments(1).asInstanceOf[CallArgument.Specified].value + val two = + rhs.arguments.apply(1).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( plus.getId, @@ -134,7 +138,8 @@ class ChangesetBuilderTest .asInstanceOf[Expression.Binding] val rhs = ir.expression.asInstanceOf[Application.Prefix] val x = ir.name - val one = rhs.arguments(0).asInstanceOf[CallArgument.Specified].value + val one = + rhs.arguments.apply(0).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( x.getId, @@ -152,7 +157,8 @@ class ChangesetBuilderTest .asInstanceOf[Expression.Binding] val x = ir.name val rhs = ir.expression.asInstanceOf[Application.Prefix] - val one = rhs.arguments(0).asInstanceOf[CallArgument.Specified].value + val one = + rhs.arguments.apply(0).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( x.getId, @@ -186,7 +192,7 @@ class ChangesetBuilderTest .asInstanceOf[Expression.Binding] val rhs = ir.expression.asInstanceOf[Application.Prefix] val undefinedArg = - rhs.arguments(1).asInstanceOf[CallArgument.Specified] + rhs.arguments.apply(1).asInstanceOf[CallArgument.Specified] val undefinedError = undefinedArg.value.asInstanceOf[errors.Resolution] val undefinedName = undefinedError.originalName @@ -209,10 +215,10 @@ class ChangesetBuilderTest val secondLine = ir.body.children()(1).asInstanceOf[Application.Prefix] val y = - secondLine.arguments(0).asInstanceOf[CallArgument.Specified].value + secondLine.arguments.apply(0).asInstanceOf[CallArgument.Specified].value val plus = secondLine.function val x = - secondLine.arguments(1).asInstanceOf[CallArgument.Specified].value + secondLine.arguments.apply(1).asInstanceOf[CallArgument.Specified].value invalidated(ir, code, edit) should contain theSameElementsAs Seq( y.getId, @@ -265,7 +271,7 @@ class ChangesetBuilderTest .body .asInstanceOf[Application.Prefix] val yExprFunction = yExpr.function - val yExprFunctionArg = yExpr.arguments(0).value + val yExprFunctionArg = yExpr.arguments.apply(0).value val secondLine = ir.body.children()(1).asInstanceOf[Expression.Binding] val zName = secondLine.name @@ -328,7 +334,7 @@ class ChangesetBuilderTest val thirdLine = ir.body.children()(2).asInstanceOf[Application.Prefix] val y = - thirdLine.arguments(0).asInstanceOf[CallArgument.Specified].value + thirdLine.arguments.apply(0).asInstanceOf[CallArgument.Specified].value val plus = thirdLine.function invalidated(ir, code, edit) should contain theSameElementsAs Seq( @@ -351,9 +357,10 @@ class ChangesetBuilderTest .preprocessExpression(freshInlineContext) .get .asInstanceOf[Expression.Binding] - val x = ir.name - val rhs = ir.expression.asInstanceOf[Application.Prefix] - val one = rhs.arguments(0).asInstanceOf[CallArgument.Specified].value + val x = ir.name + val rhs = ir.expression.asInstanceOf[Application.Prefix] + val one = + rhs.arguments.apply(0).asInstanceOf[CallArgument.Specified].value val plus = rhs.function invalidated(ir, code, edits: _*) should contain theSameElementsAs Seq( @@ -383,7 +390,7 @@ class ChangesetBuilderTest val z = secondLine.expression.asInstanceOf[Application.Force].target val thirdLine = body.children()(2).asInstanceOf[Application.Prefix] val y = - thirdLine.arguments(0).asInstanceOf[CallArgument.Specified].value + thirdLine.arguments.apply(0).asInstanceOf[CallArgument.Specified].value val plus = thirdLine.function invalidated(ir, code, edits: _*) should contain theSameElementsAs Seq( @@ -435,8 +442,8 @@ class ChangesetBuilderTest .asInstanceOf[Expression.Block] val x = mainBody.expressions(0).asInstanceOf[Expression.Binding] val xExpr = x.expression.asInstanceOf[Application.Prefix] - val undefinedName = xExpr - .arguments(1) + val undefinedName = xExpr.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[errors.Resolution] diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/pass/analyse/test/AliasAnalysisTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/pass/analyse/test/AliasAnalysisTest.scala index a7dd4252b6c5..d71bb2d680f3 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/pass/analyse/test/AliasAnalysisTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/pass/analyse/test/AliasAnalysisTest.scala @@ -903,8 +903,8 @@ class AliasAnalysisTest extends CompilerTest { .id lambda.body shouldBe an[Application.Prefix] val app = lambda.body.asInstanceOf[Application.Prefix] - val valueUseId = app - .arguments(1) + val valueUseId = app.arguments + .apply(1) .value .getMetadata(AliasAnalysis) .get @@ -992,8 +992,8 @@ class AliasAnalysisTest extends CompilerTest { .get .unsafeAs[AliasMetadata.ChildScope] .scope - val arg2Scope = app - .arguments(1) + val arg2Scope = app.arguments + .apply(1) .getMetadata(AliasAnalysis) .get .unsafeAs[AliasMetadata.ChildScope] @@ -1040,8 +1040,8 @@ class AliasAnalysisTest extends CompilerTest { } "not resolve links for unknown symbols" in { - val unknownHereId = app - .arguments(1) + val unknownHereId = app.arguments + .apply(1) .value .getMetadata(AliasAnalysis) .get @@ -1196,8 +1196,8 @@ class AliasAnalysisTest extends CompilerTest { .unsafeAs[AliasMetadata.Occurrence] .id - val bUse = body - .arguments(1) + val bUse = body.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] @@ -1232,8 +1232,8 @@ class AliasAnalysisTest extends CompilerTest { .unsafeAs[AliasMetadata.Occurrence] .id - val numUse = body - .arguments(0) + val numUse = body.arguments + .apply(0) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] @@ -1244,8 +1244,8 @@ class AliasAnalysisTest extends CompilerTest { .unsafeAs[AliasMetadata.Occurrence] .id - val integerUse = body - .arguments(1) + val integerUse = body.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/CompilerTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/CompilerTest.scala index cb8d21dbddea..0054f0aaa462 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/CompilerTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/CompilerTest.scala @@ -222,15 +222,14 @@ trait CompilerRunner { Definition.Data( Name.Literal("TestAtom", isMethod = false, identifiedLocation = null), List( - DefinitionArgument - .Specified( - Name - .Literal("arg", isMethod = false, identifiedLocation = null), - None, - Some(ir), - suspended = false, - identifiedLocation = null - ) + new DefinitionArgument.Specified( + Name + .Literal("arg", isMethod = false, identifiedLocation = null), + None, + Some(ir), + suspended = false, + identifiedLocation = null + ) ), List(), false, diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DataflowAnalysisTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DataflowAnalysisTest.scala index 7584fc8f37d3..01506e745f4e 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DataflowAnalysisTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DataflowAnalysisTest.scala @@ -324,7 +324,7 @@ class DataflowAnalysisTest extends CompilerTest { printlnExpr.arguments.head.asInstanceOf[CallArgument.Specified] val printlnArgIOExpr = printlnArgIO.value.asInstanceOf[errors.Resolution] val printlnArgB = - printlnExpr.arguments(1).asInstanceOf[CallArgument.Specified] + printlnExpr.arguments.apply(1).asInstanceOf[CallArgument.Specified] val printlnArgBExpr = printlnArgB.value.asInstanceOf[Name.Literal] // The `c =` expression @@ -336,7 +336,7 @@ class DataflowAnalysisTest extends CompilerTest { plusExpr.arguments.head.asInstanceOf[CallArgument.Specified] val plusExprArgAExpr = plusExprArgA.value.asInstanceOf[Name.Literal] val plusExprArgB = - plusExpr.arguments(1).asInstanceOf[CallArgument.Specified] + plusExpr.arguments.apply(1).asInstanceOf[CallArgument.Specified] val plusExprArgBExpr = plusExprArgB.value.asInstanceOf[Name.Literal] // The `frobnicate` return expression @@ -346,7 +346,7 @@ class DataflowAnalysisTest extends CompilerTest { frobExpr.arguments.head.asInstanceOf[CallArgument.Specified] val frobArgAExpr = frobArgA.value.asInstanceOf[Name.Literal] val frobArgC = - frobExpr.arguments(1).asInstanceOf[CallArgument.Specified] + frobExpr.arguments.apply(1).asInstanceOf[CallArgument.Specified] val frobArgCExpr = frobArgC.value.asInstanceOf[Name.Literal] // The global symbols @@ -956,7 +956,7 @@ class DataflowAnalysisTest extends CompilerTest { fnBody.arguments.head.asInstanceOf[CallArgument.Specified] val plusArgXExpr = plusArgX.value.asInstanceOf[Name.Literal] val plusArgY = - fnBody.arguments(1).asInstanceOf[CallArgument.Specified] + fnBody.arguments.apply(1).asInstanceOf[CallArgument.Specified] val plusArgYExpr = plusArgY.value.asInstanceOf[Name.Literal] // Identifiers @@ -1016,7 +1016,7 @@ class DataflowAnalysisTest extends CompilerTest { val appArg10Expr = appArg10.value.asInstanceOf[Literal.Number] val appArg10Name = appArg10.name.get.asInstanceOf[Name.Literal] val appArgFn = - app.arguments(1).asInstanceOf[CallArgument.Specified] + app.arguments.apply(1).asInstanceOf[CallArgument.Specified] val lam = appArgFn.value.asInstanceOf[Function.Lambda] val lamArgX = lam.arguments.head.asInstanceOf[DefinitionArgument.Specified] @@ -1025,7 +1025,7 @@ class DataflowAnalysisTest extends CompilerTest { val mulArg1 = mul.arguments.head.asInstanceOf[CallArgument.Specified] val mulArg1Expr = mulArg1.value.asInstanceOf[Name.Literal] - val mulArg2 = mul.arguments(1).asInstanceOf[CallArgument.Specified] + val mulArg2 = mul.arguments.apply(1).asInstanceOf[CallArgument.Specified] val mulArg2Expr = mulArg2.value.asInstanceOf[Name.Literal] // Identifiers @@ -1210,8 +1210,8 @@ class DataflowAnalysisTest extends CompilerTest { bindingExpr.arguments.head.asInstanceOf[CallArgument.Specified] val numArgExpr = numArg.value.asInstanceOf[Literal.Number] val undefinedArg = - bindingExpr - .arguments(1) + bindingExpr.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] val undefinedExpr = undefinedArg.value.asInstanceOf[errors.Resolution] val undefinedName = undefinedExpr.originalName @@ -1277,9 +1277,9 @@ class DataflowAnalysisTest extends CompilerTest { val vector = ir.body .asInstanceOf[Application.Sequence] - val xUseId = mkStaticDep(vector.items(0).getId()) - val yId = mkStaticDep(vector.items(1).getId()) - val litId = mkStaticDep(vector.items(2).getId()) + val xUseId = mkStaticDep(vector.items.apply(0).getId()) + val yId = mkStaticDep(vector.items.apply(1).getId()) + val litId = mkStaticDep(vector.items.apply(2).getId()) val vecId = mkStaticDep(vector.getId()) val appId = mkStaticDep(ir.body.getId()) val lamId = mkStaticDep(ir.getId()) @@ -1360,8 +1360,8 @@ class DataflowAnalysisTest extends CompilerTest { val aArg = consBranchExpression.arguments.head .asInstanceOf[CallArgument.Specified] val aUse = aArg.value.asInstanceOf[Name.Literal] - val bArg = consBranchExpression - .arguments(1) + val bArg = consBranchExpression.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] val bUse = bArg.value.asInstanceOf[Name.Literal] @@ -1560,7 +1560,8 @@ class DataflowAnalysisTest extends CompilerTest { val fooFunction = fooExpr.function.asInstanceOf[Name] val fooArg1 = fooExpr.arguments.head.asInstanceOf[CallArgument.Specified] val fooArg1Expr = fooArg1.value.asInstanceOf[Name] - val fooArg2 = fooExpr.arguments(1).asInstanceOf[CallArgument.Specified] + val fooArg2 = + fooExpr.arguments.apply(1).asInstanceOf[CallArgument.Specified] val fooArg2Expr = fooArg2.value.asInstanceOf[Literal.Number] // The global symbols diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DemandAnalysisTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DemandAnalysisTest.scala index 79904d5656d3..050e583d8d75 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DemandAnalysisTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/DemandAnalysisTest.scala @@ -141,8 +141,8 @@ class DemandAnalysisTest extends CompilerTest { .asInstanceOf[CallArgument.Specified] .value shouldBe an[Name] - app - .arguments(1) + app.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value shouldBe an[Name] } @@ -160,9 +160,9 @@ class DemandAnalysisTest extends CompilerTest { .body .asInstanceOf[Application.Sequence] - vec.items(0) shouldBe an[Application.Force] - vec.items(1) shouldBe an[Application.Force] - vec.items(2) shouldBe an[Application.Force] + vec.items.apply(0) shouldBe an[Application.Force] + vec.items.apply(1) shouldBe an[Application.Force] + vec.items.apply(2) shouldBe an[Application.Force] } } @@ -234,7 +234,7 @@ class DemandAnalysisTest extends CompilerTest { oprCall.function.asInstanceOf[Name].name shouldEqual "<|" oprCall.arguments.length shouldEqual 2 - val xArg = oprCall.arguments(1).asInstanceOf[CallArgument.Specified] + val xArg = oprCall.arguments.apply(1).asInstanceOf[CallArgument.Specified] xArg.value shouldBe an[Expression.Block] xArg.value diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/GatherDiagnosticsTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/GatherDiagnosticsTest.scala index d055ad66bf55..175b00816f9e 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/GatherDiagnosticsTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/GatherDiagnosticsTest.scala @@ -23,7 +23,7 @@ class GatherDiagnosticsTest extends CompilerTest { "Error Gathering" should { val error1 = errors.Syntax(null, errors.Syntax.UnrecognizedToken) val plusOp = Name.Literal("+", isMethod = true, identifiedLocation = null) - val plusApp = Application.Prefix( + val plusApp = new Application.Prefix( plusOp, List( new CallArgument.Specified( @@ -32,20 +32,17 @@ class GatherDiagnosticsTest extends CompilerTest { false, identifiedLocation = null ) - ), - hasDefaultsSuspended = false, - identifiedLocation = null + ) ) val lam = new Function.Lambda( List( - DefinitionArgument - .Specified( - Name.Literal("bar", isMethod = false, identifiedLocation = null), - None, - None, - suspended = false, - identifiedLocation = null - ) + new DefinitionArgument.Specified( + Name.Literal("bar", isMethod = false, identifiedLocation = null), + None, + None, + suspended = false, + identifiedLocation = null + ) ), plusApp, identifiedLocation = null @@ -93,14 +90,13 @@ class GatherDiagnosticsTest extends CompilerTest { Definition.Type( typeName, List( - DefinitionArgument - .Specified( - fooName, - None, - Some(error2), - suspended = false, - identifiedLocation = null - ) + new DefinitionArgument.Specified( + fooName, + None, + Some(error2), + suspended = false, + identifiedLocation = null + ) ), List(), identifiedLocation = null diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallMegaPass.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallMegaPass.scala index 7758bda458a5..0d0bfcd392bc 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallMegaPass.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallMegaPass.scala @@ -266,26 +266,27 @@ case object TailCallMegaPass extends IRPass { isInTailPosition: Boolean ): Application = { val newApp = application match { - case app @ Application.Prefix(fn, args, _, _, _) => + case app: Application.Prefix => app .copy( - function = analyseExpression(fn, isInTailPosition = false), - arguments = args.map(analyseCallArg) + function = + analyseExpression(app.function, isInTailPosition = false), + arguments = app.arguments.map(analyseCallArg) ) - case force @ Application.Force(target, _, _) => + case force: Application.Force => force - .copy( - target = analyseExpression(target, isInTailPosition) + .copyWithTarget( + analyseExpression(force.target, isInTailPosition) ) - case vector @ Application.Sequence(items, _, _) => + case vector: Application.Sequence => vector - .copy(items = - items.map(analyseExpression(_, isInTailPosition = false)) + .copyWithItems( + vector.items.map(analyseExpression(_, isInTailPosition = false)) ) - case tSet @ Application.Typeset(expr, _, _) => + case tSet: Application.Typeset => tSet - .copy(expression = - expr.map(analyseExpression(_, isInTailPosition = false)) + .copyWithExpression( + tSet.expression.map(analyseExpression(_, isInTailPosition = false)) ) case _: Operator => throw new CompilerError("Unexpected binary operator.") @@ -304,7 +305,7 @@ case object TailCallMegaPass extends IRPass { arg .copy( // Note [Call Argument Tail Position] - value = analyseExpression(arg.value, isInTailPosition = true) + analyseExpression(arg.value, isInTailPosition = true) ) .updateMetadata(TAIL_META) } @@ -477,11 +478,11 @@ case object TailCallMegaPass extends IRPass { arg: DefinitionArgument ): DefinitionArgument = { arg match { - case arg @ DefinitionArgument.Specified(_, _, default, _, _, _) => + case arg: DefinitionArgument.Specified => + val default = arg.defaultValue arg - .copy( - defaultValue = - default.map(x => analyseExpression(x, isInTailPosition = false)) + .copyWithDefaultValue( + default.map(x => analyseExpression(x, isInTailPosition = false)) ) } } diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallTest.scala index fd4d86c4ced2..86218bf57379 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/TailCallTest.scala @@ -239,7 +239,8 @@ class TailCallTest extends MiniPassTest { .asInstanceOf[Expression.Block] .returnValue .asInstanceOf[Application.Prefix] - .arguments(2) + .arguments + .apply(2) .value .asInstanceOf[Expression.Block] .returnValue diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaMegaPass.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaMegaPass.scala index 64e43809e7f6..c8d066c29010 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaMegaPass.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaMegaPass.scala @@ -150,7 +150,7 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { new Function.Lambda( List( - DefinitionArgument.Specified( + new DefinitionArgument.Specified( name = Name.Literal( newName.name, isMethod = false, @@ -180,17 +180,17 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { freshNameSupply: FreshNameSupply ): Expression = { application match { - case p @ Application.Prefix(fn, args, _, _, _) => + case p: Application.Prefix => // Determine which arguments are lambda shorthand - val argIsUnderscore = determineLambdaShorthand(args) + val argIsUnderscore = determineLambdaShorthand(p.arguments) // Generate a new name for the arg value for each shorthand arg val updatedArgs = - args + p.arguments .zip(argIsUnderscore) .map(updateShorthandArg(_, freshNameSupply)) .map { case s: CallArgument.Specified => - s.copy(value = desugarExpression(s.value, freshNameSupply)) + s.copy(desugarExpression(s.value, freshNameSupply)) } // Generate a definition arg instance for each shorthand arg @@ -202,19 +202,19 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { } // Determine whether or not the function itself is shorthand - val functionIsShorthand = fn.isInstanceOf[Name.Blank] + val functionIsShorthand = p.function.isInstanceOf[Name.Blank] val (updatedFn, updatedName) = if (functionIsShorthand) { val newFn = freshNameSupply .newName() .copy( - location = fn.location, - passData = fn.passData, - diagnostics = fn.diagnostics + location = p.function.location, + passData = p.function.passData, + diagnostics = p.function.diagnostics ) val newName = newFn.name (newFn, Some(newName)) } else { - val newFn = desugarExpression(fn, freshNameSupply) + val newFn = desugarExpression(p.function, freshNameSupply) (newFn, None) } @@ -234,12 +234,12 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { val resultExpr = if (functionIsShorthand) { new Function.Lambda( List( - DefinitionArgument.Specified( + new DefinitionArgument.Specified( Name .Literal( updatedName.get, isMethod = false, - fn.location.orNull + p.function.location.orNull ), None, None, @@ -256,11 +256,11 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { case lam: Function.Lambda => lam.copy(location = p.location) case result => result } - case f @ Application.Force(tgt, _, _) => - f.copy(target = desugarExpression(tgt, freshNameSupply)) - case vector @ Application.Sequence(items, _, _) => + case f: Application.Force => + f.copyWithTarget(desugarExpression(f.target, freshNameSupply)) + case vector: Application.Sequence => var bindings: List[Name] = List() - val newItems = items.map { + val newItems = vector.items.map { case blank: Name.Blank => val name = freshNameSupply .newName() @@ -273,11 +273,11 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { name case it => desugarExpression(it, freshNameSupply) } - val newVec = vector.copy(newItems) + val newVec = vector.copyWithItems(newItems) val locWithoutId = newVec.location.map(l => new IdentifiedLocation(l.location())) bindings.foldLeft(newVec: Expression) { (body, bindingName) => - val defArg = DefinitionArgument.Specified( + val defArg = new DefinitionArgument.Specified( bindingName, ascribedType = None, defaultValue = None, @@ -286,8 +286,10 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { ) new Function.Lambda(List(defArg), body, locWithoutId.orNull) } - case tSet @ Application.Typeset(expr, _, _) => - tSet.copy(expression = expr.map(desugarExpression(_, freshNameSupply))) + case tSet: Application.Typeset => + tSet.copyWithExpression( + tSet.expression.map(desugarExpression(_, freshNameSupply)) + ) case _: Operator => throw new CompilerError( "Operators should be desugared by the point of underscore " + @@ -418,7 +420,7 @@ case object LambdaShorthandToLambdaMegaPass extends IRPass { diagnostics = nameBlank.diagnostics ) - val lambdaArg = DefinitionArgument.Specified( + val lambdaArg = new DefinitionArgument.Specified( scrutineeName.copy(id = null), None, None, diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaTest.scala index 8201be729048..7f0fa88c8660 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/LambdaShorthandToLambdaTest.scala @@ -109,13 +109,13 @@ class LambdaShorthandToLambdaTest extends CompilerTest { .body .asInstanceOf[Application.Prefix] - val arg2Name = body - .arguments(1) + val arg2Name = body.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] - val arg4Name = body - .arguments(3) + val arg4Name = body.arguments + .apply(3) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] @@ -153,8 +153,8 @@ class LambdaShorthandToLambdaTest extends CompilerTest { .value .asInstanceOf[Name.Literal] val arg3Name = - app - .arguments(2) + app.arguments + .apply(2) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] @@ -251,7 +251,7 @@ class LambdaShorthandToLambdaTest extends CompilerTest { irFn.arguments.head.asInstanceOf[DefinitionArgument.Specified].name val body = irFn.body.asInstanceOf[Application.Prefix] - val rightArg = body.arguments(1).value.asInstanceOf[Name.Literal] + val rightArg = body.arguments.apply(1).value.asInstanceOf[Name.Literal] argName.name shouldEqual rightArg.name } @@ -279,7 +279,7 @@ class LambdaShorthandToLambdaTest extends CompilerTest { val leftCallArgName = body.arguments.head.value.asInstanceOf[Name.Literal] val rightCallArgName = - body.arguments(1).value.asInstanceOf[Name.Literal] + body.arguments.apply(1).value.asInstanceOf[Name.Literal] underscoreArgName.name shouldEqual leftCallArgName.name rightArgLambdaArgName.name shouldEqual rightCallArgName.name @@ -305,7 +305,7 @@ class LambdaShorthandToLambdaTest extends CompilerTest { app.arguments.length shouldEqual 2 val leftArg = app.arguments.head.value.asInstanceOf[Name.Literal] - val rightArg = app.arguments(1).value.asInstanceOf[Name.Literal] + val rightArg = app.arguments.apply(1).value.asInstanceOf[Name.Literal] arg1Name.name shouldEqual leftArg.name arg2Name.name shouldEqual rightArg.name @@ -334,7 +334,7 @@ class LambdaShorthandToLambdaTest extends CompilerTest { app.arguments.length shouldEqual 2 val appLeftName = app.arguments.head.value.asInstanceOf[Name.Literal] - val appRightName = app.arguments(1).value.asInstanceOf[Name.Literal] + val appRightName = app.arguments.apply(1).value.asInstanceOf[Name.Literal] leftArgName.name shouldEqual appLeftName.name rightArgName.name shouldEqual appRightName.name @@ -352,10 +352,10 @@ class LambdaShorthandToLambdaTest extends CompilerTest { val fun2 = fun1.body.asInstanceOf[Function.Lambda] val vec = fun2.body.asInstanceOf[Application.Sequence] - fun1.arguments(0).name shouldEqual vec.items(1) - fun2.arguments(0).name shouldEqual vec.items(3) - vec.items(0) shouldBe an[Literal.Number] - vec.items(2) shouldBe an[Application.Prefix] + fun1.arguments(0).name shouldEqual vec.items.apply(1) + fun2.arguments(0).name shouldEqual vec.items.apply(3) + vec.items.apply(0) shouldBe an[Literal.Number] + vec.items.apply(2) shouldBe an[Application.Prefix] } } @@ -377,12 +377,12 @@ class LambdaShorthandToLambdaTest extends CompilerTest { .body .asInstanceOf[Application.Prefix] - irBody - .arguments(1) + irBody.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value shouldBe an[Function.Lambda] - val lamArg = irBody - .arguments(1) + val lamArg = irBody.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Function.Lambda] @@ -420,12 +420,12 @@ class LambdaShorthandToLambdaTest extends CompilerTest { .body .asInstanceOf[Application.Prefix] - irBody - .arguments(1) + irBody.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value shouldBe an[Function.Lambda] - val lamArg = irBody - .arguments(1) + val lamArg = irBody.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Function.Lambda] @@ -607,8 +607,8 @@ class LambdaShorthandToLambdaTest extends CompilerTest { .value .asInstanceOf[Name] .name - val appArg2Name = app - .arguments(1) + val appArg2Name = app.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name] diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/OperatorToFunctionTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/OperatorToFunctionTest.scala index 48828c6e3ec6..4a6af7d61eda 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/OperatorToFunctionTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/OperatorToFunctionTest.scala @@ -2,13 +2,14 @@ package org.enso.compiler.test.pass.desugar import org.enso.compiler.Passes import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext} -import org.enso.compiler.core.ir.Module import org.enso.compiler.core.ir.{ CallArgument, Empty, Expression, IdentifiedLocation, Location, + MetadataStorage, + Module, Name } import org.enso.compiler.core.ir.expression.{Application, Operator} @@ -71,11 +72,12 @@ class OperatorToFunctionTest extends MiniPassTest { val binOp = Operator.Binary(leftArg, name, rightArg, loc) - val opFn = Application.Prefix( + val opFn = new Application.Prefix( name, List(leftArg, rightArg), - hasDefaultsSuspended = false, - loc + false, + loc, + new MetadataStorage() ) (binOp, opFn) @@ -132,11 +134,9 @@ class OperatorToFunctionTest extends MiniPassTest { "be translated recursively in synthetic IR" in { val recursiveIR = Operator.Binary(oprArg, opName, rightArg, null) - val recursiveIRResult = Application.Prefix( + val recursiveIRResult = new Application.Prefix( opName, - List(oprFnArg, rightArg), - hasDefaultsSuspended = false, - null + List(oprFnArg, rightArg) ) OperatorToFunctionTestPass.runExpression( @@ -180,11 +180,9 @@ class OperatorToFunctionTest extends MiniPassTest { "be translated recursively" in { val recursiveIR = Operator.Binary(oprArg, opName, rightArg, identifiedLocation = null) - val recursiveIRResult = Application.Prefix( + val recursiveIRResult = new Application.Prefix( opName, - List(oprFnArg, rightArg), - hasDefaultsSuspended = false, - identifiedLocation = null + List(oprFnArg, rightArg) ) val miniPass = OperatorToFunction.createForInlineCompilation(ctx) diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpMegaPass.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpMegaPass.scala index 2c32b9ba3dd3..de5161ef2720 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpMegaPass.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpMegaPass.scala @@ -111,7 +111,7 @@ case object SectionsToBinOpMegaPass extends IRPass { true, identifiedLocation = null ) - val rightDefArg = DefinitionArgument.Specified( + val rightDefArg = new DefinitionArgument.Specified( rightArgName.duplicate(), None, None, @@ -128,7 +128,7 @@ case object SectionsToBinOpMegaPass extends IRPass { true, identifiedLocation = null ) - val leftDefArg = DefinitionArgument.Specified( + val leftDefArg = new DefinitionArgument.Specified( leftArgName.duplicate(), None, None, @@ -177,7 +177,7 @@ case object SectionsToBinOpMegaPass extends IRPass { true, identifiedLocation = null ) - val leftDefArg = DefinitionArgument.Specified( + val leftDefArg = new DefinitionArgument.Specified( leftArgName.duplicate(), None, None, @@ -193,7 +193,7 @@ case object SectionsToBinOpMegaPass extends IRPass { true, identifiedLocation = null ) - val rightDefArg = DefinitionArgument.Specified( + val rightDefArg = new DefinitionArgument.Specified( rightArgName.duplicate(), None, None, @@ -251,7 +251,7 @@ case object SectionsToBinOpMegaPass extends IRPass { identifiedLocation = null ) val leftDefArg = - DefinitionArgument.Specified( + new DefinitionArgument.Specified( leftArgName.duplicate(), None, None, @@ -269,7 +269,7 @@ case object SectionsToBinOpMegaPass extends IRPass { true, identifiedLocation = null ) - val rightDefArg = DefinitionArgument.Specified( + val rightDefArg = new DefinitionArgument.Specified( rightArgName.duplicate(), None, None, diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpTest.scala index d3d4238d7ff5..f165323c9e93 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpTest.scala @@ -117,8 +117,8 @@ class SectionsToBinOpTest extends MiniPassTest { .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] - val lamBodySecondArg = lamBody - .arguments(1) + val lamBodySecondArg = lamBody.arguments + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] @@ -228,8 +228,8 @@ class SectionsToBinOpTest extends MiniPassTest { .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] - val appRightName = app - .arguments(1) + val appRightName = app.arguments + .apply(1) .value .asInstanceOf[Name.Literal] diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/optimise/LambdaConsolidateTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/optimise/LambdaConsolidateTest.scala index 6ed7db57e3ab..f0b48a965cc4 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/optimise/LambdaConsolidateTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/optimise/LambdaConsolidateTest.scala @@ -156,7 +156,8 @@ class LambdaConsolidateTest extends CompilerTest { .name shouldEqual "x" ir.body .asInstanceOf[Application.Prefix] - .arguments(1) + .arguments() + .apply(1) .asInstanceOf[CallArgument.Specified] .value .asInstanceOf[Name.Literal] @@ -228,16 +229,15 @@ class LambdaConsolidateTest extends CompilerTest { val ir: Function.Lambda = new Function.Lambda( List( - DefinitionArgument - .Specified( - Name - .Literal("a", isMethod = false, identifiedLocation = null), - None, - None, - suspended = false, - identifiedLocation = null - ), - DefinitionArgument.Specified( + new DefinitionArgument.Specified( + Name + .Literal("a", isMethod = false, identifiedLocation = null), + None, + None, + suspended = false, + identifiedLocation = null + ), + new DefinitionArgument.Specified( Name.Literal("b", isMethod = false, identifiedLocation = null), None, None, @@ -247,7 +247,7 @@ class LambdaConsolidateTest extends CompilerTest { ), new Function.Lambda( List( - DefinitionArgument.Specified( + new DefinitionArgument.Specified( Name .Literal("c", isMethod = false, identifiedLocation = null), None, diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/ExpressionAnnotationsTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/ExpressionAnnotationsTest.scala index 4ca693f624a3..37ce07645dc1 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/ExpressionAnnotationsTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/ExpressionAnnotationsTest.scala @@ -115,7 +115,8 @@ class ExpressionAnnotationsTest extends CompilerTest { val correct = items.returnValue .asInstanceOf[Application.Prefix] - .arguments(0) + .arguments + .apply(0) .value .asInstanceOf[Application.Prefix] correct.function.asInstanceOf[Name].name shouldEqual "bar" diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/GlobalNamesTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/GlobalNamesTest.scala index c79fd0998d74..80d1accaa833 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/GlobalNamesTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/GlobalNamesTest.scala @@ -113,7 +113,7 @@ class GlobalNamesTest extends CompilerTest { val app = x3Expr.asInstanceOf[Application.Prefix] app.function.asInstanceOf[Name.Literal].name shouldEqual "constant" app.arguments.length shouldEqual 1 - app.arguments(0).value.getMetadata(GlobalNames) shouldEqual Some( + app.arguments.apply(0).value.getMetadata(GlobalNames) shouldEqual Some( Resolution(ResolvedModule(ctx.moduleReference())) ) } @@ -131,7 +131,7 @@ class GlobalNamesTest extends CompilerTest { val app = x5Expr.asInstanceOf[Application.Prefix] app.function.asInstanceOf[Name.Literal].name shouldEqual "add_one" app.arguments.length shouldEqual 2 - app.arguments(0).value.getMetadata(GlobalNames) shouldEqual Some( + app.arguments.apply(0).value.getMetadata(GlobalNames) shouldEqual Some( Resolution(ResolvedModule(ctx.moduleReference())) ) } @@ -142,7 +142,7 @@ class GlobalNamesTest extends CompilerTest { val app = yExpr.asInstanceOf[Application.Prefix] app.function.asInstanceOf[Name.Literal].name shouldEqual "add_one" app.arguments.length shouldEqual 1 - app.arguments(0).value.getMetadata(GlobalNames) shouldEqual Some( + app.arguments.apply(0).value.getMetadata(GlobalNames) shouldEqual Some( Resolution(ResolvedModule(ctx.moduleReference())) ) } @@ -181,8 +181,8 @@ class GlobalNamesTest extends CompilerTest { .asInstanceOf[Name.Literal] .name shouldEqual "method" moduleMethodCall.arguments.length shouldEqual 2 - moduleMethodCall - .arguments(0) + moduleMethodCall.arguments + .apply(0) .value .getMetadata(GlobalNames) shouldEqual Some( Resolution(ResolvedModule(ctx.moduleReference())) diff --git a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/TypeSignaturesTest.scala b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/TypeSignaturesTest.scala index 17e9377d4286..57d970b042e5 100644 --- a/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/TypeSignaturesTest.scala +++ b/engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/resolve/TypeSignaturesTest.scala @@ -271,7 +271,8 @@ class TypeSignaturesTest extends CompilerTest { } "work recursively" in { - val arg2Value = ir.asInstanceOf[Application.Prefix].arguments(1).value + val arg2Value = + ir.asInstanceOf[Application.Prefix].arguments.apply(1).value val arg2Signature = arg2Value.getMetadata(TypeSignatures) arg2Signature shouldBe defined arg2Signature.get.signature.showCode() shouldEqual "Int" @@ -279,7 +280,8 @@ class TypeSignaturesTest extends CompilerTest { // But arg1 has no signature: val arg1Signature = ir .asInstanceOf[Application.Prefix] - .arguments(0) + .arguments + .apply(0) .value .getMetadata(TypeSignatures) arg1Signature shouldBe empty diff --git a/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JCallArgument.java b/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JCallArgument.java index 12a8596bfc15..f39f4d28edf5 100644 --- a/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JCallArgument.java +++ b/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JCallArgument.java @@ -38,5 +38,10 @@ public JSpecified( @IRField boolean isSynthetic, @IRChild Option name, @IRChild Expression value) { super(isSynthetic, name, value); } + + @Override + public String showCode(int indent) { + return ""; + } } } diff --git a/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JExpression.java b/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JExpression.java index 92116fbfd0d3..04659812271f 100644 --- a/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JExpression.java +++ b/engine/runtime-parser-processor-tests/src/main/java/org/enso/runtime/parser/processor/test/gen/ir/core/JExpression.java @@ -30,6 +30,11 @@ public JBlock( @IRField boolean suspended) { super(expressions, returnValue, suspended); } + + @Override + public String showCode(int indent) { + return ""; + } } @GenerateIR(interfaces = {JExpression.class}) @@ -38,5 +43,10 @@ final class JBinding extends JBindingGen { public JBinding(@IRChild Name name, @IRChild JExpression expression) { super(name, expression); } + + @Override + public String showCode(int indent) { + return ""; + } } } diff --git a/engine/runtime-parser-processor-tests/src/test/java/org/enso/runtime/parser/processor/test/TestIRProcessorInline.java b/engine/runtime-parser-processor-tests/src/test/java/org/enso/runtime/parser/processor/test/TestIRProcessorInline.java index e0866a4538e2..6fef47fca344 100644 --- a/engine/runtime-parser-processor-tests/src/test/java/org/enso/runtime/parser/processor/test/TestIRProcessorInline.java +++ b/engine/runtime-parser-processor-tests/src/test/java/org/enso/runtime/parser/processor/test/TestIRProcessorInline.java @@ -66,6 +66,11 @@ public void simpleIRNodeWithoutFields_CompilationSucceeds() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """); var compiler = Compiler.javac().withProcessors(new IRProcessor()); @@ -118,6 +123,11 @@ public void annotatedClass_MustExtendGeneratedSuperclass() { public final class JName { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -139,6 +149,11 @@ interface MySuperIR { } public final class MyIR extends MyIRGen { @GenerateFields public MyIR() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var generatedClass = generatedClass("MyIR", src); @@ -159,6 +174,12 @@ interface MySuperIR_2 { } public final class MyIR extends MyIRGen { @GenerateFields public MyIR() {} + + @Override + public String showCode(int indent) { + return ""; + } + } """; var generatedClass = generatedClass("MyIR", src); @@ -180,6 +201,11 @@ public final class JName extends JNameGen { public JName(@IRField String name) { super(name); } + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -198,6 +224,11 @@ public void generatedClassHasProtectedConstructor() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -223,6 +254,11 @@ public final class JName extends JNameGen { public JName() { super(); } + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -243,6 +279,11 @@ public final class JName extends JNameGen { public JName(@IRField boolean suspended, @IRField String name) { super(suspended, name); } + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -264,6 +305,11 @@ public final class JName extends JNameGen { public JName(DiagnosticStorage diag, IdentifiedLocation loc) { super(diag, loc); } + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -286,6 +332,11 @@ public final class JName extends JNameGen { public JName(DiagnosticStorage diag, IdentifiedLocation loc, @IRField boolean suspended) { super(diag, loc, suspended); } + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -303,6 +354,11 @@ public void generatedClass_IsAbstract() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -320,6 +376,11 @@ public void generatedClass_CanHaveArbitraryName() { public final class JName extends MySuperGeneratedClass { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -341,6 +402,11 @@ public void generatedClass_DuplicateMethodHasSpecificReturnType() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -359,6 +425,11 @@ public void generatedClass_HasParameterlessDuplicateMethod() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -376,6 +447,11 @@ public void generatedMethod_setLocation_returnsSubClassType() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -393,6 +469,11 @@ public void generatedMethod_mapExpressions_returnsSubClassType() { public final class JName extends JNameGen { @GenerateFields public JName() {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var genClass = generatedClass("JName", src); @@ -410,6 +491,11 @@ public void annotatedConstructor_MustNotHaveUnannotatedParameters() { public final class JName extends JNameGen { @GenerateFields public JName(int param) {} + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -431,6 +517,11 @@ public final class JName extends JNameGen { public JName(MetadataStorage passData) { super(passData); } + + @Override + public String showCode(int indent) { + return ""; + } } """; var compilation = compile("JName", src); @@ -454,6 +545,11 @@ public final class MyIR extends MyIRGen { public MyIR(@IRChild Expression expression) { super(expression); } + + @Override + public String showCode(int indent) { + return ""; + } } """); assertThat(genSrc, containsString("Expression expression()")); @@ -476,6 +572,11 @@ public final class MyIR extends MyIRGen { public MyIR(@IRField boolean suspended) { super(suspended); } + + @Override + public String showCode(int indent) { + return ""; + } } """); assertThat(genSrc, containsString("boolean suspended()")); @@ -502,6 +603,11 @@ public final class MyIR extends MyIRGen { public MyIR(@IRField boolean suspended) { super(suspended); } + + @Override + public String showCode(int indent) { + return ""; + } } """); assertThat(src, containsString("boolean suspended()")); @@ -528,6 +634,11 @@ public final class MyIR extends MyIRGen { public MyIR(@IRField boolean suspended) { super(suspended); } + + @Override + public String showCode(int indent) { + return ""; + } } """); @@ -558,6 +669,11 @@ public final class MyIR extends MyIRGen { public MyIR(@IRField boolean suspended) { super(suspended); } + + @Override + public String showCode(int indent) { + return ""; + } } """); assertThat(src, containsString("boolean suspended()")); @@ -583,6 +699,11 @@ public final class JBlank extends JBlankGen { public JBlank(@IRField String name) { super(name); } + + @Override + public String showCode(int indent) { + return ""; + } } } """); @@ -608,6 +729,11 @@ public final class JName extends JNameGen { public JName(@IRChild List expressions) { super(expressions); } + + @Override + public String showCode(int indent) { + return ""; + } } """); assertThat(src, containsString("class JNameGen")); @@ -632,6 +758,11 @@ public final class JName extends JNameGen { public JName(@IRChild Option expression) { super(expression); } + + @Override + public String showCode(int indent) { + return ""; + } } """); assertThat(src, containsString("class JNameGen")); diff --git a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/GeneratedClassContext.java b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/GeneratedClassContext.java index 71a02b5ab702..a690724ef937 100644 --- a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/GeneratedClassContext.java +++ b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/GeneratedClassContext.java @@ -136,7 +136,7 @@ public ProcessedClass getProcessedClass() { return processedClass; } - List getMetaFields() { + public List getMetaFields() { return metaFields; } diff --git a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/IRNodeClassGenerator.java b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/IRNodeClassGenerator.java index 8df6dc6d5f0d..bc3143823098 100644 --- a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/IRNodeClassGenerator.java +++ b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/IRNodeClassGenerator.java @@ -5,6 +5,10 @@ import java.util.Set; import java.util.stream.Collectors; import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.PackageElement; +import javax.lang.model.element.TypeElement; import org.enso.runtime.parser.processor.field.Field; import org.enso.runtime.parser.processor.field.FieldCollector; import org.enso.runtime.parser.processor.methodgen.BuilderMethodGenerator; @@ -101,12 +105,39 @@ Set imports() { .collect(Collectors.toUnmodifiableSet()); var allImports = new HashSet(); allImports.addAll(defaultImportedTypes); + addImportForType(allImports, processedClass.getClazz()); + for (var ifaceToImplement : processedClass.getInterfaces()) { + addImportForType(allImports, ifaceToImplement); + } allImports.addAll(importsForFields); return allImports.stream() .map(importedType -> "import " + importedType + ";") .collect(Collectors.toUnmodifiableSet()); } + /** + * Adds import for a type that is not in an unnamed package. + * + * @param imports Set of imports to potentially add to + */ + private void addImportForType(Set imports, TypeElement type) { + if (!isInUnnamedPackage(type)) { + imports.add(type.getQualifiedName().toString()); + } + } + + private boolean isInUnnamedPackage(TypeElement type) { + Element enclosingElement = type.getEnclosingElement(); + while (enclosingElement != null) { + if (enclosingElement.getKind() == ElementKind.PACKAGE) { + var pkg = (PackageElement) enclosingElement; + return pkg.isUnnamed(); + } + enclosingElement = enclosingElement.getEnclosingElement(); + } + return false; + } + /** Generates the body of the class - fields, field setters, method overrides, builder, etc. */ String classBody() { var code = @@ -117,10 +148,16 @@ String classBody() { $validateConstructor + /** Empty builder */ public static Builder builder() { return new Builder(); } + /** Builder with initial values */ + public static Builder builder($processedClassName obj) { + return new Builder(obj); + } + $copyMethod $userDefinedGetters @@ -140,6 +177,7 @@ public static Builder builder() { .replace("$fields", fieldsCode()) .replace("$defaultCtor", defaultConstructor()) .replace("$validateConstructor", validateConstructor()) + .replace("$processedClassName", processedClass.getClazz().getSimpleName().toString()) .replace("$copyMethod", copyMethodGenerator.generateMethodCode()) .replace("$userDefinedGetters", userDefinedGetters()) .replace("$overrideIRMethods", overrideIRMethods()) @@ -397,11 +435,6 @@ public DiagnosticStorage diagnosticsCopy() { } $duplicateMethods - - @Override - public String showCode(int indent) { - throw new UnsupportedOperationException("unimplemented"); - } """ .replace("$childrenMethodBody", childrenMethodBody()) .replace("$setLocationMethod", setLocationMethodGenerator.generateMethodCode()) diff --git a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/BuilderMethodGenerator.java b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/BuilderMethodGenerator.java index 53148cbb6efa..f965de9fb90f 100644 --- a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/BuilderMethodGenerator.java +++ b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/BuilderMethodGenerator.java @@ -67,6 +67,8 @@ public static final class Builder { Builder() {} + $copyConstructor + $fieldSetters $buildMethod @@ -77,12 +79,43 @@ private void validate() { } """ .replace("$fieldDeclarations", Utils.indent(fieldDeclarations, 2)) + .replace("$copyConstructor", Utils.indent(copyConstructor(), 2)) .replace("$fieldSetters", Utils.indent(fieldSetters, 2)) .replace("$buildMethod", Utils.indent(buildMethod(), 2)) .replace("$validationCode", Utils.indent(validationCode, 4)); return code; } + private String copyConstructor() { + var sb = new StringBuilder(); + sb.append("Builder(") + .append(generatedClassContext.getProcessedClass().getClazz().getSimpleName()) + .append(" obj) {") + .append(System.lineSeparator()); + // Meta fields are accessed directly. + for (var metaField : generatedClassContext.getMetaFields()) { + sb.append(" ") + .append("this.") + .append(metaField.name()) + .append(" = obj.") + .append(metaField.name()) + .append(";") + .append(System.lineSeparator()); + } + // User fields are accessed via getters + for (var userField : generatedClassContext.getUserFields()) { + sb.append(" ") + .append("this.") + .append(userField.getName()) + .append(" = obj.") + .append(userField.getName()) + .append("();") + .append(System.lineSeparator()); + } + sb.append("}"); + return sb.toString(); + } + private String buildMethod() { var sb = new StringBuilder(); var processedClassName = diff --git a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/SetLocationMethodGenerator.java b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/SetLocationMethodGenerator.java index 39900dd180fd..088b6d8b0ddd 100644 --- a/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/SetLocationMethodGenerator.java +++ b/engine/runtime-parser-processor/src/main/java/org/enso/runtime/parser/processor/methodgen/SetLocationMethodGenerator.java @@ -38,7 +38,7 @@ public String generateMethodCode() { if (location.isDefined()) { loc = location.get(); } - return builder().location(loc).build(); + return builder(($retType) this).location(loc).build(); } """ .replace("$retType", retType()); diff --git a/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/DefinitionArgument.java b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/DefinitionArgument.java new file mode 100644 index 000000000000..6ac71b256395 --- /dev/null +++ b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/DefinitionArgument.java @@ -0,0 +1,138 @@ +package org.enso.compiler.core.ir; + +import java.util.function.Function; +import org.enso.compiler.core.IR; +import org.enso.runtime.parser.dsl.GenerateFields; +import org.enso.runtime.parser.dsl.GenerateIR; +import org.enso.runtime.parser.dsl.IRChild; +import org.enso.runtime.parser.dsl.IRField; +import scala.Option; + +public interface DefinitionArgument extends IR { + Name name(); + + Option ascribedType(); + + Option defaultValue(); + + boolean suspended(); + + @Override + DefinitionArgument mapExpressions(Function fn); + + @Override + DefinitionArgument duplicate( + boolean keepLocations, + boolean keepMetadata, + boolean keepDiagnostics, + boolean keepIdentifiers); + + DefinitionArgument withName(Name ir); + + @GenerateIR(interfaces = {DefinitionArgument.class}) + final class Specified extends DefinitionArgumentSpecifiedGen { + @GenerateFields + public Specified( + @IRChild Name name, + @IRChild Option ascribedType, + @IRChild Option defaultValue, + @IRField boolean suspended, + IdentifiedLocation identifiedLocation, + MetadataStorage passData, + DiagnosticStorage diagnostics) { + super(name, ascribedType, defaultValue, suspended, identifiedLocation, passData, diagnostics); + } + + public Specified( + Name name, + Option ascribedType, + Option defaultValue, + boolean suspended, + IdentifiedLocation identifiedLocation) { + this( + name, + ascribedType, + defaultValue, + suspended, + identifiedLocation, + new MetadataStorage(), + null); + } + + public Specified( + Name name, + Option ascribedType, + Option defaultValue, + boolean suspended, + IdentifiedLocation identifiedLocation, + MetadataStorage passData) { + this(name, ascribedType, defaultValue, suspended, identifiedLocation, passData, null); + } + + public Specified(Name name) { + this(name, Option.empty(), Option.empty(), false, null, new MetadataStorage()); + } + + @Override + public String showCode(int indent) { + String withoutLazy; + if (defaultValue().isDefined() && ascribedType().isDefined()) { + var name = name().showCode(indent); + var typeExpr = ascribedType().get().showCode(indent); + var defaultExpr = defaultValue().get().showCode(indent); + withoutLazy = String.format("(%s : (%s) = (%s))", name, typeExpr, defaultExpr); + } else if (defaultValue().isDefined()) { + var name = name().showCode(indent); + var defaultExpr = defaultValue().get().showCode(indent); + withoutLazy = String.format("(%s = %s)", name, defaultExpr); + } else if (ascribedType().isDefined()) { + var name = name().showCode(indent); + var typeExpr = ascribedType().get().showCode(indent); + withoutLazy = String.format("((%s : %s))", name, typeExpr); + } else { + withoutLazy = name().showCode(indent); + } + if (suspended()) { + return "~" + withoutLazy; + } else { + return withoutLazy; + } + } + + @Override + public DefinitionArgument withName(Name ir) { + return copy( + diagnostics, passData, location, id, ir, ascribedType(), defaultValue(), suspended()); + } + + public Specified copyWithAscribedType(Option ascribedType) { + return copy( + diagnostics, passData, location, id, name(), ascribedType, defaultValue(), suspended()); + } + + public Specified copyWithDefaultValue(Option defaultValue) { + return copy( + diagnostics, passData, location, id, name(), ascribedType(), defaultValue, suspended()); + } + + public Specified copyWithSuspended(boolean suspended) { + return copy( + diagnostics, passData, location, id, name(), ascribedType(), defaultValue(), suspended); + } + + public Specified copy(Option defaultValue, Option ascribedType) { + return copy( + diagnostics, passData, location, id, name(), ascribedType, defaultValue, suspended()); + } + + public Specified copy(Name name, Option defaultValue) { + return copy( + diagnostics, passData, location, id, name, ascribedType(), defaultValue, suspended()); + } + + public Specified copyWithNameAndAscribedType(Name name, Option ascribedType) { + return copy( + diagnostics, passData, location, id, name, ascribedType, defaultValue(), suspended()); + } + } +} diff --git a/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java index 46a833939618..c35812ede20c 100644 --- a/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java +++ b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/Empty.java @@ -13,4 +13,9 @@ public Empty(IdentifiedLocation identifiedLocation, MetadataStorage passData) { public Empty(IdentifiedLocation identifiedLocation) { this(identifiedLocation, new MetadataStorage()); } + + @Override + public String showCode(int indent) { + return "IR.Empty"; + } } diff --git a/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/expression/Application.java b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/expression/Application.java new file mode 100644 index 000000000000..0b6d1d3a1c71 --- /dev/null +++ b/engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/expression/Application.java @@ -0,0 +1,189 @@ +package org.enso.compiler.core.ir.expression; + +import java.util.function.Function; +import org.enso.compiler.core.ir.CallArgument; +import org.enso.compiler.core.ir.DiagnosticStorage; +import org.enso.compiler.core.ir.Expression; +import org.enso.compiler.core.ir.IRKind; +import org.enso.compiler.core.ir.IdentifiedLocation; +import org.enso.compiler.core.ir.MetadataStorage; +import org.enso.runtime.parser.dsl.GenerateFields; +import org.enso.runtime.parser.dsl.GenerateIR; +import org.enso.runtime.parser.dsl.IRChild; +import org.enso.runtime.parser.dsl.IRField; +import scala.Option; +import scala.collection.immutable.List; + +public interface Application extends Expression { + + /** A standard prefix function application. */ + @GenerateIR(interfaces = {Application.class, IRKind.Primitive.class}) + final class Prefix extends ApplicationPrefixGen { + @GenerateFields + public Prefix( + @IRChild Expression function, + @IRChild List arguments, + @IRField boolean hasDefaultsSuspended, + IdentifiedLocation identifiedLocation, + MetadataStorage passData, + DiagnosticStorage diagnostics) { + super(function, arguments, hasDefaultsSuspended, identifiedLocation, passData, diagnostics); + } + + public Prefix( + Expression function, + List arguments, + boolean hasDefaultsSuspended, + IdentifiedLocation identifiedLocation, + MetadataStorage passData) { + this(function, arguments, hasDefaultsSuspended, identifiedLocation, passData, null); + } + + public Prefix(Expression function, List arguments) { + this(function, arguments, false, null, new MetadataStorage(), null); + } + + public Prefix copy(Expression function, List arguments) { + return copy( + diagnostics(), + passData(), + identifiedLocation(), + id, + function, + arguments, + hasDefaultsSuspended()); + } + + public Prefix copyWithArguments(List arguments) { + return copy( + diagnostics(), + passData(), + identifiedLocation(), + id, + function(), + arguments, + hasDefaultsSuspended()); + } + + public Prefix copyWithFunction(Expression function) { + return copy( + diagnostics(), + passData(), + identifiedLocation(), + id, + function, + arguments(), + hasDefaultsSuspended()); + } + + @Override + public String showCode(int indent) { + var argStr = arguments().map(arg -> arg.showCode(indent)).mkString(" "); + var funcStr = function().showCode(indent); + return "((" + funcStr + ") " + argStr + ")"; + } + } + + /** A representation of a term that is explicitly forced. */ + @GenerateIR(interfaces = {Application.class, IRKind.Primitive.class}) + final class Force extends ApplicationForceGen { + /** + * @param target The expression being forced + * @param identifiedLocation + * @param passData + */ + @GenerateFields + public Force( + @IRChild Expression target, + IdentifiedLocation identifiedLocation, + MetadataStorage passData) { + super(target, identifiedLocation, passData); + } + + @Override + public String showCode(int indent) { + return "(FORCE " + target().showCode(indent) + ")"; + } + + public Force copyWithTarget(Expression target) { + return copy(diagnostics(), passData(), identifiedLocation(), id, target); + } + } + + /** Literal applications in Enso. */ + interface Literal extends Application { + @Override + Literal mapExpressions(Function fn); + + @Override + Literal setLocation(Option location); + + @Override + Literal duplicate( + boolean keepLocations, + boolean keepMetadata, + boolean keepDiagnostics, + boolean keepIdentifiers); + } + + /** + * A representation of a typeset literal. + * + *

These are necessary as they delimit pattern contexts. + */ + @GenerateIR(interfaces = {Literal.class, IRKind.Primitive.class}) + final class Typeset extends ApplicationTypesetGen { + + /** + * @param expression The expression of the typeset body. + */ + @GenerateFields + public Typeset( + @IRChild Option expression, + IdentifiedLocation identifiedLocation, + MetadataStorage passData) { + super(expression, identifiedLocation, passData); + } + + @Override + public String showCode(int indent) { + String exprString; + if (expression().isDefined()) { + exprString = expression().get().showCode(indent); + } else { + exprString = ""; + } + return "{" + exprString + "}"; + } + + public Typeset copyWithExpression(Option expression) { + return copy(diagnostics(), passData(), identifiedLocation(), id, expression); + } + } + + /** A representation of a vector literal. */ + @GenerateIR(interfaces = {Literal.class, IRKind.Primitive.class}) + final class Sequence extends ApplicationSequenceGen { + + /** + * @param items The items being put in the vector. + */ + @GenerateFields + public Sequence( + @IRChild List items, + IdentifiedLocation identifiedLocation, + MetadataStorage passData) { + super(items, identifiedLocation, passData); + } + + @Override + public String showCode(int indent) { + var itemsStr = items().map(it -> it.showCode(indent)).mkString(" "); + return "[" + itemsStr + "]"; + } + + public Sequence copyWithItems(List items) { + return copy(diagnostics(), passData(), identifiedLocation(), id, items); + } + } +} diff --git a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/DefinitionArgument.scala b/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/DefinitionArgument.scala deleted file mode 100644 index 765dd45d52ff..000000000000 --- a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/DefinitionArgument.scala +++ /dev/null @@ -1,251 +0,0 @@ -package org.enso.compiler.core.ir - -import org.enso.compiler.core.Implicits.{ShowPassData, ToStringHelper} -import org.enso.compiler.core.{IR, Identifier} - -import java.util.UUID -import scala.jdk.FunctionConverters.enrichAsScalaFromFunction - -/** Definition-site arguments in Enso. */ -sealed trait DefinitionArgument extends IR { - - /** The name of the argument. */ - val name: Name - - /** The type of the argument */ - val ascribedType: Option[Expression] - - /** The default value of the argument. */ - val defaultValue: Option[Expression] - - /** Whether or not the argument is suspended. */ - val suspended: Boolean - - /** @inheritdoc */ - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): DefinitionArgument - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): DefinitionArgument - - def withName(ir: Name): DefinitionArgument -} - -object DefinitionArgument { - - /** The representation of an argument from a [[Function]] or - * [[module.scope.Definition.Data]] definition site. - * - * To create an ignored argument, the argument name should be an - * [[Name.Blank]]. - * - * @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 identifiedLocation the source location that the node corresponds to - * @param passData the pass metadata associated with this node - */ - sealed case class Specified( - override val name: Name, - override val ascribedType: Option[Expression], - override val defaultValue: Option[Expression], - override val suspended: Boolean, - override val identifiedLocation: IdentifiedLocation, - override val 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 identifiedLocation 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, - identifiedLocation: IdentifiedLocation, - passData: MetadataStorage, - diagnostics: DiagnosticStorage - ) = { - this( - name, - ascribedType, - defaultValue, - suspended, - identifiedLocation, - passData - ) - this.diagnostics = diagnostics - } - - /** Creates a copy of `this`. - * - * @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 compiler diagnostics for this node - * @param id the identifier for the new node - * @return a copy of `this`, updated with the specified values - */ - def copy( - name: Name = name, - ascribedType: Option[Expression] = ascribedType, - defaultValue: Option[Expression] = defaultValue, - suspended: Boolean = suspended, - location: Option[IdentifiedLocation] = location, - passData: MetadataStorage = passData, - diagnostics: DiagnosticStorage = diagnostics, - id: UUID @Identifier = id - ): Specified = { - if ( - name != this.name - || ascribedType != this.ascribedType - || defaultValue != this.defaultValue - || suspended != this.suspended - || location != this.location - || (passData ne this.passData) - || diagnostics != this.diagnostics - || id != this.id - ) { - val res = Specified( - name, - ascribedType, - defaultValue, - suspended, - location.orNull, - passData - ) - res.diagnostics = diagnostics - res.id = id - res - } else this - } - - def copyWithAscribedType( - ascribedType: Expression - ): Specified = { - copy(ascribedType = Some(ascribedType)) - } - - override def withName(ir: Name): DefinitionArgument = copy(name = ir) - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Specified = - copy( - name = name.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ), - ascribedType = ascribedType.map( - _.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ) - ), - defaultValue = defaultValue.map( - _.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ) - ), - location = if (keepLocations) location else None, - passData = - if (keepMetadata) passData.duplicate else new MetadataStorage(), - diagnostics = if (keepDiagnostics) diagnosticsCopy else null, - id = if (keepIdentifiers) id else null - ) - - /** @inheritdoc */ - override def setLocation( - location: Option[IdentifiedLocation] - ): Specified = copy(location = location) - - /** @inheritdoc */ - def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Specified = { - copy( - name = name.mapExpressions(fn), - ascribedType = ascribedType.map(fn.asScala), - defaultValue = defaultValue.map(fn.asScala) - ) - } - - /** String representation. */ - override def toString: String = - s""" - |DefinitionArgument.Specified( - |name = $name, - |ascribedType = $ascribedType, - |defaultValue = $defaultValue, - |suspended = $suspended, - |location = $location, - |passData = ${this.showPassData}, - |diagnostics = $diagnostics, - |id = $id - |) - |""".toSingleLine - - /** @inheritdoc */ - override def children: List[IR] = - name :: ascribedType.toList ++ defaultValue.toList - - /** @inheritdoc */ - override def showCode(indent: Int): String = { - val withoutLazy = - if (defaultValue.isDefined && ascribedType.isDefined) { - val name = this.name.showCode(indent) - val typeExpr = this.ascribedType.get.showCode(indent) - val defaultExpr = this.defaultValue.get.showCode(indent) - s"($name : ($typeExpr) = ($defaultExpr))" - } else if (defaultValue.isDefined) { - val name = this.name.showCode(indent) - val defaultExpr = this.defaultValue.get.showCode(indent) - s"($name = $defaultExpr)" - } else if (ascribedType.isDefined) { - val name = this.name.showCode(indent) - val typeExpr = this.ascribedType.get.showCode(indent) - s"($name : $typeExpr)" - } else { - s"${name.showCode(indent)}" - } - - if (suspended) { - s"~$withoutLazy" - } else { - withoutLazy - } - } - } -} diff --git a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Literal.scala b/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Literal.scala index a5383ca8a336..ead8b9c56ad3 100644 --- a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Literal.scala +++ b/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/Literal.scala @@ -6,7 +6,7 @@ import org.enso.compiler.core.{CompilerError, IR, Identifier} import java.util.UUID /** Enso literals. */ -sealed trait Literal extends Expression with IRKind.Primitive { +trait Literal extends Expression with IRKind.Primitive { /** @inheritdoc */ override def mapExpressions( diff --git a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/expression/Application.scala b/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/expression/Application.scala deleted file mode 100644 index 1778b046c156..000000000000 --- a/engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/expression/Application.scala +++ /dev/null @@ -1,494 +0,0 @@ -package org.enso.compiler.core.ir -package expression - -import org.enso.compiler.core.Implicits.{ShowPassData, ToStringHelper} -import org.enso.compiler.core.{IR, Identifier} - -import java.util.UUID -import scala.jdk.FunctionConverters.enrichAsScalaFromFunction - -/** All function applications in Enso. */ -trait Application extends Expression - -object Application { - - /** A standard prefix function 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 identifiedLocation 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 identifiedLocation: IdentifiedLocation, - 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 identifiedLocation 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, - identifiedLocation: IdentifiedLocation, - passData: MetadataStorage, - diagnostics: DiagnosticStorage - ) = { - this( - function, - arguments, - hasDefaultsSuspended, - identifiedLocation, - passData - ) - this.diagnostics = diagnostics - } - - /** Creates a copy of `this`. - * - * @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 - * @param id the identifier for the new node - * @return a copy of `this`, updated with the specified values - */ - def copy( - function: Expression = function, - arguments: List[CallArgument] = arguments, - hasDefaultsSuspended: Boolean = hasDefaultsSuspended, - location: Option[IdentifiedLocation] = location, - passData: MetadataStorage = passData, - diagnostics: DiagnosticStorage = diagnostics, - id: UUID @Identifier = id - ): Prefix = { - if ( - function != this.function - || arguments != this.arguments - || hasDefaultsSuspended != this.hasDefaultsSuspended - || location != this.location - || (passData ne this.passData) - || diagnostics != this.diagnostics - || id != this.id - ) { - val res = - Prefix( - function, - arguments, - hasDefaultsSuspended, - location.orNull, - passData - ) - res.diagnostics = diagnostics - res.id = id - res - } else this - } - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Prefix = - copy( - function = function.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ), - arguments = arguments.map( - _.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ) - ), - location = if (keepLocations) location else None, - passData = - if (keepMetadata) passData.duplicate else new MetadataStorage(), - diagnostics = if (keepDiagnostics) diagnosticsCopy else null, - id = if (keepIdentifiers) id else null - ) - - /** @inheritdoc */ - override def setLocation(location: Option[IdentifiedLocation]): Prefix = - copy(location = location) - - /** @inheritdoc */ - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Prefix = { - copy(function = fn(function), arguments.map(_.mapExpressions(fn))) - } - - /** String representation. */ - override def toString: String = - s""" - |Application.Prefix( - |function = $function, - |arguments = $arguments, - |hasDefaultsSuspended = $hasDefaultsSuspended, - |location = $location, - |passData = ${this.showPassData}, - |diagnostics = $diagnostics, - |id = $id - |) - |""".toSingleLine - - /** @inheritdoc */ - override def children: List[IR] = function :: arguments - - /** @inheritdoc */ - override def showCode(indent: Int): String = { - val argStr = arguments.map(_.showCode(indent)).mkString(" ") - - s"((${function.showCode(indent)}) $argStr)" - } - } - - /** A representation of a term that is explicitly forced. - * - * @param target the expression being forced - * @param identifiedLocation 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 identifiedLocation: IdentifiedLocation, - override val passData: MetadataStorage = new MetadataStorage() - ) extends Application - with IRKind.Primitive - with LazyDiagnosticStorage - with LazyId { - - /** Creates a copy of `this`. - * - * @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 id the identifier for the new node - * @return a copy of `this`, updated with the specified values - */ - def copy( - target: Expression = target, - location: Option[IdentifiedLocation] = location, - passData: MetadataStorage = passData, - diagnostics: DiagnosticStorage = diagnostics, - id: UUID @Identifier = id - ): Force = { - if ( - target != this.target - || location != this.location - || (passData ne this.passData) - || diagnostics != this.diagnostics - || id != this.id - ) { - val res = Force(target, location.orNull, passData) - res.diagnostics = diagnostics - res.id = id - res - } else this - } - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Force = - copy( - target = target.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ), - location = if (keepLocations) location else None, - passData = - if (keepMetadata) passData.duplicate else new MetadataStorage(), - diagnostics = if (keepDiagnostics) diagnosticsCopy else null, - id = if (keepIdentifiers) id else null - ) - - /** @inheritdoc */ - override def setLocation(location: Option[IdentifiedLocation]): Force = - copy(location = location) - - /** @inheritdoc */ - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Force = { - copy(target = fn(target)) - } - - /** String representation. */ - override def toString: String = - s""" - |Application.Force( - |target = $target, - |location = $location, - |passData = ${this.showPassData}, - |diagnostics = $diagnostics, - |id = $id - |) - |""".toSingleLine - - /** @inheritdoc */ - override def children: List[IR] = List(target) - - /** @inheritdoc */ - override def showCode(indent: Int): String = - s"(FORCE ${target.showCode(indent)})" - } - - /** Literal applications in Enso. */ - sealed trait Literal extends Application { - - /** @inheritdoc */ - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Literal - - /** @inheritdoc */ - override def setLocation(location: Option[IdentifiedLocation]): Literal - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Literal - } - - /** A representation of a typeset literal. - * - * These are necessary as they delimit pattern contexts. - * - * @param expression the expression of the typeset body - * @param identifiedLocation 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 identifiedLocation: IdentifiedLocation, - override val passData: MetadataStorage = new MetadataStorage() - ) extends Literal - with IRKind.Primitive - with LazyDiagnosticStorage - with LazyId { - - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Typeset = - copy(expression = expression.map(fn.asScala)) - - /** Creates a copy of `this`. - * - * @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 id the identifier for the new node - * @return a copy of `this`, updataed with the specified values - */ - def copy( - expression: Option[Expression] = expression, - location: Option[IdentifiedLocation] = location, - passData: MetadataStorage = passData, - diagnostics: DiagnosticStorage = diagnostics, - id: UUID @Identifier = id - ): Typeset = { - if ( - expression != this.expression - || location != this.location - || (passData ne this.passData) - || diagnostics != this.diagnostics - || id != this.id - ) { - val res = Typeset(expression, location.orNull, passData) - res.diagnostics = diagnostics - res.id = id - res - } else this - } - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Typeset = - copy( - expression = expression.map( - _.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ) - ), - location = if (keepLocations) location else None, - passData = - if (keepMetadata) passData.duplicate else new MetadataStorage(), - diagnostics = if (keepDiagnostics) diagnosticsCopy else null, - id = if (keepIdentifiers) id else null - ) - - /** @inheritdoc */ - override def setLocation( - location: Option[IdentifiedLocation] - ): Typeset = copy(location = location) - - /** String representation. */ - override def toString: String = - s"""Application.Typeset( - |expression = $expression, - |location = $location, - |passData = ${this.showPassData}, - |diagnostics = $diagnostics, - |id = $id - |) - |""".toSingleLine - - /** @inheritdoc */ - override def children: List[IR] = - expression.map(List(_)).getOrElse(List()) - - /** @inheritdoc */ - override def showCode(indent: Int): String = { - val exprString = if (expression.isDefined) { - expression.get.showCode(indent) - } else "" - - s"{ $exprString }" - } - } - - /** A representation of a vector literal. - * - * @param items the items being put in the vector - * @param identifiedLocation 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 identifiedLocation: IdentifiedLocation, - override val passData: MetadataStorage = new MetadataStorage() - ) extends Literal - with IRKind.Primitive - with LazyDiagnosticStorage - with LazyId { - - override def mapExpressions( - fn: java.util.function.Function[Expression, Expression] - ): Sequence = - copy(items = items.map(fn.asScala)) - - /** Creates a copy of `this`. - * - * @param items the items held by this 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 id the identifier for the new node - * @return a copy of `this`, updated with the specified values - */ - def copy( - items: List[Expression] = items, - location: Option[IdentifiedLocation] = location, - passData: MetadataStorage = passData, - diagnostics: DiagnosticStorage = diagnostics, - id: UUID @Identifier = id - ): Sequence = { - if ( - items != this.items - || location != this.location - || (passData ne this.passData) - || diagnostics != this.diagnostics - || id != this.id - ) { - val res = Sequence(items, location.orNull, passData) - res.diagnostics = diagnostics - res.id = id - res - } else this - } - - /** @inheritdoc */ - override def duplicate( - keepLocations: Boolean = true, - keepMetadata: Boolean = true, - keepDiagnostics: Boolean = true, - keepIdentifiers: Boolean = false - ): Sequence = - copy( - items = items.map( - _.duplicate( - keepLocations, - keepMetadata, - keepDiagnostics, - keepIdentifiers - ) - ), - location = if (keepLocations) location else None, - passData = - if (keepMetadata) passData.duplicate else new MetadataStorage(), - diagnostics = if (keepDiagnostics) diagnosticsCopy else null, - id = if (keepIdentifiers) id else null - ) - - /** @inheritdoc */ - override def setLocation( - location: Option[IdentifiedLocation] - ): Sequence = copy(location = location) - - /** String representation. */ - override def toString: String = - s""" - |Application.Vector( - |items = $items, - |location = $location, - |passData = ${this.showPassData}, - |diagnostics = $diagnostics, - |id = $id - |) - |""".toSingleLine - - /** @inheritdoc */ - override def children: List[IR] = items - - /** @inheritdoc */ - override def showCode(indent: Int): String = { - val itemsStr = items.map(_.showCode(indent)).mkString(", ") - s"[$itemsStr]" - } - } - -} diff --git a/engine/runtime-suggestions/src/main/scala/org/enso/compiler/suggestions/SuggestionBuilder.scala b/engine/runtime-suggestions/src/main/scala/org/enso/compiler/suggestions/SuggestionBuilder.scala index a9b4758eab8b..8b2cb12598e5 100644 --- a/engine/runtime-suggestions/src/main/scala/org/enso/compiler/suggestions/SuggestionBuilder.scala +++ b/engine/runtime-suggestions/src/main/scala/org/enso/compiler/suggestions/SuggestionBuilder.scala @@ -423,7 +423,7 @@ final class SuggestionBuilder[A: IndexedSource]( argument: DefinitionArgument ): Suggestion = { val getterName = argument.name.name - val thisArg = DefinitionArgument.Specified( + val thisArg = new DefinitionArgument.Specified( name = Name.Self(identifiedLocation = null), ascribedType = None, defaultValue = None, @@ -566,23 +566,17 @@ final class SuggestionBuilder[A: IndexedSource]( (acc, targs.lastOption) } else { vargs match { - case DefinitionArgument.Specified( - name: Name.Self, - _, - defaultValue, - suspended, - _, - _ - ) +: vtail => + case (defArg: DefinitionArgument.Specified) +: vtail + if defArg.name().isInstanceOf[Name.Self] => if (isStatic) { go(vtail, targs, acc) } else { val thisArg = Suggestion.Argument( - name = name.name, + name = defArg.name.name, reprType = selfType.toString, - isSuspended = suspended, - hasDefault = defaultValue.isDefined, - defaultValue = defaultValue.map(buildDefaultValue) + isSuspended = defArg.suspended, + hasDefault = defArg.defaultValue.isDefined, + defaultValue = defArg.defaultValue.map(buildDefaultValue) ) go(vtail, targs, acc :+ thisArg) } @@ -770,7 +764,9 @@ final class SuggestionBuilder[A: IndexedSource]( */ private def buildDefaultValue(expr: IR): String = expr match { - case Application.Prefix(name, path, _, _, _) => + case app: Application.Prefix => + val name = app.function + val path = app.arguments path.map(_.value.showCode()).mkString(".") + "." + name.showCode() case other => other.showCode() } diff --git a/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala b/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala index fa692ea1876c..b8c64198afb0 100644 --- a/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala +++ b/engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala @@ -2343,18 +2343,23 @@ class IrToTruffle( subjectToInstrumentation: Boolean ): RuntimeExpression = application match { - case Application.Prefix(fn, Nil, true, _, _) => - run(fn, subjectToInstrumentation) + case app: Application.Prefix + if app.arguments.isEmpty && app.hasDefaultsSuspended => + run(app.function, subjectToInstrumentation) case app: Application.Prefix => processApplicationWithArgs(app, subjectToInstrumentation) - case Application.Force(expr, location, _) => + case force: Application.Force => setLocation( - ForceNode.build(this.run(expr, subjectToInstrumentation)), - location + ForceNode.build(this.run(force.target, subjectToInstrumentation)), + force.identifiedLocation + ) + case seq: Application.Sequence => + val itemNodes = + seq.items.map(run(_, subjectToInstrumentation)).toArray + setLocation( + SequenceLiteralNode.build(itemNodes), + seq.identifiedLocation ) - case Application.Sequence(items, location, _) => - val itemNodes = items.map(run(_, subjectToInstrumentation)).toArray - setLocation(SequenceLiteralNode.build(itemNodes), location) case _: Application.Typeset => setLocation( ErrorNode.build( @@ -2381,12 +2386,10 @@ class IrToTruffle( application: Application.Prefix, subjectToInstrumentation: Boolean ): RuntimeExpression = { - val Application.Prefix(fn, args, hasDefaultsSuspended, loc, _) = - application val callArgFactory = new CallArgumentProcessor(scope, scopeName, currentVarName) - val arguments = args + val arguments = application.arguments val callArgs = new ArrayBuffer[callable.argument.CallArgument]() for ((unprocessedArg, position) <- arguments.view.zipWithIndex) { @@ -2395,19 +2398,19 @@ class IrToTruffle( callArgs.append(arg) } - val defaultsExecutionMode = if (hasDefaultsSuspended) { + val defaultsExecutionMode = if (application.hasDefaultsSuspended) { InvokeCallableNode.DefaultsExecutionMode.IGNORE } else { InvokeCallableNode.DefaultsExecutionMode.EXECUTE } val appNode = ApplicationNode.build( - this.run(fn, subjectToInstrumentation), + this.run(application.function, subjectToInstrumentation), callArgs.toArray, defaultsExecutionMode ) - setLocation(appNode, loc) + setLocation(appNode, application.identifiedLocation) } }