canHaveSideEffect rename

This commit is contained in:
Michael Bogdanov
2014-11-19 17:04:08 +03:00
parent d685921271
commit fad64faabb
2 changed files with 34 additions and 25 deletions
@@ -64,15 +64,15 @@ public abstract class StackValue {
@NotNull @NotNull
public final Type type; public final Type type;
private final boolean hasSideEffects; private final boolean canHaveSideEffects;
protected StackValue(@NotNull Type type) { protected StackValue(@NotNull Type type) {
this(type, true); this(type, true);
} }
protected StackValue(@NotNull Type type, boolean hasSideEffects) { protected StackValue(@NotNull Type type, boolean canHaveSideEffects) {
this.type = type; this.type = type;
this.hasSideEffects = hasSideEffects; this.canHaveSideEffects = canHaveSideEffects;
} }
/** /**
@@ -120,8 +120,8 @@ public abstract class StackValue {
store(value, v, false); store(value, v, false);
} }
public boolean hasSideEffects() { public boolean canHaveSideEffects() {
return hasSideEffects; return canHaveSideEffects;
} }
public void store(@NotNull StackValue value, @NotNull InstructionAdapter v, boolean skipReceiver) { public void store(@NotNull StackValue value, @NotNull InstructionAdapter v, boolean skipReceiver) {
@@ -439,29 +439,37 @@ public abstract class StackValue {
) { ) {
if (resolvedCall.getDispatchReceiver().exists() || resolvedCall.getExtensionReceiver().exists() || isLocalFunCall(callableMethod)) { if (resolvedCall.getDispatchReceiver().exists() || resolvedCall.getExtensionReceiver().exists() || isLocalFunCall(callableMethod)) {
boolean hasExtensionReceiver = resolvedCall.getExtensionReceiver().exists(); boolean hasExtensionReceiver = resolvedCall.getExtensionReceiver().exists();
StackValue extensionReceiver = genReceiver(receiver, codegen, resolvedCall, callableMethod, true);
StackValue dispatchReceiver = platformStaticCallIfPresent( StackValue dispatchReceiver = platformStaticCallIfPresent(
genReceiver(hasExtensionReceiver ? none() : receiver, codegen, resolvedCall, callableMethod, false), genReceiver(hasExtensionReceiver ? none() : receiver, codegen, resolvedCall, callableMethod, false),
resolvedCall.getResultingDescriptor() resolvedCall.getResultingDescriptor()
); );
StackValue extensionReceiver = genReceiver(receiver, codegen, resolvedCall, callableMethod, true);
return new CallReceiver(dispatchReceiver, extensionReceiver, return new CallReceiver(dispatchReceiver, extensionReceiver,
CallReceiver.calcType(resolvedCall, codegen.typeMapper, callableMethod)); CallReceiver.calcType(resolvedCall, codegen.typeMapper, callableMethod));
} }
return receiver; return receiver;
} }
private static StackValue genReceiver(@NotNull StackValue receiver, @NotNull ExpressionCodegen codegen, ResolvedCall resolvedCall, @Nullable CallableMethod callableMethod, boolean isExtension) { private static StackValue genReceiver(
@NotNull StackValue receiver,
@NotNull ExpressionCodegen codegen,
@NotNull ResolvedCall resolvedCall,
@Nullable CallableMethod callableMethod,
boolean isExtension
) {
ReceiverValue receiverValue = isExtension ? resolvedCall.getExtensionReceiver() : resolvedCall.getDispatchReceiver(); ReceiverValue receiverValue = isExtension ? resolvedCall.getExtensionReceiver() : resolvedCall.getDispatchReceiver();
if (receiver == none()) { if (receiver == none()) {
if (receiverValue.exists()) { if (receiverValue.exists()) {
return codegen.generateReceiverValue(receiverValue); return codegen.generateReceiverValue(receiverValue);
} else if (isLocalFunCall(callableMethod) && !isExtension) { }
else if (isLocalFunCall(callableMethod) && !isExtension) {
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor(); CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
StackValue value = codegen.findLocalOrCapturedValue(descriptor.getOriginal()); StackValue value = codegen.findLocalOrCapturedValue(descriptor.getOriginal());
assert value != null : "Local fun should be found in locals or in captured params: " + resolvedCall; assert value != null : "Local fun should be found in locals or in captured params: " + resolvedCall;
return value; return value;
} }
} else if (receiverValue.exists()) { }
else if (receiverValue.exists()) {
return receiver; return receiver;
} }
return none(); return none();
@@ -469,11 +477,11 @@ public abstract class StackValue {
private static StackValue platformStaticCallIfPresent(@NotNull StackValue resultReceiver, @NotNull CallableDescriptor descriptor) { private static StackValue platformStaticCallIfPresent(@NotNull StackValue resultReceiver, @NotNull CallableDescriptor descriptor) {
if (AnnotationsPackage.isPlatformStaticInObject(descriptor)) { if (AnnotationsPackage.isPlatformStaticInObject(descriptor)) {
//dispatch receiver if (resultReceiver.canHaveSideEffects()) {
if (resultReceiver.hasSideEffects()) { return coercion(resultReceiver, Type.VOID_TYPE);
resultReceiver = coercion(resultReceiver, Type.VOID_TYPE); }
} else { else {
resultReceiver = none(); return none();
} }
} }
return resultReceiver; return resultReceiver;
@@ -1073,7 +1081,7 @@ public abstract class StackValue {
public final String name; public final String name;
public Field(Type type, Type owner, String name, boolean isStatic, StackValue receiver) { public Field(Type type, Type owner, String name, boolean isStatic, StackValue receiver) {
super(type, isStatic, isStatic, receiver, receiver.hasSideEffects()); super(type, isStatic, isStatic, receiver, receiver.canHaveSideEffects());
this.owner = owner; this.owner = owner;
this.name = name; this.name = name;
} }
@@ -1251,7 +1259,7 @@ public abstract class StackValue {
final String name; final String name;
public FieldForSharedVar(Type type, Type owner, String name, StackValue.Field receiver) { public FieldForSharedVar(Type type, Type owner, String name, StackValue.Field receiver) {
super(type, false, false, receiver, false); super(type, false, false, receiver, receiver.canHaveSideEffects());
this.owner = owner; this.owner = owner;
this.name = name; this.name = name;
} }
@@ -1383,7 +1391,7 @@ public abstract class StackValue {
@NotNull StackValue extensionReceiver, @NotNull StackValue extensionReceiver,
@NotNull Type type @NotNull Type type
) { ) {
super(type, dispatchReceiver.hasSideEffects() || extensionReceiver.hasSideEffects()); super(type, dispatchReceiver.canHaveSideEffects() || extensionReceiver.canHaveSideEffects());
this.dispatchReceiver = dispatchReceiver; this.dispatchReceiver = dispatchReceiver;
this.extensionReceiver = extensionReceiver; this.extensionReceiver = extensionReceiver;
} }
@@ -1404,7 +1412,8 @@ public abstract class StackValue {
else if (dispatchReceiver != null) { else if (dispatchReceiver != null) {
if (AnnotationsPackage.isPlatformStaticInObject(descriptor)) { if (AnnotationsPackage.isPlatformStaticInObject(descriptor)) {
return Type.VOID_TYPE; return Type.VOID_TYPE;
} else { }
else {
return callableMethod != null ? callableMethod.getThisType() : typeMapper.mapType(dispatchReceiver.getType()); return callableMethod != null ? callableMethod.getThisType() : typeMapper.mapType(dispatchReceiver.getType());
} }
} }
@@ -1445,9 +1454,9 @@ public abstract class StackValue {
boolean isStaticPut, boolean isStaticPut,
boolean isStaticStore, boolean isStaticStore,
@NotNull StackValue receiver, @NotNull StackValue receiver,
boolean hasSideEffects boolean canHaveSideEffects
) { ) {
super(type, hasSideEffects); super(type, canHaveSideEffects);
this.receiver = receiver; this.receiver = receiver;
this.isStaticPut = isStaticPut; this.isStaticPut = isStaticPut;
this.isStaticStore = isStaticStore; this.isStaticStore = isStaticStore;
@@ -1465,7 +1474,7 @@ public abstract class StackValue {
@Override @Override
public void putReceiver(@NotNull InstructionAdapter v, boolean isRead) { public void putReceiver(@NotNull InstructionAdapter v, boolean isRead) {
boolean hasReceiver = isNonStaticAccess(isRead); boolean hasReceiver = isNonStaticAccess(isRead);
if (hasReceiver || receiver.hasSideEffects()) { if (hasReceiver || receiver.canHaveSideEffects()) {
receiver.put(hasReceiver ? receiver.type : Type.VOID_TYPE, v); receiver.put(hasReceiver ? receiver.type : Type.VOID_TYPE, v);
} }
} }
@@ -1533,7 +1542,7 @@ public abstract class StackValue {
private final boolean[] isReadOperations; private final boolean[] isReadOperations;
public ComplexReceiver(StackValueWithSimpleReceiver value, boolean[] isReadOperations) { public ComplexReceiver(StackValueWithSimpleReceiver value, boolean[] isReadOperations) {
super(value.type, value.receiver.hasSideEffects()); super(value.type, value.receiver.canHaveSideEffects());
this.originalValueWithReceiver = value; this.originalValueWithReceiver = value;
this.isReadOperations = isReadOperations; this.isReadOperations = isReadOperations;
} }
@@ -1556,7 +1565,7 @@ public abstract class StackValue {
} }
} }
if (!wasPut && receiver.hasSideEffects()) { if (!wasPut && receiver.canHaveSideEffects()) {
receiver.put(Type.VOID_TYPE, v); receiver.put(Type.VOID_TYPE, v);
} }
} }
@@ -1590,7 +1599,7 @@ public abstract class StackValue {
@NotNull StackValueWithSimpleReceiver originalValue, @NotNull StackValueWithSimpleReceiver originalValue,
@NotNull ComplexReceiver receiver @NotNull ComplexReceiver receiver
) { ) {
super(type, bothReceiverStatic(originalValue), bothReceiverStatic(originalValue), receiver, originalValue.hasSideEffects()); super(type, bothReceiverStatic(originalValue), bothReceiverStatic(originalValue), receiver, originalValue.canHaveSideEffects());
this.originalValue = originalValue; this.originalValue = originalValue;
} }
@@ -24,7 +24,7 @@ import org.jetbrains.jet.codegen.StackValue.StackValueWithSimpleReceiver
class CoercionValue( class CoercionValue(
val value: StackValue, val value: StackValue,
val castType: Type val castType: Type
) : StackValue(castType, value.hasSideEffects()) { ) : StackValue(castType, value.canHaveSideEffects()) {
override fun putSelector(type: Type, v: InstructionAdapter) { override fun putSelector(type: Type, v: InstructionAdapter) {
value.putSelector(castType, v) value.putSelector(castType, v)