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

frontend: Fix SpecializeGenericTypes #5133

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Feb 19, 2025

A significant rewrite of SpecializeGenericTypes. Namely it fixes problems occurring in more complex specializations where a specialized type might depend on another specialized type and their order of insertion can be incorrect. Instead the types are now inspected to check for their dependencies and inserted just after all of the dependencies. I've also change the naming scheme of the specializations so that simple once are more readable (although for complex once the types quickly becomes ugly).

A caveat is that many passes seem to use very similar, but slightly different patterns and these passes still contain bugs (e.g. EliminateTuples. SpecializeGenericFunctions). Ideally, we would want to factor out the common parts and implement only the specific once, but I don't have time for that (at least not now). Namely at least the insertion part should be factorable for any pass that inserts global objects that can have dependencies.

Without the changes, the added test fails with

1217: Error compiling
1217: In file: ./p4c/frontends/p4/typeChecking/typeChecker.cpp:144
1217: type-spec-nested.p4(3): Could not find type of <Type_Struct>(3478) S2_0/2 struct S2_0 {
1217:   int<6> x;
1217:   int<6> y; }
1217: struct S2<T> {
1217:        ^^

The reason is that the specialization of S2 is inserted after specialization of S1 which refers to it.

@vlstill vlstill added bug This behavior is unintended and should be fixed. core Topics concerning the core segments of the compiler (frontend, midend, parser) labels Feb 19, 2025
@vlstill vlstill self-assigned this Feb 19, 2025
@vlstill vlstill force-pushed the fix-nested-generic-spec branch from 8d17ce1 to 988e1b6 Compare February 19, 2025 19:45
Always place the specialized structs *right before* the original.

Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
@vlstill vlstill changed the title frontend: Fix and simplify specializeGenericTypes frontend: Fix specializeGenericTypes Feb 21, 2025
@vlstill vlstill force-pushed the fix-nested-generic-spec branch 2 times, most recently from d13e3d7 to 22142e6 Compare February 21, 2025 19:19
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
@vlstill
Copy link
Contributor Author

vlstill commented Feb 21, 2025

@fruffy or anyone familiar with Bazel, any idea what is behind the bazel failure (e.g. here)? I can see it did not find absl/strings/str_replace.h, but I don't know how to find it as there is no @com_google_absl//absl/strings:str_replace.

@vlstill vlstill changed the title frontend: Fix specializeGenericTypes frontend: Fix SpecializeGenericTypes Feb 21, 2025
Co-authored-by: Anton Korobeynikov <anton@korobeynikov.info>
Signed-off-by: Vladimír Štill <git@vstill.eu>
Signed-off-by: Vladimír Štill <vladimir.still@altera.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This behavior is unintended and should be fixed. core Topics concerning the core segments of the compiler (frontend, midend, parser)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants