Skip to content

Conversation

@asevko
Copy link

@asevko asevko commented Dec 24, 2025

During the migration of a large project (~1800 targets) to a new version of Xcode, we faced constant build system crashes.

The first crash occurred during recursive lookupMacroDeclaration and lookupConditionParameter evaluation, which is being fixed in #992.

A second crash appeared in multiple places but always reduced to MacroEvaluationProgram.executeInContext. Evaluating the instruction evalNamedMacro and then calling value.expression.evaluate(context:resultBuilder:alwaysEvalAsString) blew the call stack.

This PR converts that recursive evaluation of the value expression to a stack-based approach that can handle any depth.

Each frame on the stack represents an in-progress evaluation of a macro expression. When we need to evaluate a nested macro, instead of making a recursive call, we push the current state onto the stack and start evaluating the nested expression. When we complete an expression evaluation, we pop the stack and continue.

This fix, combined with the one in #992, resolves the issue described in https://forums.swift.org/t/xcode-15-3-xcbuildservice-crash-infinite-loop-when-building-ios-project/70643/7.

@asevko asevko marked this pull request as ready for review December 24, 2025 14:12
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