Skip to content

Commit

Permalink
[cfe] Make (Abstract)Super*.interfaceTarget non-nullable
Browse files Browse the repository at this point in the history
This is a step towards improving the semantics of these nodes.

TEST=existing

Change-Id: I95bdb86790414b38af73e9e932cc228b3c0f1f6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249040
Commit-Queue: Johnni Winther <[email protected]>
Reviewed-by: Alexander Markov <[email protected]>
Reviewed-by: Jens Johansen <[email protected]>
Reviewed-by: Joshua Litt <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Bot committed Jun 23, 2022
1 parent 3c79377 commit 391540c
Show file tree
Hide file tree
Showing 36 changed files with 637 additions and 434 deletions.
43 changes: 15 additions & 28 deletions pkg/compiler/lib/src/ir/static_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1085,22 +1085,14 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
ir.DartType visitSuperPropertyGet(ir.SuperPropertyGet node) {
ir.DartType resultType;
final interfaceTarget = node.interfaceTarget;
if (interfaceTarget == null) {
// TODO(johnniwinther): Resolve and set the target here.
resultType = const ir.DynamicType();
ir.Class declaringClass = interfaceTarget.enclosingClass!;
if (declaringClass.typeParameters.isEmpty) {
resultType = interfaceTarget.superGetterType;
} else {
ir.Class declaringClass = interfaceTarget.enclosingClass!;
if (declaringClass.typeParameters.isEmpty) {
resultType = interfaceTarget.superGetterType;
} else {
ir.InterfaceType receiver = typeEnvironment.getTypeAsInstanceOf(
thisType,
declaringClass,
currentLibrary,
typeEnvironment.coreTypes)!;
resultType = ir.Substitution.fromInterfaceType(receiver)
.substituteType(interfaceTarget.superGetterType);
}
ir.InterfaceType receiver = typeEnvironment.getTypeAsInstanceOf(
thisType, declaringClass, currentLibrary, typeEnvironment.coreTypes)!;
resultType = ir.Substitution.fromInterfaceType(receiver)
.substituteType(interfaceTarget.superGetterType);
}
_staticTypeCache._expressionTypes[node] = resultType;
handleSuperPropertyGet(node, resultType);
Expand All @@ -1125,19 +1117,14 @@ abstract class StaticTypeVisitor extends StaticTypeBase {
ArgumentTypes argumentTypes = _visitArguments(node.arguments);
ir.DartType returnType;
final interfaceTarget = node.interfaceTarget;
if (interfaceTarget == null) {
// TODO(johnniwinther): Resolve and set the target here.
returnType = const ir.DynamicType();
} else {
ir.Class superclass = interfaceTarget.enclosingClass!;
ir.InterfaceType receiverType = typeEnvironment.getTypeAsInstanceOf(
thisType, superclass, currentLibrary, typeEnvironment.coreTypes)!;
returnType = ir.Substitution.fromInterfaceType(receiverType)
.substituteType(interfaceTarget.function.returnType);
returnType = ir.Substitution.fromPairs(
interfaceTarget.function.typeParameters, node.arguments.types)
.substituteType(returnType);
}
ir.Class superclass = interfaceTarget.enclosingClass!;
ir.InterfaceType receiverType = typeEnvironment.getTypeAsInstanceOf(
thisType, superclass, currentLibrary, typeEnvironment.coreTypes)!;
returnType = ir.Substitution.fromInterfaceType(receiverType)
.substituteType(interfaceTarget.function.returnType);
returnType = ir.Substitution.fromPairs(
interfaceTarget.function.typeParameters, node.arguments.types)
.substituteType(returnType);
_staticTypeCache._expressionTypes[node] = returnType;
handleSuperMethodInvocation(node, argumentTypes, returnType);
return returnType;
Expand Down
5 changes: 5 additions & 0 deletions pkg/compiler/lib/src/ir/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ ir.Member? getEffectiveSuperTarget(ir.Member? target) {
if (target.stubKind == ir.ProcedureStubKind.ConcreteMixinStub) {
return getEffectiveSuperTarget(target.stubTarget);
}
// TODO(johnniwinther): Remove this when the CFE reports an error on
// missing concrete super targets.
if (target.isAbstract) {
return null;
}
}
return target;
}
6 changes: 3 additions & 3 deletions pkg/dart2wasm/lib/code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
w.ValueType visitSuperMethodInvocation(
SuperMethodInvocation node, w.ValueType expectedType) {
Reference target =
_lookupSuperTarget(node.interfaceTarget!, setter: false).reference;
_lookupSuperTarget(node.interfaceTarget, setter: false).reference;
w.BaseFunction targetFunction = translator.functions.getFunction(target);
w.ValueType receiverType = targetFunction.type.inputs.first;
w.ValueType thisType = visitThis(receiverType);
Expand Down Expand Up @@ -1515,7 +1515,7 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
@override
w.ValueType visitSuperPropertyGet(
SuperPropertyGet node, w.ValueType expectedType) {
Member target = _lookupSuperTarget(node.interfaceTarget!, setter: false);
Member target = _lookupSuperTarget(node.interfaceTarget, setter: false);
if (target is Procedure && !target.isGetter) {
throw "Not supported: Super tear-off at ${node.location}";
}
Expand All @@ -1525,7 +1525,7 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
@override
w.ValueType visitSuperPropertySet(
SuperPropertySet node, w.ValueType expectedType) {
Member target = _lookupSuperTarget(node.interfaceTarget!, setter: true);
Member target = _lookupSuperTarget(node.interfaceTarget, setter: true);
return _directSet(target, ThisExpression(), node.value,
preserved: expectedType != voidMarker);
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/dev_compiler/lib/src/kernel/compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4790,12 +4790,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
@override
js_ast.Expression visitAbstractSuperPropertyGet(
AbstractSuperPropertyGet node) {
return _emitSuperPropertyGet(node.interfaceTarget!);
return _emitSuperPropertyGet(node.interfaceTarget);
}

@override
js_ast.Expression visitSuperPropertyGet(SuperPropertyGet node) {
return _emitSuperPropertyGet(node.interfaceTarget!);
return _emitSuperPropertyGet(node.interfaceTarget);
}

js_ast.Expression _emitSuperPropertyGet(Member target) {
Expand All @@ -4813,12 +4813,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
@override
js_ast.Expression visitAbstractSuperPropertySet(
AbstractSuperPropertySet node) {
return _emitSuperPropertySet(node.interfaceTarget!, node.value);
return _emitSuperPropertySet(node.interfaceTarget, node.value);
}

@override
js_ast.Expression visitSuperPropertySet(SuperPropertySet node) {
return _emitSuperPropertySet(node.interfaceTarget!, node.value);
return _emitSuperPropertySet(node.interfaceTarget, node.value);
}

js_ast.Expression _emitSuperPropertySet(Member target, Expression value) {
Expand Down Expand Up @@ -5432,12 +5432,12 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
@override
js_ast.Expression visitAbstractSuperMethodInvocation(
AbstractSuperMethodInvocation node) {
return _emitSuperMethodInvocation(node.interfaceTarget!, node.arguments);
return _emitSuperMethodInvocation(node.interfaceTarget, node.arguments);
}

@override
js_ast.Expression visitSuperMethodInvocation(SuperMethodInvocation node) {
return _emitSuperMethodInvocation(node.interfaceTarget!, node.arguments);
return _emitSuperMethodInvocation(node.interfaceTarget, node.arguments);
}

js_ast.Expression _emitSuperMethodInvocation(
Expand Down
77 changes: 45 additions & 32 deletions pkg/front_end/lib/src/fasta/kernel/expression_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,13 @@ class SuperPropertyAccessGenerator extends Generator {
}

Expression _createRead() {
Member? getter = this.getter;
if (getter == null) {
return _helper.buildUnresolvedError(name.text, fileOffset,
isSuper: true, kind: UnresolvedKind.Getter);
} else {
return new SuperPropertyGet(name, getter)..fileOffset = fileOffset;
}
return new SuperPropertyGet(name, getter)..fileOffset = fileOffset;
}

@override
Expand All @@ -849,13 +851,13 @@ class SuperPropertyAccessGenerator extends Generator {
}

Expression _createWrite(int offset, Expression value) {
Member? setter = this.setter;
if (setter == null) {
return _helper.buildUnresolvedError(name.text, fileOffset,
rhs: value, isSuper: true, kind: UnresolvedKind.Setter);
} else {
return new SuperPropertySet(name, value, setter)..fileOffset = offset;
}
SuperPropertySet write = new SuperPropertySet(name, value, setter)
..fileOffset = offset;
return write;
}

@override
Expand Down Expand Up @@ -1227,40 +1229,44 @@ class SuperIndexedAccessGenerator extends Generator {

@override
Expression buildSimpleRead() {
Procedure? getter = this.getter;
if (getter == null) {
return _helper.buildUnresolvedError(indexGetName.text, fileOffset,
isSuper: true,
arguments:
_helper.forest.createArguments(fileOffset, <Expression>[index]),
kind: UnresolvedKind.Method,
length: noLength);
} else {
return _helper.forest.createSuperMethodInvocation(
fileOffset,
indexGetName,
getter,
_helper.forest.createArguments(fileOffset, <Expression>[index]));
}
return _helper.forest.createSuperMethodInvocation(
fileOffset,
indexGetName,
getter,
_helper.forest.createArguments(fileOffset, <Expression>[index]));
}

@override
Expression buildAssignment(Expression value, {bool voidContext: false}) {
if (voidContext) {
if (setter == null) {
return _helper.buildUnresolvedError(indexSetName.text, fileOffset,
isSuper: true,
arguments: _helper.forest
.createArguments(fileOffset, <Expression>[index, value]),
kind: UnresolvedKind.Method,
length: noLength);
}
return _helper.forest.createSuperMethodInvocation(
fileOffset,
indexSetName,
setter,
_helper.forest
.createArguments(fileOffset, <Expression>[index, value]));
Procedure? setter = this.setter;
if (setter == null) {
return _helper.buildUnresolvedError(indexSetName.text, fileOffset,
isSuper: true,
arguments: _helper.forest
.createArguments(fileOffset, <Expression>[index, value]),
kind: UnresolvedKind.Method,
length: noLength);
} else {
return new SuperIndexSet(setter, index, value)..fileOffset = fileOffset;
if (voidContext) {
return _helper.forest.createSuperMethodInvocation(
fileOffset,
indexSetName,
setter,
_helper.forest
.createArguments(fileOffset, <Expression>[index, value]));
} else {
return new SuperIndexSet(setter, index, value)..fileOffset = fileOffset;
}
}
}

Expand All @@ -1281,13 +1287,20 @@ class SuperIndexedAccessGenerator extends Generator {
bool voidContext: false,
bool isPreIncDec: false,
bool isPostIncDec: false}) {
return new CompoundSuperIndexSet(
getter, setter, index, binaryOperator, value,
readOffset: fileOffset,
binaryOffset: offset,
writeOffset: fileOffset,
forEffect: voidContext,
forPostIncDec: isPostIncDec);
Procedure? getter = this.getter;
Procedure? setter = this.setter;
if (getter == null || setter == null) {
return buildAssignment(
buildBinaryOperation(token, binaryOperator, value));
} else {
return new CompoundSuperIndexSet(
getter, setter, index, binaryOperator, value,
readOffset: fileOffset,
binaryOffset: offset,
writeOffset: fileOffset,
forEffect: voidContext,
forPostIncDec: isPostIncDec);
}
}

@override
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/kernel/forest.dart
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ class Forest {
}

SuperMethodInvocation createSuperMethodInvocation(
int fileOffset, Name name, Procedure? procedure, Arguments arguments) {
int fileOffset, Name name, Procedure procedure, Arguments arguments) {
// ignore: unnecessary_null_comparison
assert(fileOffset != null);
return new SuperMethodInvocation(name, arguments, procedure)
Expand Down
6 changes: 3 additions & 3 deletions pkg/front_end/lib/src/fasta/kernel/internal_ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2682,7 +2682,7 @@ class IndexSet extends InternalExpression {
///
class SuperIndexSet extends InternalExpression {
/// The []= member.
Member? setter;
Member setter;

/// The index expression of the operation.
Expression index;
Expand Down Expand Up @@ -3707,10 +3707,10 @@ class NullAwareIfNullSet extends InternalExpression {
///
class CompoundSuperIndexSet extends InternalExpression {
/// The [] member.
Member? getter;
Member getter;

/// The []= member.
Member? setter;
Member setter;

/// The index expression of the operation.
Expression index;
Expand Down
Loading

0 comments on commit 391540c

Please sign in to comment.