Skip to content

Add regression test for bug already fixed #75653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2024
Merged
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
93 changes: 93 additions & 0 deletions validation-test/compiler_crashers_2_fixed/issue-70429.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// RUN: %target-swift-frontend -emit-ir %s -disable-availability-checking

// https://github.com/swiftlang/swift/issues/70429

public protocol Node: Sendable {}
public protocol BlockNode: Node {}
public protocol InlineNode: Node {}

// MARK: - Block nodes

public struct Paragraph: BlockNode {
public init() {}
}

// MARK: - NodeGroup

/// Intermediate aggregate for nodes.
///
/// Its intended usage is for building node groups through result builders.
public struct NodeGroup<each N: Node>: Sendable {
@usableFromInline let nodes: (repeat each N)

@usableFromInline init(nodes: repeat each N) {
self.nodes = (repeat each nodes)
}

@usableFromInline func merging<each M>(_ group: NodeGroup<repeat each M>) -> NodeGroup<repeat each N, repeat each M> {
NodeGroup<repeat each N, repeat each M>(nodes: repeat each self.nodes, repeat each group.nodes)
}
}

@resultBuilder public enum GroupBuilder {
public static func buildExpression<N: Node>(_ expression: N) -> NodeGroup<N> {
NodeGroup(nodes: expression)
}

public static func buildPartialBlock<each N: Node>(first: consuming NodeGroup<repeat each N>) -> NodeGroup<repeat each N> {
first
}

public static func buildPartialBlock<each A, each N>(accumulated: consuming NodeGroup<repeat each A>, next: consuming NodeGroup<repeat each N>) -> NodeGroup<repeat each A, repeat each N> {
let tmp = accumulated.merging(next)
return tmp
}
}

// MARK: - Zero or More

/// Group defining a bunch of children nodes, which can occur zero or more times in a non-sequential order.
public struct ZeroOrMore<each N: Node>: Node {
/// All nodes hold by this group.
public let nodes: (repeat each N)

public init(nodes: repeat each N) where repeat each N: InlineNode {
self.nodes = (repeat each nodes)
}

public init(nodes: repeat each N) where repeat each N: BlockNode {
self.nodes = (repeat each nodes)
}

public init(@GroupBuilder group: () -> NodeGroup<repeat each N>) where repeat each N: InlineNode {
self.nodes = group().nodes
}

public init(@GroupBuilder group: () -> NodeGroup<repeat each N>) where repeat each N: BlockNode {
self.nodes = group().nodes
}
}

// When all children blocks are block nodes, the group is a block node itself.
extension ZeroOrMore: BlockNode where repeat each N: BlockNode {}
// When all children blocks are inline nodes, the group is an inline node itself.
extension ZeroOrMore: InlineNode where repeat each N: InlineNode {}

// MARK: - Schema

/// A ``Schema`` defines what a text document can contain/display.
public protocol Schema: Sendable {
associatedtype Document: BlockNode

var document: Document { get }
}

public struct MarkdownSchema: Schema {
public init() {}

public var document: some BlockNode {
ZeroOrMore {
Paragraph()
}
}
}