Skip to content

Remove now unecessary MSVC trailing objects workaround #7890

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 1 commit into from
Mar 6, 2017
Merged

Remove now unecessary MSVC trailing objects workaround #7890

merged 1 commit into from
Mar 6, 2017

Conversation

hughbe
Copy link
Contributor

@hughbe hughbe commented Mar 3, 2017

Unfortunately, MSVC is still buggy, and reports that the functions

size_t numTrailingObjects(typename TrailingObjectsIdentifier::template OverloadToken<Identifier>) const;

and

size_t numTrailingObjects(typename TrailingObjectsIdentifier::template OverloadToken<SourceLoc>) const;

have identical function parameters, which is obviously incorrect. But apparently this is because we're using TrailingObjects incorrectly here:

https://reviews.llvm.org/D29880

I just noticed that the test case I wrote is passing a bogus first-argument to the template -- and so is your modified version in the comment above. So any errors resulting from that are probably not useful to examine. The testcase should've look like this instead:

I'm assuming the error coming from swift is actually from something else?

@hughbe
Copy link
Contributor Author

hughbe commented Mar 3, 2017

@swift-ci please smoke test

@hughbe hughbe requested a review from jrose-apple March 3, 2017 13:25
@hughbe
Copy link
Contributor Author

hughbe commented Mar 3, 2017

@swift-ci please smoke test

1 similar comment
@hughbe
Copy link
Contributor Author

hughbe commented Mar 3, 2017

@swift-ci please smoke test

@jrose-apple
Copy link
Contributor

I'm sorry, I don't understand this change, and looking back at the comment on the LLVM review I don't understand it there either. I see that TrailingObjectsBase isn't actually a templated type, and so it doesn't matter how we get there through TrailingObjects, but isn't it still more correct to use the type we're actually inheriting from? And if it doesn't matter at all, we should still be consistent, possibly standardizing on TrailingObjectsBase instead of TrailingObjects-with-only-one-trailing-type.

@hughbe
Copy link
Contributor Author

hughbe commented Mar 4, 2017

No problem, I was confused too. Basically, the code should be the following in Expr.h:

  // ...

  using TrailingObjects = llvm::TrailingObjects<Derived, Identifier, SourceLoc>;
  friend TrailingObjects;

  // ...

  size_t numTrailingObjects(
      typename TrailingObjects::template OverloadToken<Identifier>) const {
    return asDerived().getNumArguments();
  }

  size_t numTrailingObjects(
      typename TrailingObjects::template OverloadToken<SourceLoc>) const {
    return asDerived().hasArgumentLabelLocs() ? asDerived().getNumArguments()
                                              : 0;
  }

  // ...

but for some reason, MSVC gets horribly confused, and thinks these are the same functions:

swift\include\swift/AST/Expr.h(681): error C2535: 'size_t swift::TrailingCallArguments::numTrailingObjects(TrailingObjects<BaseTy,TrailingTys...>::TrailingObjectsImpl<llvm::trailing_objects_internal::AlignmentCalcHelper<TrailingTys...>::Alignment,BaseTy,llvm::TrailingObjects<BaseTy,TrailingTys...>,BaseTy,TrailingTys...>::OverloadToken) const': member function already defined or declared (compiling source file swift\lib\AST\ASTNode.cpp)

swift\include\swift/AST/Expr.h(675): note: see declaration of 'swift::TrailingCallArguments::numTrailingObjects' (compiling source file swift\lib\AST\ASTNode.cpp)

swift\include\swift/AST/Expr.h(745): note: see reference to class template instantiation 'swift::TrailingCallArguments' being compiled (compiling source file swift\lib\AST\ASTNode.cpp)

The fix (/workaround/hack) is like the following here:

template <typename Derived>
class Class5Tmpl : private llvm::TrailingObjects<Derived, float, int> {
  using TrailingObjects = typename llvm::TrailingObjects<Derived, float>;
  friend TrailingObjects;

  size_t numTrailingObjects(
      typename TrailingObjects::template OverloadToken<float>) const {
    return 1;
  }

  size_t numTrailingObjects(
      typename TrailingObjects::template OverloadToken<int>) const {
    return 2;
  }
}

class Class5 : public Class5Tmpl<Class5> {};

However, then we get errors in the following code in Expr.h:

  // ...

  /// Determine the total size to allocate.
  static size_t totalSizeToAlloc(ArrayRef<Identifier> argLabels,
                                 ArrayRef<SourceLoc> argLabelLocs,
                                 bool hasTrailingClosure) {
    return TrailingObjects::template totalSizeToAlloc<Identifier, SourceLoc>(
        argLabels.size(), argLabelLocs.size());
  }

  // ...
> swift\include\swift/AST/Expr.h(707): error C2672: 'llvm::TrailingObjects<Derived,swift::Identifier>::totalSizeToAlloc': no matching overloaded function found
>           with
>           [
>               Derived=swift::CallExpr
>           ] (compiling source file swift\lib\AST\Expr.cpp)
>   swift\include\swift/AST/Expr.h(705): note: while compiling class template member function 'size_t swift::TrailingCallArguments<swift::CallExpr>::totalSizeToAlloc(llvm::ArrayRef<swift::Identifier>,llvm::ArrayRef<swift::SourceLoc>,bool)' (compiling source file swift\lib\AST\Expr.cpp)
>   swift\lib\AST\Expr.cpp(1734): note: see reference to function template instantiation 'size_t swift::TrailingCallArguments<swift::CallExpr>::totalSizeToAlloc(llvm::ArrayRef<swift::Identifier>,llvm::ArrayRef<swift::SourceLoc>,bool)' being compiled
>   swift\include\swift/AST/Expr.h(3753): note: see reference to class template instantiation 'swift::TrailingCallArguments<swift::CallExpr>' being compiled (compiling source file swift\lib\AST\Expr.cpp)
> swift\include\swift/AST/Expr.h(707): error C2780: 'std::enable_if<std::is_same<llvm::TrailingObjects<Derived,swift::Identifier>::Foo<swift::Identifier>,llvm::TrailingObjects<Derived,swift::Identifier>::Foo<Tys...>>::value,std::size_t>::type llvm::TrailingObjects<Derived,swift::Identifier>::totalSizeToAlloc(std::Ty2)': expects 1 arguments - 2 provided
>           with
>           [
>               Derived=swift::CallExpr,
>               Ty2=std::size_t
>           ] (compiling source file swift\lib\AST\Expr.cpp)
>   llvm\include\llvm/Support/TrailingObjects.h(350): note: see declaration of 'llvm::TrailingObjects<Derived,swift::Identifier>::totalSizeToAlloc'
>           with
>           [
>               Derived=swift::CallExpr
>           ] (compiling source file swift\lib\AST\Expr.cpp)

@jrose-apple
Copy link
Contributor

All right, I'll trust you on this. Maybe leave a comment behind to note why we're doing something so strange. :-)

@hughbe
Copy link
Contributor Author

hughbe commented Mar 6, 2017

@swift-ci please smoke test and merge

1 similar comment
@hughbe
Copy link
Contributor Author

hughbe commented Mar 6, 2017

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit 4def042 into swiftlang:master Mar 6, 2017
@hughbe hughbe deleted the msvc-workaround branch March 6, 2017 05:04
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