On the design of generic value parameters #1212
kyouko-taiga
started this conversation in
Language design
Replies: 1 comment 9 replies
-
My instinct is that compile-time value parameters should act like rvalue expressions wherever they appear in expression context. That makes them a little different to deal with than regular parameters, but at the same time, making the user call out Brain slowing down; may answer the rest later… |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As I started implementing generic (aka compile-time) value parameters (see #1211), I realized that our design has many rough edges that we should fix. I'm starting this thread to discuss them. The following are a semi-organized description of my observations so far.
The passing convention of compile-time parameters
Run-time parameters have one of 4 passing conventions:
set
,let
,inout
, orsink
. The precise meaning of these conventions is strongly related to some notion of temporality, which is a little tricky to define at compile-time.I think it would be simpler, at least to start, to say that the passing convention of all generic value parameters is
let
. The idea is that when we write this:We're writing a family of functions that all access some global constant, distinct for each member of that family. Global constants are always
let
bindings, and therefore so are generic value parameters.This interpretation may clash with some ideas that have been discussed for type parameters. In particular, if static
sink
subscripts are allowed. The rationale was that an expression of the formT.property
was notionally creating an instance ofT
and then consuming it to produce some property. I don't think this model doesn't work if generic parameters have thelet
convention.The lifetime of compile-time parameters
If compile-time arguments are understood as global constant, then they are "immortal" and never deinitialized.
The initialization of compile-time parameters
When compile-time arguments are initialized?
I think we should not promise any particular evaluation order, on any compile-time expression.
If we go that route, then I think one way to represent compile-time values is to have some trait that explains to the compiler how they can be serialized and then deserialized in the monomorphized form of a function, or at run-time before we call an existentialized function.
Beta Was this translation helpful? Give feedback.
All reactions