Skip to content

Conversation

Michael137
Copy link

This patch works around an assertion that we hit in the LambdaExpr constructor when we call it from ASTNodeImporter::VisitLambdaExpr (see llvm#149477). The lambda that we imported doesn't have the NumCaptures field accurately set to the one on the source decl. This is because in MinimalImport mode, we skip importing of lambda definitions:
https://github.com/llvm/llvm-project/blob/e21b0dd81928a3266df0e3ede008fb7a6676ff95/clang/lib/AST/ASTImporter.cpp#L2499

In practice we have seen this assertion occur in our import-std-module test-suite when libc++ headers decide to use lambdas inside inline function bodies (the latest failure being caused by llvm#144602).

To avoid running into this whenever libc++ decides to use lambdas in headers, this patch skips ASTImport of lambdas alltogether. Ideally this would bubble up to the user or log as an error, but we swallow the ASTImportErrors currently. The only way this codepath is hit is when lambdas are used inside functions in defined in the expression evaluator, or when importing AST nodes from Clang modules. Both of these are very niche use-cases (for now), so a workaround seemed appropriate.

(cherry picked from commit 0bbb794)

rdar://160792616

This patch works around an assertion that we hit in the `LambdaExpr`
constructor when we call it from `ASTNodeImporter::VisitLambdaExpr` (see
llvm#149477). The lambda that we
imported doesn't have the `NumCaptures` field accurately set to the one
on the source decl. This is because in `MinimalImport` mode, we skip
importing of lambda definitions:
https://github.com/llvm/llvm-project/blob/e21b0dd81928a3266df0e3ede008fb7a6676ff95/clang/lib/AST/ASTImporter.cpp#L2499

In practice we have seen this assertion occur in our `import-std-module`
test-suite when libc++ headers decide to use lambdas inside inline
function bodies (the latest failure being caused by
llvm#144602).

To avoid running into this whenever libc++ decides to use lambdas in
headers, this patch skips `ASTImport` of lambdas alltogether. Ideally
this would bubble up to the user or log as an error, but we swallow the
`ASTImportError`s currently. The only way this codepath is hit is when
lambdas are used inside functions in defined in the expression
evaluator, or when importing AST nodes from Clang modules. Both of these
are very niche use-cases (for now), so a workaround seemed appropriate.

(cherry picked from commit 0bbb794)
@Michael137 Michael137 requested a review from a team as a code owner September 23, 2025 10:43
@Michael137
Copy link
Author

@swift-ci test

@adrian-prantl
Copy link

@swift-ci test windows

2 similar comments
@Michael137
Copy link
Author

@swift-ci test windows

@Michael137
Copy link
Author

@swift-ci test windows

@Michael137
Copy link
Author

@swift-ci test macos

@Michael137
Copy link
Author

@swift-ci test

@adrian-prantl adrian-prantl merged commit 2c269df into swift/release/6.2 Sep 29, 2025
3 checks passed
@adrian-prantl adrian-prantl deleted the lldb/lambda-import-to-6.2 branch September 29, 2025 19:31
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