RESOLVED FIXED 237437
[WebGPU] Abide by the WebKit Style Guide
https://bugs.webkit.org/show_bug.cgi?id=237437
Summary [WebGPU] Abide by the WebKit Style Guide
Myles C. Maxfield
Reported 2022-03-03 10:27:29 PST
[WebGPU] Abide by the WebKit Style Guide
Attachments
Patch (51.71 KB, patch)
2022-03-03 10:30 PST, Myles C. Maxfield
no flags
Patch (51.36 KB, patch)
2022-03-03 11:35 PST, Myles C. Maxfield
no flags
Myles C. Maxfield
Comment 1 2022-03-03 10:30:04 PST
Darin Adler
Comment 2 2022-03-03 10:33:48 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review > Source/WebGPU/ChangeLog:9 > + 1. "Donât add explicit initializations to nil" Wait, what? What is that guideline? Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! > Source/WebGPU/WebGPU/BindGroup.h:55 > - id <MTLBuffer> m_vertexArgumentBuffer { nil }; > - id <MTLBuffer> m_fragmentArgumentBuffer { nil }; > - id <MTLBuffer> m_computeArgumentBuffer { nil }; > + id<MTLBuffer> m_vertexArgumentBuffer; > + id<MTLBuffer> m_fragmentArgumentBuffer; > + id<MTLBuffer> m_computeArgumentBuffer; Removing the { nil } here does not seem right.
Myles C. Maxfield
Comment 3 2022-03-03 10:35:30 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review >> Source/WebGPU/ChangeLog:9 >> + 1. "Donât add explicit initializations to nil" > > Wait, what? What is that guideline? > > Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! https://webkit.org/code-style-guidelines/#zero-objc-variables "In Objective-C, instance variables are initialized to zero automatically. Don’t add explicit initializations to nil or NO in an init method."
Myles C. Maxfield
Comment 4 2022-03-03 10:36:21 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review >>> Source/WebGPU/ChangeLog:9 >>> + 1. "Donât add explicit initializations to nil" >> >> Wait, what? What is that guideline? >> >> Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! > > https://webkit.org/code-style-guidelines/#zero-objc-variables > > "In Objective-C, instance variables are initialized to zero automatically. Don’t add explicit initializations to nil or NO in an init method." Oh, maybe that's just for ivars and not regular variables? And maybe doesn't apply in Objective-C++?
Darin Adler
Comment 5 2022-03-03 10:41:13 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review >>>> Source/WebGPU/ChangeLog:9 >>>> + 1. "Donât add explicit initializations to nil" >>> >>> Wait, what? What is that guideline? >>> >>> Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! >> >> https://webkit.org/code-style-guidelines/#zero-objc-variables >> >> "In Objective-C, instance variables are initialized to zero automatically. Don’t add explicit initializations to nil or NO in an init method." > > Oh, maybe that's just for ivars and not regular variables? > > And maybe doesn't apply in Objective-C++? Yes, just instance variables. It does apply in Objective-C++, but structure members and C++ class members are not instance variables.
Myles C. Maxfield
Comment 6 2022-03-03 11:23:15 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review >>>>> Source/WebGPU/ChangeLog:9 >>>>> + 1. "Donât add explicit initializations to nil" >>>> >>>> Wait, what? What is that guideline? >>>> >>>> Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! >>> >>> https://webkit.org/code-style-guidelines/#zero-objc-variables >>> >>> "In Objective-C, instance variables are initialized to zero automatically. Don’t add explicit initializations to nil or NO in an init method." >> >> Oh, maybe that's just for ivars and not regular variables? >> >> And maybe doesn't apply in Objective-C++? > > Yes, just instance variables. It does apply in Objective-C++, but structure members and C++ class members are not instance variables. Looking at the disassembly, it looks like it does zero-out uninitialized Obj-C objects in C++ classes. If I add a new uninitialized Obj-C member to the class, then the C++ constructor gains an extra instruction: 0x1014c53d4 <+84>: movq $0x0, 0x10(%rax) Either way, I'm happy to be defensive and explicitly zero-out these members.
Darin Adler
Comment 7 2022-03-03 11:30:24 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review >>>>>> Source/WebGPU/ChangeLog:9 >>>>>> + 1. "Donât add explicit initializations to nil" >>>>> >>>>> Wait, what? What is that guideline? >>>>> >>>>> Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! >>>> >>>> https://webkit.org/code-style-guidelines/#zero-objc-variables >>>> >>>> "In Objective-C, instance variables are initialized to zero automatically. Don’t add explicit initializations to nil or NO in an init method." >>> >>> Oh, maybe that's just for ivars and not regular variables? >>> >>> And maybe doesn't apply in Objective-C++? >> >> Yes, just instance variables. It does apply in Objective-C++, but structure members and C++ class members are not instance variables. > > Looking at the disassembly, it looks like it does zero-out uninitialized Obj-C objects in C++ classes. If I add a new uninitialized Obj-C member to the class, then the C++ constructor gains an extra instruction: > > 0x1014c53d4 <+84>: movq $0x0, 0x10(%rax) > > Either way, I'm happy to be defensive and explicitly zero-out these members. If so, this is a change from the ARC transition, although maybe it does affect non-ARC files perhaps due to a compiler option we were passing. This was not the case when we started the WebKit project; we need to double check it to be sure. Not sure that single experiment is enough. I welcome the change to remove the unneeded nil if it’s truly unneeded now.
Darin Adler
Comment 8 2022-03-03 11:30:58 PST
Comment on attachment 453758 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=453758&action=review >>>>>>> Source/WebGPU/ChangeLog:9 >>>>>>> + 1. "Donât add explicit initializations to nil" >>>>>> >>>>>> Wait, what? What is that guideline? >>>>>> >>>>>> Under ARC things are initialized without doing it explicitly, but with manual retain/release I am pretty sure you need to do it! >>>>> >>>>> https://webkit.org/code-style-guidelines/#zero-objc-variables >>>>> >>>>> "In Objective-C, instance variables are initialized to zero automatically. Don’t add explicit initializations to nil or NO in an init method." >>>> >>>> Oh, maybe that's just for ivars and not regular variables? >>>> >>>> And maybe doesn't apply in Objective-C++? >>> >>> Yes, just instance variables. It does apply in Objective-C++, but structure members and C++ class members are not instance variables. >> >> Looking at the disassembly, it looks like it does zero-out uninitialized Obj-C objects in C++ classes. If I add a new uninitialized Obj-C member to the class, then the C++ constructor gains an extra instruction: >> >> 0x1014c53d4 <+84>: movq $0x0, 0x10(%rax) >> >> Either way, I'm happy to be defensive and explicitly zero-out these members. > > If so, this is a change from the ARC transition, although maybe it does affect non-ARC files perhaps due to a compiler option we were passing. This was not the case when we started the WebKit project; we need to double check it to be sure. Not sure that single experiment is enough. I welcome the change to remove the unneeded nil if it’s truly unneeded now. The style guide is absolutely *not* talking about this, though.
Myles C. Maxfield
Comment 9 2022-03-03 11:35:07 PST
EWS
Comment 10 2022-03-03 13:03:32 PST
Committed r290791 (248031@main): <https://commits.webkit.org/248031@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 453767 [details].
Radar WebKit Bug Importer
Comment 11 2022-03-03 13:04:17 PST
Note You need to log in before you can comment on or make changes to this bug.