Address capture flakiness when a symbol is multiply defined.

Summary:
When a project defines the same symbol in different files,
the results of the capture will be different depending on
the order in which files are captured.

In particular, if a procedure with the same name is defined in different files,
it will be associated with the last file being captured.
So the results can be different if the files are processed in different order.
In case of parallel capture, this has in effect a non-deterministic behaviour.

This diff defines a canonical file (alphabetically) when a procedure is multiply
defined, so that the procedure is associated to the same file whatever the order.

Reviewed By: jeremydubreil

Differential Revision: D3805002

fbshipit-source-id: 2c561f4
master
Cristiano Calcagno 8 years ago committed by Facebook Github Bot 8
parent 977f73ff5b
commit 346d3e6d01

@ -45,12 +45,21 @@ let res_dir_attr_filename pname => {
filename filename
}; };
let store_attributes proc_attributes => { let store_attributes (proc_attributes: ProcAttributes.t) => {
let proc_name = proc_attributes.ProcAttributes.proc_name; let proc_name = proc_attributes.proc_name;
let attributes_file = res_dir_attr_filename proc_name; let attributes_file = res_dir_attr_filename proc_name;
let should_write = let should_write = not (DB.file_exists attributes_file) || (
/* only overwrite defined procedures */ switch (Serialization.from_file serializer attributes_file) {
proc_attributes.ProcAttributes.is_defined || not (DB.file_exists attributes_file); | None => true
| Some proc_attributes_on_disk =>
let higher_rank_than_on_disk () =>
DB.source_file_compare proc_attributes.loc.file proc_attributes_on_disk.loc.file > 0;
let becomes_defined = proc_attributes.is_defined && not proc_attributes_on_disk.is_defined;
/* Only overwrite the attribute file if the procedure becomes defined
or its associated file has higher rank (alphabetically) than on disk. */
becomes_defined || higher_rank_than_on_disk ()
}
);
if should_write { if should_write {
Serialization.to_file serializer attributes_file proc_attributes Serialization.to_file serializer attributes_file proc_attributes
} }

Loading…
Cancel
Save