Skip to content

Commit fd6b63b

Browse files
committed
Change api generator comment layout
How comments are laid out can have a significant effect on readability. If we're to have 80column headers, then placing documentation comments before a declaration line - rather than on the end of the same line - can enable clang format to generate more readable headers without a great change in the overall line length.. This might use more or less vertical space than the existing version, since lines aren't off the right hand side. As an example: ```cpp urLoaderConfigGetInfo( ur_loader_config_handle_t hLoaderConfig, ///< [in] handle of the loader config object ur_loader_config_info_t propName, ///< [in] type of the info to retrieve size_t propSize, ///< [in] the number of bytes pointed to by pPropValue. void *pPropValue, ///< [out][optional][typename(propName, propSize)] array of bytes holding ///< the info. ///< If propSize is not equal to or greater than the real number of bytes ///< needed to return the info ///< then the ::UR_RESULT_ERROR_INVALID_SIZE error is returned and ///< pPropValue is not used. size_t *pPropSizeRet ///< [out][optional] pointer to the actual size in bytes of the queried propName. ); ``` -> ```cpp urLoaderConfigGetInfo( /// [in] handle of the loader config object ur_loader_config_handle_t hLoaderConfig, /// [in] type of the info to retrieve ur_loader_config_info_t propName, /// [in] the number of bytes pointed to by pPropValue. size_t propSize, /// [out][optional][typename(propName, propSize)] array of bytes holding the /// info. If propSize is not equal to or greater than the real number of bytes /// needed to return the info then the ::UR_RESULT_ERROR_INVALID_SIZE error is /// returned and pPropValue is not used. void *pPropValue, /// [out][optional] pointer to the actual size in bytes of the queried propName. size_t *pPropSizeRet ); ``` The comment and declaration for pPropValue takes fewer lines here, but the shorter comments occupy more space. Here is another example, where certain sequences can end up the same length, but with a slightly more consistent appearance : enumerations where the enumerator itself is long, and explicit values for the enumerator declaration: ```cpp UR_FUNCTION_CONTEXT_SET_EXTENDED_DELETER = 7, ///< Enumerator for ::urContextSetExtendedDeleter ``` -> ```cpp /// Enumerator for ::urContextSetExtendedDeleter UR_FUNCTION_CONTEXT_SET_EXTENDED_DELETER = 7, ``` ``` The total line length change for those files touched by the generator: before: ``` 12411 include/ur_api.h 1832 include/ur_ddi.h 1564 scripts/templates/helper.py 6818 source/adapters/null/ur_nullddi.cpp 7650 source/loader/layers/tracing/ur_trcddi.cpp 10658 source/loader/layers/validation/ur_valddi.cpp 9173 source/loader/ur_ldrddi.cpp 8706 source/loader/ur_libapi.cpp 7390 source/ur_api.cpp 66202 total ``` After: ``` 13051 include/ur_api.h 1832 include/ur_ddi.h 1564 scripts/templates/helper.py 6986 source/adapters/null/ur_nullddi.cpp 7671 source/loader/layers/tracing/ur_trcddi.cpp 10153 source/loader/layers/validation/ur_valddi.cpp 8986 source/loader/ur_ldrddi.cpp 8770 source/loader/ur_libapi.cpp 7637 source/ur_api.cpp 66650 total ``` That's a less than 1% line length increase for generated code, so I think this is a win.
1 parent f68e8c0 commit fd6b63b

24 files changed

+65
-24
lines changed

scripts/templates/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""
22
Copyright (C) 2023 Intel Corporation
33
4-
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
4+
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
5+
Exceptions.
56
See LICENSE.TXT
7+
68
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
79
810
"""

scripts/templates/api.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2020 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${n}_api.cpp

scripts/templates/api.h.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2022 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${n}_api.h

scripts/templates/api_funcs.def.mako

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ from templates import helper as th
1212
*
1313
* Copyright (C) 2024 Intel Corporation
1414
*
15-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
15+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
16+
* Exceptions.
17+
*
1618
* See LICENSE.TXT
19+
*
1720
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1821
*
1922
* @file ${name}.def

scripts/templates/ddi.h.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2022 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${n}_ddi.h

scripts/templates/exp_feat.yml.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import datetime
77
%>#
88
# Copyright (C) ${year_now} Intel Corporation
99
#
10-
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
10+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
11+
# Exceptions.
1112
# See LICENSE.TXT
13+
#
1214
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1315
#
1416
# See YaML.md for syntax definition

scripts/templates/helper.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,8 @@ def make_etor_lines(namespace, tags, obj, meta=None):
825825
prologue = "%s,"%(name)
826826

827827
for line in split_line(subt(namespace, tags, item['desc'], True), 70):
828-
lines.append("%s%s %s"%(append_ws(prologue, 48), "///<", line))
829-
prologue = ""
828+
lines.append(" /// %s" % line)
829+
lines.append(prologue)
830830

831831
lines += [
832832
"/// @cond",
@@ -877,8 +877,8 @@ def make_member_lines(namespace, tags, obj, prefix="", meta=None):
877877
prologue = "%s %s %s;"%(tname, name, array_suffix)
878878

879879
for line in split_line(subt(namespace, tags, item['desc'], True), 70):
880-
lines.append("%s%s %s"%(append_ws(prologue, 48), "///<", line))
881-
prologue = ""
880+
lines.append(" /// %s" % line)
881+
lines.append(prologue)
882882
return lines
883883

884884
"""
@@ -926,8 +926,8 @@ def make_param_lines(namespace, tags, obj, decl=False, meta=None, format=["type"
926926
if "desc" in format:
927927
desc = item['desc']
928928
for line in split_line(subt(namespace, tags, desc, True), 70):
929-
lines.append("%s///< %s"%(append_ws(prologue, 48), line))
930-
prologue = ""
929+
lines.append(" /// %s" % line)
930+
lines.append(prologue)
931931
else:
932932
lines.append(prologue)
933933

scripts/templates/ldrddi.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2022-2023 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${name}.cpp

scripts/templates/ldrddi.hpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2022-2023 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${name}.hpp

scripts/templates/libapi.cpp.mako

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def define_dbg(obj, tags):
2121
*
2222
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
2323
* See LICENSE.TXT
24+
*
2425
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2526
*
2627
* @file ${name}.cpp

scripts/templates/libddi.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2022 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${name}.cpp

scripts/templates/mockddi.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2024 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${name}.cpp

scripts/templates/optional_queries.h.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ optional_queries = th.get_optional_queries(specs, namespace, tags)
77
*
88
* Copyright (C) 2024 Intel Corporation
99
*
10-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
10+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
11+
* Exceptions.
1112
* See LICENSE.TXT
13+
*
1214
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1315
*
1416
* @file ${filename}.h

scripts/templates/print.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import print_helper as tph
1111
*
1212
* Copyright (C) 2023-2024 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${n}_print.cpp

scripts/templates/print.h.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import print_helper as tph
1111
*
1212
* Copyright (C) 2023-2024 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${n}_print.h

scripts/templates/print.hpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2023-2024 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${name}.hpp

scripts/templates/print_helper.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
55
See LICENSE.TXT
6+
67
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
78
89
A helper script for generating Printing API code and HTML documentation that aligns with the code.

scripts/templates/queue_api.cpp.mako

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from templates import helper as th
1313
*
1414
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
1515
* Exceptions. See LICENSE.TXT
16+
*
1617
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1718
*
1819
* @file ${name}.cpp
@@ -39,4 +40,4 @@ try {
3940
return exceptionToResult(std::current_exception());
4041
}
4142
%endfor
42-
}
43+
}

scripts/templates/queue_api.hpp.mako

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from templates import helper as th
1313
*
1414
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
1515
* Exceptions. See LICENSE.TXT
16+
*
1617
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1718
*
1819
* @file ${name}.hpp

scripts/templates/tools-info.hpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ from templates import helper as th
1111
*
1212
* Copyright (C) 2023 Intel Corporation
1313
*
14-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
14+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
15+
* Exceptions.
1516
* See LICENSE.TXT
17+
*
1618
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1719
*
1820
* @file ${name}.cpp

scripts/templates/trcddi.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ from templates import helper as th
1010
*
1111
* Copyright (C) 2023 Intel Corporation
1212
*
13-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
13+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
14+
* Exceptions.
1415
* See LICENSE.TXT
16+
*
1517
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1618
*
1719
* @file ${name}.cpp

scripts/templates/ur_interface_loader.cpp.mako

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from templates import helper as th
1414
//
1515
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
1616
// Exceptions. See LICENSE.TXT
17+
//
1718
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1819
//
1920
//===----------------------------------------------------------------------===//

scripts/templates/ur_interface_loader.hpp.mako

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ from templates import helper as th
1414
//
1515
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
1616
// Exceptions. See LICENSE.TXT
17+
//
1718
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1819
//
1920
//===----------------------------------------------------------------------===//

scripts/templates/valddi.cpp.mako

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ from templates import helper as th
1313
*
1414
* Copyright (C) 2023-2024 Intel Corporation
1515
*
16-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
16+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
17+
* Exceptions.
1718
* See LICENSE.TXT
19+
*
1820
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1921
*
2022
* @file ${name}.cpp

0 commit comments

Comments
 (0)