Number of warnings to add has to be derived from size of accumulated warnings

This commit is contained in:
Jaroslav Tulach 2024-08-15 07:55:45 +00:00
parent 9b30d7ad82
commit 0b9a49ba9b
4 changed files with 18 additions and 18 deletions

View File

@ -52,6 +52,7 @@ import org.enso.interpreter.runtime.data.EnsoTimeZone;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.data.hash.EnsoHashMap;
import org.enso.interpreter.runtime.data.hash.HashMapInsertAllNode;
import org.enso.interpreter.runtime.data.hash.HashMapSizeNode;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.error.DataflowError;
import org.enso.interpreter.runtime.error.PanicException;
@ -509,11 +510,11 @@ public abstract class InvokeMethodNode extends BaseNode {
@Cached BranchProfile anyWarningsProfile,
@Cached HostMethodCallNode hostMethodCallNode,
@Shared @Cached AppendWarningNode appendWarningNode,
@Cached HashMapSizeNode mapSizeNode,
@Cached HashMapInsertAllNode mapInsertAllNode) {
Object[] args = new Object[argExecutors.length];
boolean anyWarnings = false;
var accumulatedWarnings = EnsoHashMap.empty();
var maxWarnings = EnsoContext.get(this).getWarningsLimit();
for (int i = 0; i < argExecutors.length; i++) {
var r = argExecutors[i].executeThunk(frame, arguments[i + 1], state, TailStatus.NOT_TAIL);
if (r instanceof DataflowError) {
@ -524,8 +525,11 @@ public abstract class InvokeMethodNode extends BaseNode {
anyWarnings = true;
try {
EnsoHashMap rWarnsMap = warnings.getWarnings(r, false);
var maxWarningsToAdd =
EnsoContext.get(this).getWarningsLimit() - mapSizeNode.execute(accumulatedWarnings);
accumulatedWarnings =
mapInsertAllNode.executeInsertAll(frame, accumulatedWarnings, rWarnsMap, maxWarnings);
mapInsertAllNode.executeInsertAll(
frame, accumulatedWarnings, rWarnsMap, maxWarningsToAdd);
args[i] = warnings.removeWarnings(r);
} catch (UnsupportedMessageException e) {
var ctx = EnsoContext.get(this);

View File

@ -13,6 +13,7 @@ import org.enso.interpreter.node.ExpressionNode;
import org.enso.interpreter.runtime.EnsoContext;
import org.enso.interpreter.runtime.data.hash.EnsoHashMap;
import org.enso.interpreter.runtime.data.hash.HashMapInsertAllNode;
import org.enso.interpreter.runtime.data.hash.HashMapSizeNode;
import org.enso.interpreter.runtime.type.TypesGen;
import org.enso.interpreter.runtime.warning.AppendWarningNode;
import org.enso.interpreter.runtime.warning.WarningsLibrary;
@ -68,11 +69,11 @@ abstract class InstantiateNode extends ExpressionNode {
VirtualFrame frame,
@Cached(parameters = {"constructor"}) AtomConstructorInstanceNode createInstanceNode,
@Cached AppendWarningNode appendWarningNode,
@Cached HashMapSizeNode mapSizeNode,
@Cached HashMapInsertAllNode mapInsertAllNode) {
Object[] argumentValues = new Object[arguments.length];
boolean anyWarnings = false;
var accumulatedWarnings = EnsoHashMap.empty();
var maxWarnings = EnsoContext.get(this).getWarningsLimit();
for (int i = 0; i < arguments.length; i++) {
CountingConditionProfile profile = profiles[i];
CountingConditionProfile warningProfile = warningProfiles[i];
@ -84,9 +85,11 @@ abstract class InstantiateNode extends ExpressionNode {
anyWarnings = true;
try {
var argumentWarnsMap = warnings.getWarnings(argument, false);
var maxWarningsToAdd =
EnsoContext.get(this).getWarningsLimit() - mapSizeNode.execute(accumulatedWarnings);
accumulatedWarnings =
mapInsertAllNode.executeInsertAll(
frame, accumulatedWarnings, argumentWarnsMap, maxWarnings);
frame, accumulatedWarnings, argumentWarnsMap, maxWarningsToAdd);
argumentValues[i] = warnings.removeWarnings(argument);
} catch (UnsupportedMessageException e) {
throw EnsoContext.get(this).raiseAssertionPanic(this, null, e);

View File

@ -33,21 +33,20 @@ public abstract class HashMapInsertAllNode extends Node {
* @param maxItems Maximum number of items to insert into the map from the container.
*/
public abstract EnsoHashMap executeInsertAll(
VirtualFrame frame, EnsoHashMap self, EnsoHashMap container, int maxItems);
VirtualFrame frame, EnsoHashMap self, EnsoHashMap container, long maxItems);
@Specialization
EnsoHashMap doEnsoHashMaps(
VirtualFrame frame,
EnsoHashMap self,
EnsoHashMap other,
int maxItems,
long maxItems,
@Cached HashCodeNode hashCodeNode,
@Cached EqualsNode equalsNode) {
assert maxItems > 0;
var selfSize = self.getHashSize();
if (selfSize >= maxItems) {
if (maxItems <= 0) {
return self;
}
var selfSize = self.getHashSize();
var otherSize = other.getHashSize();
if (otherSize == 0) {
return self;
@ -56,17 +55,13 @@ public abstract class HashMapInsertAllNode extends Node {
var selfMapBuilder = self.getMapBuilder(frame, true, hashCodeNode, equalsNode);
var selfEntriesIt = selfMapBuilder.getEntriesIterator(selfMapBuilder.generation());
var itemsInserted = 0;
while (selfEntriesIt.hasNext()) {
if (itemsInserted >= maxItems) {
break;
}
var selfEntry = selfEntriesIt.next();
mapBuilder.put(frame, selfEntry.key(), selfEntry.value(), hashCodeNode, equalsNode);
itemsInserted++;
}
var otherMapBuilder = other.getMapBuilder(frame, true, hashCodeNode, equalsNode);
var otherEntriesIt = otherMapBuilder.getEntriesIterator(otherMapBuilder.generation());
var itemsInserted = 0;
while (otherEntriesIt.hasNext()) {
if (itemsInserted >= maxItems) {
break;

View File

@ -133,10 +133,8 @@ public abstract class AppendWarningNode extends Node {
var maxWarns = withWarnings.maxWarnings;
var warnsMap = withWarnings.warnings;
var curWarnsCnt = (int) mapSizeNode.execute(warnsMap);
warnsMap =
mapInsertAllNode.executeInsertAll(frame, warnsMap, newWarnsMap, maxWarns - curWarnsCnt);
var isLimitReached =
mapSizeNode.execute(withWarnings.warnings) + mapSizeNode.execute(newWarnsMap) >= maxWarns;
warnsMap = mapInsertAllNode.executeInsertAll(frame, warnsMap, newWarnsMap, maxWarns);
var isLimitReached = mapSizeNode.execute(warnsMap) >= maxWarns;
return new WithWarnings(withWarnings.value, withWarnings.maxWarnings, isLimitReached, warnsMap);
}