Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes crash instrumenting generic func body nested in another func #78564

Conversation

chrismiles
Copy link
Contributor

@chrismiles chrismiles commented Jan 10, 2025

The crash was caused by attempting to add logging expressions that capture generic variables while using the outer func decl context that was not the generic decl context of the inner (generic) func.

The fix "pushes" the current func decl context while instrumenting the body. Rather than always using the top-level func decl context for all nested func bodies.

rdar://127009854
rdar://127009134

@chrismiles chrismiles self-assigned this Jan 10, 2025
@chrismiles chrismiles added the playground transform Area → compiler → type checker: The Xcode playground transform label Jan 10, 2025
@chrismiles
Copy link
Contributor Author

@swift-ci Please smoke test

@chrismiles chrismiles changed the title Fixes crash instrumenting generic func body next in another func Fixes crash instrumenting generic func body nested in another func Jan 13, 2025
@chrismiles chrismiles marked this pull request as ready for review January 13, 2025 21:54
@chrismiles chrismiles requested review from abertelrud, dbukowski, xedin, slavapestov and hborla and removed request for xedin, slavapestov and hborla January 13, 2025 21:54
Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

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

This fix looks good to me!


BraceStmt *InstrumenterBase::transformBraceStmtWithLocalDeclContext(
BraceStmt *BS, DeclContext *localDC, const ParameterList *PL,
bool TopLevel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this you can use RAII llvm::SaveAndRestore in a few spots were you need it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh cool, that looks simpler, thanks! Will take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use llvm::SaveAndRestore, which simplified the changes. Thanks!

… func.

The crash was caused by attempting to add logging expressions that capture generic variables while using the outer func decl context that was not the generic decl context of the inner (generic) func.

The fix "pushes" the current func decl context while instrumenting the body. Rather than always using the top-level func decl context for all nested func bodies.
@chrismiles chrismiles force-pushed the eng/chrismiles/playground-transform-crash-parsing-nested-generic-func branch from 4629e85 to f2846ce Compare January 14, 2025 19:20
@chrismiles
Copy link
Contributor Author

@swift-ci Please smoke test

@chrismiles
Copy link
Contributor Author

@swift-ci Please smoke test

@chrismiles chrismiles merged commit 73b184d into main Jan 15, 2025
3 checks passed
@chrismiles chrismiles deleted the eng/chrismiles/playground-transform-crash-parsing-nested-generic-func branch January 15, 2025 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
playground transform Area → compiler → type checker: The Xcode playground transform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants