Skip to content

(rust/lira_opt) initial - #20

Draft
belovdv wants to merge 2 commits into
masterfrom
lira_opt
Draft

belovdv wants to merge 2 commits into
masterfrom
lira_opt

Conversation

@belovdv

@belovdv belovdv commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Added:

  • set of rewrites,
  • operations transformations,
  • template ir,
  • rewrites via snippets.

Added:
- set of rewrites,
- operations transformations,
- template ir,
- rewrites via snippets.
@belovdv
belovdv requested a review from uslsteen October 14, 2026 08:49
Comment on lines +19 to +21
if let Some(start) = ["seq:", "semantic:"].iter().find(|s| l.starts_with(*s))
&& !line.ends_with("\"\"")
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these changes only in Rust LIRA library?

@belovdv belovdv Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a rust implementation specific bug. It was not present in python (idk about ruby)

Comment thread rust/lira/src/ir.rs Outdated
Comment on lines +73 to +99
pub fn set_tmp_prefix(&mut self, prefix: impl ToString) {
self.tmp_prefix = prefix.to_string();
}
pub fn update_tmp_prefix<'a, 's: 'a>(
&'s mut self,
base: &str,
names_to_avoid: impl Iterator<Item = &'a String> + Clone,
) {
let names_to_avoid = || {
names_to_avoid
.clone()
.chain(self.stmts.iter().flat_map(|stmt| stmt.outputs.iter()))
};
for i in 0..names_to_avoid().count() + 1 {
let prefix = format!("{base}{i}");
if names_to_avoid().all(|name| !name.starts_with(&prefix)) {
self.tmp_counter = 0;
self.tmp_prefix = prefix;
return;
}
}
unreachable!("names_to_avoid len + 1 prefixes should've been enough")
}
pub fn gen_temp_name(&mut self) -> String {
self.tmp_counter += 1;
format!("{}{}", self.tmp_prefix, self.tmp_counter)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused public functions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, rust/lira_trs/src/impl_dfg3lira.rs and rust/lira_trs/src/dfg.rs modules implement their own local gen_temp_name with the same functionality (impl_dfg3lira.rs:115, dfg.rs:58). Why is it so?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused private functions - dead code, what's the problem with unused locally public function?

Comment thread rust/lira/src/ir.rs Outdated
Comment on lines +104 to +111
pub fn try_push_gen_temp_names(&mut self, mut stmt: Statement) -> anyhow::Result<()> {
assert!(stmt.outputs.is_empty());
assert!(!stmt.outputs_types.is_empty());
stmt.outputs = (0..stmt.outputs_types.len())
.map(|_| self.gen_temp_name())
.collect();
self.try_push(stmt)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead code.

Comment thread rust/lira/src/ir.rs Outdated
Comment on lines +30 to +31
tmp_prefix: String,
tmp_counter: usize,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused members.

Comment thread rust/lira/src/ir_std.rs
Comment on lines 420 to -162
"fold" => {
let op = get!(op);
let args = &self.inputs[..];
StmtSpecificStd::Fold { op, args }
let _op = get!(op);
let _args = &self.inputs[..];
todo!()
}
"scan" => {
let op = get!(op);
let args = &self.inputs[..];
StmtSpecificStd::Scan { op, args }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s wrong with this? Why this statements marked with todo!() ? And why does lira_trs use its own statements (fold.op, scan.op in rust/lira_trs/src/lib.rs)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code isn't used. It can be removed from this PR.
In general though each language should provide statement concretization.

Comment thread rust/lira_trs/src/lib.rs
"cond.sys_reg.write",
"fop",
"env",
"cond.env",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are statements in rust/lira/src/ir_std.rs named things like cond_env, whereas here you use cond.env?

Globally: why use a . as a separator at all, instead of an _ (e.g., scan.fop, cond.write, etc.)?

@belovdv belovdv Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cond_env is a mistake.

cond. is a common prefix with similar semantic. Same for other usages of . - they separate parts that have meaning on their own. _ separates words in atomic name.

Imho naming convention is not a part of this PR, but rather #19

Comment thread rust/lira/src/ir_std.rs
Comment on lines +331 to +333
let cond = self.inputs[0].as_str();
let on_false = self.inputs[0].as_str();
let rsi = self.inputs[0].as_str();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there is a bug.
cond, on_false, and rsi are all read from self.inputs[0].
Should be [0], [1], and [2] ?

Comment thread rust/lira/src/ir_std.rs
Comment on lines +395 to +397
let value = &self.inputs[0];
let index = &self.inputs[0];
let on_false = &self.inputs[0];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there is a bug.
Open diff & compare with previous version.

Comment thread rust/lira/src/ir_std.rs
Comment on lines +407 to +410
let base = &self.inputs[0];
let cond = &self.inputs[0];
let value = &self.inputs[0];
let index = &self.inputs[0];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like there is a bug.
Open diff & compare with previous version.

@belovdv
belovdv marked this pull request as draft October 20, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants