Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow count of elements in repeated-element array syntax to be any comptime Field #445

Open
jfecher opened this issue Nov 7, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Nov 7, 2022

Problem

PR #440 expands the repeated-element array syntax to accept a count of elements where count is an integer expression containing only literals, basic numeric operations, or global constants. Although this should cover most usecases, it is theoretically overly limiting to users.

Solution

We could allow all expressions that evaluate to a comptime Field (or other countable integer type) as part of the count expression. Then both expressions in [expr; expr] would be arbitrary, just with type checking constraints limiting the second to be known at compile-time.

Alternatives considered

Alternatively, we could say users do not need this flexibility and choose not to have this feature.

@jfecher jfecher added the enhancement New feature or request label Nov 7, 2022
@kevaundray
Copy link
Contributor

@f01dab1e feel free to take this on; if you choose to, please write a summary of how you plan to take it on in this issue beforehand

@ghost ghost mentioned this issue Jul 26, 2023
@ghost
Copy link

ghost commented Aug 14, 2023

should we start introducing the concept of const? and allow only const expressions?

@jfecher
Copy link
Contributor Author

jfecher commented Aug 14, 2023

Right now, it seems like the main thing we're missing is the ability to use numeric generics in these array size expressions. I don't think we'd need full const expression support (e.g. const functions), we should start with this main missing feature I think.

@ghost
Copy link

ghost commented Aug 18, 2023

I was asked to write a plan...

introduce a new type: AbstractConst, something like this:

struct AbstractConst {
    nodes: Vec<Node>,
}

enum Node {
    Leaf(u64 | Param),
    Binary(Node, BinOp, Node),
    Unary(UnOp, Node),
}

expand unification with the try_unify_const function. something like this:

fn try_unify_const(a: AbstractConst, b: AbstractConst) -> bool {
 match (a.root(), b.root()) {
     (Leaf(a), Leaf(b)) => a == b,
     (UnaryOp(a_op, av), UnaryOp(b_op, bv)) if a_op == b_op => {
         try_unify_const(a.subtree(av), b.subtree(bv))
     }
     <...>
 }
}

when the user supplies type parameters with values it is easy to execute...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants