mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 11:52:59 +03:00
Moving construction of IR into runtime parser project (#7096)
This commit is contained in:
parent
7955bec129
commit
6abcbcb00c
24
build.sbt
24
build.sbt
@ -273,6 +273,7 @@ lazy val enso = (project in file("."))
|
||||
searcher,
|
||||
launcher,
|
||||
downloader,
|
||||
`runtime-parser`,
|
||||
`runtime-language-epb`,
|
||||
`runtime-instrument-common`,
|
||||
`runtime-instrument-id-execution`,
|
||||
@ -496,11 +497,7 @@ lazy val syntax = (project in file("lib/scala/syntax/specialization"))
|
||||
version := "0.1",
|
||||
logBuffered := false,
|
||||
libraryDependencies ++= Seq(
|
||||
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
|
||||
"com.lihaoyi" %% "pprint" % pprintVersion,
|
||||
"io.circe" %% "circe-core" % circeVersion,
|
||||
"io.circe" %% "circe-generic" % circeVersion,
|
||||
"io.circe" %% "circe-parser" % circeVersion
|
||||
"org.scalatest" %% "scalatest" % scalatestVersion % Test
|
||||
),
|
||||
(Compile / compile) := (Compile / compile)
|
||||
.dependsOn(RecompileParser.run(`syntax-definition`))
|
||||
@ -1359,13 +1356,26 @@ lazy val runtime = (project in file("engine/runtime"))
|
||||
.dependsOn(`logging-utils`)
|
||||
.dependsOn(`polyglot-api`)
|
||||
.dependsOn(`text-buffer`)
|
||||
.dependsOn(`runtime-parser`)
|
||||
.dependsOn(pkg)
|
||||
.dependsOn(`edition-updater`)
|
||||
.dependsOn(`connected-lock-manager`)
|
||||
.dependsOn(syntax)
|
||||
.dependsOn(`syntax-rust-definition`)
|
||||
.dependsOn(testkit % Test)
|
||||
|
||||
lazy val `runtime-parser` =
|
||||
(project in file("engine/runtime-parser"))
|
||||
.settings(
|
||||
frgaalJavaCompilerSetting,
|
||||
instrumentationSettings,
|
||||
libraryDependencies ++= Seq(
|
||||
"junit" % "junit" % junitVersion % Test,
|
||||
"com.novocode" % "junit-interface" % junitIfVersion % Test exclude ("junit", "junit-dep"),
|
||||
"org.scalatest" %% "scalatest" % scalatestVersion % Test
|
||||
)
|
||||
)
|
||||
.dependsOn(syntax)
|
||||
.dependsOn(`syntax-rust-definition`)
|
||||
|
||||
lazy val `runtime-instrument-common` =
|
||||
(project in file("engine/runtime-instrument-common"))
|
||||
.configs(Benchmark)
|
||||
|
@ -86,21 +86,6 @@ The license information can be found along with the copyright notices.
|
||||
Copyright notices related to this dependency can be found in the directory `com.ibm.icu.icu4j-73.1`.
|
||||
|
||||
|
||||
'fansi_2.13', licensed under the MIT, is distributed with the engine.
|
||||
The license information can be found along with the copyright notices.
|
||||
Copyright notices related to this dependency can be found in the directory `com.lihaoyi.fansi_2.13-0.4.0`.
|
||||
|
||||
|
||||
'pprint_2.13', licensed under the MIT, is distributed with the engine.
|
||||
The license information can be found along with the copyright notices.
|
||||
Copyright notices related to this dependency can be found in the directory `com.lihaoyi.pprint_2.13-0.8.1`.
|
||||
|
||||
|
||||
'sourcecode_2.13', licensed under the MIT, is distributed with the engine.
|
||||
The license information can be found along with the copyright notices.
|
||||
Copyright notices related to this dependency can be found in the directory `com.lihaoyi.sourcecode_2.13-0.3.0`.
|
||||
|
||||
|
||||
'decline_2.13', licensed under the Apache-2.0, is distributed with the engine.
|
||||
The license file can be found at `licenses/APACHE2.0`.
|
||||
Copyright notices related to this dependency can be found in the directory `com.monovore.decline_2.13-2.4.1`.
|
||||
|
@ -1,25 +0,0 @@
|
||||
License
|
||||
=======
|
||||
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Li Haoyi (haoyi.sg@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Li Haoyi
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
@ -1,25 +0,0 @@
|
||||
License
|
||||
=======
|
||||
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Li Haoyi (haoyi.sg@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
@ -2,9 +2,9 @@ package org.enso.compiler.context
|
||||
|
||||
import com.oracle.truffle.api.source.Source
|
||||
import java.util.UUID
|
||||
import org.enso.compiler.EnsoCompiler
|
||||
import org.enso.compiler.core.EnsoParser
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.analyse.DataflowAnalysis
|
||||
import org.enso.interpreter.instrument.execution.model.PendingEdit
|
||||
import org.enso.syntax.text.Location
|
||||
@ -87,9 +87,9 @@ final class ChangesetBuilder[A: TextEditor: IndexedSource](
|
||||
}
|
||||
|
||||
val source = Source.newBuilder("enso", value, null).build
|
||||
Using(new EnsoCompiler) { compiler =>
|
||||
Using(new EnsoParser) { compiler =>
|
||||
compiler
|
||||
.generateIRInline(compiler.parse(source))
|
||||
.generateIRInline(compiler.parse(source.getCharacters()))
|
||||
.flatMap(_ match {
|
||||
case ir: IR.Literal => Some(ir.setLocation(oldIr.location))
|
||||
case _ => None
|
||||
|
@ -4,6 +4,7 @@ import cats.implicits._
|
||||
import com.oracle.truffle.api.TruffleLogger
|
||||
import org.enso.compiler.CompilerResult
|
||||
import org.enso.compiler.context._
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
CachePreferenceAnalysis,
|
||||
@ -286,12 +287,10 @@ final class EnsureCompiledJob(protected val files: Iterable[File])
|
||||
private def buildCacheInvalidationCommands(
|
||||
changeset: Changeset[_],
|
||||
source: CharSequence
|
||||
)(implicit ctx: RuntimeContext): Seq[CacheInvalidation] = {
|
||||
): Seq[CacheInvalidation] = {
|
||||
val invalidateExpressionsCommand =
|
||||
CacheInvalidation.Command.InvalidateKeys(changeset.invalidated)
|
||||
val scopeIds = ctx.executionService.getContext.getCompiler
|
||||
.parseMeta(source)
|
||||
.map(_._2)
|
||||
val scopeIds = splitMeta(source.toString())._2.map(_._2)
|
||||
val invalidateStaleCommand =
|
||||
CacheInvalidation.Command.InvalidateStale(scopeIds)
|
||||
Seq(
|
||||
@ -308,6 +307,37 @@ final class EnsureCompiledJob(protected val files: Iterable[File])
|
||||
)
|
||||
}
|
||||
|
||||
type IDMap = Seq[(org.enso.data.Span, java.util.UUID)]
|
||||
private def splitMeta(code: String): (String, IDMap, io.circe.Json) = {
|
||||
import io.circe.Json
|
||||
import io.circe.Error
|
||||
import io.circe.generic.auto._
|
||||
import io.circe.parser._
|
||||
|
||||
def idMapFromJson(json: String): Either[Error, IDMap] = decode[IDMap](json)
|
||||
|
||||
val METATAG = "\n\n\n#### METADATA ####\n"
|
||||
code.split(METATAG) match {
|
||||
case Array(input) => (input, Seq(), Json.obj())
|
||||
case Array(input, rest) =>
|
||||
val meta = rest.split('\n')
|
||||
if (meta.length < 2) {
|
||||
throw new CompilerError(s"Expected two lines after METADATA.")
|
||||
}
|
||||
val idmap = idMapFromJson(meta(0)).left.map { error =>
|
||||
throw new CompilerError("Could not deserialize idmap.", error)
|
||||
}.merge
|
||||
val metadata = decode[Json](meta(1)).left.map { error =>
|
||||
throw new CompilerError("Could not deserialize metadata.", error)
|
||||
}.merge
|
||||
(input, idmap, metadata)
|
||||
case arr: Array[_] =>
|
||||
throw new CompilerError(
|
||||
s"Could not not deserialize metadata (found ${arr.length - 1} metadata sections)"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Run the invalidation commands.
|
||||
*
|
||||
* @param module the compiled module
|
||||
|
@ -0,0 +1,11 @@
|
||||
package org.enso.compiler.core;
|
||||
|
||||
public class CompilerError extends RuntimeException {
|
||||
public CompilerError(String message) {
|
||||
this(message, null);
|
||||
}
|
||||
|
||||
public CompilerError(String message, Throwable cause) {
|
||||
super("Compiler Internal Error: " + message, cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.enso.compiler.core;
|
||||
|
||||
public interface ConstantsNames {
|
||||
public static final String SELF_ARGUMENT = "self";
|
||||
public static final String SELF_TYPE_ARGUMENT = "Self";
|
||||
public static final String THAT_ARGUMENT = "that";
|
||||
public static final String FROM_MEMBER = "from";
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package org.enso.compiler;
|
||||
package org.enso.compiler.core;
|
||||
|
||||
import com.oracle.truffle.api.source.Source;
|
||||
import org.enso.compiler.core.IR;
|
||||
import org.enso.syntax2.Parser;
|
||||
import org.enso.syntax2.Tree;
|
||||
|
||||
public final class EnsoCompiler implements AutoCloseable {
|
||||
public final class EnsoParser implements AutoCloseable {
|
||||
private final Parser parser;
|
||||
|
||||
public EnsoCompiler() {
|
||||
public EnsoParser() {
|
||||
Parser p;
|
||||
try {
|
||||
p = Parser.create();
|
||||
@ -31,15 +29,6 @@ public final class EnsoCompiler implements AutoCloseable {
|
||||
return generateIR(tree);
|
||||
}
|
||||
|
||||
IR.Module compile(Source src) {
|
||||
var tree = parse(src);
|
||||
return generateIR(tree);
|
||||
}
|
||||
|
||||
public Tree parse(Source src) {
|
||||
return parser.parse(src.getCharacters());
|
||||
}
|
||||
|
||||
public Tree parse(CharSequence src) {
|
||||
return parser.parse(src);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.enso.compiler;
|
||||
package org.enso.compiler.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
@ -61,7 +61,6 @@ import org.enso.compiler.core.IR$Type$Function;
|
||||
import org.enso.compiler.core.IR.IdentifiedLocation;
|
||||
import org.enso.compiler.core.ir.DiagnosticStorage;
|
||||
import org.enso.compiler.core.ir.MetadataStorage;
|
||||
import org.enso.interpreter.epb.EpbParser;
|
||||
import org.enso.syntax.text.Location;
|
||||
import org.enso.syntax2.ArgumentDefinition;
|
||||
import org.enso.syntax2.Base;
|
||||
@ -279,7 +278,7 @@ final class TreeToIr {
|
||||
var methodRef = new IR$Name$MethodReference(Option.empty(), buildName(name), nameLoc, meta(), diag());
|
||||
var args = translateArgumentsDefinition(fn.getArgs());
|
||||
var languageName = fn.getLanguage().codeRepr();
|
||||
var language = EpbParser.ForeignLanguage.getBySyntacticTag(languageName);
|
||||
var language = languageName;
|
||||
if (language == null) {
|
||||
var message = "Language '" + languageName + "' is not a supported polyglot language.";
|
||||
var error = translateSyntaxError(inputAst, new IR$Error$Syntax$InvalidForeignDefinition(message));
|
||||
@ -424,7 +423,7 @@ final class TreeToIr {
|
||||
var name = buildName(fn.getName());
|
||||
var args = translateArgumentsDefinition(fn.getArgs());
|
||||
var languageName = fn.getLanguage().codeRepr();
|
||||
var language = EpbParser.ForeignLanguage.getBySyntacticTag(languageName);
|
||||
var language = languageName;
|
||||
if (language == null) {
|
||||
var message = "Language '" + languageName + "' is not a supported polyglot language.";
|
||||
var error = translateSyntaxError(inputAst, new IR$Error$Syntax$InvalidForeignDefinition(message));
|
@ -0,0 +1,3 @@
|
||||
package org.enso.compiler.core
|
||||
|
||||
abstract class CompilerStub {}
|
@ -1,12 +1,10 @@
|
||||
package org.enso.compiler.core
|
||||
|
||||
import org.enso.interpreter.Constants
|
||||
import org.enso.compiler.core.ConstantsNames
|
||||
import org.enso.compiler.core.IR.{Expression, IdentifiedLocation}
|
||||
import org.enso.compiler.core.ir.MetadataStorage.MetadataPair
|
||||
import org.enso.compiler.core.ir.{DiagnosticStorage, MetadataStorage}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.interpreter.epb.EpbParser
|
||||
import org.enso.compiler.core.ir.ProcessingPass
|
||||
import org.enso.syntax.text.{Debug, Location}
|
||||
import com.oracle.truffle.api.source.Source
|
||||
|
||||
@ -2986,7 +2984,7 @@ object IR {
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
) extends Name {
|
||||
override protected var id: Identifier = randomId
|
||||
override val name: String = Constants.Names.SELF_ARGUMENT
|
||||
override val name: String = ConstantsNames.SELF_ARGUMENT
|
||||
|
||||
/** Creates a copy of `self`.
|
||||
*
|
||||
@ -3062,7 +3060,7 @@ object IR {
|
||||
override val diagnostics: DiagnosticStorage = DiagnosticStorage()
|
||||
) extends Name {
|
||||
override protected var id: Identifier = randomId
|
||||
override val name: String = Constants.Names.SELF_TYPE_ARGUMENT
|
||||
override val name: String = ConstantsNames.SELF_TYPE_ARGUMENT
|
||||
|
||||
/** Creates a copy of `Self`.
|
||||
*
|
||||
@ -6822,7 +6820,7 @@ object IR {
|
||||
* @param diagnostics compiler diagnostics for this node
|
||||
*/
|
||||
sealed case class Definition(
|
||||
lang: EpbParser.ForeignLanguage,
|
||||
lang: String,
|
||||
code: String,
|
||||
override val location: Option[IdentifiedLocation],
|
||||
override val passData: MetadataStorage = MetadataStorage(),
|
||||
@ -6842,7 +6840,7 @@ object IR {
|
||||
* @return a copy of `this`, updated with the specified values
|
||||
*/
|
||||
def copy(
|
||||
lang: EpbParser.ForeignLanguage = lang,
|
||||
lang: String = lang,
|
||||
code: String = code,
|
||||
location: Option[IdentifiedLocation] = location,
|
||||
passData: MetadataStorage = passData,
|
||||
@ -9062,7 +9060,9 @@ object IR {
|
||||
* @param metadataPair the pair to add to the storage
|
||||
* @tparam K the concrete type of the pass
|
||||
*/
|
||||
def updateMetadata[K <: IRPass](metadataPair: MetadataPair[K]): T = {
|
||||
def updateMetadata[K <: ProcessingPass](
|
||||
metadataPair: MetadataPair[K]
|
||||
): T = {
|
||||
ir.passData.update(metadataPair)
|
||||
ir
|
||||
}
|
||||
@ -9073,7 +9073,7 @@ object IR {
|
||||
* @tparam K the concrete type of `pass`
|
||||
* @return the metadata for `pass`, if it exists
|
||||
*/
|
||||
def getMetadata[K <: IRPass](pass: K): Option[pass.Metadata] = {
|
||||
def getMetadata[K <: ProcessingPass](pass: K): Option[pass.Metadata] = {
|
||||
ir.passData.get(pass)
|
||||
}
|
||||
|
||||
@ -9086,8 +9086,8 @@ object IR {
|
||||
* @return the metadata for `pass`, if it exists
|
||||
*/
|
||||
@throws[CompilerError]
|
||||
def unsafeGetMetadata[K <: IRPass](
|
||||
pass: IRPass,
|
||||
def unsafeGetMetadata[K <: ProcessingPass](
|
||||
pass: ProcessingPass,
|
||||
msg: => String
|
||||
): pass.Metadata = {
|
||||
ir.passData.getUnsafe(pass)(msg)
|
@ -1,9 +1,9 @@
|
||||
package org.enso.compiler.core.ir
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.core.ir.MetadataStorage.MetadataPair
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.core.ir.ProcessingPass
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.core.CompilerStub
|
||||
|
||||
/** Stores metadata for the various passes.
|
||||
*
|
||||
@ -14,8 +14,8 @@ import org.enso.compiler.pass.IRPass
|
||||
class MetadataStorage(
|
||||
startingMeta: Seq[MetadataPair[_]] = Seq()
|
||||
) extends Serializable {
|
||||
private var metadata: Map[IRPass, Any] = Map(
|
||||
startingMeta.map(_.asPair.asInstanceOf[(IRPass, Any)]): _*
|
||||
private var metadata: Map[ProcessingPass, Any] = Map(
|
||||
startingMeta.map(_.asPair.asInstanceOf[(ProcessingPass, Any)]): _*
|
||||
)
|
||||
|
||||
/** Adds a metadata pair to the node metadata.
|
||||
@ -25,7 +25,7 @@ class MetadataStorage(
|
||||
* @param metadataPair the pair to add to the storage
|
||||
* @tparam K the concrete type of the pass
|
||||
*/
|
||||
def update[K <: IRPass](metadataPair: MetadataPair[K]): Unit = {
|
||||
def update[K <: ProcessingPass](metadataPair: MetadataPair[K]): Unit = {
|
||||
update(metadataPair.pass)(metadataPair.metadata)
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ class MetadataStorage(
|
||||
* @param newMeta the metadata to add for `pass`
|
||||
* @tparam K the concrete type of `pass`
|
||||
*/
|
||||
def update[K <: IRPass](pass: K)(newMeta: pass.Metadata): Unit = {
|
||||
def update[K <: ProcessingPass](pass: K)(newMeta: pass.Metadata): Unit = {
|
||||
metadata = metadata + (pass -> newMeta)
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ class MetadataStorage(
|
||||
* @tparam K the concrete type of `pass`
|
||||
* @return the removed metadata for that pass, if it exists
|
||||
*/
|
||||
def remove[K <: IRPass](pass: K): Option[pass.Metadata] = {
|
||||
def remove[K <: ProcessingPass](pass: K): Option[pass.Metadata] = {
|
||||
if (metadata.contains(pass)) {
|
||||
val res = get(pass)
|
||||
metadata = metadata.filter(t => t._1 != pass)
|
||||
@ -62,7 +62,7 @@ class MetadataStorage(
|
||||
* @tparam K the concrete type of `pass`
|
||||
* @return the metadata for `pass`, if it exists
|
||||
*/
|
||||
def get[K <: IRPass](pass: K): Option[pass.Metadata] = {
|
||||
def get[K <: ProcessingPass](pass: K): Option[pass.Metadata] = {
|
||||
metadata.get(pass).map(_.asInstanceOf[pass.Metadata])
|
||||
}
|
||||
|
||||
@ -74,8 +74,7 @@ class MetadataStorage(
|
||||
* @throws CompilerError if no metadata exists for `pass`
|
||||
* @return the metadata for `pass`, if it exists
|
||||
*/
|
||||
@throws[CompilerError]
|
||||
def getUnsafe[K <: IRPass](
|
||||
def getUnsafe[K <: ProcessingPass](
|
||||
pass: K
|
||||
)(msg: => String = s"Missing metadata for pass $pass"): pass.Metadata = {
|
||||
get(pass).getOrElse(throw new CompilerError(msg))
|
||||
@ -99,8 +98,12 @@ class MetadataStorage(
|
||||
* @tparam V the output value type
|
||||
* @return a map containing the results of transforming the metadata storage
|
||||
*/
|
||||
def map[K, V](f: (IRPass, IRPass.Metadata) => (K, V)): Map[K, V] = {
|
||||
metadata.asInstanceOf[Map[IRPass, IRPass.Metadata]].map(f.tupled)
|
||||
def map[K, V](
|
||||
f: (ProcessingPass, ProcessingPass.Metadata) => (K, V)
|
||||
): Map[K, V] = {
|
||||
metadata
|
||||
.asInstanceOf[Map[ProcessingPass, ProcessingPass.Metadata]]
|
||||
.map(f.tupled)
|
||||
}
|
||||
|
||||
/** Prepares the metadata for serialization.
|
||||
@ -118,10 +121,12 @@ class MetadataStorage(
|
||||
*
|
||||
* @param compiler the Enso compiler
|
||||
*/
|
||||
def prepareForSerialization(compiler: Compiler): Unit = {
|
||||
def prepareForSerialization(compiler: CompilerStub): Unit = {
|
||||
this.metadata = metadata.map { case (pass, value) =>
|
||||
val newVal =
|
||||
value.asInstanceOf[IRPass.Metadata].prepareForSerialization(compiler)
|
||||
val metadata = value.asInstanceOf[ProcessingPass.Metadata]
|
||||
val newVal = metadata
|
||||
// HP: could avoid casting by wrapping Metadata with some global compiler reference
|
||||
.prepareForSerialization(compiler.asInstanceOf[metadata.Compiler])
|
||||
(pass, newVal)
|
||||
}
|
||||
}
|
||||
@ -136,11 +141,11 @@ class MetadataStorage(
|
||||
* @param compiler the Enso compiler
|
||||
* @return `true` if restoration was successful, `false` otherwise
|
||||
*/
|
||||
def restoreFromSerialization(compiler: Compiler): Boolean = {
|
||||
def restoreFromSerialization(compiler: CompilerStub): Boolean = {
|
||||
this.metadata = metadata.map { case (pass, value) =>
|
||||
val meta = value
|
||||
.asInstanceOf[IRPass.Metadata]
|
||||
.restoreFromSerialization(compiler)
|
||||
val metadata = value.asInstanceOf[ProcessingPass.Metadata]
|
||||
val meta = metadata
|
||||
.restoreFromSerialization(compiler.asInstanceOf[metadata.Compiler])
|
||||
.getOrElse(return false)
|
||||
(pass, meta)
|
||||
}
|
||||
@ -167,7 +172,7 @@ class MetadataStorage(
|
||||
val res = MetadataStorage()
|
||||
res.metadata = for {
|
||||
(pass, meta) <- this.metadata
|
||||
duplicated <- meta.asInstanceOf[IRPass.Metadata].duplicate()
|
||||
duplicated <- meta.asInstanceOf[ProcessingPass.Metadata].duplicate()
|
||||
} yield (pass, duplicated)
|
||||
|
||||
res
|
||||
@ -188,7 +193,7 @@ object MetadataStorage extends MetadataStorageSyntax {
|
||||
*
|
||||
* @tparam P the concrete pass type
|
||||
*/
|
||||
sealed trait MetadataPair[P <: IRPass] {
|
||||
sealed trait MetadataPair[P <: ProcessingPass] {
|
||||
|
||||
/** The pass itself. */
|
||||
val pass: P
|
||||
@ -231,7 +236,7 @@ object MetadataStorage extends MetadataStorageSyntax {
|
||||
* @tparam P the concrete type of `newPass`
|
||||
* @return a metadata pair containing `newPass` and `configuration`
|
||||
*/
|
||||
def apply[P <: IRPass](newPass: P)(
|
||||
def apply[P <: ProcessingPass](newPass: P)(
|
||||
newMetadata: newPass.Metadata
|
||||
): MetadataPair[newPass.type] = {
|
||||
new MetadataPair[newPass.type] {
|
||||
@ -249,7 +254,7 @@ trait MetadataStorageSyntax {
|
||||
* @param pass the pass to create a pair with
|
||||
* @tparam P the concrete type of `pass`
|
||||
*/
|
||||
implicit final class ToPair[P <: IRPass](val pass: P) {
|
||||
implicit final class ToPair[P <: ProcessingPass](val pass: P) {
|
||||
|
||||
/** Concatenates [[pass]] with a metadata object for that pass.
|
||||
*
|
@ -0,0 +1,60 @@
|
||||
package org.enso.compiler.core.ir
|
||||
|
||||
import org.enso.compiler.core.CompilerStub
|
||||
|
||||
trait ProcessingPass extends Serializable {
|
||||
|
||||
/** The type of the metadata object that the pass writes to the IR. */
|
||||
type Metadata <: ProcessingPass.Metadata
|
||||
|
||||
}
|
||||
|
||||
object ProcessingPass {
|
||||
trait Metadata extends Serializable {
|
||||
|
||||
type Compiler <: CompilerStub
|
||||
|
||||
/** The name of the metadata as a string. */
|
||||
val metadataName: String
|
||||
|
||||
/** Prepares the metadata for serialization.
|
||||
*
|
||||
* Metadata prepared for serialization should not contain any links that
|
||||
* span more than one module, or any other properties that are problematic
|
||||
* when serialized.
|
||||
*
|
||||
* Due to the type safety properties of
|
||||
* [[org.enso.compiler.core.ir.MetadataStorage]], to allow this conversion
|
||||
* to work it must be type-refined to return `typeof this`. To that end,
|
||||
* there is no default definition for this method.
|
||||
*
|
||||
* @param compiler the Enso compiler
|
||||
* @return `this`, but prepared for serialization
|
||||
*/
|
||||
def prepareForSerialization(compiler: Compiler): Metadata
|
||||
|
||||
/** Restores metadata after it has been deserialized.
|
||||
*
|
||||
* Due to the type safety properties of
|
||||
* [[org.enso.compiler.core.ir.MetadataStorage]], to allow this conversion
|
||||
* to work it must be type-refined to return `typeof this`. To that end,
|
||||
* there is no default definition for this method.
|
||||
*
|
||||
* @param compiler the Enso compiler
|
||||
* @return `this`, but restored from serialization, or [[None]] if
|
||||
* restoration could not be performed
|
||||
*/
|
||||
def restoreFromSerialization(compiler: Compiler): Option[Metadata]
|
||||
|
||||
/** Creates a duplicate of this metadata if applicable.
|
||||
*
|
||||
* This method should employ deep-copy semantics where appropriate. It may
|
||||
* return None to indicate that this metadata should not be preserved
|
||||
* during duplication.
|
||||
*
|
||||
* @return Some duplicate of this metadata or None if this metadata should
|
||||
* not be preserved
|
||||
*/
|
||||
def duplicate(): Option[Metadata]
|
||||
}
|
||||
}
|
@ -1,25 +1,28 @@
|
||||
package org.enso.compiler;
|
||||
package org.enso.compiler.core;
|
||||
|
||||
import com.oracle.truffle.api.source.Source;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.function.Function;
|
||||
import org.enso.compiler.core.IR;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.oracle.truffle.api.source.Source;
|
||||
|
||||
public class EnsoCompilerTest {
|
||||
private static EnsoCompiler ensoCompiler;
|
||||
public class EnsoParserTest {
|
||||
private static EnsoParser ensoCompiler;
|
||||
|
||||
@BeforeClass
|
||||
public static void initEnsoCompiler() {
|
||||
ensoCompiler = new EnsoCompiler();
|
||||
public static void initEnsoParser() {
|
||||
ensoCompiler = new EnsoParser();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeEnsoCompiler() throws Exception {
|
||||
public static void closeEnsoParser() throws Exception {
|
||||
ensoCompiler.close();
|
||||
}
|
||||
|
||||
@ -1262,17 +1265,112 @@ public class EnsoCompilerTest {
|
||||
var old = compile(code1);
|
||||
var now = compile(code2);
|
||||
var msg = "IR for " + code1 + " shall be equal to IR for " + code2;
|
||||
CompilerTest.assertIR(msg, old, now);
|
||||
assertIR(msg, old, now);
|
||||
}
|
||||
|
||||
private static IR.Module compile(String code) {
|
||||
return compile(ensoCompiler, code);
|
||||
}
|
||||
|
||||
public static IR.Module compile(EnsoCompiler c, String code) {
|
||||
public static IR.Module compile(EnsoParser c, String code) {
|
||||
var src = Source.newBuilder("enso", code, "test-" + Integer.toHexString(code.hashCode()) + ".enso").build();
|
||||
var ir = c.compile(src);
|
||||
var ir = c.compile(src.getCharacters());
|
||||
assertNotNull("IR was generated", ir);
|
||||
return ir;
|
||||
}
|
||||
|
||||
static void assertIR(String msg, IR.Module old, IR.Module now) throws IOException {
|
||||
Function<IR, String> filter = f -> simplifyIR(f, true, true, false);
|
||||
String ir1 = filter.apply(old);
|
||||
String ir2 = filter.apply(now);
|
||||
if (!ir1.equals(ir2)) {
|
||||
String name = findTestMethodName();
|
||||
var home = new File(System.getProperty("java.io.tmpdir")).toPath();
|
||||
var file1 = home.resolve(name + ".1");
|
||||
var file2 = home.resolve(name + ".2");
|
||||
Files.writeString(file1, ir1, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||
Files.writeString(file2, ir2, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
|
||||
assertEquals(msg, file1, file2);
|
||||
}
|
||||
}
|
||||
|
||||
private static String findTestMethodName() {
|
||||
for (var e : new Exception().getStackTrace()) {
|
||||
if (e.getMethodName().startsWith("test")) {
|
||||
return e.getMethodName();
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
/** Takes an {@link IR} and converts it to text representation suitable for
|
||||
* "diffing" while "simplifying" it.
|
||||
*
|
||||
* @param ir the intermediate representation
|
||||
* @param noIds remove all UUIDs or keep them? Multiple runs usually assign
|
||||
* random/different UUIDs to various IR elements. Removing them is a best
|
||||
* way to make the converted text comparable
|
||||
* @param noLocations locations may slightly differ. Usually off-by-one.
|
||||
* Especially when running old and new parser in parallel - removing them
|
||||
* may be useful
|
||||
* @param lessDocs documentation often isn't an essential part of the IR
|
||||
* one can easily remove it by specifying {@code false}
|
||||
* @return string representation of the IR
|
||||
*/
|
||||
private static String simplifyIR(IR ir, boolean noIds, boolean noLocations, boolean lessDocs) {
|
||||
String txt = ir.pretty();
|
||||
if (noIds) {
|
||||
txt = txt.replaceAll("[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]\\-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]\\-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]\\-[0-9a-f][0-9a-f][0-9a-f][0-9a-f]\\-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]", "_");
|
||||
}
|
||||
if (noLocations) {
|
||||
for (;;) {
|
||||
final String pref = " Location(";
|
||||
int at = txt.indexOf(pref);
|
||||
if (at == -1) {
|
||||
break;
|
||||
}
|
||||
int to = at + pref.length();
|
||||
int depth = 1;
|
||||
while (depth > 0) {
|
||||
switch (txt.charAt(to)) {
|
||||
case '(' -> depth++;
|
||||
case ')' -> depth--;
|
||||
}
|
||||
to++;
|
||||
}
|
||||
txt = txt.substring(0, at) + "Location[_]" + txt.substring(to);
|
||||
}
|
||||
}
|
||||
if (lessDocs) {
|
||||
for (;;) {
|
||||
final String pref = "IR.Comment.Documentation(";
|
||||
int at = txt.indexOf(pref);
|
||||
if (at == -1) {
|
||||
break;
|
||||
}
|
||||
int to = txt.indexOf("location =", at + pref.length());
|
||||
txt = txt.substring(0, at) + "IR.Comment.Doc(" + txt.substring(to);
|
||||
}
|
||||
for (;;) {
|
||||
final String pref = "IR.Case.Pattern.Doc(";
|
||||
int at = txt.indexOf(pref);
|
||||
if (at == -1) {
|
||||
break;
|
||||
}
|
||||
int to = txt.indexOf("location =", at + pref.length());
|
||||
txt = txt.substring(0, at) + "IR.Comment.CaseDoc(" + txt.substring(to);
|
||||
}
|
||||
}
|
||||
for (;;) {
|
||||
final String pref = "IR.Error.Syntax(";
|
||||
int at = txt.indexOf(pref);
|
||||
if (at == -1) {
|
||||
break;
|
||||
}
|
||||
int to = txt.indexOf("reason =", at + pref.length());
|
||||
txt = txt.substring(0, at) + "IR.Error.Syntax (" + txt.substring(to);
|
||||
}
|
||||
return txt;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.enso.compiler.core;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ParserDependenciesTest {
|
||||
|
||||
public ParserDependenciesTest() {}
|
||||
|
||||
@Test
|
||||
public void avoidCatsDependency() {
|
||||
try {
|
||||
var clazz = Class.forName("cats.Align");
|
||||
assertNull("No cats classes shall be available in the parser project", clazz);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
// correct
|
||||
}
|
||||
}
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
package org.enso.interpreter;
|
||||
|
||||
import org.enso.compiler.core.ConstantsNames;
|
||||
|
||||
/** Language-level constants for use throughout the program. */
|
||||
public class Constants {
|
||||
public static final String SCOPE_SEPARATOR = ".";
|
||||
|
||||
/** Names for different language elements. */
|
||||
public static class Names {
|
||||
public static final String SELF_ARGUMENT = "self";
|
||||
public static final String SELF_TYPE_ARGUMENT = "Self";
|
||||
public static final String THAT_ARGUMENT = "that";
|
||||
public static final String FROM_MEMBER = "from";
|
||||
public static final String SELF_ARGUMENT = ConstantsNames.SELF_ARGUMENT;
|
||||
public static final String SELF_TYPE_ARGUMENT = ConstantsNames.SELF_TYPE_ARGUMENT;
|
||||
public static final String THAT_ARGUMENT = ConstantsNames.THAT_ARGUMENT;
|
||||
public static final String FROM_MEMBER = ConstantsNames.FROM_MEMBER;
|
||||
}
|
||||
|
||||
/** Cache sizes for different AST nodes. */
|
||||
|
@ -19,7 +19,7 @@ import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import org.enso.compiler.Passes;
|
||||
import org.enso.compiler.context.FreshNameSupply;
|
||||
import org.enso.compiler.exception.CompilerError;
|
||||
import org.enso.compiler.core.CompilerError;
|
||||
import org.enso.compiler.phase.BuiltinsIrBuilder;
|
||||
import org.enso.interpreter.EnsoLanguage;
|
||||
import org.enso.interpreter.dsl.TypeProcessor;
|
||||
|
@ -4,9 +4,12 @@ import com.oracle.truffle.api.TruffleLogger
|
||||
import com.oracle.truffle.api.source.{Source, SourceSection}
|
||||
import org.enso.compiler.codegen.{IrToTruffle, RuntimeStubsGenerator}
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.core.CompilerStub
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.EnsoParser
|
||||
import org.enso.compiler.data.{BindingsMap, CompilerConfig}
|
||||
import org.enso.compiler.exception.{CompilationAbortedException, CompilerError}
|
||||
import org.enso.compiler.exception.CompilationAbortedException
|
||||
import org.enso.compiler.pass.PassManager
|
||||
import org.enso.compiler.pass.analyse._
|
||||
import org.enso.compiler.phase.{
|
||||
@ -21,8 +24,8 @@ import org.enso.interpreter.runtime.scope.{LocalScope, ModuleScope}
|
||||
import org.enso.interpreter.runtime.{EnsoContext, Module}
|
||||
import org.enso.pkg.QualifiedName
|
||||
import org.enso.polyglot.{LanguageInfo, RuntimeOptions}
|
||||
import org.enso.syntax.text.Parser
|
||||
import org.enso.syntax.text.Parser.IDMap
|
||||
//import org.enso.syntax.text.Parser
|
||||
//import org.enso.syntax.text.Parser.IDMap
|
||||
import org.enso.syntax2.Tree
|
||||
|
||||
import java.io.{PrintStream, StringReader}
|
||||
@ -48,7 +51,7 @@ class Compiler(
|
||||
val builtins: Builtins,
|
||||
val packageRepository: PackageRepository,
|
||||
config: CompilerConfig
|
||||
) {
|
||||
) extends CompilerStub {
|
||||
private val freshNameSupply: FreshNameSupply = new FreshNameSupply
|
||||
private val passes: Passes = new Passes(config)
|
||||
private val passManager: PassManager = passes.passManager
|
||||
@ -68,7 +71,7 @@ class Compiler(
|
||||
if (config.outputRedirect.isDefined)
|
||||
new PrintStream(config.outputRedirect.get)
|
||||
else context.getOut
|
||||
private lazy val ensoCompiler: EnsoCompiler = new EnsoCompiler()
|
||||
private lazy val ensoCompiler: EnsoParser = new EnsoParser()
|
||||
|
||||
/** The thread pool that handles parsing of modules. */
|
||||
private val pool: ExecutorService = if (config.parallelParsing) {
|
||||
@ -591,7 +594,7 @@ class Compiler(
|
||||
)
|
||||
|
||||
val src = module.getSource
|
||||
val tree = ensoCompiler.parse(src)
|
||||
val tree = ensoCompiler.parse(src.getCharacters)
|
||||
val expr = ensoCompiler.generateIR(tree)
|
||||
|
||||
val exprWithModuleExports =
|
||||
@ -663,7 +666,7 @@ class Compiler(
|
||||
"<interactive_source>"
|
||||
)
|
||||
.build()
|
||||
val tree = ensoCompiler.parse(source)
|
||||
val tree = ensoCompiler.parse(source.getCharacters)
|
||||
|
||||
ensoCompiler.generateIRInline(tree).flatMap { ir =>
|
||||
val compilerOutput = runCompilerPhasesInline(ir, newContext)
|
||||
@ -713,15 +716,16 @@ class Compiler(
|
||||
* @param source The inline code to parse
|
||||
* @return A Tree representation of `source`
|
||||
*/
|
||||
def parseInline(source: Source): Tree = ensoCompiler.parse(source)
|
||||
def parseInline(source: Source): Tree =
|
||||
ensoCompiler.parse(source.getCharacters())
|
||||
|
||||
/** Parses the metadata of the provided language sources.
|
||||
*
|
||||
* @param source the code to parse
|
||||
* @return the source metadata
|
||||
*/
|
||||
def parseMeta(source: CharSequence): IDMap =
|
||||
Parser().splitMeta(source.toString)._2
|
||||
// def parseMeta(source: CharSequence): IDMap =
|
||||
// Parser().splitMeta(source.toString)._2
|
||||
|
||||
/** Enhances the provided IR with import/export statements for the provided list
|
||||
* of fully qualified names of modules. The statements are considered to be "synthetic" i.e. compiler-generated.
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.enso.compiler.codegen
|
||||
|
||||
import com.oracle.truffle.api.source.{Source, SourceSection}
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Import
|
||||
import org.enso.compiler.core.IR.Name.Special
|
||||
@ -11,7 +12,7 @@ import org.enso.compiler.data.BindingsMap.{
|
||||
ResolvedModule
|
||||
}
|
||||
import org.enso.compiler.data.{BindingsMap, CompilerConfig}
|
||||
import org.enso.compiler.exception.{BadPatternMatch, CompilerError}
|
||||
import org.enso.compiler.exception.BadPatternMatch
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis.Graph.{Scope => AliasScope}
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis.{Graph => AliasGraph}
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
@ -1663,7 +1664,7 @@ class IrToTruffle(
|
||||
val bodyExpr = body match {
|
||||
case IR.Foreign.Definition(lang, code, _, _, _) =>
|
||||
buildForeignBody(
|
||||
lang,
|
||||
EpbParser.ForeignLanguage.getBySyntacticTag(lang),
|
||||
code,
|
||||
arguments.map(_.name.name),
|
||||
argSlotIdxs
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.enso.compiler.codegen
|
||||
|
||||
import org.enso.compiler.data.BindingsMap
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.analyse.BindingAnalysis
|
||||
import org.enso.interpreter.runtime.Module
|
||||
import org.enso.interpreter.runtime.builtin.Builtins
|
||||
|
@ -1,10 +1,10 @@
|
||||
package org.enso.compiler.data
|
||||
|
||||
import org.enso.compiler.{Compiler, PackageRepository}
|
||||
import org.enso.compiler.{PackageRepository}
|
||||
import org.enso.compiler.PackageRepository.ModuleMap
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.data.BindingsMap.{DefinedEntity, ModuleReference}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.BindingAnalysis
|
||||
import org.enso.compiler.pass.resolve.MethodDefinitions
|
||||
@ -26,12 +26,12 @@ import scala.annotation.unused
|
||||
case class BindingsMap(
|
||||
definedEntities: List[DefinedEntity],
|
||||
currentModule: ModuleReference
|
||||
) extends IRPass.Metadata {
|
||||
) extends IRPass.IRMetadata {
|
||||
import BindingsMap._
|
||||
|
||||
override val metadataName: String = "Bindings Map"
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(this)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(this)
|
||||
|
||||
/** Other modules, imported by [[currentModule]].
|
||||
*/
|
||||
@ -979,7 +979,7 @@ object BindingsMap {
|
||||
}
|
||||
|
||||
/** A metadata-friendly storage for resolutions */
|
||||
case class Resolution(target: ResolvedName) extends IRPass.Metadata {
|
||||
case class Resolution(target: ResolvedName) extends IRPass.IRMetadata {
|
||||
|
||||
/** The name of the metadata as a string. */
|
||||
override val metadataName: String = "Resolution"
|
||||
@ -1005,7 +1005,7 @@ object BindingsMap {
|
||||
* @return Some duplicate of this metadata or None if this metadata should
|
||||
* not be preserved
|
||||
*/
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(this)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(this)
|
||||
}
|
||||
|
||||
/** A reference to a module.
|
||||
|
@ -1,8 +0,0 @@
|
||||
package org.enso.compiler.exception
|
||||
|
||||
/** A compiler internal error for "should never happen" situations.
|
||||
*
|
||||
* @param message the message for the exception
|
||||
*/
|
||||
class CompilerError(message: String)
|
||||
extends RuntimeException(s"Compiler Internal Error: $message")
|
@ -1,9 +1,9 @@
|
||||
package org.enso.compiler.pass
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.ir.ProcessingPass
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import shapeless.=:!=
|
||||
|
||||
import java.util.UUID
|
||||
@ -19,13 +19,13 @@ import scala.reflect.ClassTag
|
||||
* its header the requirements it has for pass configuration and for passes
|
||||
* that must run before it.
|
||||
*/
|
||||
trait IRPass extends Serializable {
|
||||
trait IRPass extends ProcessingPass {
|
||||
|
||||
/** An identifier for the pass. Useful for keying it in maps. */
|
||||
val key: IRPass.Identifier = IRPass.genId
|
||||
|
||||
/** The type of the metadata object that the pass writes to the IR. */
|
||||
type Metadata <: IRPass.Metadata
|
||||
type Metadata <: ProcessingPass.Metadata
|
||||
|
||||
/** The type of configuration for the pass. */
|
||||
type Config <: IRPass.Configuration
|
||||
@ -114,40 +114,14 @@ object IRPass {
|
||||
* they are guaranteed to have `restoreFromSerialization` called after they
|
||||
* have been deserialized and before any other operations occur.
|
||||
*/
|
||||
trait Metadata extends Serializable {
|
||||
trait IRMetadata extends ProcessingPass.Metadata {
|
||||
|
||||
type Metadata = IRMetadata
|
||||
type Compiler = org.enso.compiler.Compiler
|
||||
|
||||
/** The name of the metadata as a string. */
|
||||
val metadataName: String
|
||||
|
||||
/** Prepares the metadata for serialization.
|
||||
*
|
||||
* Metadata prepared for serialization should not contain any links that
|
||||
* span more than one module, or any other properties that are problematic
|
||||
* when serialized.
|
||||
*
|
||||
* Due to the type safety properties of
|
||||
* [[org.enso.compiler.core.ir.MetadataStorage]], to allow this conversion
|
||||
* to work it must be type-refined to return `typeof this`. To that end,
|
||||
* there is no default definition for this method.
|
||||
*
|
||||
* @param compiler the Enso compiler
|
||||
* @return `this`, but prepared for serialization
|
||||
*/
|
||||
def prepareForSerialization(compiler: Compiler): Metadata
|
||||
|
||||
/** Restores metadata after it has been deserialized.
|
||||
*
|
||||
* Due to the type safety properties of
|
||||
* [[org.enso.compiler.core.ir.MetadataStorage]], to allow this conversion
|
||||
* to work it must be type-refined to return `typeof this`. To that end,
|
||||
* there is no default definition for this method.
|
||||
*
|
||||
* @param compiler the Enso compiler
|
||||
* @return `this`, but restored from serialization, or [[None]] if
|
||||
* restoration could not be performed
|
||||
*/
|
||||
def restoreFromSerialization(compiler: Compiler): Option[Metadata]
|
||||
|
||||
/** Casts the pass to the provided type.
|
||||
*
|
||||
* @param ev ensures that the pass type must be specified
|
||||
@ -195,7 +169,7 @@ object IRPass {
|
||||
object Metadata {
|
||||
|
||||
/** An empty metadata type for passes that do not create any metadata. */
|
||||
sealed case class Empty() extends Metadata {
|
||||
sealed case class Empty() extends IRMetadata {
|
||||
override val metadataName: String = "Empty"
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -2,7 +2,7 @@ package org.enso.compiler.pass
|
||||
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
|
||||
// TODO [AA] In the future, the pass ordering should be _computed_ from the list
|
||||
// of available passes, rather than just verified.
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.enso.compiler.pass.analyse
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Pattern
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis.Graph.{Occurrence, Scope}
|
||||
import org.enso.compiler.pass.desugar._
|
||||
@ -801,7 +800,7 @@ case object AliasAnalysis extends IRPass {
|
||||
// === Data Definitions =====================================================
|
||||
|
||||
/** Information about the aliasing state for a given IR node. */
|
||||
sealed trait Info extends IRPass.Metadata {
|
||||
sealed trait Info extends IRPass.IRMetadata {
|
||||
|
||||
/** The aliasing graph. */
|
||||
val graph: Graph
|
||||
@ -830,7 +829,7 @@ case object AliasAnalysis extends IRPass {
|
||||
): Option[Root] = Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = None
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = None
|
||||
}
|
||||
|
||||
/** Aliasing information about a child scope.
|
||||
@ -853,7 +852,7 @@ case object AliasAnalysis extends IRPass {
|
||||
): Option[Child] = Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = None
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = None
|
||||
}
|
||||
}
|
||||
|
||||
@ -878,7 +877,7 @@ case object AliasAnalysis extends IRPass {
|
||||
): Option[Occurrence] = Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = None
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Import
|
||||
import org.enso.compiler.core.IR.Module.Scope.Import.Polyglot
|
||||
import org.enso.compiler.data.BindingsMap
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
|
||||
import scala.collection.mutable
|
||||
|
@ -4,7 +4,7 @@ import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage.ToPair
|
||||
import org.enso.compiler.data.BindingsMap.{Resolution, ResolvedMethod}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.desugar.ComplexType
|
||||
import org.enso.compiler.pass.resolve.{
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.enso.compiler.pass.analyse
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition.Method
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.desugar._
|
||||
|
||||
@ -185,7 +184,7 @@ case object CachePreferenceAnalysis extends IRPass {
|
||||
*/
|
||||
sealed case class WeightInfo(
|
||||
weights: mutable.HashMap[IR.ExternalId, Double] = mutable.HashMap()
|
||||
) extends IRPass.Metadata {
|
||||
) extends IRPass.IRMetadata {
|
||||
|
||||
/** The name of the metadata as a string. */
|
||||
override val metadataName: String = "CachePreferenceAnalysis.Weights"
|
||||
@ -218,7 +217,7 @@ case object CachePreferenceAnalysis extends IRPass {
|
||||
def asJavaWeights: util.Map[IR.ExternalId, java.lang.Double] =
|
||||
weights.asJava.asInstanceOf[util.Map[IR.ExternalId, java.lang.Double]]
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] =
|
||||
override def duplicate(): Option[IRPass.IRMetadata] =
|
||||
Some(copy(weights = this.weights))
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,11 @@
|
||||
package org.enso.compiler.pass.analyse
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition.Method
|
||||
import org.enso.compiler.core.IR.{ExternalId, Pattern}
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.DataflowAnalysis.DependencyInfo.Type.asStatic
|
||||
|
||||
@ -956,7 +955,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
sealed case class DependencyInfo(
|
||||
dependents: DependencyMapping = DependencyMapping(),
|
||||
dependencies: DependencyMapping = DependencyMapping()
|
||||
) extends IRPass.Metadata {
|
||||
) extends IRPass.IRMetadata {
|
||||
override val metadataName: String = "DataflowAnalysis.DependencyInfo"
|
||||
|
||||
/** Combines two dependency information containers.
|
||||
@ -971,7 +970,7 @@ case object DataflowAnalysis extends IRPass {
|
||||
)
|
||||
}
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] = None
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = None
|
||||
|
||||
/** @inheritdoc */
|
||||
override def prepareForSerialization(compiler: Compiler): DependencyInfo =
|
||||
|
@ -2,7 +2,7 @@ package org.enso.compiler.pass.analyse
|
||||
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.optimise.LambdaConsolidate
|
||||
import org.enso.compiler.pass.resolve.OverloadsResolution
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.enso.compiler.pass.analyse
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
@ -120,12 +119,12 @@ case object GatherDiagnostics extends IRPass {
|
||||
* @param diagnostics a list of the errors found in the IR
|
||||
*/
|
||||
case class DiagnosticsMeta(diagnostics: List[IR.Diagnostic])
|
||||
extends IRPass.Metadata {
|
||||
extends IRPass.IRMetadata {
|
||||
|
||||
/** The name of the metadata as a string. */
|
||||
override val metadataName: String = "GatherDiagnostics.Diagnostics"
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] =
|
||||
override def duplicate(): Option[IRPass.IRMetadata] =
|
||||
Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.enso.compiler.pass.analyse
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Pattern
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.desugar._
|
||||
import org.enso.compiler.pass.resolve.{ExpressionAnnotations, GlobalNames}
|
||||
@ -466,7 +465,7 @@ case object TailCall extends IRPass {
|
||||
}
|
||||
|
||||
/** Expresses the tail call state of an IR Node. */
|
||||
sealed trait TailPosition extends IRPass.Metadata {
|
||||
sealed trait TailPosition extends IRPass.IRMetadata {
|
||||
|
||||
/** A boolean representation of the expression's tail state. */
|
||||
def isTail: Boolean
|
||||
@ -478,7 +477,7 @@ case object TailCall extends IRPass {
|
||||
override val metadataName: String = "TailCall.TailPosition.Tail"
|
||||
override def isTail: Boolean = true
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(Tail)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(Tail)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def prepareForSerialization(compiler: Compiler): Tail.type = this
|
||||
@ -496,7 +495,7 @@ case object TailCall extends IRPass {
|
||||
override val metadataName: String = "TailCall.TailPosition.NotTail"
|
||||
override def isTail: Boolean = false
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(NotTail)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(NotTail)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def prepareForSerialization(compiler: Compiler): NotTail.type =
|
||||
|
@ -7,7 +7,7 @@ import org.enso.compiler.core.IR.Module.Scope.Definition
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition.Method
|
||||
import org.enso.compiler.core.IR.Name.MethodReference
|
||||
import org.enso.compiler.core.ir.{DiagnosticStorage, MetadataStorage}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -6,7 +6,7 @@ import org.enso.compiler.core.IR.DefinitionArgument
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition.Method
|
||||
import org.enso.compiler.core.ir.MetadataStorage.ToPair
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.desugar
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition.Method
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -2,7 +2,7 @@ package org.enso.compiler.pass.desugar
|
||||
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.desugar
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Pattern
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.desugar
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Application.Operator.Section
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse._
|
||||
import org.enso.compiler.pass.lint.UnusedBindings
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.lint
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Pattern
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.lint
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.{Case, Pattern}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis
|
||||
import org.enso.compiler.pass.desugar._
|
||||
|
@ -1,10 +1,9 @@
|
||||
package org.enso.compiler.pass.optimise
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.AliasAnalysis
|
||||
import org.enso.compiler.pass.desugar._
|
||||
@ -209,8 +208,8 @@ case object ApplicationSaturation extends IRPass {
|
||||
type KnownFunctionsMapping = Map[String, FunctionSpec]
|
||||
|
||||
/** Describes the saturation state of a function application. */
|
||||
sealed trait CallSaturation extends IRPass.Metadata {
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(this)
|
||||
sealed trait CallSaturation extends IRPass.IRMetadata {
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(this)
|
||||
}
|
||||
object CallSaturation {
|
||||
sealed case class Over(additionalArgCount: Int) extends CallSaturation {
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.optimise
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.DefinitionArgument
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -3,7 +3,7 @@ package org.enso.compiler.pass.optimise
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.{IdentifiedLocation, Pattern}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.enso.compiler.pass.resolve
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Case.Branch
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.desugar.{ComplexType, GenerateMethodBodies}
|
||||
|
||||
@ -225,7 +224,7 @@ case object DocumentationComments extends IRPass {
|
||||
*
|
||||
* @param documentation the documentation as a string
|
||||
*/
|
||||
sealed case class Doc(documentation: String) extends IRPass.Metadata {
|
||||
sealed case class Doc(documentation: String) extends IRPass.IRMetadata {
|
||||
override val metadataName: String =
|
||||
"DocumentationComments.Doc(\"" + documentation + "\")"
|
||||
|
||||
@ -237,6 +236,6 @@ case object DocumentationComments extends IRPass {
|
||||
Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(this)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(this)
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import org.enso.compiler.data.BindingsMap.{
|
||||
Resolution,
|
||||
ResolvedType
|
||||
}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, BindingAnalysis}
|
||||
import org.enso.compiler.pass.desugar.Imports
|
||||
@ -401,7 +401,7 @@ case object FullyQualifiedNames extends IRPass {
|
||||
* @param target the partially resolved name
|
||||
*/
|
||||
sealed case class FQNResolution(target: PartiallyResolvedFQN)
|
||||
extends IRPass.Metadata {
|
||||
extends IRPass.IRMetadata {
|
||||
|
||||
override val metadataName: String =
|
||||
"FullyQualifiedNames.Resolution"
|
||||
@ -417,7 +417,7 @@ case object FullyQualifiedNames extends IRPass {
|
||||
target.restoreFromSerialization(compiler).map(FQNResolution)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(this)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(this)
|
||||
}
|
||||
|
||||
sealed trait PartiallyResolvedFQN {
|
||||
|
@ -4,7 +4,7 @@ import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
|
||||
/** A pass responsible for the discovery of [[IR.Name.GenericAnnotation]]
|
||||
|
@ -10,7 +10,7 @@ import org.enso.compiler.data.BindingsMap.{
|
||||
ResolvedMethod,
|
||||
ResolvedModule
|
||||
}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, BindingAnalysis}
|
||||
import org.enso.interpreter.Constants
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.enso.compiler.pass.resolve
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.{Case, Pattern}
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{
|
||||
AliasAnalysis,
|
||||
@ -379,7 +378,7 @@ case object IgnoredBindings extends IRPass {
|
||||
// === Pass Metadata ========================================================
|
||||
|
||||
/** States whether or not the binding was ignored. */
|
||||
sealed trait State extends IRPass.Metadata {
|
||||
sealed trait State extends IRPass.IRMetadata {
|
||||
val isIgnored: Boolean
|
||||
}
|
||||
object State {
|
||||
@ -399,7 +398,7 @@ case object IgnoredBindings extends IRPass {
|
||||
): Option[Ignored.type] = Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(Ignored)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(Ignored)
|
||||
}
|
||||
|
||||
/** States that the binding is not ignored. */
|
||||
@ -418,7 +417,7 @@ case object IgnoredBindings extends IRPass {
|
||||
): Option[NotIgnored.type] = Some(this)
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(NotIgnored)
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(NotIgnored)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage.ToPair
|
||||
import org.enso.compiler.data.BindingsMap
|
||||
import org.enso.compiler.data.BindingsMap.{Resolution, ResolvedType, Type}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.BindingAnalysis
|
||||
import org.enso.compiler.pass.desugar.{
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.enso.compiler.pass.resolve
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition
|
||||
@ -117,9 +116,9 @@ case object ModuleAnnotations extends IRPass {
|
||||
* @param annotations the initial annotations for the container
|
||||
*/
|
||||
case class Annotations(annotations: Seq[IR.Name.Annotation])
|
||||
extends IRPass.Metadata {
|
||||
override val metadataName: String = "Annotations"
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(this.copy())
|
||||
extends IRPass.IRMetadata {
|
||||
override val metadataName: String = "Annotations"
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(this.copy())
|
||||
|
||||
/** Add an annotation to the annotations container.
|
||||
*
|
||||
@ -140,7 +139,7 @@ case object ModuleAnnotations extends IRPass {
|
||||
/** @inheritdoc */
|
||||
override def restoreFromSerialization(
|
||||
compiler: Compiler
|
||||
): Option[IRPass.Metadata] = {
|
||||
): Option[IRPass.IRMetadata] = {
|
||||
annotations.foreach { ann =>
|
||||
ann.preorder.foreach { ir =>
|
||||
if (!ir.passData.restoreFromSerialization(compiler)) {
|
||||
|
@ -2,7 +2,7 @@ package org.enso.compiler.pass.resolve
|
||||
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.desugar.{ComplexType, GenerateMethodBodies}
|
||||
|
||||
|
@ -4,7 +4,7 @@ import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage.ToPair
|
||||
import org.enso.compiler.data.BindingsMap
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse.{AliasAnalysis, BindingAnalysis}
|
||||
import org.enso.compiler.pass.desugar.{GenerateMethodBodies, NestedPatternMatch}
|
||||
|
@ -5,7 +5,7 @@ import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition
|
||||
import org.enso.compiler.core.IR.Module.Scope.Definition.Method
|
||||
import org.enso.compiler.core.IR.Type
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse._
|
||||
import org.enso.compiler.pass.desugar.ComplexType
|
||||
|
@ -4,7 +4,7 @@ import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.IR.{Application, IdentifiedLocation}
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse._
|
||||
import org.enso.compiler.pass.desugar.{
|
||||
|
@ -1,10 +1,9 @@
|
||||
package org.enso.compiler.pass.resolve
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.pass.analyse._
|
||||
import org.enso.compiler.pass.lint.UnusedBindings
|
||||
@ -305,7 +304,7 @@ case object TypeSignatures extends IRPass {
|
||||
*
|
||||
* @param signature the expression for the type signature
|
||||
*/
|
||||
case class Signature(signature: IR.Expression) extends IRPass.Metadata {
|
||||
case class Signature(signature: IR.Expression) extends IRPass.IRMetadata {
|
||||
override val metadataName: String = "TypeSignatures.Signature"
|
||||
|
||||
/** @inheritdoc */
|
||||
@ -327,7 +326,7 @@ case object TypeSignatures extends IRPass {
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
override def duplicate(): Option[IRPass.Metadata] =
|
||||
override def duplicate(): Option[IRPass.IRMetadata] =
|
||||
Some(this.copy(signature = signature.duplicate()))
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.enso.compiler.phase
|
||||
|
||||
import org.enso.compiler.EnsoCompiler
|
||||
import org.enso.compiler.core.EnsoParser
|
||||
import org.enso.compiler.Passes
|
||||
import org.enso.compiler.context.{FreshNameSupply, ModuleContext}
|
||||
import org.enso.compiler.data.CompilerConfig
|
||||
@ -38,7 +38,7 @@ object BuiltinsIrBuilder {
|
||||
freshNameSupply = Some(freshNameSupply),
|
||||
compilerConfig = CompilerConfig(warningsEnabled = false)
|
||||
)
|
||||
val initialIr = Using(new EnsoCompiler) { compiler =>
|
||||
val initialIr = Using(new EnsoParser) { compiler =>
|
||||
compiler.compile(module.getSource.getCharacters)
|
||||
}.get
|
||||
val irAfterModDiscovery = passManager.runPassesOnModule(
|
||||
|
@ -10,7 +10,7 @@ import org.enso.compiler.data.BindingsMap.{
|
||||
ResolvedType,
|
||||
Type
|
||||
}
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.analyse.BindingAnalysis
|
||||
import org.enso.editions.LibraryName
|
||||
import org.enso.interpreter.runtime.Module
|
||||
|
@ -2,30 +2,28 @@ package org.enso.compiler;
|
||||
|
||||
import com.oracle.truffle.api.source.Source;
|
||||
import java.io.File;
|
||||
import org.enso.compiler.core.IR;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.function.Function;
|
||||
import org.enso.compiler.core.EnsoParser;
|
||||
import org.enso.compiler.core.IR;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public abstract class CompilerTest {
|
||||
|
||||
protected static EnsoCompiler ensoCompiler;
|
||||
protected static EnsoParser ensoCompiler;
|
||||
|
||||
@BeforeClass
|
||||
public static void initEnsoCompiler() {
|
||||
ensoCompiler = new EnsoCompiler();
|
||||
public static void initEnsoParser() {
|
||||
ensoCompiler = new EnsoParser();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeEnsoCompiler() throws Exception {
|
||||
public static void closeEnsoParser() throws Exception {
|
||||
ensoCompiler.close();
|
||||
}
|
||||
|
||||
@ -33,7 +31,7 @@ public abstract class CompilerTest {
|
||||
var src =
|
||||
Source.newBuilder("enso", code, "test-" + Integer.toHexString(code.hashCode()) + ".enso")
|
||||
.build();
|
||||
IR.Module ir = ensoCompiler.compile(src);
|
||||
IR.Module ir = ensoCompiler.compile(src.getCharacters());
|
||||
assertNotNull("IR was generated", ir);
|
||||
return ir;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.HashMap;
|
||||
import org.enso.compiler.core.EnsoParser;
|
||||
import org.enso.compiler.core.IR;
|
||||
import org.enso.compiler.core.IR$Comment$Documentation;
|
||||
import org.enso.compiler.core.IR$Function$Binding;
|
||||
@ -20,19 +21,18 @@ import org.junit.Test;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import scala.Function1;
|
||||
|
||||
public class VectorArraySignatureTest {
|
||||
private static EnsoCompiler ensoCompiler;
|
||||
private static EnsoParser ensoCompiler;
|
||||
|
||||
@BeforeClass
|
||||
public static void initEnsoCompiler() {
|
||||
ensoCompiler = new EnsoCompiler();
|
||||
public static void initEnsoParser() {
|
||||
ensoCompiler = new EnsoParser();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeEnsoCompiler() throws Exception {
|
||||
public static void closeEnsoParser() throws Exception {
|
||||
ensoCompiler.close();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.enso.compiler.test
|
||||
|
||||
import org.enso.compiler.EnsoCompiler
|
||||
import org.enso.compiler.context.{FreshNameSupply, InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.EnsoParser
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage.ToPair
|
||||
import org.enso.compiler.data.BindingsMap.ModuleReference
|
||||
@ -30,7 +30,7 @@ trait CompilerRunner {
|
||||
* @return the [[IR]] representing [[source]]
|
||||
*/
|
||||
def toIrModule: IR.Module = {
|
||||
val compiler = new EnsoCompiler()
|
||||
val compiler = new EnsoParser()
|
||||
try compiler.compile(source)
|
||||
finally compiler.close()
|
||||
}
|
||||
@ -48,7 +48,7 @@ trait CompilerRunner {
|
||||
* @return the [[IR]] representing [[source]], if it is a valid expression
|
||||
*/
|
||||
def toIrExpression: Option[IR.Expression] = {
|
||||
val compiler = new EnsoCompiler()
|
||||
val compiler = new EnsoParser()
|
||||
try compiler.generateIRInline(compiler.parse(source))
|
||||
finally compiler.close()
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
package org.enso.compiler.test.core.ir
|
||||
|
||||
import org.enso.compiler.Compiler
|
||||
import org.enso.compiler.context.{InlineContext, ModuleContext}
|
||||
import org.enso.compiler.core.IR
|
||||
import org.enso.compiler.core.ir.MetadataStorage
|
||||
import org.enso.compiler.core.ir.MetadataStorage._
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.IRPass
|
||||
import org.enso.compiler.test.CompilerTest
|
||||
import shapeless.test.illTyped
|
||||
@ -36,7 +35,7 @@ class MetadataStorageTest extends CompilerTest {
|
||||
copyOfIr: T
|
||||
): T = copyOfIr
|
||||
|
||||
sealed case class Metadata1() extends IRPass.Metadata {
|
||||
sealed case class Metadata1() extends IRPass.IRMetadata {
|
||||
override val metadataName: String = "TestPass1.Metadata1"
|
||||
|
||||
override def prepareForSerialization(
|
||||
@ -47,7 +46,7 @@ class MetadataStorageTest extends CompilerTest {
|
||||
compiler: Compiler
|
||||
): Option[Metadata1] = Some(this)
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(Metadata1())
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(Metadata1())
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +72,7 @@ class MetadataStorageTest extends CompilerTest {
|
||||
copyOfIr: T
|
||||
): T = copyOfIr
|
||||
|
||||
sealed case class Metadata2() extends IRPass.Metadata {
|
||||
sealed case class Metadata2() extends IRPass.IRMetadata {
|
||||
override val metadataName: String = "TestPass2.Metadata2"
|
||||
|
||||
override def prepareForSerialization(
|
||||
@ -84,7 +83,7 @@ class MetadataStorageTest extends CompilerTest {
|
||||
compiler: Compiler
|
||||
): Option[Metadata2] = Some(this)
|
||||
|
||||
override def duplicate(): Option[IRPass.Metadata] = Some(Metadata2())
|
||||
override def duplicate(): Option[IRPass.IRMetadata] = Some(Metadata2())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.enso.compiler.test.pass
|
||||
|
||||
import org.enso.compiler.Passes
|
||||
import org.enso.compiler.exception.CompilerError
|
||||
import org.enso.compiler.core.CompilerError
|
||||
import org.enso.compiler.pass.{
|
||||
IRPass,
|
||||
PassConfiguration,
|
||||
|
@ -1,64 +0,0 @@
|
||||
package org.enso.syntax.text
|
||||
|
||||
import org.enso.data.Span
|
||||
import io.circe
|
||||
import io.circe.Json
|
||||
import io.circe.generic.auto._
|
||||
import io.circe.parser._
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
class InternalError(reason: String, cause: Throwable = None.orNull)
|
||||
extends Exception(s"Internal error $reason", cause)
|
||||
|
||||
////////////////
|
||||
//// Parser ////
|
||||
////////////////
|
||||
|
||||
object SourceFile {
|
||||
val METATAG = "\n\n\n#### METADATA ####\n"
|
||||
}
|
||||
|
||||
class Parser {
|
||||
import Parser._
|
||||
|
||||
def splitMeta(code: String): (String, IDMap, Json) = {
|
||||
import SourceFile._
|
||||
code.split(METATAG) match {
|
||||
case Array(input) => (input, Seq(), Json.obj())
|
||||
case Array(input, rest) =>
|
||||
val meta = rest.split('\n')
|
||||
if (meta.length < 2) {
|
||||
throw new ParserError(s"Expected two lines after METADATA.")
|
||||
}
|
||||
val idmap = idMapFromJson(meta(0)).left.map { error =>
|
||||
throw new ParserError("Could not deserialize idmap.", error)
|
||||
}.merge
|
||||
val metadata = decode[Json](meta(1)).left.map { error =>
|
||||
throw new ParserError("Could not deserialize metadata.", error)
|
||||
}.merge
|
||||
(input, idmap, metadata)
|
||||
case arr: Array[_] =>
|
||||
throw new ParserError(
|
||||
s"Could not not deserialize metadata (found ${arr.length - 1} metadata sections)"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object Parser {
|
||||
|
||||
type IDMap = Seq[(Span, UUID)]
|
||||
|
||||
def apply(): Parser = new Parser()
|
||||
|
||||
def idMapFromJson(json: String): Either[circe.Error, IDMap] =
|
||||
decode[IDMap](json)
|
||||
|
||||
//// Exceptions ////
|
||||
|
||||
class ParserError(reason: String, cause: Throwable = None.orNull)
|
||||
extends InternalError(s"in parser $reason", cause)
|
||||
}
|
@ -1 +0,0 @@
|
||||
LICENSE
|
@ -1 +0,0 @@
|
||||
/com-lihaoyi/fansi/blob/master/LICENSE
|
@ -1 +0,0 @@
|
||||
LICENSE
|
@ -1 +0,0 @@
|
||||
/com-lihaoyi/PPrint/blob/master/LICENSE
|
@ -1 +0,0 @@
|
||||
LICENSE
|
@ -1 +0,0 @@
|
||||
/com-lihaoyi/sourcecode/blob/master/LICENSE
|
@ -1,3 +1,3 @@
|
||||
8318FC8DB8AD68F5E645BD2B7230C9EAC76273B2546C885DC6B2EA46CB8C88E2
|
||||
34887BA71DCE953A646B7D4B8DA9C67719E4D2C3ECC24F935DADC3BE92671750
|
||||
57D3FECE4A826A4D447995504980012D29E6FF665FA3049D93C0A342D2B56C61
|
||||
62D7111156F2837511DAE7CA11AEA5129ABD14236AA13070393304B4887F271F
|
||||
0
|
||||
|
Loading…
Reference in New Issue
Block a user