Skip to content

[Modules] Record side effect info in EvaluatedStmt (#146468) #10957

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

Conversation

hnrklssn
Copy link

@hnrklssn hnrklssn commented Jul 3, 2025

All deserialized VarDecl initializers are EvaluatedStmt, but not all EvaluatedStmt initializers are from a PCH. Calling VarDecl::hasInitWithSideEffects can trigger constant evaluation, but it's hard to know ahead of time whether that will trigger deserialization - even if the initializer is fully deserialized, it may contain a call to a constructor whose body is not deserialized. By caching the result of VarDecl::hasInitWithSideEffects and populating that cache during deserialization we can guarantee that calling it won't trigger deserialization regardless of the state of the initializer. This also reduces memory usage by removing the InitSideEffectVars set in ASTReader.

rdar://154717930
(cherry picked from commit 2910c24)

@hnrklssn hnrklssn requested a review from a team as a code owner July 3, 2025 22:47
@hnrklssn
Copy link
Author

hnrklssn commented Jul 3, 2025

@swift-ci please test

hnrklssn and others added 3 commits July 7, 2025 16:11
All deserialized VarDecl initializers are EvaluatedStmt, but not all
EvaluatedStmt initializers are from a PCH. Calling
`VarDecl::hasInitWithSideEffects` can trigger constant evaluation, but
it's hard to know ahead of time whether that will trigger
deserialization - even if the initializer is fully deserialized, it may
contain a call to a constructor whose body is not deserialized. By
caching the result of `VarDecl::hasInitWithSideEffects` and populating
that cache during deserialization we can guarantee that calling it won't
trigger deserialization regardless of the state of the initializer.
This also reduces memory usage by removing the `InitSideEffectVars` set
in `ASTReader`.

rdar://154717930
(cherry picked from commit 2910c24)
EvaluateAsInitializer does not support evaluating values with dependent
types. This was previously guarded with a check for the initializer
expression, but it is possible for the VarDecl to have a dependent type
without the initializer having a dependent type, when the initializer is
a specialized template type and the VarDecl has the unspecialized type.
This adds a guard checking for dependence in the VarDecl type as well.
This fixes the issue raised by Google in
llvm#145447

(cherry picked from commit c885005)
@hnrklssn hnrklssn force-pushed the fix-vardecl-init-serialization-fr branch from e31ab98 to 668ed82 Compare July 7, 2025 23:11
@hnrklssn
Copy link
Author

hnrklssn commented Jul 7, 2025

Because #10945 reverted #10925, this now re-lands it, with two fixes cherry-picked

@hnrklssn
Copy link
Author

hnrklssn commented Jul 7, 2025

@swift-ci please test

@hnrklssn
Copy link
Author

hnrklssn commented Jul 8, 2025

@swift-ci please test macos platform

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.

1 participant