Skip to content

[MoveOnlyAddressChecker] Fix representation for reinit'd fields. #66945

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

Merged
merged 4 commits into from
Jun 28, 2023

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Jun 27, 2023

The move-only address checker records instructions that reinit fields in its reinitInsts map. Previously, that map mapped from an instruction to a range of fields of the value. But an instruction can use multiple discontiguous fields of a single value. (Indeed an attempt to add a second range that was reinit'd by an already reinit'ing instruction--even if it were overlapping or adjacent--would have no effect and the map wouldn't be updated.) Here, this is fixed by fixing the representation and updating the storage whenver a new range is seen to be reinit'd by the instruction. As in #66728 , a SmallBitVector is the representation chosen.

rdar://111356251

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler requested a review from atrick June 27, 2023 00:49
@nate-chandler
Copy link
Contributor Author

CC: @kavon @gottesmm @jckarter

@nate-chandler
Copy link
Contributor Author

@swift-ci please test macos platform

if (bits.size() == 0)
return;

Optional<std::pair<unsigned, /*isSet*/ bool>> current = llvm::None;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be simpler to do:

Optional<unsigned> current = None
for ...
  if (current) {
    if (!isSet) {
      callback
      current = None
    }
  } else if (isSet) {
    current = bit
  }
}
if (current) { callback }

disclaimer, I didn't think hard about this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

LGTM!

Test case could use a comment but you don't need to restart CI just for that.

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

LGTM. In a subsequent PR just on main, can you add a swift test case as well?

Used the TypeTreeLeafTypeRange::setBits helper rather than looping over
the range and setting the bits in place.
In preparation to share the getOrCreateConsumingBlock functionality with
another overload of recordConsumingBlock.
The new overload iterates over the contiguous ranges in the bit vector
and calls through to the overload that takes a range.
The address checker records instructions that reinit fields in its
reinitInsts map.  Previously, that map mapped from an instruction to a
range of fields of the type.  But an instruction can use multiple
discontiguous fields of a single value.  (Indeed an attempt to add a
second range that was reinit'd by an already reinit'ing
instruction--even if it were overlapping or adjacent--would have no
effect and the map wouldn't be updated.)  Here, this is fixed by fixing
the representation and updating the storage whenver a new range is seen
to be reinit'd by the instruction.  As in
swiftlang#66728 , a SmallBitVector is the
representation chosen.

rdar://111356251
@nate-chandler
Copy link
Contributor Author

Rebased and force-pushed in order to prefix the new use of Optional with llvm:: which is now required on main.

@nate-chandler
Copy link
Contributor Author

@swift-ci please test and merge

@nate-chandler
Copy link
Contributor Author

@swift-ci please smoke test macos platform

@nate-chandler nate-chandler merged commit 1259125 into swiftlang:main Jun 28, 2023
@nate-chandler nate-chandler deleted the rdar111356251 branch June 28, 2023 02:52
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