-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix errors and warnings building swift/SILGen on Windows using MSVC #5955
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
hughbe
commented
Nov 28, 2016
- Reference deleted function error
- Constructor overload error
- Iterator internal stdlib error
- Disable assertion failing on MSVC
@@ -174,7 +174,10 @@ class Callee { | |||
const Kind kind; | |||
|
|||
// Move, don't copy. | |||
// Work around MSVC error: attempting to reference a deleted function. | |||
#if !defined(_MSC_VER) || defined(__clang__) |
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'd love to get rid of this. The problem here is caused by this code:
Callee getCallee() {
assert(ApplyCallee && "did not find callee?!");
return *std::move(ApplyCallee);
}
This gives me the error
1>C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SILGen\SILGenApply.cpp(1496): error C2280: '
anonymous-namespace'::Callee::Callee(const
anonymous-namespace'::Callee &)': attempting to reference a deleted function
1> C:\Users\Lukey\Documents\GitHub\my-swift\swift\lib\SILGen\SILGenApply.cpp(179): note: see declaration of '`anonymous-namespace'::Callee::Callee'
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.
Note: replacing delete
with default
below fixes any errors (@jrose-apple)
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.
Replacing delete
with default
is wrong, since the type is intended to be move-only. Does llvm::Optional
not support move semantics when built for MSVC? Does std::move(*ApplyCallee)
work?
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.
Yes it does @jckarter. Thanks!!
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.
You might want to take a look at #5948 in which I try to work around a similar error. Unfortunately, this time the code that triggers this is compiler generated __delDtor(unsigned int)
@@ -1693,7 +1693,7 @@ RValue RValueEmitter::visitMemberRefExpr(MemberRefExpr *E, SGFContext C) { | |||
// and releases. | |||
if (auto *N = E->getBase()->getType()->getNominalOrBoundGenericNominal()) | |||
if (auto RV = NominalTypeMemberRefRValueEmitter(E, C, N).emit(SGF)) | |||
return RValue(std::move(RV).getValue()); | |||
return RValue(const_cast<RValue&&>(std::move(RV).getValue())); |
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.
Why is this necessary? An rvalue reference-to-const
has almost no reason to exist.
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.
Hmm, seems like a Visual Studio bug, rather than something MSVC specific. I can reproduce this from the IDE in intellisense but not MSVC. I wrote this in about a month ago so I think I just assumed IDE errors == MSVC errors for this.
The error is:
swift::lowering::RValue(const swift::Lowering::RValue &) is inaccessible
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 reverted this cahnge
@gottesmm FYI |
@swift-ci please test |
Build failed |
Build failed |
What's causing these failures - it doesn't look like things are actually failing in the CI? |
"Wrong SHA" failures are a workaround for a bug with the Jenkins GitHub plugin we're using. There are general plans to upgrade the CI system so meanwhile we just put in an expedient hack to fail and automatically retry the build. |
Tests seem to have passed, this was never merged |
Derp, you did a test only trigger |
Ah, yeah, hoping for final sign-off from @jckarter. |
@@ -56,7 +56,9 @@ class SILPassPipelinePlan final { | |||
SILPassPipelinePlan() = default; | |||
~SILPassPipelinePlan() = default; | |||
SILPassPipelinePlan(const SILPassPipelinePlan &) = default; | |||
#if !defined(_MSC_VER) || defined(__clang__) | |||
SILPassPipelinePlan(SILPassPipelinePlan &&) = delete; |
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.
If MSVC doesn't like the = delete
, can we at least leave an llvm_unreachable
implementation behind? It must have been deleted for a reason, and it'd be nice to still check dynamically.
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'm not sure that's the right thing to do.
The errors are
1>C:\Users\hbellamy\Documents\GitHub\my-swift\swift\lib\SILOptimizer\PassManager\PassPipeline.cpp(104): error C2280: 'swift::SILPassPipelinePlan::SILPassPipelinePlan(swift::SILPassPipelinePlan &&)': attempting to reference a deleted function
1> C:\Users\hbellamy\Documents\GitHub\my-swift\swift\include\swift/SILOptimizer/PassManager/PassPipeline.h(51): note: see declaration of 'swift::SILPassPipelinePlan::SILPassPipelinePlan'
It comes from this code
SILPassPipelinePlan
SILPassPipelinePlan::getDiagnosticPassPipeline(SILOptions Options) {
SILPassPipelinePlan P;
if (SILViewSILGenCFG) {
addCFGPrinterPipeline(P, "SIL View SILGen CFG");
}
// If we are asked do debug serialization, instead of running all diagnostic
// passes, just run mandatory inlining with dead transparent function cleanup
// disabled.
if (Options.DebugSerialization) {
addMandatoryDebugSerialization(P);
return P;
}
// Lower all ownership instructions right after SILGen for now.
addOwnershipModelEliminatorPipeline(P);
// Otherwise run the rest of diagnostics.
addMandatoryOptPipeline(P);
if (SILViewGuaranteedCFG) {
addCFGPrinterPipeline(P, "SIL View Guaranteed CFG");
}
return P;
}
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.
@gottesmm FYI
I've pushed a test fix as a seperate commit - I'm not sure if it's correct, but it seems to get rid of the build errors
// extent.params.begin(), extent.params.end())" due to a missing "<" | ||
// parameter. | ||
for (auto param : extent.Params) { | ||
innerParams.append(std::initializer_list<SILParameterInfo>({ param })); |
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.
innerParams.push_back(param);
would be simpler.
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.
Fixed
@@ -4239,7 +4247,9 @@ namespace { | |||
// with specialized emitters above, enum constructors use | |||
// the AST-level abstraction pattern, to ensure that function | |||
// types in payloads are re-abstracted correctly. | |||
#if !defined(_MSC_VER) || defined(__clang__) | |||
assert(!AssumedPlusZeroSelf); |
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.
We should look into what's making this assertion fail. It could indicate a serious problem.
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.
For now, I'm going to revert this change. It's possible this is related to my changes elsewhere in my working branch. However, in previous PRs I have seen assertions happening as they assume a define left to right ordering of method results passed to a method, so could be something more
Thanks Joe!
|
@@ -101,7 +101,7 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(SILOptions Options) { | |||
// disabled. | |||
if (Options.DebugSerialization) { | |||
addMandatoryDebugSerialization(P); | |||
return P; | |||
return const_cast<const SILPassPipelinePlan&>(P); |
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.
What is this cast for? This probably defeats NRVO. Looking at the code here, I suspect the deleted move constructor was intended to prevent people from writing pessimizing std::move
s, but Clang has a warning for that now. AFAICT it should be safe to just remove the SILPassPipelinePlan(SILPassPipelinePlan &&) = delete;
declaration.
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 was just experimenting with ideas to fix the error. I can remove the delete decleration if you'd like
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 any obvious reason to keep it. Pinging @gottesmm since he put it there.
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.
Removed, thanks
…MSVC - https://connect.microsoft.com/VisualStudio/feedback/details/3116505/msvc-fails-to-compile-code-that-compiles-with-clang-reports-attempting-to-reference-a-deleted-function-error-from-destructor - https://connect.microsoft.com/VisualStudio/feedback/details/3116636/msvc-reports-ambiguous-symbol-error-for-friend-class-declaration-in-an-anonymous-namespace
Looks good, thanks @hughbe ! |
@swift-ci Please smoke test |