Closed Bug 1976408 Opened 9 months ago Closed 9 months ago

C++20 error: static assertion failed due to requirement '!std::is_pointer_v<js::SharedPropMap *>': Pointer type not allowed for StructGCPolicy

Categories

(Core :: JavaScript: GC, defect)

defect

Tracking

()

RESOLVED FIXED
142 Branch
Tracking Status
firefox140 --- unaffected
firefox141 --- wontfix
firefox142 --- fixed

People

(Reporter: cpeterson, Assigned: sfink)

References

Details

Attachments

(2 files)

When compiling Firefox with -std=c++20, the build fails with the following static assertion failure in GCPolicyAPI.h. This is a code or compiler regression introduced within the last few months because I successfully compiled Firefox with -std=c++20 (using my patch in bug 1768116) earlier this year.

Bug 1679736 and bug 1459577 are some old fixed bugs related to this std::is_pointer_v assertion.

GCPolicyAPI.h:90:17: error: static assertion failed due to requirement '!std::is_pointer_v<js::SharedPropMap *>': Pointer type not allowed for StructGCPolicy
   90 |   static_assert(!std::is_pointer_v<T>,
In file included from firefox/js/src/ctypes/Library.cpp:9:
In file included from firefox/js/src/jsapi.h:30:
In file included from firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/CallAndConstruct.h:15:
In file included from firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/RootingAPI.h:24:
firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/GCPolicyAPI.h:90:17: error: static assertion failed due to requirement '!std::is_pointer_v<js::SharedPropMap *>': Pointer type not allowed for StructGCPolicy
   90 |   static_assert(!std::is_pointer_v<T>,
      |                 ^~~~~~~~~~~~~~~~~~~~~
firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/GCPolicyAPI.h:108:26: note: in instantiation of template class 'JS::StructGCPolicy<js::SharedPropMap *>' requested here
  108 | struct GCPolicy : public StructGCPolicy<T> {};
      |                          ^
firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/GCVector.h:168:7: note: in instantiation of template class 'JS::GCPolicy<js::SharedPropMap *>' requested here
  168 |       GCPolicy<T>::trace(trc, &elem, "vector element");
      |       ^
firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/GCPolicyAPI.h:93:67: note: in instantiation of member function 'JS::GCVector<js::SharedPropMap *, 8>::trace' requested here
   93 |   static void trace(JSTracer* trc, T* tp, const char* name) { tp->trace(trc); }
      |                                                                   ^
firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/RootingAPI.h:971:22: note: in instantiation of member function 'JS::StructGCPolicy<JS::StackGCVector<js::SharedPropMap *>>::trace' requested here
  971 |     JS::GCPolicy<T>::trace(trc, self->address(), name);
      |                      ^
firefox/obj-aarch64-apple-darwin24.5.0/dist/include/js/RootingAPI.h:967:7: note: in instantiation of member function 'js::TypedRootedTraceableBase<js::StackRootedTraceableBase, JS::StackGCVector<js::SharedPropMap *>>::trace' requested here
  967 | class TypedRootedTraceableBase : public Base {
      |       ^
Assignee: nobody → sphink
Status: NEW → ASSIGNED

I'm not totally clear on where the instantiation is coming from because clang is truncating the instantiation chain even when I pass -ftemplate-backtrace-limit=0, and gcc doesn't show this error.

But I have a patch that fixes it anyway. The problem is that js::SharedPropMap is an internal type, and the GC policy header only instantiates the pointer policy for public types. Anything else falls back to the struct policy, which produces the error here. So something is instantiating a Rooted<...SharedPropMap*...> without including (directly or indirectly) gc/Policy.h, which changes the default policy for pointers to be the pointer policy.

I just included gc/Policy.h in vm/PropMap.h, which did the trick. (I don't know if it's still possible to get in trouble by forward-declaring SharedPropMap? We probably already require the type to instantiate Rooted stuff, so I think it should be fine.)

Thanks! I had localized this error to PropMap.h's JS::RootedVector<SharedPropMap*> maps_; declaration from bug 1961324, but I that was as far as I understood.

https://searchfox.org/mozilla-central/rev/1eb4f27ece7cb96ac94b635ad0dc95c00d1443db/js/src/vm/PropMap.h#1211

(In reply to Chris Peterson [:cpeterson] from comment #3)

Thanks! I had localized this error to PropMap.h's JS::RootedVector<SharedPropMap*> maps_; declaration from bug 1961324, but I that was as far as I understood.

https://searchfox.org/mozilla-central/rev/1eb4f27ece7cb96ac94b635ad0dc95c00d1443db/js/src/vm/PropMap.h#1211

The errors that come from this are unfortunate. I probably ought to come up with something where it would complain about a line that we could add a comment on, suggesting the likely fix. Maybe instead of defaulting to StructGCPolicy, it could fall back to UnhandledPointerGCPolicyReadTheComment. But I'm not sure how to do that without colliding with InternalGCPointerPolicy.

Oh, wait! I can just expand the static_assert message in StructGCPolicy.

Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 142 Branch
Pushed by amarc@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e9b35f656087 https://hg.mozilla.org/integration/autoland/rev/108061884438 Revert "Bug 1976408 - Improve error message when falling back to StructGCPolicy<pointer> r=jonco" for causing bugzilla-components failure

Backed out for causing bugzilla-components failure

Flags: needinfo?(sphink)
Flags: needinfo?(sphink)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: