Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow duplicate but equal templates/functions #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion program_structure/src/program_library/function_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct FunctionData {
name: String,
file_id: FileID,
num_of_params: usize,
name_of_params: Vec<String>,
pub name_of_params: Vec<String>,
param_location: FileLocation,
body: Statement,
}
Expand Down
34 changes: 28 additions & 6 deletions program_structure/src/program_library/program_merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Merger {
for definition in definitions {
let (name, meta) = match definition {
Definition::Template { name, args, arg_location, body, meta, parallel, is_custom_gate } => {
if self.contains_function(&name) || self.contains_template(&name) {
if self.contains_function(&name) {
(Option::Some(name), meta)
} else {
let new_data = TemplateData::new(
Expand All @@ -44,12 +44,24 @@ impl Merger {
parallel,
is_custom_gate,
);
self.get_mut_template_info().insert(name.clone(), new_data);
(Option::None, meta)
if self.contains_template(&name) {
let existing_template = self.get_template_info().get(&name).unwrap();
// Ignore duplicate but equal
if existing_template.name_of_params == new_data.name_of_params
&& existing_template.input_declarations == new_data.input_declarations
&& existing_template.output_declarations == new_data.output_declarations {
(Option::None, meta)
} else {
(Option::Some(name), meta)
}
} else {
self.get_mut_template_info().insert(name.clone(), new_data);
(Option::None, meta)
}
}
}
Definition::Function { name, body, args, arg_location, meta } => {
if self.contains_function(&name) || self.contains_template(&name) {
if self.contains_template(&name) {
(Option::Some(name), meta)
} else {
let new_data = FunctionData::new(
Expand All @@ -61,8 +73,18 @@ impl Merger {
arg_location,
&mut self.fresh_id,
);
self.get_mut_function_info().insert(name.clone(), new_data);
(Option::None, meta)
if self.contains_function(&name) {
let existing_function = self.get_function_info().get(&name).unwrap();
// Ignore duplicate but equal
if existing_function.name_of_params == new_data.name_of_params {
(Option::None, meta)
} else {
(Option::Some(name), meta)
}
} else {
self.get_mut_function_info().insert(name.clone(), new_data);
(Option::None, meta)
}
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions program_structure/src/program_library/template_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ pub struct TemplateData {
name: String,
body: Statement,
num_of_params: usize,
name_of_params: Vec<String>,
pub name_of_params: Vec<String>,
param_location: FileLocation,
input_signals: SignalInfo,
output_signals: SignalInfo,
is_parallel: bool,
is_custom_gate: bool,
/* Only used to know the order in which signals are declared.*/
input_declarations: SignalDeclarationOrder,
output_declarations: SignalDeclarationOrder,
pub input_declarations: SignalDeclarationOrder,
pub output_declarations: SignalDeclarationOrder,
}

impl TemplateData {
Expand Down