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

Correct the type for bytecode evaluation of enum value (via ColonRef) #1545

Merged

Conversation

cdleary
Copy link
Collaborator

@cdleary cdleary commented Aug 18, 2024

Fixes #1541

  • Makes the type of the constexpr value annotated on enum members the type of the enum itself -- this causes bytecode emission to pick up the correctly typed value in the constexpr map
  • Display the Bits value underlying the enum more uniformly
  • Removes dead PrettyPrintValue

Note that this change found an issue only present in downstream code samples that was then surfaced as a new example. This subsequent issue was for constexpr evaluation of arrays with ellipsis.

There were cases where we were confusing:

  • the number of members in the array literal with
  • the array size, even though there were ellipses (in which case the number of members is determined by the type annotation)

Also removed accidental complexity in the course of making it consistent -- now ConstexprEvaluator calls into the bytecode intepreter directly instead of reimplementing another interpretation routine for HandleArray.

VLOG(5) << absl::StreamFormat(
"noting node: `%s` (%p) has constexpr value: `%s`",
const_expr->ToString(), const_expr, value.ToString());
const_exprs_.insert_or_assign(const_expr, std::move(value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, re review delay: The replacement of the const expr value sounds benign, however it breaks some other code outside this repository which I have yet to narrow down (time-slicing myself this week).

Highlevel: apparently in some for-loop in a proc, NoteConstExpr() is called with some array as value, and later for the same AstNode with a shorter array ... then things go south when some place attempts to access a non-existent index on the shorter array...
I've yet to determine the details. Will write a reproduction and fix when time permits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can get a trimmed down / publishable repro I'd be happy to debug and fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright. The new https://github.com/google/xls/blob/main/xls/examples/memory_proc.x serves as a useful example for beginners, but it will also be a repo.

Essentially, the state, which is an array representing the 'memory' is replaced with a single value. Which might actually might be different problem somewhere else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok found the issue, it was for constexpr evaluation of arrays with ellipsis.

There were cases where we were confusing the number of members in the array literal with the array size even though there were ellipses.

Also removed accidental complexity in the course of making it consistent -- now ConstexprEvaluator calls into the bytecode intepreter directly instead of reimplementing another interpretation routine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to tag you @hzeller -- thanks for the reproducer!

copybara-service bot pushed a commit that referenced this pull request Aug 22, 2024
Also helps to identify issue with
#1545

#xls-build-gardener

PiperOrigin-RevId: 666531259
@cdleary cdleary force-pushed the cdleary/2024-08-17-enum-in-struct branch from bb66506 to 2fda13b Compare August 23, 2024 17:29
xls/examples/ram.x Outdated Show resolved Hide resolved
@copybara-service copybara-service bot merged commit 4f467ee into google:main Aug 26, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DSLX bytecode interpreter should create values of the same shape with ZeroMacro or Literal.
4 participants