Restored array_to_subslice3 & code quality optimizations following the DST PR - #313
Restored array_to_subslice3 & code quality optimizations following the DST PR#313Lin23299 wants to merge 3 commits into
Conversation
|
You are correct. Having these as a late-phase cleanup that is untyped was necessary only because the definition of slice was opaque, and now this is not a great solution. I think 2. should be definitely ruled out, for the reasons that you mention. I think we should do a mix of 1. and 3. I think it's mostly going to boil down to a cosmetic / taste factor, as to what we think is most readable in the C code:
An additional complication is that What do you think? |
|
Looking at the diff I agree with you that we want to avoid macros as much as possible, and reverting to the old style where the macro receives a type argument is definitely a regression, so let's not do that. |
Totally agreed. I'll try to implement these optimizations after helping @ssyram to fix the issues on #311 |
According to #312 , I first tried to restore this optimization using
array_to_subslice3. I think the result is ok but what's happening here feels strange for me.At this phase (
PreCleanup3), we are rewritingarray_to_subsliceusingRangeinto aarray_to_subslice3using 2size_ts , but the difference here is that we have the monomorphized definition ofEurydice_array_to_subslice_XX. We have to remove it after this optimization. So basically we define the functionarray_to_subsliceusing abstract syntax withDst_Ref, and replace it later with a C macro by passing the monomorphized return typeDst_Ref_XX.Back to the quality issue, it seems to me that the point is to get rid of the
Rangetype. If so, maybe a better solution is to rewrite them earlier before the monomorphization, therefore we can get a monomorphized func def ofarray_to_subslice3_XXusingsize_ts instead of C macro definition?For the general optimization point, I agree that we could have many improvements. Following the discussion above, I think the question is to choose from:
I'm not sure which one is better, my previous plan is based on 1. Actually the current version is a mixup of 1 and 2 cuz I only wrote the abstract syntax for the functions could not be defined using macro. The
array_to_subslice3issue implies that it is possible to switch from 1 back to 2 for these functions. @protzEdit: I just found that the current macro definition causes stack smashing in
test-libcruxand I don't know why. This is a reason I personally prefer 1 than 2 because C macro is more error-prone.