-
Notifications
You must be signed in to change notification settings - Fork 5
Conversation
This reverts commit c46e7f4.
…ed by errors in generated DeepSeqCond instance
… higher-rank struct
This all looks good now! This is ready to merge when the BSC PR is merged. I am temped to squash this into a single commit. Unless you think there are parts of the history worth preserving as individual commits? |
Did you ever add a test like this (perhaps to
This demonstrates polymorphism of type |
I'm not aware of any, sounds reasonable to me.
Ah, good catch. I think I tested this in debugging by tweaking my Classic test cases, but nothing actually got committed. I added the function version as a BSV test case. However the
This is seemingly arising from the
I'm not really sure what the right thing to do is in this case. |
Yes, I believe you are incorrectly constructing the instance -- and am sorry that I wasn't reviewing your bsc PR close enough to catch that! This line in
is applying the typeclass member and not the evaluator primitive (as the comment on the function says is the intention). This is what is introducing the proviso. I think you should be using (Also, at the place at the top where the primitives for the classes are imported, the comment says "internal class members", but of course two -- soon to be three -- of them are the evaluator primitives, not the class members -- the names do not make that clear and don't even follow a consistent form between the three, unfortunately. I think I already have an open comment on the bsc PR, suggesting that comments and groupings on the Id importing can be improved.) |
@nanavati pointed out that the The only way that not having these |
Indeed. However, what we want to call This also explains why your tests are currently seeing the wrong behavior (even though I know I had prototyped this in the generics branch before). See my comment just now that I attached to the previous commit, at the same time that you were force-pushing a new commit :) The Prelude instance needs to look like this:
Where you have |
Ah. The issue is that my scheme calls We could fix the check. Or... we could keep your scheme (where there is no Deriving-generated DeepSeqCond instance and the ConcPoly instance directly calls the primitive on the polywrap type) and just change IExpand to do something different when it see a polywrap type: specifically, it should add the field selector to the given expression, and then proceed applying to that. Do you and @nanavati have an opinion on which of these is better? |
FYI, I was able to get your code to work by adding this code to IExpand's handling of
I had a hard time constructing the However, all of this complication can be avoided by using a PrimDeepSeqCond instance, created in Deriving, to do the field selection. But then IExpand's assertion for PrimSeqCond wouldn't be able to identify that it's being called on the field of a PolyWrap struct -- I don't think. In the example with |
@nanavati pointed out that always surfacing the implicit condition on higher-rank members doesn't seem to match the current behavior. We added https://github.com/B-Lang-org/bsc-testsuite/blob/master/bsc.typechecker/higherrank/DeepSeqCond.bs to document the compiler's current behavior, which is to not surface the condition for If so, then just deriving a |
What I've been talking about would not change this behavior. But thank you for bringing it up. It seems there are three situations:
Existing BSC has the following behaviors on DeepSeqCond:
Your changes have the following behaviors:
My two proposals (in the earlier comment) were about getting your Generic branch to have this behavior (matching existing BSC on 1 and 2 and doing better on 3):
Lifting is possible in situations 2 and 3 because no polymorphism exists when it gets to ISyntax: BSC has defaulted the generic variables to PrimUnit. In situation 1, the generated ISyntax looks like this:
You can see that the call to It seems like we have two options here: (A) be backwards compatible with the existing behavior ("no lift/lift/lift", per my proposals) or (B) we decide what the right thing to do is and we implement that (for example "no lift/no lift/no lift", per your original PR behavior). I'm OK with either A or B. It's a bit easier to go with A, knowing that we're not breaking behavior for anyone; but also I doubt that anyone is relying on the current behavior -- and arguably they shouldn't (and the defaulting to PrimUnit is maybe something that shouldn't be happening in this code, anyway, and therefore not not relied on for behavior) -- so maybe B is worth doing. As long as we have test cases for all the situations, to document the chosen behavior and catch if anything changes, then I'm fine with either. (I did wonder whether a second version of the |
I already have option (B) working via deriving a |
Wait, with my changes I am actually seeing the condition being lifted for
I have no idea why this is working if IExpand can't handle conditions from inside lambdas. But I feel that we have already spent way to much time on this corner-case, so I am tempted to just update the test to reflect this behavior and move on. |
This reverts commit 3f695d8.
* Add tests for derived Generic instances * Add test for CShow library (based on Generic) * Add a CustomBits example demo'ing the use of Generic * Add more tests for the features that are now implemented using Generic (Uninitialized, Undefined, DeepSeqCond/impCondOf), particularly the situations with polymorphism * Update expected results for b381 test now that this is no longer masked by errors in generated DeepSeqCond instance
This adds test cases for the generics mechanism added in B-Lang-org/bsc#284, and makes a couple of other minor changes required for the testsuite to pass.
make check
passes for me, pending #17 being merged.The generics test cases include a use of generics to implement a custom version of
Bits
, tests forCShow
, and both positive and negative tests that the generic representation types are as expected and that thefrom
andto
methods of the derivedGeneric
instances work properly.One change required to make the existing tests pass was in
bsc.bluetcl/targeted/type
, as the generated polymorphic field wrappers now show up in the bluetcl output. I'm not really sure how to avoid this if the change in behavior is undesirable, but since polymorphic fields rarely show up in actual code I doubt that this is an issue.Another such change is the one to
bsc.bugs/b381
, as discussed previously in an email.Additionally there are a few miscellaneous tests added, and some minor unrelated cleanup.