This is an archive of the discontinued LLVM Phabricator instance.

Revert "[TableGen] Use heap allocated arrays instead of vectors for TreePatternNode::Types and ResultPerm. NFC"
ClosedPublic

Authored by tmatheson on Jul 8 2023, 4:17 PM.

Details

Summary

While working on DAGISelMatcherEmitter I've hit several runtime errors
caused by accessing TreePatternNode::Types out of bounds. These were
difficult to debug because the switch from std::vector to unique_ptr
removes bounds checking.

I don't think the slight reduction in class size is worth the extra
debugging and memory safety problems, so I suggest we revert this.

This reverts commit d34125a1a825208b592cfa8f5fc3566303d691a4.

Diff Detail

Unit TestsFailed

Event Timeline

tmatheson created this revision.Jul 8 2023, 4:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2023, 4:17 PM
tmatheson requested review of this revision.Jul 8 2023, 4:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2023, 4:17 PM
This revision is now accepted and ready to land.Jul 8 2023, 5:16 PM

Alternatively, could we add bounds checking to getExtType and make more use of it?

This revision was landed with ongoing or failed builds.Jul 9 2023, 2:18 AM
This revision was automatically updated to reflect the committed changes.

Thanks, I've done a complete revert for simplicity, but I do think that using getNumTypes() etc rather than Types.size() was nicer.

My concern with adding the bounds checking to getExtType would be that the class is already quite sprawling, and it would only be a matter of time before someone used Types directly and raised the same problems. Ideally whatever does the bounds checking should be encapsulated well so that we can be confident it is correct. std::vector accomplishes this already.

I'm not sure what the performance bottlenecks are here but maybe avoiding the allocation in most cases with SmallVector is something to consider too. Or combining the two vectors, since they should always be the same length.