From 486c5fc2c4fe25902a14c6243e94c8888b0e793b Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Tue, 8 Feb 2022 23:53:44 +0000 Subject: [PATCH] Bug 1751071 - Correctly forward-declare/import included but unused types in ipdlh headers, r=ipc-reviewers,mccr8 Differential Revision: https://phabricator.services.mozilla.com/D137164 --- dom/clients/manager/ClientIPCTypes.ipdlh | 2 +- dom/ipc/DOMTypes.ipdlh | 4 +- dom/serviceworkers/ServiceWorkerOpArgs.ipdlh | 2 +- gfx/layers/ipc/LayersMessages.ipdlh | 10 +-- gfx/layers/ipc/LayersSurfaces.ipdlh | 2 +- gfx/layers/ipc/WebRenderMessages.ipdlh | 2 +- ipc/ipdl/ipdl/builtin.py | 1 + ipc/ipdl/ipdl/lower.py | 63 ++++++++++++------- netwerk/ipc/NeckoChannelParams.ipdlh | 2 +- .../backgroundhangmonitor/HangTypes.ipdlh | 4 +- 10 files changed, 55 insertions(+), 37 deletions(-) diff --git a/dom/clients/manager/ClientIPCTypes.ipdlh b/dom/clients/manager/ClientIPCTypes.ipdlh index 514c47983745..c32b63eb0967 100644 --- a/dom/clients/manager/ClientIPCTypes.ipdlh +++ b/dom/clients/manager/ClientIPCTypes.ipdlh @@ -12,7 +12,7 @@ include "mozilla/dom/BindingIPCUtils.h"; include "mozilla/dom/ClientIPCUtils.h"; include "ipc/ErrorIPCUtils.h"; -using class mozilla::TimeStamp from "mozilla/TimeStamp.h"; +using mozilla::TimeStamp from "mozilla/TimeStamp.h"; using ClientType from "mozilla/dom/ClientsBinding.h"; using FrameType from "mozilla/dom/ClientBinding.h"; using mozilla::StorageAccess from "mozilla/StorageAccess.h"; diff --git a/dom/ipc/DOMTypes.ipdlh b/dom/ipc/DOMTypes.ipdlh index c9193b7703b8..cebaa72aa28b 100644 --- a/dom/ipc/DOMTypes.ipdlh +++ b/dom/ipc/DOMTypes.ipdlh @@ -24,7 +24,7 @@ using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; [MoveOnly=data] using struct mozilla::SerializedStructuredCloneBuffer from "mozilla/ipc/SerializedStructuredCloneBuffer.h"; -using class mozilla::dom::LoadingSessionHistoryInfo +using struct mozilla::dom::LoadingSessionHistoryInfo from "mozilla/dom/SessionHistoryEntry.h"; using LayoutDeviceIntRect from "Units.h"; @@ -45,7 +45,7 @@ using mozilla::dom::MaybeDiscardedBrowsingContext from "mozilla/dom/BrowsingCont [RefCounted] using class nsIInputStream from "mozilla/ipc/IPCStreamUtils.h"; [RefCounted] using class nsIReferrerInfo from "nsIReferrerInfo.h"; [RefCounted] using class nsIVariant from "nsIVariant.h"; -using class mozilla::TimeStamp from "mozilla/TimeStamp.h"; +using mozilla::TimeStamp from "mozilla/TimeStamp.h"; [RefCounted] using class mozilla::dom::BrowsingContext from "mozilla/dom/BrowsingContext.h"; namespace mozilla { diff --git a/dom/serviceworkers/ServiceWorkerOpArgs.ipdlh b/dom/serviceworkers/ServiceWorkerOpArgs.ipdlh index 67f23101598b..bd5e45ba16e4 100644 --- a/dom/serviceworkers/ServiceWorkerOpArgs.ipdlh +++ b/dom/serviceworkers/ServiceWorkerOpArgs.ipdlh @@ -10,7 +10,7 @@ include FetchTypes; include "mozilla/dom/ServiceWorkerIPCUtils.h"; using ServiceWorkerState from "mozilla/dom/ServiceWorkerBinding.h"; -using class mozilla::TimeStamp from "mozilla/TimeStamp.h"; +using mozilla::TimeStamp from "mozilla/TimeStamp.h"; namespace mozilla { namespace dom { diff --git a/gfx/layers/ipc/LayersMessages.ipdlh b/gfx/layers/ipc/LayersMessages.ipdlh index 0a5efaee9590..99b3ae7cf9ef 100644 --- a/gfx/layers/ipc/LayersMessages.ipdlh +++ b/gfx/layers/ipc/LayersMessages.ipdlh @@ -15,16 +15,16 @@ include "mozilla/GfxMessageUtils.h"; using mozilla::gfx::Glyph from "mozilla/gfx/2D.h"; using mozilla::gfx::SamplingFilter from "mozilla/gfx/2D.h"; using struct mozilla::gfx::DeviceColor from "mozilla/gfx/2D.h"; -using struct mozilla::gfx::Point from "mozilla/gfx/Point.h"; -using struct mozilla::gfx::Point3D from "mozilla/gfx/Point.h"; +using mozilla::gfx::Point from "mozilla/gfx/Point.h"; +using mozilla::gfx::Point3D from "mozilla/gfx/Point.h"; using mozilla::gfx::IntPoint from "mozilla/gfx/Point.h"; -using class mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h"; -using class mozilla::SideBits from "mozilla/gfx/Types.h"; +using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h"; +using mozilla::SideBits from "mozilla/gfx/Types.h"; using nscolor from "nsColor.h"; using nscoord from "nsCoord.h"; using struct nsRect from "nsRect.h"; using struct nsPoint from "nsPoint.h"; -using class mozilla::TimeDuration from "mozilla/TimeStamp.h"; +using mozilla::TimeDuration from "mozilla/TimeStamp.h"; using class mozilla::TimeStamp from "mozilla/TimeStamp.h"; using mozilla::ScreenRotation from "mozilla/WidgetUtils.h"; using nsCSSPropertyID from "nsCSSPropertyID.h"; diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index 3f7a806178ee..f8564e744bf8 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -4,7 +4,7 @@ include "gfxipc/ShadowLayerUtils.h"; -using struct gfxPoint from "gfxPoint.h"; +using gfxPoint from "gfxPoint.h"; using nsIntRegion from "nsRegion.h"; using mozilla::StereoMode from "ImageTypes.h"; using struct mozilla::null_t from "mozilla/ipc/IPCCore.h"; diff --git a/gfx/layers/ipc/WebRenderMessages.ipdlh b/gfx/layers/ipc/WebRenderMessages.ipdlh index dda247b9e00b..48957c1757f8 100644 --- a/gfx/layers/ipc/WebRenderMessages.ipdlh +++ b/gfx/layers/ipc/WebRenderMessages.ipdlh @@ -31,7 +31,7 @@ using mozilla::LayoutDeviceSize from "Units.h"; using mozilla::ImageIntRect from "Units.h"; using mozilla::gfx::Rect from "mozilla/gfx/Rect.h"; using mozilla::VideoInfo::Rotation from "MediaInfo.h"; -using class mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h"; +using mozilla::gfx::Matrix4x4 from "mozilla/gfx/Matrix.h"; using struct mozilla::void_t from "mozilla/ipc/IPCCore.h"; namespace mozilla { diff --git a/ipc/ipdl/ipdl/builtin.py b/ipc/ipdl/ipdl/builtin.py index 143624023740..a675d74a51e7 100644 --- a/ipc/ipdl/ipdl/builtin.py +++ b/ipc/ipdl/ipdl/builtin.py @@ -60,6 +60,7 @@ HeaderIncludes = ( CppIncludes = ( "ipc/IPCMessageUtils.h", + "ipc/IPCMessageUtilsSpecializations.h", "nsIFile.h", "mozilla/ipc/Endpoint.h", "mozilla/ipc/ProtocolMessageUtils.h", diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 405f308c8e3d..52547465f841 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -1646,6 +1646,10 @@ class _GenerateProtocolCode(ipdl.ast.Visitor): self.hdrfile.addthing( CppDirective("include", '"' + _ipdlhHeaderName(inc.tu) + '.h"') ) + # Inherit cpp includes defined by imported header files, as they may + # be required to serialize an imported `using` type. + for cxxinc in inc.tu.cxxIncludes: + cxxinc.accept(self) else: self.cppIncludeHeaders += [ _protocolHeaderName(inc.tu.protocol, "parent") + ".h", @@ -3573,33 +3577,46 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor): self.externalIncludes.add(inc.file) def visitInclude(self, inc): - ip = inc.tu.protocol - if not ip: - return + if inc.tu.filetype == "header": + # Including a header will declare any globals defined by "using" + # statements into our scope. To serialize these, we also may need + # cxx include statements, so visit them as well. + for cxxinc in inc.tu.cxxIncludes: + cxxinc.accept(self) + for using in inc.tu.using: + using.accept(self) + else: + # Includes for protocols only include types explicitly exported by + # those protocols. + ip = inc.tu.protocol + if ip == self.protocol: + return - self.actorForwardDecls.extend( - [ - _makeForwardDeclForActor(ip.decl.type, self.side), - _makeForwardDeclForActor(ip.decl.type, _otherSide(self.side)), - Whitespace.NL, - ] - ) - self.protocolCxxIncludes.append(_protocolHeaderName(ip, self.side)) - - if ip.decl.fullname is not None: - self.includedActorTypedefs.append( - Typedef( - Type(_actorName(ip.decl.fullname, self.side.title())), - _actorName(ip.decl.shortname, self.side.title()), - ) + self.actorForwardDecls.extend( + [ + _makeForwardDeclForActor(ip.decl.type, self.side), + _makeForwardDeclForActor(ip.decl.type, _otherSide(self.side)), + Whitespace.NL, + ] ) + self.protocolCxxIncludes.append(_protocolHeaderName(ip, self.side)) - self.includedActorTypedefs.append( - Typedef( - Type(_actorName(ip.decl.fullname, _otherSide(self.side).title())), - _actorName(ip.decl.shortname, _otherSide(self.side).title()), + if ip.decl.fullname is not None: + self.includedActorTypedefs.append( + Typedef( + Type(_actorName(ip.decl.fullname, self.side.title())), + _actorName(ip.decl.shortname, self.side.title()), + ) + ) + + self.includedActorTypedefs.append( + Typedef( + Type( + _actorName(ip.decl.fullname, _otherSide(self.side).title()) + ), + _actorName(ip.decl.shortname, _otherSide(self.side).title()), + ) ) - ) def visitProtocol(self, p): self.hdrfile.addcode( diff --git a/netwerk/ipc/NeckoChannelParams.ipdlh b/netwerk/ipc/NeckoChannelParams.ipdlh index 92dc563a17ce..51ad6add2ab7 100644 --- a/netwerk/ipc/NeckoChannelParams.ipdlh +++ b/netwerk/ipc/NeckoChannelParams.ipdlh @@ -33,7 +33,7 @@ using nsContentPolicyType from "nsIContentPolicy.h"; using mozilla::net::PreferredAlternativeDataDeliveryTypeIPC from "nsICacheInfoChannel.h"; using nsILoadInfo::CrossOriginEmbedderPolicy from "nsILoadInfo.h"; using nsILoadInfo::StoragePermissionState from "nsILoadInfo.h"; -using class mozilla::dom::LoadingSessionHistoryInfo from "mozilla/dom/SessionHistoryEntry.h"; +using struct mozilla::dom::LoadingSessionHistoryInfo from "mozilla/dom/SessionHistoryEntry.h"; namespace mozilla { namespace net { diff --git a/toolkit/components/backgroundhangmonitor/HangTypes.ipdlh b/toolkit/components/backgroundhangmonitor/HangTypes.ipdlh index 3d8dd5aff2e1..e791bd6f4408 100644 --- a/toolkit/components/backgroundhangmonitor/HangTypes.ipdlh +++ b/toolkit/components/backgroundhangmonitor/HangTypes.ipdlh @@ -4,7 +4,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -using class mozilla::TimeDuration from "mozilla/TimeStamp.h"; +using mozilla::TimeDuration from "mozilla/TimeStamp.h"; namespace mozilla { @@ -92,4 +92,4 @@ struct HangDetails HangAnnotation[] annotations; }; -} // namespace mozilla \ No newline at end of file +} // namespace mozilla