public List<ShapeId> dequeueSortedShapes() {
        List<ShapeId> result = new ArrayList<>(satisfiedShapes.size() + forwardDependencies.size());

        while (!satisfiedShapes.isEmpty()) {
            ShapeId current = satisfiedShapes.poll();
            forwardDependencies.remove(current);
            result.add(current);

            for (ShapeId dependent : reverseDependencies.getOrDefault(current, Collections.emptySet())) {
                Set<ShapeId> dependentDependencies = forwardDependencies.get(dependent);
                dependentDependencies.remove(current);
                if (dependentDependencies.isEmpty()) {
                    satisfiedShapes.offer(dependent);
                }
            }
        }

        reverseDependencies.clear();

        if (!forwardDependencies.isEmpty()) {
            throw new CycleException(new TreeSet<>(forwardDependencies.keySet()), result);
        }

        return result;
    }
Sort the shapes and returns the ordered list of shape IDs.

@return Returns the topologically sorted list of shape IDs.
@throws CycleException if cycles exist between shapes.
smithy-model/src/main/java/software/amazon/smithy/model/loader/TopologicalShapeSort.java