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

Rename as_bool to as_truthy, and fix TypeSet::as_bool #6027

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

elliottt
Copy link
Member

@elliottt elliottt commented Mar 15, 2023

Rename the as_bool functions in cranelift-codegen-meta to as_truthy to better describe their behavior. Additionally, fix the implementation of TypeSet::as_truthy to match the behavior of Type::as_truthy, as it was returning an empty TypeSet when it should have been mirroring the behavior.

This bug was introduced in #5031 when we removed booleans from cranelift.

Comment on lines -449 to +458
copy.ints = NumSet::new();

// If this type set represents a scalar, `as_truthy` produces an I8, otherwise it returns a
// vector of the same number of lanes, whose elements are integers of the same width. For
// example, F32X4 gets turned into I32X4, while I32 gets turned into I8.
if self.lanes.len() == 1 && self.lanes.contains(&1) {
copy.ints = NumSet::from([8]);
} else {
copy.ints.extend(&self.floats)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Here's the bug fix for TypeSet::as_truthy. I've also updated the tests to ensure this is doing what we expect now, given the semantics of as_truthy_pedantic.

@elliottt elliottt marked this pull request as ready for review March 15, 2023 19:29
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:meta Everything related to the meta-language. labels Mar 15, 2023
Copy link
Contributor

@jameysharp jameysharp left a comment

Choose a reason for hiding this comment

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

This all looks correct, thanks!

I don't know if it really makes sense to special-case scalar truthy values to always be I8, but we don't have to figure that out right now. I believe this PR is consistent with the current state of our instruction definitions, at least.

@elliottt elliottt added this pull request to the merge queue Mar 17, 2023
@elliottt elliottt merged commit 78dbe93 into bytecodealliance:main Mar 17, 2023
@elliottt elliottt deleted the trevor/rename-as-bool branch March 17, 2023 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:meta Everything related to the meta-language. cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants