Skip to content

Conversation

@hnrklssn
Copy link
Member

@hnrklssn hnrklssn commented Sep 11, 2025

Explanation: This serializes the result of VarDecl::hasInitWithSideEffects, to prevent triggering deserialization of the initializer expression when deserialization is already occurring.
Issues: rdar://154717930
Original PRs: llvm#143739 llvm#146468 llvm#147378
Risk: Low, this has been in llvm.org/main for a while now
Testing: Added a regression test.
Reviewers: @benlangmuir

hnrklssn and others added 3 commits September 11, 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 requested a review from a team as a code owner September 11, 2025 23:14
@hnrklssn
Copy link
Member Author

@swift-ci please test llvm

@hnrklssn
Copy link
Member Author

@swift-ci please test

@hnrklssn hnrklssn closed this Sep 12, 2025
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