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
@asevko
Copy link
Author

asevko commented Jan 3, 2026

@jakepetroules can you please run CI tests? I don't have permission for that.

Thanks in advance!

@heckj
Copy link
Member

heckj commented Jan 3, 2026

@swift-ci please test

@owenv
Copy link
Collaborator

owenv commented Jan 5, 2026

@swift-ci test

Copy link
Collaborator

@owenv owenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one small comment, otherwise this change lgtm

@asevko
Copy link
Author

asevko commented Jan 5, 2026

@owenv Thanks for review! I've fixed your comment

@asevko asevko requested a review from owenv January 5, 2026 20:36
@owenv
Copy link
Collaborator

owenv commented Jan 5, 2026

@swift-ci test

@asevko
Copy link
Author

asevko commented Jan 6, 2026

@owenv the Swift Test macOS Platform (Swift main) failed with following assertation:

Assertion failed: (Cand2.Conversions.size() == NumArgs && "Overload candidate mismatch"), function isBetterOverloadCandidate, file SemaOverload.cpp, line 10825.

It doesn't seem, that it's connected with that PR

@owenv
Copy link
Collaborator

owenv commented Jan 6, 2026

@swift-ci test macOS

@asevko
Copy link
Author

asevko commented Jan 6, 2026

Pull request / Test / Swift SDK for Android Build (nightly-main - noble - NDK r27d) (pull_request) failed with

LLVM ERROR: IO failure on output stream: No space left on device

@owenv
Copy link
Collaborator

owenv commented Jan 6, 2026

that's a known issue in the android job, we can merge this

@owenv owenv merged commit fa8f0b1 into swiftlang:main Jan 6, 2026
94 of 95 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.

4 participants