Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 143678657001
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 989e723f7125
Choose a head ref
  • 2 commits
  • 13 files changed
  • 1 contributor

Commits on Jan 8, 2015

  1. [Truffle] Add option to raise ArgumentError instead of TypeError on u…

    …nsupported specialisation.
    chrisseaton committed Jan 8, 2015
    1
    Copy the full SHA
    8bac368 View commit details
  2. 3
    Copy the full SHA
    989e723 View commit details
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@
package org.jruby.truffle.nodes.core;

import org.jruby.runtime.Visibility;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -54,4 +55,6 @@

int[] lowerFixnumParameters() default {};

UnsupportedOperationBehavior unsupportedOperationBehavior() default UnsupportedOperationBehavior.TYPE_ERROR;

}
Original file line number Diff line number Diff line change
@@ -189,7 +189,7 @@ private static RubyRootNode makeGenericMethod(RubyContext context, MethodDetails

final CheckArityNode checkArity = new CheckArityNode(context, sourceSection, arity);
final RubyNode block = SequenceNode.sequence(context, sourceSection, checkArity, methodNode);
final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, block);
final ExceptionTranslatingNode exceptionTranslatingNode = new ExceptionTranslatingNode(context, sourceSection, block, methodDetails.getMethodAnnotation().unsupportedOperationBehavior());

return new RubyRootNode(context, sourceSection, null, sharedMethodInfo, exceptionTranslatingNode);
}
15 changes: 8 additions & 7 deletions core/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.BranchProfile;
import com.oracle.truffle.api.utilities.ConditionProfile;
import org.jruby.truffle.nodes.methods.UnsupportedOperationBehavior;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyArray;
import org.jruby.truffle.runtime.core.RubyBignum;
@@ -218,8 +219,8 @@ public int mul(int a, int b) {
}

@Specialization
public long mulWithOverflow(int a, int b) {
return (long) a * (long) b;
public Object mulWithOverflow(int a, int b) {
return fixnumOrBignum(bignum(a).multiply(bignum(b)));
}

@Specialization(rewriteOn = ArithmeticException.class)
@@ -618,7 +619,7 @@ public RubyArray divMod(long a, RubyBignum b) {

}

@CoreMethod(names = "<", required = 1)
@CoreMethod(names = "<", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
public abstract static class LessNode extends CoreMethodNode {

public LessNode(RubyContext context, SourceSection sourceSection) {
@@ -670,7 +671,7 @@ public boolean less(long a, RubyBignum b) {
}
}

@CoreMethod(names = "<=", required = 1)
@CoreMethod(names = "<=", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
public abstract static class LessEqualNode extends CoreMethodNode {

public LessEqualNode(RubyContext context, SourceSection sourceSection) {
@@ -831,7 +832,7 @@ public int compare(long a, RubyBignum b) {
}
}

@CoreMethod(names = ">=", required = 1)
@CoreMethod(names = ">=", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
public abstract static class GreaterEqualNode extends CoreMethodNode {

public GreaterEqualNode(RubyContext context, SourceSection sourceSection) {
@@ -883,7 +884,7 @@ public boolean greaterEqual(long a, RubyBignum b) {
}
}

@CoreMethod(names = ">", required = 1)
@CoreMethod(names = ">", required = 1, unsupportedOperationBehavior = UnsupportedOperationBehavior.ARGUMENT_ERROR)
public abstract static class GreaterNode extends CoreMethodNode {

public GreaterNode(RubyContext context, SourceSection sourceSection) {
@@ -1301,7 +1302,7 @@ public SizeNode(SizeNode prev) {

@Specialization
public int size() {
return Integer.SIZE / Byte.SIZE;
return Long.SIZE / Byte.SIZE;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. This
* Copyright (c) 2014, 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
@@ -29,14 +29,21 @@

public class ExceptionTranslatingNode extends RubyNode {

private final UnsupportedOperationBehavior unsupportedOperationBehavior;

@Child protected RubyNode child;

private final BranchProfile controlProfile = BranchProfile.create();
private final BranchProfile rethrowProfile = BranchProfile.create();

public ExceptionTranslatingNode(RubyContext context, SourceSection sourceSection, RubyNode child) {
this(context, sourceSection, child, UnsupportedOperationBehavior.TYPE_ERROR);
}

public ExceptionTranslatingNode(RubyContext context, SourceSection sourceSection, RubyNode child, UnsupportedOperationBehavior unsupportedOperationBehavior) {
super(context, sourceSection);
this.child = child;
this.unsupportedOperationBehavior = unsupportedOperationBehavior;
}

@Override
@@ -116,7 +123,14 @@ private RubyException translate(UnsupportedSpecializationException exception) {
}
}

return getContext().getCoreLibrary().typeError(builder.toString(), this);
switch (unsupportedOperationBehavior) {
case TYPE_ERROR:
return getContext().getCoreLibrary().typeError(builder.toString(), this);
case ARGUMENT_ERROR:
return getContext().getCoreLibrary().argumentError(builder.toString(), this);
default:
throw new UnsupportedOperationException();
}
}

public RubyException translate(Throwable throwable) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.methods;

public enum UnsupportedOperationBehavior {
TYPE_ERROR,
ARGUMENT_ERROR
}
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/fixnum/bit_or_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/fixnum/bit_xor_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/gt_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/gte_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/lt_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/lte_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/fixnum/minus_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/fixnum/multiply_tags.txt

This file was deleted.