Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import sk.ainet.tape.Execution
*/
public class MinervaExportFacade @kotlin.jvm.JvmOverloads constructor(
public val backendName: String = MinervaExportBackend.backendName,
public val compatibilityValidator: MinervaCompatibilityValidator = MinervaCompatibilityValidator()
public val compatibilityValidator: MinervaCompatibilityValidator = MinervaCompatibilityValidator(),
public val graphCanonicalizer: MinervaGraphCanonicalizer = MinervaGraphCanonicalizer()
) {

/**
Expand Down Expand Up @@ -91,14 +92,23 @@ public class MinervaExportFacade @kotlin.jvm.JvmOverloads constructor(
return compatibilityValidationFailedResult(options, context, compatibilityReport)
}

val intermediate = try {
graphCanonicalizer.convert(graph, context)
} catch (exception: MinervaLoweringException) {
return loweringFailedResult(options, context, compatibilityReport, exception)
}

val failure = MinervaExportFailure(
kind = MinervaExportFailureKind.NOT_IMPLEMENTED,
stage = GraphExportStage.LOWERING,
stage = GraphExportStage.WRITING,
code = "minerva.export.not_implemented",
message = "Minerva export passed phase-one compatibility validation; lowering, compiler invocation, packaging, and verification are implemented in follow-up issues.",
message = "Minerva export lowered the graph to phase-one IR; compiler invocation, packaging, and verification are implemented in follow-up issues.",
details = mapOf(
"nextStep" to "Implement MinervaGraphCanonicalizer",
"issue" to "#692"
"nextStep" to "Invoke the Minerva compiler and write the runtime project.",
"issue" to "#693",
"layers" to intermediate.layerCount.toString(),
"input" to intermediate.input.id,
"output" to intermediate.output.id
)
)
context.error(
Expand All @@ -107,7 +117,13 @@ public class MinervaExportFacade @kotlin.jvm.JvmOverloads constructor(
message = failure.message,
details = failure.details
)
return failedResult(options, context, failure, compatibilityReport)
return failedResult(
options = options,
context = context,
failure = failure,
compatibilityReport = compatibilityReport,
intermediate = intermediate
)
}

private fun unsupportedModelResult(model: Any, options: MinervaExportOptions): MinervaExportResult {
Expand Down Expand Up @@ -179,11 +195,40 @@ public class MinervaExportFacade @kotlin.jvm.JvmOverloads constructor(
return failedResult(options, context, failure, report)
}

private fun loweringFailedResult(
options: MinervaExportOptions,
context: GraphExportContext,
compatibilityReport: MinervaCompatibilityReport,
exception: MinervaLoweringException
): MinervaExportResult {
val details = mutableMapOf(
"code" to exception.code,
"issue" to "#692"
)
exception.nodeId?.let { details["nodeId"] = it }
exception.operationName?.let { details["operationName"] = it }
details += exception.details
val failure = MinervaExportFailure(
kind = MinervaExportFailureKind.LOWERING_FAILED,
stage = GraphExportStage.LOWERING,
code = exception.code,
message = exception.message ?: "Minerva graph lowering failed.",
details = details
)
return failedResult(
options = options,
context = context,
failure = failure,
compatibilityReport = compatibilityReport
)
}

private fun failedResult(
options: MinervaExportOptions,
context: GraphExportContext,
failure: MinervaExportFailure,
compatibilityReport: MinervaCompatibilityReport? = null
compatibilityReport: MinervaCompatibilityReport? = null,
intermediate: MinervaIntermediate? = null
): MinervaExportResult {
return MinervaExportResult(
options = options,
Expand All @@ -192,7 +237,8 @@ public class MinervaExportFacade @kotlin.jvm.JvmOverloads constructor(
artifacts = context.artifacts,
failure = failure,
metadata = context.metadata,
compatibilityReport = compatibilityReport
compatibilityReport = compatibilityReport,
intermediate = intermediate
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public enum class MinervaExportFailureKind {
RECORDING_FAILED,
GRAPH_VALIDATION_FAILED,
COMPATIBILITY_VALIDATION_FAILED,
LOWERING_FAILED,
NOT_IMPLEMENTED
}

Expand Down Expand Up @@ -201,7 +202,8 @@ public data class MinervaExportResult(
public val artifacts: List<GraphExportArtifact> = emptyList(),
public val failure: MinervaExportFailure? = null,
public val metadata: Map<String, String> = emptyMap(),
public val compatibilityReport: MinervaCompatibilityReport? = null
public val compatibilityReport: MinervaCompatibilityReport? = null,
public val intermediate: MinervaIntermediate? = null
) {
init {
require(status != GraphExportStatus.SUCCESS || bundle != null) {
Expand Down
Loading
Loading