Skip to content

Commit

Permalink
recongize constantant in mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
vita-dounai committed Nov 10, 2021
1 parent 2736e06 commit be8b88e
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions src/analyzer/ifds/problems/conflict_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,6 @@ impl<'tcx, 'graph> IfdsProblem<'tcx> for ConflictFields<'tcx, 'graph> {
| KnownNames::LiquidStorageValueGetMut
| KnownNames::LiquidStorageValueMutateWith
| KnownNames::LiquidStorageValueSet
| KnownNames::LiquidStorageCollectionsMappingExtend
| KnownNames::LiquidStorageCollectionsVecUse
| KnownNames::LiquidStorageCollectionsIterableMappingUse
) {
let this = &args[0];
let read_only = match this.ty(local_decls, self.tcx).kind() {
Expand Down Expand Up @@ -968,6 +965,35 @@ impl<'tcx, 'graph> IfdsProblem<'tcx> for ConflictFields<'tcx, 'graph> {
KnownNames::LiquidStorageCollectionsMappingInsert
| KnownNames::LiquidStorageCollectionsMappingRemove
) {
if let Operand::Constant(box constant) = &args[1] {
let key = if let Some(constant) = self.resolve_const(constant) {
Key::Const(constant)
} else {
Key::All
};

return Box::new(move |fact| {
if fact == &ConflictField::Zero {
let mut results = HashSet::new();
for container in &states {
results.insert(ConflictField::Field {
container: *container,
key: key.clone(),
read_only: false,
});
results.insert(ConflictField::Field {
container: *container,
key: Key::Len,
read_only: false,
});
}
results
} else {
HashSet::from_iter([fact.clone()])
}
});
}

let key_local = match &args[1] {
Operand::Copy(place) | Operand::Move(place) => place.local,
_ => unreachable!(),
Expand Down Expand Up @@ -1007,10 +1033,35 @@ impl<'tcx, 'graph> IfdsProblem<'tcx> for ConflictFields<'tcx, 'graph> {
});
}

if matches!(fn_name, KnownNames::LiquidStorageCollectionsMappingExtend) {
return Box::new(move |fact| {
if fact == &ConflictField::Zero {
let mut results = HashSet::new();
for container in &states {
results.insert(ConflictField::Field {
container: *container,
key: Key::All,
read_only: false,
});
results.insert(ConflictField::Field {
container: *container,
key: Key::Len,
read_only: false,
});
}
results
} else {
HashSet::from_iter([fact.clone()])
}
});
}

if matches!(
fn_name,
KnownNames::LiquidStorageCollectionsMappingLen
| KnownNames::LiquidStorageCollectionsMappingIsEmpty
| KnownNames::LiquidStorageCollectionsVecUse
| KnownNames::LiquidStorageCollectionsIterableMappingUse
) {
return Box::new(move |fact| {
if fact == &ConflictField::Zero {
Expand Down

0 comments on commit be8b88e

Please sign in to comment.