Skip to content

Commit ebdc555

Browse files
committed
Having assert checks for CharSXPWrapper instead of throwing RInternal should not reach here errors.
1 parent f585c15 commit ebdc555

File tree

1 file changed

+37
-59
lines changed

1 file changed

+37
-59
lines changed

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/builtin/MatchInternalNode.java

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -455,45 +455,36 @@ protected RIntVector match(RAbstractStringVector x, RAbstractStringVector table,
455455
@Specialization(guards = {"x.getLength() == 1", "isCharSXP(x)", "isCharSXP(table)"})
456456
@CompilerDirectives.TruffleBoundary
457457
protected int matchSizeOne(RList x, RList table, int nomatch,
458-
@Cached("create()") NAProfile naProfile,
459-
@Cached("create()") BranchProfile foundProfile,
460-
@Cached("create()") BranchProfile notFoundProfile) {
458+
@Cached("create()") NAProfile naProfile,
459+
@Cached("create()") BranchProfile foundProfile,
460+
@Cached("create()") BranchProfile notFoundProfile) {
461461
Object data = x.getDataAt(0);
462462
Object tableData;
463463

464-
if (data instanceof CharSXPWrapper) {
465-
String element = ((CharSXPWrapper) data).getContents();
466-
int length = table.getLength();
467-
if (naProfile.isNA(element)) {
468-
for (int i = 0; i < length; i++) {
469-
tableData = table.getDataAt(i);
470-
if (tableData instanceof CharSXPWrapper) {
471-
if (RRuntime.isNA(((CharSXPWrapper) tableData).getContents())) {
472-
foundProfile.enter();
473-
return i + 1;
474-
}
475-
} else {
476-
throw RInternalError.shouldNotReachHere();
477-
}
478-
}
479-
} else {
480-
for (int i = 0; i < length; i++) {
481-
tableData = table.getDataAt(i);
482-
if (tableData instanceof CharSXPWrapper) {
483-
if (element.equals(((CharSXPWrapper) tableData).getContents())) {
484-
foundProfile.enter();
485-
return i + 1;
486-
}
487-
} else {
488-
throw RInternalError.shouldNotReachHere();
489-
}
464+
assert data instanceof CharSXPWrapper;
465+
String element = ((CharSXPWrapper) data).getContents();
466+
int length = table.getLength();
467+
if (naProfile.isNA(element)) {
468+
for (int i = 0; i < length; i++) {
469+
tableData = table.getDataAt(i);
470+
assert tableData instanceof CharSXPWrapper;
471+
if (RRuntime.isNA(((CharSXPWrapper) tableData).getContents())) {
472+
foundProfile.enter();
473+
return i + 1;
490474
}
491475
}
492-
notFoundProfile.enter();
493-
return nomatch;
494476
} else {
495-
throw RInternalError.shouldNotReachHere();
477+
for (int i = 0; i < length; i++) {
478+
tableData = table.getDataAt(i);
479+
assert tableData instanceof CharSXPWrapper;
480+
if (element.equals(((CharSXPWrapper) tableData).getContents())) {
481+
foundProfile.enter();
482+
return i + 1;
483+
}
484+
}
496485
}
486+
notFoundProfile.enter();
487+
return nomatch;
497488
}
498489

499490
@Specialization(guards = {"x.getLength() != 1", "isCharSXP(x)", "isCharSXP(table)"})
@@ -508,47 +499,34 @@ protected RIntVector match(RList x, RList table, int nomatch) {
508499
NonRecursiveHashSetCharacter hashSet = new NonRecursiveHashSetCharacter(x.getLength());
509500
for (int i = 0; i < result.length; i++) {
510501
element = x.getDataAt(i);
511-
if (element instanceof CharSXPWrapper) {
512-
hashSet.add(((CharSXPWrapper) element).getContents());
513-
} else {
514-
throw RInternalError.shouldNotReachHere();
515-
}
502+
assert element instanceof CharSXPWrapper;
503+
hashSet.add(((CharSXPWrapper) element).getContents());
516504
}
517505
for (int i = table.getLength() - 1; i >= 0; i--) {
518506
element = table.getDataAt(i);
519-
if (element instanceof CharSXPWrapper) {
520-
String val = ((CharSXPWrapper) element).getContents();
521-
if (hashSet.contains(val)) {
522-
hashTable.put(val, i);
523-
}
524-
} else {
525-
throw RInternalError.shouldNotReachHere();
507+
assert element instanceof CharSXPWrapper;
508+
String val = ((CharSXPWrapper) element).getContents();
509+
if (hashSet.contains(val)) {
510+
hashTable.put(val, i);
526511
}
527512
}
528513
} else {
529514
hashTable = new NonRecursiveHashMapCharacter(table.getLength());
530515
for (int i = table.getLength() - 1; i >= 0; i--) {
531516
element = table.getDataAt(i);
532-
if (element instanceof CharSXPWrapper) {
533-
hashTable.put(((CharSXPWrapper) element).getContents(), i);
534-
} else {
535-
throw RInternalError.shouldNotReachHere();
536-
}
537-
517+
assert element instanceof CharSXPWrapper;
518+
hashTable.put(((CharSXPWrapper) element).getContents(), i);
538519
}
539520
}
540521
for (int i = 0; i < result.length; i++) {
541522
element = x.getDataAt(i);
542-
if (element instanceof CharSXPWrapper) {
543-
String xx = ((CharSXPWrapper) element).getContents();
544-
int index = hashTable.get(xx);
545-
if (index != -1) {
546-
result[i] = index + 1;
547-
} else {
548-
matchAll = false;
549-
}
523+
assert element instanceof CharSXPWrapper;
524+
String xx = ((CharSXPWrapper) element).getContents();
525+
int index = hashTable.get(xx);
526+
if (index != -1) {
527+
result[i] = index + 1;
550528
} else {
551-
throw RInternalError.shouldNotReachHere();
529+
matchAll = false;
552530
}
553531
}
554532
return RDataFactory.createIntVector(result, setCompleteState(matchAll, nomatch));

0 commit comments

Comments
 (0)