[libcxx-commits] [clang] [libcxx] [Clang][WIP] Normalize constraints before checking for satisfaction (PR #141776)
Younan Zhang via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Sep 9 08:53:19 PDT 2025
================
@@ -543,30 +672,330 @@ static ExprResult calculateConstraintSatisfaction(
return ExprError();
}
- assert(EvalResult.Val.isInt() &&
- "evaluating bool expression didn't produce int");
- Satisfaction.IsSatisfied = EvalResult.Val.getInt().getBoolValue();
- if (!Satisfaction.IsSatisfied)
- Satisfaction.Details.emplace_back(SubstitutedAtomicExpr.get());
+ assert(EvalResult.Val.isInt() &&
+ "evaluating bool expression didn't produce int");
+ Satisfaction.IsSatisfied = EvalResult.Val.getInt().getBoolValue();
+ if (!Satisfaction.IsSatisfied)
+ Satisfaction.Details.emplace_back(SubstitutedAtomicExpr.get());
+
+ return SubstitutedAtomicExpr;
+}
+
+ExprResult CalculateConstraintSatisfaction::Calculate(
+ const AtomicConstraint &Constraint,
+ const MultiLevelTemplateArgumentList &MLTAL) {
+
+ unsigned Size = Satisfaction.Details.size();
+ llvm::FoldingSetNodeID ID;
+ UnsignedOrNone OuterPackSubstIndex =
+ Constraint.getPackSubstitutionIndex()
+ ? Constraint.getPackSubstitutionIndex()
+ : PackSubstitutionIndex;
+ // Constraint.getConstraintExpr()->Profile(ID, S.Context, /*Canonical=*/true,
+ // /*ProfileLambdaExpr=*/true);
+ auto *Previous = Constraint.getConstraintExpr();
+ ID.AddPointer(Constraint.getConstraintExpr());
+ ID.AddInteger(OuterPackSubstIndex.toInternalRepresentation());
+ ID.AddBoolean(Constraint.hasParameterMapping());
+ HashParameterMapping(S, MLTAL, ID, OuterPackSubstIndex)
+ .VisitConstraint(Constraint);
+
+ if (auto Iter = S.ConceptIdSatisfactionCache.find(ID);
+ Iter != S.ConceptIdSatisfactionCache.end()) {
+
+ auto &Cached = Iter->second.Satisfaction;
+ Satisfaction.ContainsErrors = Cached.ContainsErrors;
+ Satisfaction.IsSatisfied = Cached.IsSatisfied;
+ Satisfaction.Details.insert(Satisfaction.Details.begin() + Size,
+ Cached.Details.begin(), Cached.Details.end());
+ return Iter->second.SubstExpr;
+ }
----------------
zyn0217 wrote:
I added an assert here to detect the incorrect cache values. I think it'd be better to get it back, before we can ensure the patch works on many other libraries.
https://github.com/llvm/llvm-project/pull/141776
More information about the libcxx-commits
mailing list