← Back to Pull requests

Translate BlockPCs #799

Merged
manasij7479 merged 4 files (71 lines) on Nov 11, 2020 21:40 UTC
View on GitHub
manasij7479 manasij7479 commented on Oct 23, 2020 11:15 UTC
Author

No description provided by author.

Diff: 71 lines (+53 / -18) across 4 files Reviewer: zhengyang92 Review duration: 27985m
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.33) × (1 − Review Confidence (0.76)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.33 · 71 lines diff across 4 files
0.33
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.52 · 5 substantive comment(s)
0.52
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
75%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.256
Real PR Conversation Timeline
12 items
regehr regehr commented on Oct 26, 2020 03:45 UTC
Contributor

any comments @zhengyangl? it seems fine to me

zhengyang92 zhengyang92 commented on code on Oct 26, 2020 03:46 UTC
Code Review
include/souper/Infer/AliveDriver.h:1
@@ -70,7 +70,7 @@ class AliveDriver {
 };
 
 bool isTransformationValid(Inst* LHS, Inst* RHS, const std::vector<InstMapping> &PCs,
-                           InstContext &IC);
+                           const souper::BlockPCs & BPCs, InstContext &IC);

remove space between & and BPCs

zhengyang92 zhengyang92 commented on code on Oct 26, 2020 03:57 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -868,11 +868,15 @@ struct RefinementProblem {
   souper::Inst *LHS;
   souper::Inst *RHS;
   souper::Inst *Pre;
+  BlockPCs BPCs;
 
   RefinementProblem ReplacePhi(souper::InstContext &IC, std::map<Block *, size_t> &Change) {
     std::map<souper::Block *, std::set<souper::Inst *>> Phis;
     collectPhis(LHS, Phis);
     collectPhis(Pre, Phis);
+    for (auto &BPC : BPCs) {
+      collectPhis(BPC.PC.LHS, Phis);

Is it possible that BPC.PC.RHS is a phi node?

zhengyang92 zhengyang92 commented on code on Oct 26, 2020 04:04 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -890,20 +894,27 @@ struct RefinementProblem {
     Result.LHS = getInstCopy(LHS, IC, InstCache, BlockCache, &ConstMap, false);
     Result.RHS = getInstCopy(RHS, IC, InstCache, BlockCache, &ConstMap, false);
     Result.Pre = getInstCopy(Pre, IC, InstCache, BlockCache, &ConstMap, false);
+    Result.BPCs = BPCs;
+    for (auto &BPC : Result.BPCs) {
+      BPC.PC.LHS = getInstCopy(BPC.PC.LHS, IC, InstCache, BlockCache,
+                               &ConstMap, false);
+    }
 
     // Recursively call ReplacePhi, because Result might have Phi`s
     return Result.ReplacePhi(IC, Change);
   }
   bool operator == (const RefinementProblem &P) const {
-    return LHS == P.LHS && RHS == P.RHS && Pre == P.Pre;
+    return LHS == P.LHS && RHS == P.RHS &&
+           Pre == P.Pre && BPCs.size() == P.BPCs.size();

This size() comparison is too loose and may cause tricky failures in future. Could we implement operator= for BPCs and checks the equality for each element?

zhengyang92 zhengyang92 commented on code on Oct 26, 2020 04:12 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -946,23 +957,33 @@ std::unordered_set<RefinementProblem, RefinementProblem::Hash>
   std::unordered_set<RefinementProblem, RefinementProblem::Hash> Result;
 
   for (auto Change : ChangeList) {
-    Result.insert(P.ReplacePhi(IC, Change));
+    auto Goal = P.ReplacePhi(IC, Change);
+    // Consider switching to better data structures for dealing with BPCs
+    for (auto [Block, Pred] : Change) {
+      for (BlockPCMapping BPC : Goal.BPCs) {

please use reference when possible to avoid copying

zhengyang92 zhengyang92 commented on code on Oct 26, 2020 04:12 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -946,23 +957,33 @@ std::unordered_set<RefinementProblem, RefinementProblem::Hash>
   std::unordered_set<RefinementProblem, RefinementProblem::Hash> Result;
 
   for (auto Change : ChangeList) {
-    Result.insert(P.ReplacePhi(IC, Change));
+    auto Goal = P.ReplacePhi(IC, Change);
+    // Consider switching to better data structures for dealing with BPCs
+    for (auto [Block, Pred] : Change) {
+      for (BlockPCMapping BPC : Goal.BPCs) {
+        if (BPC.B == Block && BPC.PredIdx == Pred) {
+          auto Ante = IC.getInst(Inst::Eq, 1, {BPC.PC.LHS, BPC.PC.RHS});
+          Goal.Pre = IC.getInst(Inst::And, 1, {Goal.Pre, Ante});
+        }
+      }
+    }
+    Result.insert(Goal);
   }
-
   return Result;
 }
 
 }
 bool souper::isTransformationValid(souper::Inst* LHS, souper::Inst* RHS,
                                    const std::vector<InstMapping> &PCs,
+                                   const souper::BlockPCs & BPCs,

eliminate space between & and BPcs

zhengyang92 zhengyang92 requested changes on Oct 26, 2020 04:16 UTC
Changes Requested Reviewer

Looks good in general:) A few places need to be fixed.

regehr regehr commented on code on Oct 26, 2020 04:31 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -946,23 +957,33 @@ std::unordered_set<RefinementProblem, RefinementProblem::Hash>
   std::unordered_set<RefinementProblem, RefinementProblem::Hash> Result;
 
   for (auto Change : ChangeList) {
-    Result.insert(P.ReplacePhi(IC, Change));
+    auto Goal = P.ReplacePhi(IC, Change);
+    // Consider switching to better data structures for dealing with BPCs
+    for (auto [Block, Pred] : Change) {
+      for (BlockPCMapping BPC : Goal.BPCs) {
+        if (BPC.B == Block && BPC.PredIdx == Pred) {
+          auto Ante = IC.getInst(Inst::Eq, 1, {BPC.PC.LHS, BPC.PC.RHS});
+          Goal.Pre = IC.getInst(Inst::And, 1, {Goal.Pre, Ante});
+        }
+      }
+    }
+    Result.insert(Goal);
   }
-
   return Result;
 }
 
 }
 bool souper::isTransformationValid(souper::Inst* LHS, souper::Inst* RHS,
                                    const std::vector<InstMapping> &PCs,
+                                   const souper::BlockPCs & BPCs,

also, a couple lines above, always put the "*" next to the variable name, not next to the type, since in some circumstances that is misleading

manasij7479 manasij7479 commented on code on Oct 27, 2020 00:39 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -890,20 +894,27 @@ struct RefinementProblem {
     Result.LHS = getInstCopy(LHS, IC, InstCache, BlockCache, &ConstMap, false);
     Result.RHS = getInstCopy(RHS, IC, InstCache, BlockCache, &ConstMap, false);
     Result.Pre = getInstCopy(Pre, IC, InstCache, BlockCache, &ConstMap, false);
+    Result.BPCs = BPCs;
+    for (auto &BPC : Result.BPCs) {
+      BPC.PC.LHS = getInstCopy(BPC.PC.LHS, IC, InstCache, BlockCache,
+                               &ConstMap, false);
+    }
 
     // Recursively call ReplacePhi, because Result might have Phi`s
     return Result.ReplacePhi(IC, Change);
   }
   bool operator == (const RefinementProblem &P) const {
-    return LHS == P.LHS && RHS == P.RHS && Pre == P.Pre;
+    return LHS == P.LHS && RHS == P.RHS &&
+           Pre == P.Pre && BPCs.size() == P.BPCs.size();

Good point. Being slightly slower to avoid tricky failures seems reasonable.

manasij7479 manasij7479 commented on code on Oct 27, 2020 00:48 UTC
Code Review
lib/Infer/AliveDriver.cpp:1
@@ -868,11 +868,15 @@ struct RefinementProblem {
   souper::Inst *LHS;
   souper::Inst *RHS;
   souper::Inst *Pre;
+  BlockPCs BPCs;
 
   RefinementProblem ReplacePhi(souper::InstContext &IC, std::map<Block *, size_t> &Change) {
     std::map<souper::Block *, std::set<souper::Inst *>> Phis;
     collectPhis(LHS, Phis);
     collectPhis(Pre, Phis);
+    for (auto &BPC : BPCs) {
+      collectPhis(BPC.PC.LHS, Phis);

Seems to be just True or False.

regehr regehr commented on Nov 11, 2020 21:40 UTC
Contributor

LGTM, thanks!

Reviewers
Assignees
manasij7479 manasij7479
Labels
risk: low confidence: 75.6% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 33.0% (LOW) · Higher = larger blast radius
33.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 75.6% · Lower = rushed or shallow review
75.6%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 8% · Safe to merge
8%
Repository