Skip to content

Commit b4db396

Browse files
Merge pull request #7444 from jakobandersen/cpp_parentKey_parallel
C++, fix merging overloaded functions in parallel builds.
2 parents 4caa7d7 + 1086fd4 commit b4db396

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Bugs fixed
1717
----------
1818

1919
* #7428: py domain: a reference to class ``None`` emits a nitpicky warning
20+
* #7438: C++, fix merging overloaded functions in parallel builds.
2021

2122
Testing
2223
--------

sphinx/domains/cpp.py

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4300,18 +4300,73 @@ def merge_with(self, other: "Symbol", docnames: List[str],
43004300
Symbol.debug_indent += 1
43014301
Symbol.debug_print("merge_with:")
43024302
assert other is not None
4303+
4304+
def unconditionalAdd(self, otherChild):
4305+
# TODO: hmm, should we prune by docnames?
4306+
self._children.append(otherChild)
4307+
otherChild.parent = self
4308+
otherChild._assert_invariants()
4309+
4310+
if Symbol.debug_lookup:
4311+
Symbol.debug_indent += 1
43034312
for otherChild in other._children:
4304-
ourChild = self._find_first_named_symbol(
4313+
if Symbol.debug_lookup:
4314+
Symbol.debug_print("otherChild:\n", otherChild.to_string(Symbol.debug_indent))
4315+
Symbol.debug_indent += 1
4316+
if otherChild.isRedeclaration:
4317+
unconditionalAdd(self, otherChild)
4318+
if Symbol.debug_lookup:
4319+
Symbol.debug_print("isRedeclaration")
4320+
Symbol.debug_indent -= 1
4321+
continue
4322+
candiateIter = self._find_named_symbols(
43054323
identOrOp=otherChild.identOrOp,
43064324
templateParams=otherChild.templateParams,
43074325
templateArgs=otherChild.templateArgs,
43084326
templateShorthand=False, matchSelf=False,
4309-
recurseInAnon=False, correctPrimaryTemplateArgs=False)
4327+
recurseInAnon=False, correctPrimaryTemplateArgs=False,
4328+
searchInSiblings=False)
4329+
candidates = list(candiateIter)
4330+
4331+
if Symbol.debug_lookup:
4332+
Symbol.debug_print("raw candidate symbols:", len(candidates))
4333+
symbols = [s for s in candidates if not s.isRedeclaration]
4334+
if Symbol.debug_lookup:
4335+
Symbol.debug_print("non-duplicate candidate symbols:", len(symbols))
4336+
4337+
if len(symbols) == 0:
4338+
unconditionalAdd(self, otherChild)
4339+
if Symbol.debug_lookup:
4340+
Symbol.debug_indent -= 1
4341+
continue
4342+
4343+
ourChild = None
4344+
if otherChild.declaration is None:
4345+
if Symbol.debug_lookup:
4346+
Symbol.debug_print("no declaration in other child")
4347+
ourChild = symbols[0]
4348+
else:
4349+
queryId = otherChild.declaration.get_newest_id()
4350+
if Symbol.debug_lookup:
4351+
Symbol.debug_print("queryId: ", queryId)
4352+
for symbol in symbols:
4353+
if symbol.declaration is None:
4354+
if Symbol.debug_lookup:
4355+
Symbol.debug_print("empty candidate")
4356+
# if in the end we have non matching, but have an empty one,
4357+
# then just continue with that
4358+
ourChild = symbol
4359+
continue
4360+
candId = symbol.declaration.get_newest_id()
4361+
if Symbol.debug_lookup:
4362+
Symbol.debug_print("candidate:", candId)
4363+
if candId == queryId:
4364+
ourChild = symbol
4365+
break
4366+
if Symbol.debug_lookup:
4367+
Symbol.debug_indent -= 1
43104368
if ourChild is None:
4311-
# TODO: hmm, should we prune by docnames?
4312-
self._children.append(otherChild)
4313-
otherChild.parent = self
4314-
otherChild._assert_invariants()
4369+
unconditionalAdd(self, otherChild)
43154370
continue
43164371
if otherChild.declaration and otherChild.docname in docnames:
43174372
if not ourChild.declaration:
@@ -4326,10 +4381,14 @@ def merge_with(self, other: "Symbol", docnames: List[str],
43264381
# Both have declarations, and in the same docname.
43274382
# This can apparently happen, it should be safe to
43284383
# just ignore it, right?
4329-
pass
4384+
# Hmm, only on duplicate declarations, right?
4385+
msg = "Internal C++ domain error during symbol merging.\n"
4386+
msg += "ourChild:\n" + ourChild.to_string(1)
4387+
msg += "\notherChild:\n" + otherChild.to_string(1)
4388+
logger.warning(msg, location=otherChild.docname)
43304389
ourChild.merge_with(otherChild, docnames, env)
43314390
if Symbol.debug_lookup:
4332-
Symbol.debug_indent -= 1
4391+
Symbol.debug_indent -= 2
43334392

43344393
def add_name(self, nestedName: ASTNestedName,
43354394
templatePrefix: ASTTemplateDeclarationPrefix = None) -> "Symbol":
@@ -7116,7 +7175,6 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
71167175
print("\tother:")
71177176
print(otherdata['root_symbol'].dump(1))
71187177
print("\tother end")
7119-
print("merge_domaindata end")
71207178

71217179
self.data['root_symbol'].merge_with(otherdata['root_symbol'],
71227180
docnames, self.env)
@@ -7130,6 +7188,11 @@ def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
71307188
logger.warning(msg, location=docname)
71317189
else:
71327190
ourNames[name] = docname
7191+
if Symbol.debug_show_tree:
7192+
print("\tresult:")
7193+
print(self.data['root_symbol'].dump(1))
7194+
print("\tresult end")
7195+
print("merge_domaindata end")
71337196

71347197
def _resolve_xref_inner(self, env: BuildEnvironment, fromdocname: str, builder: Builder,
71357198
typ: str, target: str, node: pending_xref,

0 commit comments

Comments
 (0)