Skip to content

Fix Swift following bitstream reader API update #25845

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 11 commits into from
Jul 1, 2019

Conversation

jfbastien
Copy link
Contributor

Upstream change in rL364464 broke downstream Swift.

@jfbastien
Copy link
Contributor Author

Looks like I might have broken something:

/s/swift/swift/stdlib/public/SwiftOnoneSupport/SwiftOnoneSupport.swift:362:11: error: Cannot pre-specialize $sSlsE20_failEarlyRangeCheck_6boundsy5IndexQz_SnyADGtF
  (0..<0)._prespecializeCollection(index: 0, range: (0..<0))
          ^

(there are a bunch of these)
But at least something builds! I'll look into what I did wrong.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

I don't see anything obviously wrong, though I admit to skimming a lot. The main thing is that since Swift already isn't set up to recover from these kinds of errors, ModuleFile::error() is already fatal in a good chunk of the program. So you can crash more deliberately there and simplify the code.

@@ -38,7 +38,9 @@ class BCOffsetRAII {

~BCOffsetRAII() {
if (Cursor)
Cursor->JumpToBit(Offset);
if (llvm::Error Err = Cursor->JumpToBit(Offset))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this can ever fail because it's jumping to a position the cursor was previously at.

}
} else {
Instance.getDiags().diagnose(SourceLoc(), diag::error_parse_input_file,
Filename, toString(MaybeRead.takeError()));
Copy link
Contributor

Choose a reason for hiding this comment

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

It still freaks me out that this is available in the else clause. Looks correct, though.

if (maybeRead.get() != byte)
return false;
} else {
// FIXME this drops the error on the floor.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is correct behavior anyway. It was reading raw bytes; if it's too short, it's not a valid signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I removed the FIXME.

if (llvm::Error Err = DeclMemberTablesCursor.JumpToBit(subTableOffset)) {
// FIXME this drops the error on the floor.
consumeError(std::move(Err));
error();
Copy link
Contributor

Choose a reason for hiding this comment

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

From here through pretty much the rest of the file, it's too late to recover, so you can use fatal(std::move(Err)) instead.

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 updated this and subsequent consumeError.

if (!maybeKind) {
LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readSILFunction: "
<< toString(maybeKind.takeError()) << "\n");
MF->error();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here and below: MF->error() is going to abort anyway, so you might as well use MF->fatal(maybeKind.takeError()).

Copy link
Contributor

Choose a reason for hiding this comment

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

These are all going to be a problem in non-asserts builds, right? Because the LLVM_DEBUG will be compiled out? Or is that okay because it happens to line up with the checking of cleanup being compiled out?

Copy link
Contributor Author

@jfbastien jfbastien Jun 28, 2019

Choose a reason for hiding this comment

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

It will be a problem in debug, yes. I'm trying to match current behavior and / or surrounding code. I'll update as you suggest (here and elsewhere).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean because the error won't be taken in release builds if you use LLVM_DEBUG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, that too.

cursor.advance(AF_DontPopBlockAtEnd);
if (!maybeNext) {
// FIXME this drops the error on the floor.
consumeError(maybeNext.takeError());
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 probably at least assert, to match the current behavior.

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 made it cantFail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That turns out to not be something we can do at the moment because it causes failures. I'll use bug-compatible old behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Uh. Are you saying we have existing corrupted modules?

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 haven't dug in :)

DeclTypeCursor.advance(AF_DontPopBlockAtEnd);
if (!maybeEntry) {
// FIXME this drops the error on the floor.
consumeError(maybeEntry.takeError());
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can continue on past this, but I guess that's no worse.

if (!maybeNext) {
// FIXME this drops the error diagnostic on the floor.
consumeError(maybeNext.takeError());
error();
Copy link
Contributor

Choose a reason for hiding this comment

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

fatal again, throughout this whole file wherever you would be calling error(). Besides what I mentioned above, it's noreturn, so you don't have to make a fake return value.

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've updated these.

@jfbastien

This comment has been minimized.

if (expected)
return std::move(expected.get());
fatal(expected.takeError());
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is new, it simplifies a good part of this patch.

Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

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

Let's go with this.

@jrose-apple
Copy link
Contributor

Expected to fail, but it should at least get to building the overlays.

@swift-ci Please smoke test

@jfbastien
Copy link
Contributor Author

jfbastien commented Jun 29, 2019

Looks like building failed because master-next had new changes that I needed to pick up. I picked them up here (also messed git up a bit in the process and fixed it).

@jfbastien jfbastien force-pushed the fix-master-next-bitstream-api branch from 152128f to 7e87847 Compare June 29, 2019 15:12
@jfbastien

This comment has been minimized.

@jfbastien

This comment has been minimized.

@jfbastien
Copy link
Contributor Author

@swift-ci Please smoke test

@jfbastien
Copy link
Contributor Author

The current build / test failures don't seem directly caused by this change.

@jrose-apple
Copy link
Contributor

The SIL serialization one might be: "Record kind for a SIL instruction is not supported - DeserializeSIL.cpp:1006". The non-SIL serialization one is also failing in a SIL way, so that could also be related. The others almost certainly not.

@jrose-apple
Copy link
Contributor

…but I don't see anything obviously wrong, and this still gets master-next a lot closer, so let's take it.

@jfbastien jfbastien merged commit 50de105 into master-next Jul 1, 2019
@jfbastien jfbastien deleted the fix-master-next-bitstream-api branch July 1, 2019 17:08
pschuh added a commit to pschuh/swift that referenced this pull request Jul 12, 2019
pschuh added a commit that referenced this pull request Jul 12, 2019
hyp pushed a commit that referenced this pull request Nov 14, 2019
* Fix Swift following bitstream reader API update

Upstream change in rL364464 broke downstream Swift.

(cherry picked from commit 50de105)

 Conflicts:
	lib/Serialization/Deserialization.cpp
	lib/Serialization/ModuleFile.cpp
	tools/driver/modulewrap_main.cpp
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.

2 participants