-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
Conversation
Looks like I might have broken something:
(there are a bunch of these) |
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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.
lib/Serialization/ModuleFile.cpp
Outdated
if (maybeRead.get() != byte) | ||
return false; | ||
} else { | ||
// FIXME this drops the error on the floor. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
lib/Serialization/ModuleFile.cpp
Outdated
if (llvm::Error Err = DeclMemberTablesCursor.JumpToBit(subTableOffset)) { | ||
// FIXME this drops the error on the floor. | ||
consumeError(std::move(Err)); | ||
error(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
lib/Serialization/DeserializeSIL.cpp
Outdated
if (!maybeKind) { | ||
LLVM_DEBUG(llvm::dbgs() << "Cursor advance error in readSILFunction: " | ||
<< toString(maybeKind.takeError()) << "\n"); | ||
MF->error(); |
There was a problem hiding this comment.
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())
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it cantFail
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated these.
This comment has been minimized.
This comment has been minimized.
if (expected) | ||
return std::move(expected.get()); | ||
fatal(expected.takeError()); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Expected to fail, but it should at least get to building the overlays. @swift-ci Please smoke test |
Upstream change in rL364464 broke downstream Swift.
Looks like building failed because |
152128f
to
7e87847
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@swift-ci Please smoke test |
The current build / test failures don't seem directly caused by this change. |
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. |
…but I don't see anything obviously wrong, and this still gets master-next a lot closer, so let's take it. |
* 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
Upstream change in rL364464 broke downstream Swift.