-
Notifications
You must be signed in to change notification settings - Fork 5
Add generics to safe, single-void functions #639
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
Conversation
* This fixes the 0 atoms affected root cause in test root_cause.c
Just making a note here about the extern int recv0_alias(void *buf, int n);
int recv0(void *buf : itype(_Array_ptr<void>) byte_count(n), int n) {
return recv0_alias(buf, n);
} rewrites to: extern int recv0_alias(void *buf, int n);
_Itype_for_any(T) int recv0(void *buf : itype(_Array_ptr<T>) byte_count(n), int n) {
return recv0_alias(buf, n);
} This is not safe because we don't know anything about what |
I've merged in the no_extra_atoms working branch now that that PR was merged, so this PR is mixed and should be considered as a draft until it can be cleaned up and re-posted. Current work is to get the benchmarks passing. The first of these only required a |
Note that merging one PR branch into another creates a risk of incorrect merging later, as described in the engineering handbook. We could help ensure a correct result by applying the procedure from the handbook for "If A is squash-merged to “main”" just before you next merge |
Yes, this is why the merge was partial (and re-considered draft), as not all my equipment is yet capable of supporting the upgrade. I'll be happy for the help when the time comes, or earlier if the upgrades are expected to be trivial. |
I'm looking at a tricky setup revealed by parsons benchmark. Here are my test cases:
Both of these deal with nested generics along with inferred generics. The type arguments are constraints from the local code, which may be safe or wild determined after constraint resolution.The parameter coming from the outer function may or may not be generic, to be determined after constraint resolution. But we don't propagate generic information through constraints, so a type parameter has two constraints, one generated at the call site to propagate wildness, and another for generics. This is not ideal, but the best option for now. The constraint holding the generics info must be the argument to the function that is also a parameter from the outer function. That way if it the function changes it to generic, that info is passed to the call site. Otherwise, nested generics are not supported. I need to come up with a non-supported example to make sure it is at least handled reasonably. In the second example, The type parameter to In the first example, the call to free is within a potentially-generic function. But that function is made wild through the use of it as a parameter in an external function. Because there is a good candidate for generics info in the call to This analysis was written after a few false starts and may not be complete, but hopefully helps people understand. It has also helped me identify specific next steps. |
This reverts commit f5cabd0. It was prematurly added from another branch that may not be used.
Fix for the above situation with nested generics was to check if the generic constraint was wild, not the generated one, and to use it instead if it is safe. If the generic constraint isn't used, the generated one will go through existing wildness checks anyway. |
Part of the process described at: #639 (comment)
Moved to a new branch and PR because this one was old and needed a significant merge with main. The new one is here |
Marked draft pending merge.Again considered draft until cleanup.This PR adds the ability for 3c to rewrite select function prototypes with generics. A variable with type
void *
is replaced by_For_any(T) ... _Ptr<T> ...
when the variable is not wild from other sources. Function pointers are not converted.Casting from
void *
is now a source of wildness unless the cast is of a generic function. The cast in this case is unnecessary, but retained for compatibility.It would be helpful to have some comments about use of Internal vs External function constraints.
Additional testing ideas would be appreciated.