Skip to content

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

Merged
merged 3 commits into from
Dec 22, 2016
Merged

Fix errors and warnings building swift/SILGen on Windows using MSVC #5955

merged 3 commits into from
Dec 22, 2016

Conversation

hughbe
Copy link
Contributor

@hughbe 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__)
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'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'

Copy link
Contributor Author

@hughbe hughbe Dec 12, 2016

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)

Copy link
Contributor

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?

Copy link
Contributor Author

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!!

Copy link
Contributor Author

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()));
Copy link
Contributor

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.

Copy link
Contributor Author

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

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 reverted this cahnge

@hughbe
Copy link
Contributor Author

hughbe commented Dec 19, 2016

@gottesmm FYI

@compnerd
Copy link
Member

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test Linux Platform
Git Commit - 2c65cec0c91436ba7704c4946b9cace7ec683382
Test requested by - @compnerd

@swift-ci
Copy link
Contributor

Build failed
Jenkins build - Swift Test OS X Platform
Git Commit - 2c65cec0c91436ba7704c4946b9cace7ec683382
Test requested by - @compnerd

@hughbe
Copy link
Contributor Author

hughbe commented Dec 19, 2016

What's causing these failures - it doesn't look like things are actually failing in the CI?

@jrose-apple
Copy link
Contributor

"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.

@hughbe
Copy link
Contributor Author

hughbe commented Dec 21, 2016

Tests seem to have passed, this was never merged

@hughbe
Copy link
Contributor Author

hughbe commented Dec 21, 2016

Derp, you did a test only trigger

@jrose-apple
Copy link
Contributor

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;
Copy link
Contributor

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.

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'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;
}

Copy link
Contributor Author

@hughbe hughbe Dec 22, 2016

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 }));
Copy link
Contributor

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.

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

@@ -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);
Copy link
Contributor

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.

Copy link
Contributor Author

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

@hughbe
Copy link
Contributor Author

hughbe commented Dec 22, 2016

Thanks Joe!
Updated the PR to address your feedback. I also rebased, and fixed several more MSVC errors. Some are known.
New ones are

@@ -101,7 +101,7 @@ SILPassPipelinePlan::getDiagnosticPassPipeline(SILOptions Options) {
// disabled.
if (Options.DebugSerialization) {
addMandatoryDebugSerialization(P);
return P;
return const_cast<const SILPassPipelinePlan&>(P);
Copy link
Contributor

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::moves, but Clang has a warning for that now. AFAICT it should be safe to just remove the SILPassPipelinePlan(SILPassPipelinePlan &&) = delete; declaration.

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 was just experimenting with ideas to fix the error. I can remove the delete decleration if you'd like

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 see any obvious reason to keep it. Pinging @gottesmm since he put it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, thanks

@jckarter
Copy link
Contributor

Looks good, thanks @hughbe !

@jrose-apple
Copy link
Contributor

@swift-ci Please smoke test

@jrose-apple jrose-apple merged commit 8f3c7eb into swiftlang:master Dec 22, 2016
@hughbe hughbe deleted the silgen-msvc branch December 23, 2016 10:25
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.

5 participants