Skip to content
Merged
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 frontends/p4/typeChecking/typeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const IR::Type *TypeInferenceBase::cloneWithFreshTypeVariables(const IR::IMayBeG
BUG_CHECK(b, "%1%: failed replacing %2% with %3%", type, v, tv);
}

TypeVariableSubstitutionVisitor sv(&tvs, true);
TypeVariableSubstitutionVisitor sv(&tvs, true, true);
sv.setCalledBy(this);
auto cl = type->to<IR::Type>()->apply(sv, getChildContext());
CHECK_NULL(cl);
Expand Down
2 changes: 2 additions & 0 deletions frontends/p4/typeChecking/typeInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ir/dump.h"
#include "typeChecker.h"

namespace P4 {
Expand Down Expand Up @@ -143,6 +144,7 @@ DEFINE_POSTORDER(IR::Annotation)
Visitor::profile_t TypeInference::init_apply(const IR::Node *node) {
auto rv = Transform::init_apply(node);
TypeInferenceBase::start(node);
LOG5(Dump(node));

return rv;
}
Expand Down
2 changes: 1 addition & 1 deletion frontends/p4/typeChecking/typeSubstitution.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class TypeSubstitution : public IHasDbPrint {
bool first = true;
for (auto it : binding) {
if (!first) out << std::endl;
out << dbp(it.first) << " " << it.first << " -> " << dbp(it.second) << " " << it.second;
out << dbp(it.first) << " -> " << dbp(it.second);
first = false;
}
}
Expand Down
15 changes: 9 additions & 6 deletions frontends/p4/typeChecking/typeSubstitutionVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ class TypeOccursVisitor : public Inspector {
class TypeVariableSubstitutionVisitor : public Transform {
protected:
const TypeVariableSubstitution *bindings;
bool replace; // If true variables that map to variables are just replaced
// in the TypeParameterList of the replaced object; else they
// are removed.
bool replace; // If true variables that map to variables are just replaced
// in the TypeParameterList of the replaced object; else they
// are removed.
bool cloneInfInt; // If true, ensure that Type_InfInt nodes are replaced with
// new ones as fresh type variables
const IR::Node *replacement(const IR::ITypeVar *original, const IR::Node *node);

public:
explicit TypeVariableSubstitutionVisitor(const TypeVariableSubstitution *bindings,
bool replace = false)
: bindings(bindings), replace(replace) {
bool replace = false, bool cloneInfInt = false)
: bindings(bindings), replace(replace), cloneInfInt(cloneInfInt) {
setName("TypeVariableSubstitution");
}

Expand All @@ -65,7 +67,8 @@ class TypeVariableSubstitutionVisitor : public Transform {
return replacement(getOriginal<IR::Type_Var>(), tv);
}
const IR::Node *preorder(IR::Type_InfInt *ti) override {
return replacement(getOriginal<IR::Type_InfInt>(), ti);
const auto *n = cloneInfInt ? IR::Type_InfInt::get() : ti;
return replacement(getOriginal<IR::Type_InfInt>(), n);
}
};

Expand Down
4 changes: 2 additions & 2 deletions ir/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ cstring IR::dbp(const IR::INode *node) {
} else if (node->is<IR::PathExpression>() || node->is<IR::Path>() ||
node->is<IR::TypeNameExpression>() || node->is<IR::Constant>() ||
node->is<IR::Type_Name>() || node->is<IR::Type_Base>() ||
node->is<IR::Type_Specialized>()) {
node->is<IR::ITypeVar>() || node->is<IR::Type_Specialized>()) {
node->getNode()->Node::dbprint(str);
str << " " << node->toString();
str << " " << node->getNode();
} else {
node->getNode()->Node::dbprint(str);
}
Expand Down
4 changes: 4 additions & 0 deletions testdata/p4_16_errors_outputs/issue3273.p4-stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
issue3273.p4(3): [--Werror=type-error] error: int: illegal return type for method
abstract int f();
^^^
[--Werror=type-error] error: int: illegal return type for method
issue3273.p4(1): [--Werror=type-error] error: Error while analyzing e
extern e {
^
45 changes: 45 additions & 0 deletions testdata/p4_16_samples/extern-int-arg1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);

header h1_t {
bit<32> f1;
bit<16> h1;
bit<8> b1;
bit<8> cnt;
}

struct headers_t {
h1_t head;
}

extern Counter {
Counter(int size);
void count(int idx);
}

control c(inout headers_t hdrs) {
Counter(256) ctr;

action a0() {
ctr.count(0);
}
action a1(bit<8> idx) {
ctr.count(idx);
}
action a2(bit<4> idx) {
ctr.count(idx);
}

table t1 {
key = { hdrs.head.f1 : exact; }
actions = { a0; a1; a2; }
}

apply {
t1.apply();
}
}

top(c()) main;
49 changes: 49 additions & 0 deletions testdata/p4_16_samples_outputs/extern-int-arg1-first.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header h1_t {
bit<32> f1;
bit<16> h1;
bit<8> b1;
bit<8> cnt;
}

struct headers_t {
h1_t head;
}

extern Counter {
Counter(int size);
void count(int idx);
}

control c(inout headers_t hdrs) {
Counter(256) ctr;
action a0() {
ctr.count(0);
}
action a1(bit<8> idx) {
ctr.count(idx);
}
action a2(bit<4> idx) {
ctr.count(idx);
}
table t1 {
key = {
hdrs.head.f1: exact @name("hdrs.head.f1");
}
actions = {
a0();
a1();
a2();
@defaultonly NoAction();
}
default_action = NoAction();
}
apply {
t1.apply();
}
}

top<headers_t>(c()) main;
51 changes: 51 additions & 0 deletions testdata/p4_16_samples_outputs/extern-int-arg1-frontend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header h1_t {
bit<32> f1;
bit<16> h1;
bit<8> b1;
bit<8> cnt;
}

struct headers_t {
h1_t head;
}

extern Counter {
Counter(int size);
void count(int idx);
}

control c(inout headers_t hdrs) {
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("c.ctr") Counter(256) ctr_0;
@name("c.a0") action a0() {
ctr_0.count(0);
}
@name("c.a1") action a1(@name("idx") bit<8> idx_2) {
ctr_0.count(idx_2);
}
@name("c.a2") action a2(@name("idx") bit<4> idx_3) {
ctr_0.count(idx_3);
}
@name("c.t1") table t1_0 {
key = {
hdrs.head.f1: exact @name("hdrs.head.f1");
}
actions = {
a0();
a1();
a2();
@defaultonly NoAction_1();
}
default_action = NoAction_1();
}
apply {
t1_0.apply();
}
}

top<headers_t>(c()) main;
51 changes: 51 additions & 0 deletions testdata/p4_16_samples_outputs/extern-int-arg1-midend.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header h1_t {
bit<32> f1;
bit<16> h1;
bit<8> b1;
bit<8> cnt;
}

struct headers_t {
h1_t head;
}

extern Counter {
Counter(int size);
void count(int idx);
}

control c(inout headers_t hdrs) {
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("c.ctr") Counter(256) ctr_0;
@name("c.a0") action a0() {
ctr_0.count(0);
}
@name("c.a1") action a1(@name("idx") bit<8> idx_2) {
ctr_0.count(idx_2);
}
@name("c.a2") action a2(@name("idx") bit<4> idx_3) {
ctr_0.count(idx_3);
}
@name("c.t1") table t1_0 {
key = {
hdrs.head.f1: exact @name("hdrs.head.f1");
}
actions = {
a0();
a1();
a2();
@defaultonly NoAction_1();
}
default_action = NoAction_1();
}
apply {
t1_0.apply();
}
}

top<headers_t>(c()) main;
47 changes: 47 additions & 0 deletions testdata/p4_16_samples_outputs/extern-int-arg1.p4
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <core.p4>

control generic<M>(inout M m);
package top<M>(generic<M> c);
header h1_t {
bit<32> f1;
bit<16> h1;
bit<8> b1;
bit<8> cnt;
}

struct headers_t {
h1_t head;
}

extern Counter {
Counter(int size);
void count(int idx);
}

control c(inout headers_t hdrs) {
Counter(256) ctr;
action a0() {
ctr.count(0);
}
action a1(bit<8> idx) {
ctr.count(idx);
}
action a2(bit<4> idx) {
ctr.count(idx);
}
table t1 {
key = {
hdrs.head.f1: exact;
}
actions = {
a0;
a1;
a2;
}
}
apply {
t1.apply();
}
}

top(c()) main;
Empty file.
Loading