Comments (15)
The example can be made even more devious by changing f
's return type to x
:
extern x f<x>();
from p4c.
The second problem isn't any harder than the first one.
Unfortunately the grammar becomes ambiguous if we allow a name instead of a nonTypeName for a typeParameter. @ChrisDodd: do you have any suggestion on how to fix this?
Java has a really ugly syntax for this issue.
from p4c.
I see a few options:
- Accept this "bug".
- Continue massaging the lexer and parser, if possible. I defer to @ChrisDodd on this.
- Adopt a different syntax for type parameters to methods -- e.g., Java's hideous (I agree) notation or maybe Scala's with square brackets.
- Rely on type inference exclusively, as in C#. I don't know how this would affect programs though -- I can easily imagine there are scenarios where we need to specify specific type arguments.
- Switch to something more powerful like a GLR parser?
-N
from p4c.
The problematic case that's really hard to parse is
header x {}
extern foo {
foo<x>(x a); // a templated constructor
}
We can disallow redeclaring types in this one case (allowing redeclaring types as type parameters in other contexts) with a fairly small grammar change; this case is problematic as you don't know that this is a ctor decl with a typeParameterList and not a (return) type with a typeArgumentList until you get to the (
after the type list.
from p4c.
Ooh, that is devious.
-N
On Wed, Oct 19, 2016 at 12:20 PM, Chris Dodd [email protected]
wrote:
The problematic case that's really hard to parse is
header x {}
extern foo {
foo(x a); // a templated constructor
}We can disallow redeclaring types in this one case (allowing redeclaring
types as type parameters in other contexts) with a fairly small grammar
change; this case is problematic as you don't know that this is a ctor decl
with a typeParameterList and not a (return) type with a typeArgumentList
until you get to the ( after the type list.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#108 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABwi0kpsWSS5scGShz6MFy3epNdhl0Rbks5q1m2RgaJpZM4KaQim
.
from p4c.
Actually we don't allow type parameters on constructors; if you need type parameters on a constructor, they have to be on the entire object.
extern E { E<T>(); } // illegal
extern E<T> { E(); } // legal
from p4c.
Well, the implementation certainly allows it -- the rule for
methodPrototype at line 526 for the constructor includes optional type
parameters. Remove those and the conflict goes away.
On Wed, Oct 19, 2016 at 1:14 PM, mbudiu-vmw [email protected]
wrote:
Actually we don't allow type parameters on constructors; if you need type
parameters on a constructor, they have to be on the entire object.extern E { E(); } // illegal
extern E { E(); } // legal—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#108 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AD4c8XPOoCismrA1NeTe0bX8_t_fs0ENks5q1nougaJpZM4KaQim
.
from p4c.
As does the spec (although presumably this was generated from the Bison grammar)...
methodPrototype
: functionPrototype ';'
| TYPE optTypeParameters '(' parameterList ')' ';'
;
from p4c.
The proposed fix causes one test failure -- p4_16_errors/generic_e/p4, which is just:
extern X<D>
{
void f<D>(in D d); // bug: D shadows D
}
The comment is correct in that there are two Ds in two different scopes, and the inner one shadows the outer one, but I'm not certain that it should be an error. It was previously giving a syntax error, which is definitely wrong (this is syntactically correct), but should it be a semantic error to have shadowing here? If so, we need a specific semantic check.
from p4c.
If type parameter declarations are binders, I might emit a warning but
would not treat this as an error...
-N
On Wed, Oct 19, 2016 at 4:17 PM, Chris Dodd [email protected]
wrote:
The proposed fix causes one test failure -- p4_16_errors/generic_e/p4,
which is just:extern X
{
void f(in D d); // bug: D shadows D
}The comment is correct in that there are two Ds in two different scopes,
and the inner one shadows the outer one, but I'm not certain that it should
be an error. It was previously giving a syntax error, which is definitely
wrong (this is syntactically correct), but should it be a semantic error to
have shadowing here? If so, we need a specific semantic check.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#108 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABwi0uXPNTOnuq9-YyOwqIQWdzfx-TM4ks5q1qUmgaJpZM4KaQim
.
from p4c.
Since extern declarations are part of the architecture, and they contain nothing but method declarations, I think that shadowing a type parameter is a really a bug in the library's design, which will confuse users. It's bad style, and it should be discouraged strongly.
from p4c.
Another view is that for all binders we morally work up to alpha
equivalence -- that is, this snippet is equivalent to
extern X
{
void f(in D d);
}
or equivalently
extern X
{
void f(in E d);
}
or equivalently
extern X
{
void f(in B d);
}
and so on, all of which are totally sensible. Hence, my preference for the
warning.
On Wed, Oct 19, 2016 at 4:24 PM, mbudiu-vmw [email protected]
wrote:
Since extern declarations are part of the architecture, and they contain
nothing but method declarations, I think that shadowing a type parameter is
a really a bug in the library's design, which will confuse users. It's bad
style, and it should be discouraged strongly.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#108 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABwi0kEdocExfxhOPnDQn6gPWzYK0Kviks5q1qaagaJpZM4KaQim
.
from p4c.
@mbudiu-vmw when you have a moment could you clarify "Actually we don't allow type parameters on constructors; if you need type parameters on a constructor, they have to be on the entire object." We should fix the spec if this is what's wanted...
from p4c.
At least a partial fix has made it to the spec: the grammar does not allow type parameters on a constructor. I don't know if the text emphasizes it.
from p4c.
Aha. I see it now. Thanks.
from p4c.
Related Issues (20)
- [P4Testgen] Build a Prototype which uses architecture templates
- [P4Testgen] Add a p4test-like target to testgen. HOT 7
- [P4Testgen] Coverage ignores empty actions HOT 5
- p4-ebpf permission denied: func 'map_initializer' doesn't have 1-th argument: invalid bpf_context HOT 5
- How to use p4lang to implement division operation in compile-time unknown value ? HOT 2
- MoveInitializers drops the srcInfo when moving to the top of a P4Control body
- Protobuf build errors with v1.2.4.7 HOT 5
- [P4Testgen] Revisit handling of varbit in P4Tools/P4Testgen
- Cannot use hvec_map for cstring keys HOT 3
- [P4Testgen] Validate options as early as possible
- [P4Testgen] The actions' coverage works weirdly if action is called from multiple tables HOT 4
- Port XDP tests from archived p4c-xdp repository
- Show a warning when a `@hidden` annotation is used on something where it is meaningless
- Clarify expected behavior of `--W*=diagnostic` option when `diagnostic` can be an error HOT 11
- Bug in p4c with some kinds of if statements inside of action bodies HOT 3
- `P4TEST_REPLACE` does not replace expected contents of `p4tc` test outputs HOT 4
- If and return/exit statements causing uninitialized_use warnings HOT 2
- hvec_map::insert has a non-standard behavior HOT 2
- P4C arm64/aarch64 support HOT 14
- Update the hash functions used in `hash.cpp` and `cstring.cpp` HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from p4c.