Closed ranjitjhala closed 1 month ago
hang on, let me merge first...
@nilehmann -- the above is ready for review. One annoying thing is the addition of the &ConstGenericArgs::empty()
to all the instantiate_*
calls, maybe you can think of something cleaner?
Added the stuff for arrays too, so this works:
pub fn test01<const N: usize>(arr: &[i32; N]) -> i32 {
arr[0] //~ ERROR assertion might fail
}
pub fn test02<const N: usize>(arr: &[i32; N]) -> i32 {
if N > 0 {
arr[0]
} else {
99
}
}
This implementation is trickier than I thought because you need to pass the list of generated vars to every call to instantiate
not just instantiate_identity
. So, after writing the review, I feel more in favor of the alternative strategy we discussed, i.e., add the list of generics as a node to the RefineTree
. I have a proof of concept of this alternative strategy for (early) refinement parameters https://github.com/flux-rs/flux/compare/a6baf287b074c60663ef95d3d4e2cdb0562f06fa..77cccecec759072bdf12aec4e414f7aac6ca6cbb#diff-29db6f382c499c956b208bc768e6f78db625b7a8a9c529c0487ce9b9700a219a. I ended up not merging it because of some issues with function sorts that wouldn't be a problem for const generics.
But how does that address the kvar / scope issue?
On Mon, Jun 17, 2024 at 11:53 AM Nico Lehmann @.***> wrote:
This implementation is trickier than I thought because you need to pass the list of generated vars to every call to instantiate not just instantiate_identity. So, after writing the review, I feel more in favor of the alternative strategy we discussed, i.e., add the list of generics as a node to the RefineTree. I have a proof of concept of this alternative strategy for (early) refinement parameters https://github.com/flux-rs/flux/compare/a6baf287b074c60663ef95d3d4e2cdb0562f06fa..77cccecec759072bdf12aec4e414f7aac6ca6cbb#diff-29db6f382c499c956b208bc768e6f78db625b7a8a9c529c0487ce9b9700a219a https://urldefense.com/v3/__https://github.com/flux-rs/flux/compare/a6baf287b074c60663ef95d3d4e2cdb0562f06fa..77cccecec759072bdf12aec4e414f7aac6ca6cbb*diff-29db6f382c499c956b208bc768e6f78db625b7a8a9c529c0487ce9b9700a219a__;Iw!!Mih3wA!B_33qdAIfM5xkUozvinPOANf7gtGq7CyCT9-9-JtOvYolOtgnpWHASjzKi1nrIPhkGmA21qLnfM55dHNEvA0MFhN$. I ended up not merging it because of some issues with function sorts that wouldn't be a problem for const generics.
— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/flux-rs/flux/pull/637*issuecomment-2174204034__;Iw!!Mih3wA!B_33qdAIfM5xkUozvinPOANf7gtGq7CyCT9-9-JtOvYolOtgnpWHASjzKi1nrIPhkGmA21qLnfM55dHNEt44OekF$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AAMS4OGZ2SGSNRZUUXH6YXLZH4WBFAVCNFSM6AAAAABJKR5UMSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNZUGIYDIMBTGQ__;!!Mih3wA!B_33qdAIfM5xkUozvinPOANf7gtGq7CyCT9-9-JtOvYolOtgnpWHASjzKi1nrIPhkGmA21qLnfM55dHNEhFnX7JO$ . You are receiving this because you were mentioned.Message ID: @.***>
--
But how does that address the kvar / scope issue?
We modify Scope::iter
to also return the const generics https://github.com/flux-rs/flux/compare/a6baf287b074c60663ef95d3d4e2cdb0562f06fa..77cccecec759072bdf12aec4e414f7aac6ca6cbb#diff-29db6f382c499c956b208bc768e6f78db625b7a8a9c529c0487ce9b9700a219aR105.
@nilehmann -- I made the changes so all the stuff is in Root
and the ConstGeneric
is carried along to fixpoint...
The one tedious thing is you have to pass tcx
into instantiate
as we need tcx
to convert the GenericArg
corresponding to a number e.g. 3
to the actual u128
...
Have made all the changes except the ParamConst
thing, see discussion above -- will take a look with fresh eyes!
ok I believe I addressed all comments -- in particular made all the ParamConst
back into DefId
.
Will merge if CI is green!
The following works now, but I'd like to get some feedback on simplifying etc. before moving to the actual use case of array lengths.
The main changes are these:
Checking Definitions
a0
)TypeEnv
to track a mappub struct ConstGenericArgs(FxHashMap<u32, Expr>)
that maps eachN
to the singleton expr,TypeEnv
to give occurrences of GenericParam the corresponding singleton-indexed type (e.g.usize[a0]
)So given
fn foo<N: usize>() -> usize{v: N < v} { N + 1 }
STEP 1. Get a name
a0
STEP 2. Substitute the sig to getfn() -> usize{v: a0 < v}
STEP 3. Extend theTypeEnv
to trackN -> a0
STEP 4. Type check usingTypeEnv
to get the constraintforall a0. a0 < a0 + 1
Checking Calls
Similar to the above, except that when we
instantiate
thegeneric_args
we again build up aConstGenericArgs
to substitute all the generic params in the refinements with the appropriate constants e.g.3
or the correspondinga0
singleton name at the callsite (using the caller'sTypeEnv
), as done incall_const_generic_args
.