Replies: 1 comment
-
Yes, no problem. This is the only way to create a new array in llvm, on the stack or anywhere.
I don't see any problem here.
We could provide a |
Beta Was this translation helpful? Give feedback.
-
Yes, no problem. This is the only way to create a new array in llvm, on the stack or anywhere.
I don't see any problem here.
We could provide a |
Beta Was this translation helpful? Give feedback.
-
This relates to guppy, also to #1556.
At the moment Guppy has less polymorphism than Hugr: users can declare functions that are polymorphic over type variables, but the kind of every type var is one of either AnyType, CopyableType or UnboundedNat. In contrast Hugr offers a wide space of kinds (aka
TypeParam
s) - AnyType, CopyableType, BoundedNat, String, ExtensionSet, and List and Tuple of TypeParam(s) making an infinite set.If current Guppy was the only language we cared about supporting, we could massively simplify Hugr by dropping support for typeparams beyond Guppy's 3. (#1405 would no longer be the case, the type-level stuff would be waaay short of what one might call a "language"!)
More likely is that we'll extend Guppy. Adding support for kinds ListOfType and ListOfCopyableType seems like something that'd be useful for end user programmers dealing with (arbitrary) tuples. Other cases may follow, noting we plan never to parametrize over "higher-order" kinds like
Type -> Type
.Currently plans for compiling polymorphic functions in guppy lean towards monomorphization, i.e. guppy generates non-polymorphic Hugrs. Again, this suggests we might massively simplify the Hugr language(!); however, that route
dyn
-like passing of vtables)Instead we might ask: what facilities do we need in Hugr for "native Hugr polymorphism" to be usable by frontends? (Having frontends that monomorphize instead of using Hugr polymorphism seems the worst of all worlds - with a Hugr more complex than it needs to be, and frontends having to do more work.)
Looking at guppy, a major source of problems here are array comprehensions and initializations. For example,
array(qubit() for _ in range(N))
, whereN
is a statically-known type parameter. The monomorphization strategy involves generating N calls toqubit()
, which seems poor.So question to @doug-q: can LLVM initialize such an array (on stack) using a loop? E.g. via a
new_uninitialized
(ornew_filled_with_poison
) and then direct indexing?And what does the Hugr look like here? Given the element type is not copyable, we need code to execute for each element, so possibilities:
new_uninitialized
/new_poisoned
in Hugr too, eithermap_array
similar to the next option:new_array
taking a function. This could be a runtime (Value edge) pointer to a function (but not yet dynamically allocated / closure - that could follow later); or (following Allow custom ops with static constant input edges #1594) with a static edge to a function. We might also want to make this afold
, passing through some arbitrary (TypeParam::Type
) state. Again this boils down to whathugr-llvm
might be able to compile (@doug-q again)?What about constant folding? Loop+direct-indexing seems unlikely to constant-fold unless we first determine the iteration count is small and then unroll;
array_map
and similar structures would require the fold impl to make a nested call/callback into the constant-folder to evaluate the argument Hugr (perhaps multiple times).Beta Was this translation helpful? Give feedback.
All reactions