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 comparisons can occur before type propagation #3001
Comments
Do you mean that Imo this should be an 'use of undeclared identifier @x' or something similar error, as |
Yeah. Maps aren't required to be defined before they're used, since they're shared across probes and so the order that they appear in a bpftrace script isn't necessarily the order in which they get read/updated at runtime. As another example, this script is valid:
But this script currently errors with the same message as the original issue:
This second script should still work as it's semantically identical to the first. The order in which probes are defined (and therefore maps are defined too) shouldn't change things. |
Ah I see your reasoning although I like the 2nd example more than the first. E.g. in For two+ probes it would indeed be nice if it detects the type independent of probe order. But maybe its better to just have the option to define maps up front? |
Agreed that declaring maps up front would be useful for big programs (opened an issue for it here: #2954). But type deduction is useful for ad-hoc investigations and we shouldn't give that up. Maps have always been initialised with a default value: 0 for integers, "" for strings, etc. (I'm not sure what for stacks...). So in your example, There could be an argument for changing this behaviour, but the initial example in this issue is specifically a bug with the current implementation. If we remove the
|
I am thinking that it might be useful to have a "strict mode" which prints errors at runtime if a program attempts to read from an undefined map (it can't be detected at compile time when there are multiple probes involved). |
Seems like bpftrace/src/ast/irbuilderbpf.cpp Line 430 in 72d54f2
But doesn't seem to work:
|
Upfront map definitions sounds useful. But perhaps would be good to think about if we can soundly determine map types in all cases. If it's not possible, I think it's reasonable to say something like: "bpftrace does its best to infer map types but in pathological cases it's better for you to annotate the map types". |
Maybe a tangent but just curious: what should the output of this be?
Should it print the map twice? Once with |
Yep, exactly. The EDIT: Ah... but it does not! |
Issue filed for the empty map printing: #3006 |
It looks like
I think it not working with |
The same issue also happens for the function call implementation in #3068, since the type of the function is not resolved yet in the first pass:
I fixed by adding |
This script should be valid:
Related to #2979
The text was updated successfully, but these errors were encountered: