Skip to content
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

swift_allocEmptyBox missing in Embedded Swift #80056

Open
TeamPuzel opened this issue Mar 17, 2025 · 0 comments
Open

swift_allocEmptyBox missing in Embedded Swift #80056

TeamPuzel opened this issue Mar 17, 2025 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@TeamPuzel
Copy link

Description

No response

Reproduction

I tried to use this:

public struct EmptyDrawable: Drawable {
    public var width: Int { 0 }
    public var height: Int { 0 }
    public init() {}
    public subscript(x: Int, y: Int) -> Color { .clear }
}

In itself it's nothing unusual, besides being a zero sized type.

The problem seems to be caused by this however:

public extension Drawable where Self: ~Copyable {
    var lazy: LazyDrawable { consuming get { .init(self) } }
}

public final class LazyDrawable: Drawable {
    private let initializer: () -> Image
    public private(set) lazy var inner: Image = self.initializer()
    public let width: Int
    public let height: Int
    
    private init(_ initializer: @escaping () -> Image, width: Int, height: Int) {
        self.initializer = initializer
        self.width = width
        self.height = height
    }
    
    public convenience init(_ inner: consuming some Drawable & ~Copyable) {
        self.init({ inner.flatten() }, width: inner.width, height: inner.height)
    }
    
    public subscript(x: Int, y: Int) -> Color {
        inner[x, y]
    }
}
@resultBuilder
public struct FlatteningDrawableBuilder {
    public static func buildPartialBlock(first: consuming some Drawable & ~Copyable) -> [LazyDrawable] { [first.lazy] }
    
    public static func buildPartialBlock(first: [LazyDrawable]) -> [LazyDrawable] { first }

    public static func buildPartialBlock(accumulated: [LazyDrawable], next: consuming some Drawable & ~Copyable) -> [LazyDrawable] {
        var acc = accumulated
        acc.append(next.lazy)
        return acc
    }
    
    public static func buildArray(_ components: [[LazyDrawable]]) -> [LazyDrawable] { components.joined() }
}

I assume Swift is trying to "allocate" space for the escaping capture of the zero sized struct.

This causes linking to fail because swift_allocEmptyBox does not exist.

Expected behavior

I expected the symbol to exist, much like the other class allocation functions. This one seems to have been omitted.

Environment

Apple Swift version 6.2-dev (LLVM 3a02857b159678d, Swift c91e295)
Target: arm64-apple-macosx15.0
Build config: +assertions

Additional information

No response

@TeamPuzel TeamPuzel added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant