Skip to content

Commit

Permalink
Move getResidualType* to Signature
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer committed Oct 12, 2024
1 parent 8f84cab commit a356d5d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
21 changes: 0 additions & 21 deletions aeneas/src/core/Operator.v3
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,13 @@ class Operator(opcode: Opcode, typeArgs: Array<Type>, sig: Signature) {
def isPolymorphic() -> bool {
return checkOpenness() == Open.OPEN;
}
// get the type of this operator when the given parameter indices are bound
def getResidualType(indexMap: Array<int>) -> Type {
if (indexMap.length == 0) return sig.funcType();
return Function.newType(getResidualParamType(indexMap), sig.returnType());
}
// get the list of residual types
def getResidualParamTypeList(indexMap: Array<int>) -> List<Type> {
if (indexMap.length == 0) return null;
var rl: List<Type>;
var p = sig.paramTypes, iv = indexMap.length - 1;
for (i = p.length - 1; i >= 0; i--) {
var pt = p[i];
if (iv < 0 || i != indexMap[iv]) rl = List.new(pt, rl);
else iv--;
}
return rl;
}
def subst(f: Type -> Type) -> Operator {
if (openness == Open.CLOSED) return this;
if (checkOpenness() == Open.OPEN) {
return Operator.new(opcode, Arrays.map(typeArgs, f), sig.subst(f));
}
return this;
}

def getResidualParamType(indexMap: Array<int>) -> Type {
return Tuple.TYPECON.create(getResidualParamTypeList(indexMap));
}
def equals(that: Operator) -> bool {
if (this == that) return true;
return this.opcode == that.opcode && Arrays.equal(this.typeArgs, that.typeArgs);
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/ir/IrOpMethodBuilder.v3
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class IrOpMethodBuilder(prog: Program) {
def createClosureMethod(context: SsaContext, ic: IrClass, op: Operator, abstracter: TypeParamAbstracter, indexMap: Array<int>) -> IrMethod {
// create parameters and method
op = op.subst(abstracter.substitute);
var paramTypes = Lists.toArray(op.getResidualParamTypeList(indexMap));
var paramTypes = Lists.toArray(op.sig.getResidualParamTypeList(indexMap));
var meth = createIrMethod(ic.ctype, abstracter.getDefaultTypeArgs(), Function.siga(paramTypes, op.sig.returnType()));
meth.facts |= Fact.M_INLINE;
context.enterMethod(meth);
Expand Down
2 changes: 1 addition & 1 deletion aeneas/src/main/Version.v3
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

// Updated by VCS scripts. DO NOT EDIT.
component Version {
def version: string = "III-7.1764";
def version: string = "III-7.1765";
var buildData: string;
}
20 changes: 20 additions & 0 deletions aeneas/src/types/Function.v3
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,24 @@ class Signature {
_ => return Function.getReturnType(funcType());
}
}
// Get the type of this signature when the given parameter indices are bound
def getResidualType(indexMap: Array<int>) -> Type {
if (indexMap.length == 0) return funcType();
return Function.newType(getResidualParamType(indexMap), returnType());
}
// get the list of residual types
def getResidualParamTypeList(indexMap: Array<int>) -> List<Type> {
if (indexMap.length == 0) return null;
var rl: List<Type>;
var p = paramTypes, iv = indexMap.length - 1;
for (i = p.length - 1; i >= 0; i--) {
var pt = p[i];
if (iv < 0 || i != indexMap[iv]) rl = List.new(pt, rl);
else iv--;
}
return rl;
}
def getResidualParamType(indexMap: Array<int>) -> Type {
return Tuple.TYPECON.create(getResidualParamTypeList(indexMap));
}
}
2 changes: 1 addition & 1 deletion aeneas/src/vst/MethodEnv.v3
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class MethodEnv {
if (op == null) return VarBinding.None;
var typeArgs = makeTypeArgs("member", expr, typeParams);
if (typeArgs != null) op = op.subst(typeArgs.substitute);
var resultType = op.getResidualType(INDEX_00);
var resultType = op.sig.getResidualType(INDEX_00);
return expr.bind(expr.expr, VarBinding.Partial(op, N), resultType);
}
def lookupEnumSetTypeMember(expr: VarExpr, etype: Type) -> VarBinding {
Expand Down

0 comments on commit a356d5d

Please sign in to comment.