This is an archive of the discontinued LLVM Phabricator instance.

[clang] Instantiate NTTPs and template default arguments with sugar
ClosedPublic

Authored by mizvekov on Oct 23 2022, 1:43 PM.

Details

Summary

This makes use of the changes introduced in D134604, in order to
instantiate non-type template parameters and default template arguments
with a final sugared substitution.

This comes at no additional relevant cost.
Since we don't track / unique them in specializations, we wouldn't be
able to resugar them later anyway.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov created this revision.Oct 23 2022, 1:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 23 2022, 1:43 PM
mizvekov requested review of this revision.Oct 23 2022, 1:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 23 2022, 1:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
mizvekov added reviewers: davrec, Restricted Project.Oct 23 2022, 2:55 PM
erichkeane accepted this revision.Oct 24 2022, 7:03 AM
This revision is now accepted and ready to land.Oct 24 2022, 7:03 AM
This revision was landed with ongoing or failed builds.Oct 25 2022, 6:23 PM
This revision was automatically updated to reflect the committed changes.

This broke building Firefox with:

In file included from Unified_cpp_dom_canvas0.cpp:65:
/tmp/gecko/dom/canvas/ClientWebGLContext.cpp:355:19: error: call to deleted function 'IdByMethod'
  const auto id = IdByMethod<MethodType, method>();
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/gecko/dom/canvas/ClientWebGLContext.cpp:438:3: note: in instantiation of function template specialization 'mozilla::ClientWebGLContext::Run<void (mozilla::HostWebGLContext::*)(unsigned long, mozilla::layers::TextureType, bool, const mozilla::webgl::SwapChainOptions &) const, &mozilla::HostWebGLContext::Present, unsigned long, const mozilla::layers::TextureType &, const bool &, mozilla::webgl::SwapChainOptions &>' requested here
  Run<RPROC(Present)>(xrFb ? xrFb->mId : 0, type, webvr, asyncOptions);
  ^
/tmp/gecko/dom/canvas/WebGLMethodDispatcher.h:20:8: note: candidate function [with MethodT = void (mozilla::HostWebGLContext::*)(unsigned long, mozilla::layers::TextureType, bool, const mozilla::webgl::SwapChainOptions &) const, Method = &mozilla::HostWebGLContext::Present] has been explicitly deleted
size_t IdByMethod() = delete;
       ^
In file included from Unified_cpp_dom_canvas0.cpp:65:
/tmp/gecko/dom/canvas/ClientWebGLContext.cpp:355:19: error: call to deleted function 'IdByMethod'
  const auto id = IdByMethod<MethodType, method>();
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/gecko/dom/canvas/ClientWebGLContext.cpp:447:3: note: in instantiation of function template specialization 'mozilla::ClientWebGLContext::Run<void (mozilla::HostWebGLContext::*)(unsigned long, mozilla::layers::TextureType, const mozilla::webgl::SwapChainOptions &) const, &mozilla::HostWebGLContext::CopyToSwapChain, unsigned long, const mozilla::layers::TextureType &, mozilla::webgl::SwapChainOptions &>' requested here
  Run<RPROC(CopyToSwapChain)>(fb ? fb->mId : 0, texType, asyncOptions);
  ^
/tmp/gecko/dom/canvas/WebGLMethodDispatcher.h:20:8: note: candidate function [with MethodT = void (mozilla::HostWebGLContext::*)(unsigned long, mozilla::layers::TextureType, const mozilla::webgl::SwapChainOptions &) const, Method = &mozilla::HostWebGLContext::CopyToSwapChain] has been explicitly deleted
size_t IdByMethod() = delete;
       ^

(etc.)

mizvekov added a comment.EditedOct 26 2022, 12:55 AM

This broke building Firefox with:
(etc.)

Thanks for reporting. Do you have preprocessed source + cc1 flags to reproduce it, so I can have a look?

rtrieu added a subscriber: rtrieu.Oct 27 2022, 9:04 PM

I noticed some build failures after your commit. I'm trying to get a standalone reproducer.

hokein added a subscriber: hokein.Oct 28 2022, 1:25 AM

I noticed some build failures after your commit. I'm trying to get a standalone reproducer.

Here is the broken testcase:

// -std=c++17
#include <string>

template <typename Type, typename... Unused>
using FixedTypeT = Type;

template <typename... Fields>
class T {
  T(const FixedTypeT<std::string_view, Fields>... names)
      : names_(std::string(names)...) {}
  std::string names_;
};

@rtrieu @hokein I just proposed a fix for this at https://reviews.llvm.org/D136977

At least for the repro posted above, this was a pre-existing bug with unexpanded packs appearing within sugar, which the present patch potentialized by preserving the type alias when instantiating the default arguments for templates.

I also filled this as https://github.com/llvm/llvm-project/issues/58679

And there is also a drive-by error recovery improvement that touches this area: https://reviews.llvm.org/D136962

This revision is now accepted and ready to land.Oct 31 2022, 8:22 AM
mizvekov updated this revision to Diff 472020.Oct 31 2022, 8:23 AM