Skip to content

037 topo shape sort#65

Merged
akollegger merged 5 commits intomainfrom
037-topo-shape-sort
Feb 24, 2026
Merged

037 topo shape sort#65
akollegger merged 5 commits intomainfrom
037-topo-shape-sort

Conversation

@akollegger
Copy link
Copy Markdown
Contributor

This pull request introduces a new structure-aware folding order for graph operations in Haskell's Pattern.Graph.Transform module, centered around the new topoShapeSort function and its integration into the paraGraph family of folds. The changes ensure that graph elements are processed in an order that respects both containment and dependency, particularly for annotations and other complex elements. This is thoroughly documented in a new reference guide.

Key changes:

Structural Folding and Processing Order

  • Introduced the topoShapeSort function to replace the previous flat arity-based sort. This function partitions elements by shape class (nodes, relationships, walks, annotations, other), then applies a topological sort within the annotation and "other" buckets using Kahn's algorithm to respect within-bucket dependencies and handle cycles gracefully.

  • Updated paraGraph and paraGraphWithSeed to use topoShapeSort for element ordering, ensuring each element receives sub-results for all previously processed direct sub-elements, and handling cycles by omitting unprocessed sub-results. [1] [2]

  • Improved the subResults contract in documentation and code: sub-results for each element are now a best-effort list, possibly omitting results for sub-elements involved in dependency cycles.

Documentation and Reference

  • Added a comprehensive reference document docs/reference/features/para-graph.md detailing the mental model, processing order, sub-result contract, cycle handling, and usage examples for paraGraph and topoShapeSort. This serves as a guide for both users and implementers.

  • Enhanced module documentation in Pattern.Graph.Transform to explain the new shape-based classification and folding order.

Technology Tracking

  • Updated CLAUDE.md to reflect the addition of Data.Map.Strict, Data.List (foldl'), and Data.Maybe (mapMaybe) as active technologies for the 037-topo-shape-sort feature, and noted the in-memory, pure algorithmic nature of the implementation. [1] [2]

These changes provide a robust, well-documented foundation for structure-aware graph folding, enabling correct and efficient analysis of complex graph structures with annotations, cycles, and arbitrary containment.

akollegger and others added 4 commits February 24, 2026 09:35
…-aware fold) by introducing topoShapeSort to require a structure's internal components to be processed first. Graph structures require careful sorting to make this work correctly.
…dering

Replace sortByArity with topoShapeSort, adding Kahn's algorithm for
correct within-bucket ordering of GAnnotation and GOther elements.
Annotations that annotate other annotations (and GOther-of-GOther chains)
are now guaranteed to receive their dependencies' results in subResults,
fixing the silent-miss bug where paraGraph would fold containing elements
before their contents when both were in the same shape-class bucket.

- withinBucketTopoSort: new Kahn's algorithm helper; cycle members
  appended in input order after non-cycle elements, no error raised
- topoShapeSort: renamed from sortByArity, gains GraphValue v constraint,
  applies withinBucketTopoSort to GAnnotation and GOther buckets
- paraGraph/paraGraphWithSeed: updated call sites; subResults lookup
  simplified to mapMaybe
- Haddock updated for paraGraph (Processing Order + subResults contract),
  paraGraphFixed (topoShapeSort reference + cycle note), and module header
  (shape vocabulary replacing arity language)
- Four new tests: annotation-of-annotation ordering (T004), cycle
  soft-failure (T005), SC-006 fold correctness (T006), GOther ordering (T007)
- 842 tests, 0 failures; zero remaining sortByArity references

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a structure-aware folding order for graph operations by implementing the topoShapeSort function to replace sortByArity. The change ensures that graph elements are processed in the correct order, respecting both shape class priorities and within-bucket dependencies. This is particularly important for annotations and GOther elements that can reference elements of their own type.

Changes:

  • Renamed sortByArity to topoShapeSort and implemented Kahn's algorithm for within-bucket topological sorting in annotation and GOther buckets
  • Updated paraGraph, paraGraphFixed, and paraGraphWithSeed documentation to reflect the new ordering semantics and explicit subResults contract
  • Added comprehensive test coverage for annotation-of-annotation, GOther-of-GOther, and cycle handling scenarios
  • Created extensive reference documentation at docs/reference/features/para-graph.md

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
libs/pattern/src/Pattern/Graph/Transform.hs Core implementation: renamed function, added withinBucketTopoSort with Kahn's algorithm, updated documentation
libs/pattern/tests/Spec/Pattern/Graph/TransformSpec.hs Added 4 new test cases for annotation-of-annotation ordering, cycle handling, fold correctness, and GOther ordering
docs/reference/features/para-graph.md New comprehensive reference guide covering mental model, processing order, laws, examples, and cross-language notes
specs/037-topo-shape-sort/*.md Complete specification suite including tasks, spec, research, plan, data model, contracts, and quickstart guide
CLAUDE.md Technology tracking update for feature dependencies
cabal.project.local Removed tests: True configuration (unrelated to feature)
apps/gramref-cli/gramref-cli.cabal Changed from Custom to Simple build type (unrelated to feature)
apps/gramref-cli/Setup.hs Deleted custom setup code for man page installation (unrelated to feature)
Comments suppressed due to low confidence (1)

apps/gramref-cli/Setup.hs:1

  • The deletion of this entire Setup.hs file (68 lines of custom setup code for man page installation) appears unrelated to the "037-topo-shape-sort" feature. This is not mentioned in the PR description or any of the specification documents. This change should be explained in the PR description or done in a separate commit/PR.

@@ -1,2 +1 @@
ignore-project: False
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change appears unrelated to the "037-topo-shape-sort" feature described in the PR. The removal of the tests: True configuration from cabal.project.local is not mentioned in the PR description or any of the specification documents. If this is an intentional cleanup, it should be explained in the PR description or done in a separate commit/PR.

Copilot uses AI. Check for mistakes.
@akollegger akollegger merged commit 08394b8 into main Feb 24, 2026
1 check passed
@akollegger akollegger deleted the 037-topo-shape-sort branch February 24, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants