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

[compiler] Add If and MakeStruct Simplifications #14231

Merged
merged 14 commits into from
Feb 10, 2024

Conversation

ehigham
Copy link
Member

@ehigham ehigham commented Jan 31, 2024

Add the following transformations:

MakeStruct("a" -> GetField(o, "x"), ...) -> CastRename(SelectFields(o, ["x"..]), newtype)
If(IsNA(x), NA(x.typ), x) -> x

The changes to SStructView (nee SSubsetStruct) were as a result of a bud that prevented subsetting and then renaming to an excluded field, ie {x, y, z} subset {z} rename {x}. Now SStructView leaves its parent SType unmodified and casts loads through the parent to the appropriate SValue.

MakeStruct("a" -> GetField(o, "x"), ...) -> CastRename(SelectFields(o, ["x"..]), newtype)
If(IsNA(x), NA(x.typ), x) -> x
patrick-schultz
patrick-schultz previously approved these changes Feb 1, 2024
Copy link
Collaborator

@patrick-schultz patrick-schultz left a comment

Choose a reason for hiding this comment

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

nice!

@ehigham ehigham dismissed patrick-schultz’s stale review February 1, 2024 21:31

submission changed owing to test failures

patrick-schultz
patrick-schultz previously approved these changes Feb 1, 2024
Copy link
Collaborator

@patrick-schultz patrick-schultz left a comment

Choose a reason for hiding this comment

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

looks good

@ehigham ehigham dismissed patrick-schultz’s stale review February 2, 2024 23:12

Possibly dangerous change to SSubsetStruct.equals

@ehigham
Copy link
Member Author

ehigham commented Feb 2, 2024

Merging in #14233 causes the failure in test_union_rows1. Some strangeness with these new dependencies - running without this commit and everything works fine.

Comment on lines 56 to 61
new SSubsetStruct(newParent.asInstanceOf[SBaseStruct], newVirtualType.fieldNames) {
override lazy val newToOldFieldMapping: Map[Int, Int] =
SSubsetStruct.this.newToOldFieldMapping
override lazy val virtualType: TStruct =
newVirtualType
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't like the anonymous subclassing here. It makes it difficult to say what an SSubsetStruct really is. I think the core issue forcing the need subclass is that newToOldFieldMapping should really be a constructor argument (as also evidenced by its appearence in the definition of equality). Then there should be no need to subclass.

Concretely, I suggest making the default constructor

class SSubsetStruct(
  private val parent: SBaseStruct,
  private val fieldNames: IndexedSeq[String],
  private val oldToNewFieldMapping
) extends SBaseStruct { ...

and adding a convenience constructor taking only the first two, and computing a default oldToNewFieldMapping as we do now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure - that sounds like a better change.

@ehigham
Copy link
Member Author

ehigham commented Feb 8, 2024

Merging in #14233 causes the failure in test_union_rows1. Some strangeness with these new dependencies - running without this commit and everything works fine.

Doesn't seem to be an issue anymore...

Copy link
Collaborator

@patrick-schultz patrick-schultz left a comment

Choose a reason for hiding this comment

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

Looks great, just one small thing

Comment on lines +45 to +50
override lazy val fieldTypes: IndexedSeq[SType] =
Array.tabulate(size) { i =>
parent
.fieldTypes(newToOldFieldMapping(i))
.castRename(rename.fields(i).typ)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this assumes that the fields of restrict have the same virtual type as the corresponding fields in parent. I'm in favor of not making SStructView support deep subsetting for now to keep things simple, but in that case, having an entire restrict type is redundant and, I think, confusing. It would be sufficient to just use a list of parent fields to subset to (but then still the full rename struct type).

Copy link
Member Author

Choose a reason for hiding this comment

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

OK

@danking danking merged commit a515ccd into hail-is:main Feb 10, 2024
3 checks passed
@ehigham ehigham deleted the ehigham/simplify-make-struct branch February 12, 2024 17:19
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.

3 participants