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

refactor: add vec repeat support for logical ops #4998

Merged
merged 9 commits into from
Aug 19, 2022

Conversation

onelson
Copy link
Contributor

@onelson onelson commented Jul 14, 2022

Fixes #4997 #4996

During #4622 lots of attention was given to Vector usage in binary ops
since the literals that could be vectorized tended to show up there.

Since boolean literals were not covered by the initial vec repeat work, I neglected to look
at logical operators (which depend on booleans to be used).

This diff adds the necessary branching to cover the vec repeat case,
looking forward to the time where boolean literals can be vectorized and also implements support for boolean literals to be vectorized.

It also adds skipped/commented out tests with reference to #4997 which
should aim to enable these code paths by finally allowing bool literals
to become vectorized.

Done checklist

  • docs/SPEC.md updated N/A
  • Test cases written

@onelson
Copy link
Contributor Author

onelson commented Jul 14, 2022

There's one more area where we call Vector.Arr without first checking to see if the value is a repeat or not.

case semantic.Vector:
vec, ok := v.(values.Vector)
if !ok {
panic("value is not a vector")
}
a := vec.Arr()
elements := make([]map[string]interface{}, a.Len())
for i := range elements {
elements[i] = TransformValue(getValue(a, i))
}
return map[string]interface{}{
"type": semantic.Vector.String(),
"elements": elements,
}

Since this is a part of the testing infra, I'm not sure it matters too much.

@onelson onelson force-pushed the onelson/fix/more-vec-repeat-support branch from c3b1ea9 to ad0a904 Compare August 17, 2022 19:25
@onelson onelson marked this pull request as ready for review August 17, 2022 20:21
@onelson onelson requested a review from a team as a code owner August 17, 2022 20:21
@onelson onelson requested review from Marwes and removed request for a team August 17, 2022 20:21
@onelson onelson force-pushed the onelson/fix/more-vec-repeat-support branch from cfadabc to 8536ba8 Compare August 17, 2022 20:29
libflux/flux-core/src/semantic/tests/vectorize.rs Outdated Show resolved Hide resolved
@@ -66,6 +66,16 @@ impl Expression {
fn vectorize(&self, env: &VectorizeEnv<'_>) -> Result<Self> {
Ok(match self {
Expression::Identifier(identifier) => {
let name = identifier.name.clone();
if env.config.features.contains(&Feature::VectorizedConst)
&& (name == "true" || name == "false")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should check the package of this Symbol so that we know that true/false is coming from universe/prelude. Otherwise this will match on any identifier called true or false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this makes sense. I'll want to do the same for float. Originally (for float) I tried to check the file field on loc but it was empty for some cases so I removed the check.

If I understand correctly, for the tests this will mean moving things from env to importer so that the package provenance is maintained.

Not sure what's needed to copy stuff over to env to approximate the prelude. Will investigate today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to work backwards from a regular script run, then make the test setup match how the symbols present in real life. Unexpectedly, the booleans are in the boolean package! I thought they were listed under universe, but no...

Owen Nelson added 5 commits August 18, 2022 09:25
During #4622 lots of attention was given to Vector usage in binary ops
since the literals that could be vectorized tended to show up there.

Since boolean literals were not on the list, I somehow neglected to look
at the logical operators (which depend on booleans to be used).

This diff adds the necessary branching to cover the vec repeat case,
looking forward to the time where boolean literals _can be vectorized_.

It also adds skipped/commented out tests with reference to #4997 which
should aim to enable these code paths by finally allowing bool literals
to become vectorized.
@onelson onelson force-pushed the onelson/fix/more-vec-repeat-support branch 2 times, most recently from da6ea4c to a27bc7f Compare August 18, 2022 18:01
@onelson onelson requested a review from Marwes August 18, 2022 18:05
Owen Nelson added 4 commits August 18, 2022 11:12
Also updates supporting test code to emulate package membership and
prelude.
Previously we rewrote any call to a function named `float`. This could
cause issues if the regular float had been shadowed.
@onelson onelson force-pushed the onelson/fix/more-vec-repeat-support branch from a27bc7f to 6563718 Compare August 18, 2022 18:12
Comment on lines +32 to +43
let imports: SemanticMap<&str, _> = imp
.into_iter()
.map(|(path, pkg)| (path, parse_map(Some(path), pkg)))
.collect();
let importer: Packages = imports
.into_iter()
.map(|(path, types)| (path.to_string(), PackageExports::try_from(types).unwrap()))
.collect();
let mut prelude = PackageExports::new();
prelude.copy_bindings_from(importer.get("boolean").unwrap());
prelude.copy_bindings_from(importer.get("universe").unwrap());
let env = Environment::from(&prelude);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I cobbled this together based on code I saw in bootstrap -- there might be a more direct/terse way to get this done.

@onelson onelson merged commit ed7c47f into master Aug 19, 2022
@onelson onelson deleted the onelson/fix/more-vec-repeat-support branch August 19, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support boolean literals for VectorRepeatValue
2 participants