Skip to content

[gen] Fix a relaxation merge problem.#1747

Open
ShaleXIONG wants to merge 4 commits intoherd:masterfrom
ShaleXIONG:better-edge-merge
Open

[gen] Fix a relaxation merge problem.#1747
ShaleXIONG wants to merge 4 commits intoherd:masterfrom
ShaleXIONG:better-edge-merge

Conversation

@ShaleXIONG
Copy link
Copy Markdown
Collaborator

Fix a problem in annotation merge, for example diyone7 -arch AArch64 L A L PosWR Fri -oneloc should be an invalid input. It is due to the resolve_edges edges function will simple ignore the A annotation inbetween two L annotations, and the two L will be merged into one L.

We also remove an unnecessary second merge process in cycle.ml.

@ShaleXIONG ShaleXIONG requested a review from fsestini March 12, 2026 17:33
Copy link
Copy Markdown
Collaborator

@fsestini fsestini left a comment

Choose a reason for hiding this comment

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

Left a few minor comments, but overall this looks fine to me.

The code being modified here -- responsible for merging edges and annotations -- is non-trivial. Therefore I'd be happier if we could introduce some regression tests. These do not need to be anything particularly complex. We could just have one test targeting the expected result of diyone7 -arch AArch64 L A L PosWR Fri -oneloc and a few other tests involving a mix of annotations and Store/Insert edges. These can be implemented as dune cram tests like we do, for example, in cat2config.

List.rev es
|> List.find ( fun e -> not @@ is_insert_store e.edge ) in
List.fold_left (fun prev_annotation e ->
match is_insert_store e.edge, prev_annotation = e.a1 with
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's not use polymorphic equality here.

I would advise against it in general, but especially in this particular case. Here we are comparing two terms of type atom for equality, but atom is an abstract type, so we don't actually know whether equality is well-defined for atoms. If there is the need to compare atoms for equality, we should extend the signature of AtomType to include a equal : atom -> atom -> bool function, and use that function for this comparison.

Copy link
Copy Markdown
Collaborator Author

@ShaleXIONG ShaleXIONG Mar 25, 2026

Choose a reason for hiding this comment

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

Done.
I will use the existing function compare_atom instead of (=).

Comment on lines +841 to +844
|> Option.fold ~none:(update_annotation input)
(* Propagate result `f e` if changed *)
~some:(fun e ->
Some(Option.value (update_annotation e) ~default:e)) in
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Personal preference, but I'd find a plain old pattern match more readable, here.

Copy link
Copy Markdown
Collaborator Author

@ShaleXIONG ShaleXIONG Mar 25, 2026

Choose a reason for hiding this comment

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

Will change to simple match.

ShaleXIONG and others added 4 commits March 25, 2026 10:01
Rework on the `resolve_edge` function in `edge.ml`. The new version
will merge all annotations to immediate left and right hand side
edges. This means the `merge_annotation` in `cycle.ml` become
unnecessary.
@ShaleXIONG
Copy link
Copy Markdown
Collaborator Author

Left a few minor comments, but overall this looks fine to me.

The code being modified here -- responsible for merging edges and annotations -- is non-trivial. Therefore I'd be happier if we could introduce some regression tests. These do not need to be anything particularly complex. We could just have one test targeting the expected result of diyone7 -arch AArch64 L A L PosWR Fri -oneloc and a few other tests involving a mix of annotations and Store/Insert edges. These can be implemented as dune cram tests like we do, for example, in cat2config.

Left a few minor comments, but overall this looks fine to me.

The code being modified here -- responsible for merging edges and annotations -- is non-trivial. Therefore I'd be happier if we could introduce some regression tests. These do not need to be anything particularly complex. We could just have one test targeting the expected result of diyone7 -arch AArch64 L A L PosWR Fri -oneloc and a few other tests involving a mix of annotations and Store/Insert edges. These can be implemented as dune cram tests like we do, for example, in cat2config.

I add a syntax check in CI. It use a similar structure in #1582. Whichever pull get merged first, then I will rebase and manually merge the second.

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