Really hard to do basic things with noncopyable types

sure, i’m probably holding them wrong, noncopyable types are just… not fun.

here’s a noncopyable struct:

@frozen public
struct DiagnosticContext<Symbolicator>:~Copyable
{
    @usableFromInline internal
    var diagnostics:[Diagnostic]
}

and then here’s an intermediate abstraction that contains a stored property of that noncopyable struct:

import Diagnostics 

extension StaticLinker
{
    struct Tables:~Copyable
    {
        var diagnostics:DiagnosticContext<StaticSymbolicator>
        ...
    }
}

and now here’s a toplevel type that contains the intermediate type

struct StaticLinker:~Copyable
{
    private
    var tables:Tables
    ....
}

now i’m trying to do

extension StaticLinker
{
    consuming
    func diagnostics() -> DiagnosticContext<StaticSymbolicator>
    {
        self.tables.diagnostics
    }
}

but that doesn’t work

error: cannot partially consume 'self'

nor does

        (consume self).tables.diagnostics
error: cannot partially consume 'unknown'

this doesn’t parse

        (consume (consume self).tables).diagnostics

this crashes the compiler

    var diagnostics:DiagnosticContext<StaticSymbolicator>
    {
        _read
        {
            yield self.tables.diagnostics
        }
    }

COW-proofing is a lot harder than i thought…

Partial consumption is coming but the read coroutine is probably closer to what you want. That ought to work, I'll look into a fix.

1 Like

oof, just ran into a compiler segfault when building in release mode only. details here: