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

ir_convert should recognize inline array as valid RHS const expr in proc config functions #1748

Open
proppy opened this issue Nov 28, 2024 · 2 comments
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end

Comments

@proppy
Copy link
Member

proppy commented Nov 28, 2024

Describe the bug
In the context of a proc config function, it seems that ir_convert doesn't recognize inline array definitions as const expr .

To Reproduce

Attempting to convert the following proc:

import float32;
type F32 = float32::F32;

const F32_0 = float32::zero(false);
const F32_2 = F32 { sign: false, bexp: u8:128, fraction: u23:0 };

proc matmul {
    weight: F32[u32:4][u32:4];
    config() {
      let weights = F32[u32:4][u32:4]:[
          [F32_2, F32_0, F32_0, F32_0], [F32_0, F32_2, F32_0, F32_0], [F32_0, F32_0, F32_2, F32_0],
          [F32_0, F32_0, F32_0, F32_2],
      ];
      (weights,)
    }

    init { () }

    next(state: ()) {
      ()
    }
}

will produce the following error:

Error: INTERNAL: Let RHS not evaluated as constexpr: weights : F32[u32:4][u32:4]:[[F32_2, F32_0, F32_0, F32_0], [F32_0, F32_2, F32_0, F32_0], [F32_0, F32_0, F32_2, F32_0], [F32_0, F32_0, F32_0, F32_2]]

Expected behavior
ir_convert infer the const expr-ness for the array let binding.

@proppy
Copy link
Member Author

proppy commented Nov 28, 2024

Note that switching let weights to const WEIGHTS doesn't seems to help.

@proppy proppy changed the title ir_conver should evaluate inline array RHS as const expr in proc config functions ir_conver should recognize inline array as valid RHS const expr in proc config functions Nov 28, 2024
@proppy
Copy link
Member Author

proppy commented Nov 28, 2024

And moving it outside of config triggers #1747 (comment).

@proppy proppy changed the title ir_conver should recognize inline array as valid RHS const expr in proc config functions ir_convert should recognize inline array as valid RHS const expr in proc config functions Nov 28, 2024
@cdleary cdleary added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end labels Nov 28, 2024
cdleary added a commit to xlsynth/xlsynth that referenced this issue Nov 29, 2024
… not useful.

Previously ConstantArray was trying to convey some type-system-level properties
as imbued in an AST node, but it was not fully accurate, and generally only
served to confuse things. This gets us back to where the AST just represents
the parsed syntax and the typechecker figures out constexpr properties and
annotates them in the type information. This also allows us to seal up the
Array AST node as final  — subclassing of AST nodes can be awkward, we
generally use hierarchy in the AST very sparingly.

This reworks the deduce routine a bit to consolidate on the main discrepancy
that was there between Arrays and ConstArrays, which was that we would, for
user convenience, annotate the element type on any un-annotated numerical
literals contained within the array. This will become better and more general
will type inference 2.0 but until that comes we want to make sure we don’t have
to change code in a sprawling way.

Just trying to tighten up invariants in advance of somebody investigating
google#1748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end
Projects
Status: No status
Development

No branches or pull requests

2 participants