Skip to content

Commit

Permalink
Fix domination within deeply nested blocks (#485)
Browse files Browse the repository at this point in the history
Co-authored-by: Ibrahim Numanagić <ibrahimpasa@gmail.com>
  • Loading branch information
arshajii and inumanag committed Oct 3, 2023
1 parent bee2c2f commit 1e6382c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 7 additions & 2 deletions codon/parser/visitors/simplify/ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ SimplifyContext::Item SimplifyContext::findDominatingBinding(const std::string &
// We went outside the function scope. Break.
if (!isOutside && (*i)->getBaseName() != getBaseName())
break;
bool completeDomination =
(*i)->scope.size() <= scope.blocks.size() &&
(*i)->scope.back() == scope.blocks[(*i)->scope.size() - 1];
if (!completeDomination && prefix < int(scope.blocks.size()) && prefix != p) {
break;
}
prefix = p;
lastGood = i;
// The binding completely dominates the current scope. Break.
if ((*i)->scope.size() <= scope.blocks.size() &&
(*i)->scope.back() == scope.blocks[(*i)->scope.size() - 1])
if (completeDomination)
break;
}
seqassert(lastGood != it->second.end(), "corrupted scoping ({})", name);
Expand Down
32 changes: 32 additions & 0 deletions test/parser/types.codon
Original file line number Diff line number Diff line change
Expand Up @@ -1998,3 +1998,35 @@ print(Tuple[-5, int].__class__.__name__)
#: Tuple
print(Tuple[5, int, str].__class__.__name__)
#: Tuple[int,str,int,str,int,str,int,str,int,str]


#%% domination_nested,barebones
def correlate(a, b, mode = 'valid'):
if mode == 'valid':
if isinstance(a, List):
xret = '1'
else:
xret = '2'
for i in a:
for j in b:
xret += 'z'
elif mode == 'same':
if isinstance(a, List):
xret = '3'
else:
xret = '4'
for i in a:
for j in b:
xret += 'z'
elif mode == 'full':
if isinstance(a, List):
xret = '5'
else:
xret = '6'
for i in a:
for j in b:
xret += 'z'
else:
raise ValueError(f"mode must be one of 'valid', 'same', or 'full' (got {repr(mode)})")
return xret
print(correlate([1], [2], 'full')) # 5z

0 comments on commit 1e6382c

Please sign in to comment.