Skip to content

Commit

Permalink
remove prepend
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertp committed Apr 25, 2023
1 parent bb80aa9 commit 2678d35
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Object doWarning(
argumentsExecutionMode,
isTail,
thatArgumentPosition);
return WithWarnings.prependTo(result, warnings);
return WithWarnings.appendTo(result, warnings);
}

@Specialization(guards = "interop.isString(that)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Object doWarning(
argumentsExecutionMode,
isTail,
thisArgumentPosition);
return WithWarnings.prependTo(result, warnings);
return WithWarnings.appendTo(result, warnings);
}

@Specialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public Object invokeWarnings(
if (result instanceof DataflowError) {
return result;
} else if (result instanceof WithWarnings withWarnings) {
return withWarnings.prepend(extracted);
return withWarnings.append(extracted);
} else {
return WithWarnings.wrap(result, extracted);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Object doWarning(
ArrayRope<Warning> warnings = that.getReassignedWarningsAsRope(this);
Object result =
childDispatch.execute(frame, state, conversion, self, that.getValue(), arguments);
return WithWarnings.prependTo(result, warnings);
return WithWarnings.appendTo(result, warnings);
}

@Specialization(guards = "interop.isString(that)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Object doWarning(
arguments[thisArgumentPosition] = selfWithoutWarnings;

Object result = childDispatch.execute(frame, state, symbol, selfWithoutWarnings, arguments);
return WithWarnings.prependTo(result, arrOfWarnings);
return WithWarnings.appendTo(result, arrOfWarnings);
}

@ExplodeLoop
Expand Down Expand Up @@ -327,7 +327,7 @@ Object doPolyglot(
Object res = hostMethodCallNode.execute(polyglotCallType, symbol.getName(), self, args);
if (anyWarnings) {
anyWarningsProfile.enter();
res = WithWarnings.prependTo(res, accumulatedWarnings);
res = WithWarnings.appendTo(res, accumulatedWarnings);
}
return res;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Array getReassignments() {
@Builtin.Specialize
public static WithWarnings attach(
EnsoContext ctx, WithWarnings value, Object warning, Object origin) {
return value.prepend(new Warning(warning, origin, ctx.clockTick()));
return value.append(new Warning(warning, origin, ctx.clockTick()));
}

@Builtin.Method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ private WithWarnings(Object value, EconomicSet<Warning> warnings, Warning... add
this.value = value;
}

private WithWarnings(Object value, EconomicSet<Warning> warnings, EconomicSet<Warning> additionalWarnings) {
assert !(value instanceof WithWarnings);
this.warnings = cloneSetAndAppend(warnings, additionalWarnings);
this.value = value;
}

public static WithWarnings wrap(Object value, Warning... warnings) {
if (value instanceof WithWarnings with) {
return with.append(warnings);
Expand All @@ -59,12 +53,8 @@ public WithWarnings append(Warning... newWarnings) {
return new WithWarnings(value, warnings, newWarnings);
}

public WithWarnings prepend(ArrayRope<Warning> newWarnings) {
return new WithWarnings(value, createSetFromArray(newWarnings.toArray(Warning[]::new)), warnings);
}

public WithWarnings prepend(Warning... newWarnings) {
return new WithWarnings(value, createSetFromArray(newWarnings), warnings);
public WithWarnings append(ArrayRope<Warning> newWarnings) {
return new WithWarnings(value, warnings, newWarnings.toArray(Warning[]::new));
}

public Warning[] getWarningsArray(WarningsLibrary warningsLibrary) {
Expand Down Expand Up @@ -116,22 +106,6 @@ public static WithWarnings appendTo(Object target, Warning[] warnings) {
}
}

public static WithWarnings prependTo(Object target, ArrayRope<Warning> warnings) {
if (target instanceof WithWarnings) {
return ((WithWarnings) target).prepend(warnings);
} else {
return new WithWarnings(target, warnings.toArray(Warning[]::new));
}
}

public static WithWarnings prependTo(Object target, Warning[] warnings) {
if (target instanceof WithWarnings) {
return ((WithWarnings) target).prepend(warnings);
} else {
return new WithWarnings(target, warnings);
}
}

@ExportMessage
Object send(Message message, Object[] args, @CachedLibrary(limit = "3") ReflectionLibrary lib)
throws Exception {
Expand Down Expand Up @@ -199,15 +173,6 @@ private EconomicSet<Warning> cloneSetAndAppend(EconomicSet<Warning> initial, War
return set;
}

@CompilerDirectives.TruffleBoundary
@SuppressWarnings("unchecked")
private EconomicSet<Warning> cloneSetAndAppend(EconomicSet<Warning> initial, EconomicSet<Warning> entries) {
EconomicSet<Warning> set = EconomicSet.create(new WarningEquivalence());
set.addAll(initial.iterator());
set.addAll(entries.iterator());
return set;
}

@Override
public String toString() {
return "WithWarnings{" + value + " + " + warnings.size() + " warnings}";
Expand Down

0 comments on commit 2678d35

Please sign in to comment.