Skip to content

Compiler: a closure is used only where its captures and delegate are - #2585

Merged
bfiete merged 1 commit into
beefytech:masterfrom
jayrulez:fix/closure-captures-in-vdata
Oct 27, 2026
Merged

bfiete merged 1 commit into
beefytech:masterfrom
jayrulez:fix/closure-captures-in-vdata

Conversation

@jayrulez

Copy link
Copy Markdown
Contributor

A closure's type is its delegate's, from the delegate's project (corlib for most), and IsTypeAccessible and IsTypeUsed checked a tuple's fields and a delegate's signature but neither for a closure: its captures were never scanned, and as a BfClosureType is no BfDelegateType it has no delegate info of its own. So a closure capturing a type of a project an executable does not reference passed as accessible, its module was marked used whenever a used module reached it, and the executable's vdata named it: the link failed on the other project's symbols.

    namespace SharedGlobals
    {
        static // in LibC, which TestsB does not reference
        {
            public static int32 LibCCaptures(LibCCaptured captured)
            {
                delegate int32() get = scope () => captured.mValue;
                return get();
            }
        }
    }

With LibA holding globals of the same namespace and TestsB calling them, TestsB failed to link on LibCCaptured.__Equals. A closure now counts as accessible and used only when its captured fields' types and its source delegate are.

Seen in a game engine where every executable that did not reference its GUI library failed to link once a second GUI library added globals to the GUI's namespace.

A closure's type is its delegate's, from the delegate's project (corlib
for most), and IsTypeAccessible and IsTypeUsed checked a tuple's fields
and a delegate's signature but neither for a closure: its captures were
never scanned, and as a BfClosureType is no BfDelegateType it has no
delegate info of its own. So a closure capturing a type of a project an
executable does not reference passed as accessible, its module was
marked used whenever a used module reached it, and the executable's
vdata named it: the link failed on the other project's symbols.

    namespace SharedGlobals
    {
        static // in LibC, which TestsB does not reference
        {
            public static int32 LibCCaptures(LibCCaptured captured)
            {
                delegate int32() get = scope () => captured.mValue;
                return get();
            }
        }
    }

With LibA holding globals of the same namespace and TestsB calling them,
TestsB failed to link on LibCCaptured.__Equals. A closure now counts as
accessible and used only when its captured fields' types and its source
delegate are.

Seen in a game engine where every executable that did not reference its
GUI library failed to link once a second GUI library added globals to the
GUI's namespace.
@bfiete
bfiete merged commit 529bfaf into beefytech:master Oct 27, 2026
5 checks passed
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