Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Commit 13411dd

Browse files
committed
Use methodKey accessor to eliminate closures in signature calls.
1 parent cf5b23e commit 13411dd

3 files changed

Lines changed: 95 additions & 45 deletions

File tree

JSIL.Libraries/Sources/JSIL.Core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8081,6 +8081,10 @@ JSIL.InterfaceMethod = function (typeObject, methodName, methodInfo) {
80818081
return this.signature != null ? JSIL.$GetSignaturePrefixForType(typeObject) + this.methodNonQualifiedKey : this.qualifiedName;
80828082
});
80838083

8084+
JSIL.SetLazyValueProperty(this, "methodKeyNonVirtual", function () {
8085+
return "i$" + this.methodKey;
8086+
});
8087+
80848088
JSIL.SetLazyValueProperty(this, "methodNonQualifiedKey", function () {
80858089
return this.signature != null ? this.signature.GetNamedKey(this.methodName, true) : this.methodName;
80868090
});
@@ -8263,7 +8267,7 @@ JSIL.InterfaceMethod.prototype.$MakeCallMethod = function (isVirtual, isStatic)
82638267
? "CallVariantInterface"
82648268
: "CallInterface");
82658269

8266-
var methodKey = isStatic? this.methodNonQualifiedKey : (isVirtual ? this.methodKey : "i$" + this.methodKey);
8270+
var methodKey = isStatic ? this.methodNonQualifiedKey : (isVirtual ? this.methodKey : this.methodKeyNonVirtual);
82678271

82688272
return this.$MakeInlineCacheBody(callType, methodKey, this.fallbackMethod);
82698273
} else {

JSIL/JavascriptAstEmitter.cs

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,9 @@ public void VisitNode (JSConditionalStructCopyExpression sce) {
854854
Output.WriteRaw("JSIL.CloneParameter");
855855
Output.LPar();
856856
Output.Identifier(sce.Parameter, ReferenceContext, false);
857+
// IK TODO: pass to identifier if we need public interfece versus object
858+
Output.Dot();
859+
Output.WriteRaw("__Type__");
857860
Output.Comma();
858861
Visit(sce.Struct);
859862
Output.RPar();
@@ -1134,7 +1137,7 @@ public void VisitNode (JSDefaultValueLiteral defaultValue) {
11341137
Output.WriteRaw("null");
11351138
} else if (defaultValue.Value.IsGenericParameter) {
11361139
VisitNode(new JSTernaryOperatorExpression(
1137-
new JSMemberReferenceExpression(new JSDotExpression(new JSType(defaultValue.Value),
1140+
new JSMemberReferenceExpression(new JSDotExpression(new JSTypeOfExpression(defaultValue.Value),
11381141
new JSStringIdentifier("IsValueType"))),
11391142
JSIL.CreateInstanceOfType(defaultValue.Value),
11401143
JSLiteral.Null(defaultValue.Value),
@@ -1217,14 +1220,10 @@ public void VisitNode (JSCachedTypeOfExpression cachedTypeOf) {
12171220
public void VisitNode (JSTypeOfExpression toe) {
12181221
Output.Identifier(
12191222
toe.Type, ReferenceContext, IncludeTypeParens.Peek()
1220-
);
1223+
);
12211224

1222-
if (toe.Type is GenericParameter) {
1223-
// Generic parameters are type objects, not public interfaces
1224-
} else {
1225-
Output.Dot();
1226-
Output.Identifier("__Type__");
1227-
}
1225+
Output.Dot();
1226+
Output.Identifier("__Type__");
12281227
}
12291228

12301229
public void VisitNode(JSMethodOfExpression moe)
@@ -2338,26 +2337,53 @@ public void VisitNode (JSInvocationExpression invocation) {
23382337
};
23392338

23402339
if (isOverloaded) {
2341-
ReferenceContext.InvokingMethod = jsm.Reference;
2342-
SignatureCacher.WriteQualifiedSignatureToOutput(
2343-
Output, this, Stack.OfType<JSFunctionExpression>().FirstOrDefault(),
2344-
jsm,
2345-
ReferenceContext
2346-
);
2340+
if (!method.DeclaringType.IsInterface) {
2341+
if (isStatic) {
2342+
Visit(invocation.Type);
2343+
} else {
2344+
Visit(invocation.ThisReference, "ThisReference");
2345+
}
23472346

2348-
Output.Dot();
2349-
Output.WriteRaw(isStatic ? "CallStatic" : invocation.ExplicitThis ? "CallNonVirtual" : "Call");
2347+
Output.OpenBracket();
2348+
ReferenceContext.InvokingMethod = jsm.Reference;
2349+
SignatureCacher.WriteQualifiedSignatureToOutput(
2350+
Output, this, Stack.OfType<JSFunctionExpression>().FirstOrDefault(),
2351+
jsm,
2352+
ReferenceContext
2353+
);
2354+
Output.Dot();
2355+
Output.WriteRaw(isStatic ? "methodNonQualifiedKey" : (invocation.ExplicitThis ? "methodKeyNonVirtual" : "methodKey"));
2356+
Output.CloseBracket();
23502357

2351-
Output.LPar();
2352-
if (!isStatic) {
2353-
Visit(invocation.ThisReference, "ThisReference");
2354-
Output.Comma();
2355-
}
2358+
Output.LPar();
2359+
if (hasGenericArguments) {
2360+
Output.CommaSeparatedList(invocation.GenericArguments, ReferenceContext, ListValueType.TypeIdentifier);
23562361

2357-
genericArgs();
2362+
if (hasArguments)
2363+
Output.Comma();
2364+
}
2365+
} else {
2366+
ReferenceContext.InvokingMethod = jsm.Reference;
2367+
SignatureCacher.WriteQualifiedSignatureToOutput(
2368+
Output, this, Stack.OfType<JSFunctionExpression>().FirstOrDefault(),
2369+
jsm,
2370+
ReferenceContext
2371+
);
23582372

2359-
if (hasArguments)
2360-
Output.Comma();
2373+
Output.Dot();
2374+
Output.WriteRaw(isStatic ? "CallStatic" : invocation.ExplicitThis ? "CallNonVirtual" : "Call");
2375+
2376+
Output.LPar();
2377+
if (!isStatic) {
2378+
Visit(invocation.ThisReference, "ThisReference");
2379+
Output.Comma();
2380+
}
2381+
2382+
genericArgs();
2383+
2384+
if (hasArguments)
2385+
Output.Comma();
2386+
}
23612387
} else {
23622388
if (isStatic) {
23632389
if (!invocation.Type.IsNull) {

JSIL/JavascriptFormatter.cs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ public void CommaSeparatedList (IEnumerable<object> values, TypeReferenceContext
342342
else if (valueType == ListValueType.Identifier)
343343
Identifier(value as dynamic, context);
344344
else if (valueType == ListValueType.TypeIdentifier)
345-
TypeIdentifier(value as dynamic, context, false);
345+
TypeIdentifier(value as dynamic, context, false, false);
346346
else if (valueType == ListValueType.TypeReference)
347-
TypeReference((TypeReference)value, context);
347+
TypeReference((TypeReference) value, context);
348348
else
349349
WriteRaw(value.ToString());
350350
},
@@ -528,14 +528,14 @@ protected void TypeReferenceInternal (GenericParameter gp, TypeReferenceContext
528528
}
529529
return;
530530
} else {
531-
TypeIdentifier(resolved, context, false);
531+
TypeIdentifier(resolved, context, false, true);
532532
return;
533533
}
534534
}
535535
}
536536

537537
if (TypeUtil.TypesAreEqual(ownerType, context.EnclosingMethodType)) {
538-
TypeIdentifier(gp, context, false);
538+
TypeIdentifier(gp, context, false, true);
539539
return;
540540
}
541541

@@ -871,11 +871,11 @@ public void Identifier (TypeReference type, TypeReferenceContext context, bool i
871871
if (type.FullName == "JSIL.Proxy.AnyType")
872872
WriteRaw("JSIL.AnyType");
873873
else
874-
TypeIdentifier(type as dynamic, context, includeParens);
874+
TypeIdentifier(type as dynamic, context, includeParens, true);
875875
}
876876

877-
protected void TypeIdentifier (TypeInfo type, TypeReferenceContext context, bool includeParens) {
878-
TypeIdentifier(type.Definition as dynamic, context, includeParens);
877+
protected void TypeIdentifier (TypeInfo type, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
878+
TypeIdentifier(type.Definition as dynamic, context, includeParens, usePublicInterface);
879879
}
880880

881881
protected bool EmitThisForParameter (GenericParameter gp) {
@@ -891,7 +891,7 @@ protected bool EmitThisForParameter (GenericParameter gp) {
891891
return false;
892892
}
893893

894-
protected void TypeIdentifier (TypeReference type, TypeReferenceContext context, bool includeParens) {
894+
protected void TypeIdentifier (TypeReference type, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
895895
if (SignatureCacher.IsTypeArgument(type)) {
896896
WriteRaw(type.Name);
897897
return;
@@ -939,7 +939,14 @@ protected void TypeIdentifier (TypeReference type, TypeReferenceContext context,
939939

940940
Identifier(type.FullName);
941941
}
942-
} else {
942+
943+
if (usePublicInterface)
944+
{
945+
Dot();
946+
WriteRaw("__PublicInterface__");
947+
}
948+
}
949+
else {
943950
var info = TypeInfo.Get(type);
944951
if ((info != null) && (info.Replacement != null)) {
945952
WriteRaw(info.Replacement);
@@ -967,16 +974,21 @@ protected void TypeIdentifier (TypeReference type, TypeReferenceContext context,
967974
type.FullName, EscapingMode.TypeIdentifier
968975
));
969976
}
977+
978+
if (!usePublicInterface) {
979+
Dot();
980+
WriteRaw("__Type__");
981+
}
970982
}
971983
}
972984

973-
protected void TypeIdentifier (ByReferenceType type, TypeReferenceContext context, bool includeParens) {
985+
protected void TypeIdentifier (ByReferenceType type, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
974986
if (includeParens)
975987
LPar();
976988

977989
WriteRaw("JSIL.Reference.Of");
978990
LPar();
979-
TypeIdentifier(type.ElementType as dynamic, context, false);
991+
TypeIdentifier(type.ElementType as dynamic, context, false, true);
980992
RPar();
981993

982994
if (includeParens) {
@@ -985,13 +997,13 @@ protected void TypeIdentifier (ByReferenceType type, TypeReferenceContext contex
985997
}
986998
}
987999

988-
protected void TypeIdentifier (ArrayType type, TypeReferenceContext context, bool includeParens) {
1000+
protected void TypeIdentifier (ArrayType type, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
9891001
if (includeParens)
9901002
LPar();
9911003

9921004
WriteRaw("System.Array.Of");
9931005
LPar();
994-
TypeIdentifier(type.ElementType as dynamic, context, false);
1006+
TypeIdentifier(type.ElementType as dynamic, context, false, true);
9951007
if (!type.IsVector)
9961008
{
9971009
Comma();
@@ -1001,29 +1013,33 @@ protected void TypeIdentifier (ArrayType type, TypeReferenceContext context, boo
10011013
RPar();
10021014
}
10031015
RPar();
1016+
if (!usePublicInterface) {
1017+
Dot();
1018+
WriteRaw("__Type__");
1019+
}
10041020

10051021
if (includeParens) {
10061022
RPar();
10071023
Space();
10081024
}
10091025
}
10101026

1011-
protected void TypeIdentifier (OptionalModifierType modopt, TypeReferenceContext context, bool includeParens) {
1027+
protected void TypeIdentifier (OptionalModifierType modopt, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
10121028
Identifier(modopt.ElementType as dynamic, context, includeParens);
10131029
}
10141030

1015-
protected void TypeIdentifier (RequiredModifierType modreq, TypeReferenceContext context, bool includeParens) {
1031+
protected void TypeIdentifier (RequiredModifierType modreq, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
10161032
Identifier(modreq.ElementType as dynamic, context, includeParens);
10171033
}
10181034

1019-
protected void TypeIdentifier (PointerType ptr, TypeReferenceContext context, bool includeParens) {
1035+
protected void TypeIdentifier (PointerType ptr, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
10201036
WriteRaw("JSIL.Pointer.Of");
10211037
LPar();
10221038
Identifier(ptr.ElementType as dynamic, context, includeParens);
10231039
RPar();
10241040
}
10251041

1026-
protected void TypeIdentifier (GenericInstanceType type, TypeReferenceContext context, bool includeParens) {
1042+
protected void TypeIdentifier (GenericInstanceType type, TypeReferenceContext context, bool includeParens, bool usePublicInterface) {
10271043
if (includeParens)
10281044
LPar();
10291045

@@ -1034,6 +1050,10 @@ protected void TypeIdentifier (GenericInstanceType type, TypeReferenceContext co
10341050
LPar();
10351051
CommaSeparatedList(type.GenericArguments, context, ListValueType.TypeIdentifier);
10361052
RPar();
1053+
if (!usePublicInterface) {
1054+
Dot();
1055+
WriteRaw("__Type__");
1056+
}
10371057

10381058
if (includeParens) {
10391059
RPar();
@@ -1330,7 +1350,7 @@ public void Signature (MethodReference method, MethodSignature signature, TypeRe
13301350
: signature.ReturnType;
13311351

13321352
if ((alwaysUseIdentifiers || context.EnclosingMethod != null) && !TypeUtil.IsOpenType(returnType, gp => !SignatureCacher.IsTypeArgument(gp)))
1333-
TypeIdentifier(returnType as dynamic, context, false);
1353+
TypeIdentifier(returnType as dynamic, context, false, true);
13341354
else
13351355
TypeReference(returnType, context);
13361356

@@ -1340,7 +1360,7 @@ public void Signature (MethodReference method, MethodSignature signature, TypeRe
13401360
WriteRaw("null");
13411361
else {
13421362
if ((alwaysUseIdentifiers || context.EnclosingMethod != null) && !TypeUtil.IsOpenType(signature.ReturnType, gp => !SignatureCacher.IsTypeArgument(gp)))
1343-
TypeIdentifier(signature.ReturnType as dynamic, context, false);
1363+
TypeIdentifier(signature.ReturnType as dynamic, context, false, true);
13441364
else
13451365
TypeReference(signature.ReturnType, context);
13461366
}
@@ -1353,7 +1373,7 @@ public void Signature (MethodReference method, MethodSignature signature, TypeRe
13531373
CommaSeparatedListCore(
13541374
signature.ParameterTypes, (pt) => {
13551375
if ((alwaysUseIdentifiers || context.EnclosingMethod != null) && !TypeUtil.IsOpenType(pt, gp => !SignatureCacher.IsTypeArgument(gp)))
1356-
TypeIdentifier(pt as dynamic, context, false);
1376+
TypeIdentifier(pt as dynamic, context, false, true);
13571377
else
13581378
TypeReference(pt, context);
13591379
}

0 commit comments

Comments
 (0)