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
8 changes: 8 additions & 0 deletions .changeset/big-laws-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@plutolang/graphviz-generator": patch
"@plutolang/base": patch
---

fix: resolve topo sort failure by adding missing resource edge

The topological sort was wrong due to a missing edge related to the resource argument. This commit adds the required edge to ensure correct sorting order.
2 changes: 2 additions & 0 deletions components/generators/graphviz/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function archToGraphviz(archRef: arch.Architecture): string {
for (const arg of res.arguments) {
if (arg.type === "closure") {
dotSource += ` ${res.id} -> ${arg.closureId} [color="black"];\n`;
} else if (arg.type === "resource" || arg.type === "capturedProperty") {
dotSource += ` ${res.id} -> ${arg.resourceId} [color="black"];\n`;
}
}
}
Expand Down
45 changes: 32 additions & 13 deletions packages/base/arch/topo-sorter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createHash } from "crypto";
import { Resource } from "./resource";
import { BundleArgument } from "./argument";
import { Architecture } from "./architecture";
import { BundleEntity, Entity, EntityType, RelationshipEntity, ResourceEntity } from "./types";
import {
Expand Down Expand Up @@ -119,20 +118,40 @@ export class TopoSorter {
// Constructor: A resource depends on its parameters.
// Thus, the edge originates from the parameter nodes and points towards the resource node.
private addEdgesOfConstructor() {
this.archRef.resources.forEach((resource) => {
const addEdgesForOneResource = (resource: Resource) => {
const targetNode = resource;
resource.arguments
.filter<BundleArgument>((arg): arg is BundleArgument => arg.type === "closure")
.forEach((arg) => {
const sourceNode = this.archRef.findClosure(arg.closureId);
if (sourceNode == undefined) {
throw Error(
`The architecture is invalid, the closure '${arg.closureId}' cannot be found.`
);

for (const arg of resource.arguments) {
switch (arg.type) {
case "closure": {
const sourceNode = this.archRef.findClosure(arg.closureId);
if (sourceNode == undefined) {
throw Error(
`The architecture is invalid, the closure '${arg.closureId}' cannot be found.`
);
}
this.addOneEdge(BundleEntity.create(sourceNode), ResourceEntity.create(targetNode));
break;
}
this.addOneEdge(BundleEntity.create(sourceNode), ResourceEntity.create(targetNode));
});
});
case "resource":
case "capturedProperty":
{
const sourceNode = this.archRef.findResource(arg.resourceId);
if (sourceNode == undefined) {
throw Error(
`The architecture is invalid, the resource '${arg.resourceId}' cannot be found.`
);
}
this.addOneEdge(ResourceEntity.create(sourceNode), ResourceEntity.create(targetNode));
}
break;
case "text":
break;
}
}
};

this.archRef.resources.forEach(addEdgesForOneResource);
}

// Create: The 'Create' relationship node depends on both the 'from' and 'to' properties.
Expand Down