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

DSLX should resolve parametric impl's const #1779

Open
proppy opened this issue Dec 10, 2024 · 1 comment
Open

DSLX should resolve parametric impl's const #1779

proppy opened this issue Dec 10, 2024 · 1 comment
Assignees
Labels
bug Something isn't working or is incorrect 🧦 sox

Comments

@proppy
Copy link
Member

proppy commented Dec 10, 2024

Describe the bug
DSLX frontend does not seems to support using a const from a parametric impl.

To Reproduce

struct Foo<N: u32> {
}

impl Foo<N> {
  const N_PLUS_1 = N + u32:1;
}

fn foo<N: u32>() -> u32 {
  Foo<N>::N_PLUS_1
}

fn foo32() -> u32 {
   foo<u32:32>()
}

#[test]
fn test_foo32() {
  assert_eq(foo32(), u32:33);
}

throws the following error:

0009: 
0010: fn foo<N: u32>() -> u32 {
0011:   Foo<N>::N_PLUS_1
~~~~~~~~~~~~~~^^ ParseError: Expected ':', got '::': Expect colon after type annotation in cast
0012: }
0013: 

Expected behavior
I would expect the parser to resolve Foo<N>::N_PLUS_1 as N + u32:1.

Note that attempting to define a local type alias:

  type F = Foo<N>;
  F::N_PLUS_1

produces a different error:

xls/dslx/constexpr_evaluator.cc:119
xls/dslx/type_system/deduce.cc:270
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce_colon_ref.cc:203
xls/dslx/type_system/deduce_colon_ref.cc:361
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:832
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:902
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/typecheck_invocation.cc:485
xls/dslx/type_system/deduce_invocation.cc:357
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:832
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:902
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce_ctx.cc:186
xls/dslx/type_system/typecheck_function.cc:198
xls/dslx/type_system/typecheck_module.cc:326
xls/dslx/type_system/typecheck_module.cc:326
xls/dslx/parse_and_typecheck.cc:102
xls/dslx/interpreter_main.cc:203
__main__.XlsRuntimeError('Error: INVALID_ARGUMENT: Expression @ 

Related: #1778

@proppy proppy added bug Something isn't working or is incorrect 🧦 sox labels Dec 10, 2024
@erinzmoore
Copy link
Collaborator

The second error referenced is from the type system: Expression @ fake.x:6:20-6:29 was not constexpr: 'N + u32:1'. Since type system v2 is in progress, we will wait for it to be ready to support this case.

Meanwhile, I'll work on the parser error (first error), but it's possible that once parsed, it will also hit the second error case and be blocked on type system v2.

copybara-service bot pushed a commit that referenced this issue Dec 17, 2024
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 🧦 sox
Projects
Status: No status
Development

No branches or pull requests

2 participants