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

Compiler bug: could not find declaration for... #818

Closed
jnfoster opened this issue Aug 2, 2017 · 2 comments
Closed

Compiler bug: could not find declaration for... #818

jnfoster opened this issue Aug 2, 2017 · 2 comments
Assignees
Labels
bug This behavior is unintended and should be fixed. fixed This topic is considered to be fixed.

Comments

@jnfoster
Copy link
Contributor

jnfoster commented Aug 2, 2017

This rather silly program

#include <core.p4>

// Architecture    
parser P();
control C();
package S(P p);
extern BoolReg {
  BoolReg();
  bool get();
  void flip();
}
extern WrapControl {
  WrapControl(C c);
  void execute();
}
   
// User Program
BoolReg() r;
    
parser Loop()(WrapControl c1, WrapControl c2) {
  state start {
    r.flip();
    transition select(r.get()) {
      true: q1;
      false: q2;
      default: accept;
    }
  }
  state q1 {
    c1.execute();
    transition start;
  }
  state q2 {
    c2.execute();
    transition start;
  }
}
    
control MyC1() {
  apply {
    // Code for Control 1
  }
}
control MyC2() {
  apply {
    // Code for Control 2
  }
}
    
S(Loop(WrapControl(MyC1()), WrapControl(MyC2()))) main;

has a mysterious error

cyclic.p4(50): error: Could not find declaration for tmp_0
S(Loop(WrapControl(MyC1()), WrapControl(MyC2()))) main;
                   ^^^^^^
cyclic.p4(50): error: Could not find declaration for tmp_1
S(Loop(WrapControl(MyC1()), WrapControl(MyC2()))) main;
                                        ^^^^^^
@jnfoster
Copy link
Contributor Author

jnfoster commented Aug 2, 2017

Addendum: this version is accepted by the compiler.

#include <core.p4>

// Architecture    
parser P();
control C();
package S(P p);
extern BoolReg {
  BoolReg();
  bool get();
  void flip();
}
extern WrapControl {
  WrapControl(C c);
  void execute();
}
   
// User Program
BoolReg() r;
    
parser Loop()(WrapControl c1, WrapControl c2) {
  state start {
    r.flip();
    transition select(r.get()) {
      true: q1;
      false: q2;
      default: accept;
    }
  }
  state q1 {
    c1.execute();
    transition start;
  }
  state q2 {
    c2.execute();
    transition start;
  }
}
    
control MyC1() {
  apply {
    // Code for Control 1
  }
}
control MyC2() {
  apply {
    // Code for Control 2
  }
}

WrapControl(MyC1()) c1;
WrapControl(MyC2()) c2;        
    
S(Loop(c1,c2)) main;

@mihaibudiu
Copy link
Contributor

The fix here is also to disallow controls to be passed as arguments to extern constructors.

@mihaibudiu mihaibudiu self-assigned this Aug 2, 2017
@mihaibudiu mihaibudiu added the bug This behavior is unintended and should be fixed. label Aug 2, 2017
mihaibudiu pushed a commit to mihaibudiu/p4c-clone that referenced this issue Aug 3, 2017
@mihaibudiu mihaibudiu added the fixed This topic is considered to be fixed. label Aug 3, 2017
mihaibudiu pushed a commit that referenced this issue Aug 7, 2017
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. fixed This topic is considered to be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants