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

Type inference fails on int type #5090

Open
jaehyun1ee opened this issue Jan 6, 2025 · 2 comments
Open

Type inference fails on int type #5090

jaehyun1ee opened this issue Jan 6, 2025 · 2 comments
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).

Comments

@jaehyun1ee
Copy link

// issue2260-1.p4

control C();
package S(C c);
T f<T>(T x) {
    return x;
}
control MyC() {
    apply {
        bit<8> y = f(255);
   }
}
S(MyC()) main;

p4c rejects issue2260-1.p4 with this error log.

However, shouldn't it infer int as the type argument for calling f? i.e.,

bit<8> y = f<int>(255); // f returns int, and it is implicitly cast to bit<8>
@fruffy fruffy added the p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/). label Jan 6, 2025
@vlstill
Copy link
Contributor

vlstill commented Jan 6, 2025

From the log it seems that T is actually inferred to be int.

Where 'T' is bound to 'int'

So this might be an error in processing return type of generic functions. Maybe it was not tested because it is hard to write useful generic functions in P4 (see e.g. #5067), except for extern functions.

@jaehyun1ee
Copy link
Author

@vlstill Maybe it is because all int should be compile-time known, as mentioned in #5091?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p4-spec Topics related to the P4 specification (https://github.com/p4lang/p4-spec/).
Projects
None yet
Development

No branches or pull requests

3 participants