@@ -162,7 +162,8 @@ import {
162
162
writeI32 ,
163
163
writeI64 ,
164
164
writeF32 ,
165
- writeF64
165
+ writeF64 ,
166
+ makeMap
166
167
} from "./util" ;
167
168
168
169
/** Compilation target. */
@@ -619,7 +620,7 @@ export class Compiler extends DiagnosticEmitter {
619
620
( noTreeShaking || ( isEntry && statement . is ( CommonFlags . EXPORT ) ) ) &&
620
621
! ( < ClassDeclaration > statement ) . isGeneric
621
622
) {
622
- this . compileClassDeclaration ( < ClassDeclaration > statement , [ ] , null ) ;
623
+ this . compileClassDeclaration ( < ClassDeclaration > statement , [ ] ) ;
623
624
}
624
625
break ;
625
626
}
@@ -958,16 +959,15 @@ export class Compiler extends DiagnosticEmitter {
958
959
/** Compiles a top-level function given its declaration. */
959
960
compileFunctionDeclaration (
960
961
declaration : FunctionDeclaration ,
961
- typeArguments : TypeNode [ ] ,
962
- contextualTypeArguments : Map < string , Type > | null = null
962
+ typeArguments : TypeNode [ ]
963
963
) : Function | null {
964
964
var element = assert ( this . program . elementsLookup . get ( declaration . fileLevelInternalName ) ) ;
965
965
assert ( element . kind == ElementKind . FUNCTION_PROTOTYPE ) ;
966
966
return this . compileFunctionUsingTypeArguments ( // reports
967
967
< FunctionPrototype > element ,
968
968
typeArguments ,
969
- contextualTypeArguments ,
970
- null , // no outer scope (is top level)
969
+ makeMap < string , Type > ( ) ,
970
+ null ,
971
971
( < FunctionPrototype > element ) . declaration . name
972
972
) ;
973
973
}
@@ -976,7 +976,7 @@ export class Compiler extends DiagnosticEmitter {
976
976
compileFunctionUsingTypeArguments (
977
977
prototype : FunctionPrototype ,
978
978
typeArguments : TypeNode [ ] ,
979
- contextualTypeArguments : Map < string , Type > | null ,
979
+ contextualTypeArguments : Map < string , Type > ,
980
980
outerScope : Flow | null ,
981
981
reportNode : Node
982
982
) : Function | null {
@@ -1234,7 +1234,11 @@ export class Compiler extends DiagnosticEmitter {
1234
1234
( < ClassPrototype > element ) . is ( CommonFlags . EXPORT )
1235
1235
) && ! ( < ClassPrototype > element ) . is ( CommonFlags . GENERIC )
1236
1236
) {
1237
- this . compileClassUsingTypeArguments ( < ClassPrototype > element , [ ] ) ;
1237
+ this . compileClassUsingTypeArguments (
1238
+ < ClassPrototype > element ,
1239
+ [ ] ,
1240
+ makeMap < string , Type > ( )
1241
+ ) ;
1238
1242
}
1239
1243
break ;
1240
1244
}
@@ -1252,8 +1256,8 @@ export class Compiler extends DiagnosticEmitter {
1252
1256
this . compileFunctionUsingTypeArguments (
1253
1257
< FunctionPrototype > element ,
1254
1258
[ ] ,
1255
- null , // no contextual type arguments
1256
- null , // no outer scope
1259
+ makeMap < string , Type > ( ) ,
1260
+ null ,
1257
1261
( < FunctionPrototype > element ) . declaration . name
1258
1262
) ;
1259
1263
}
@@ -1286,7 +1290,11 @@ export class Compiler extends DiagnosticEmitter {
1286
1290
switch ( element . kind ) {
1287
1291
case ElementKind . CLASS_PROTOTYPE : {
1288
1292
if ( ! ( < ClassPrototype > element ) . is ( CommonFlags . GENERIC ) ) {
1289
- this . compileClassUsingTypeArguments ( < ClassPrototype > element , [ ] ) ;
1293
+ this . compileClassUsingTypeArguments (
1294
+ < ClassPrototype > element ,
1295
+ [ ] ,
1296
+ makeMap < string , Type > ( )
1297
+ ) ;
1290
1298
}
1291
1299
break ;
1292
1300
}
@@ -1302,8 +1310,8 @@ export class Compiler extends DiagnosticEmitter {
1302
1310
this . compileFunctionUsingTypeArguments (
1303
1311
< FunctionPrototype > element ,
1304
1312
[ ] ,
1305
- null , // no contextual type arguments
1306
- null , // no outer scope
1313
+ makeMap < string , Type > ( ) ,
1314
+ null ,
1307
1315
( < FunctionPrototype > element ) . declaration . name
1308
1316
) ;
1309
1317
}
@@ -1325,23 +1333,22 @@ export class Compiler extends DiagnosticEmitter {
1325
1333
1326
1334
compileClassDeclaration (
1327
1335
declaration : ClassDeclaration ,
1328
- typeArguments : TypeNode [ ] ,
1329
- contextualTypeArguments : Map < string , Type > | null = null
1336
+ typeArguments : TypeNode [ ]
1330
1337
) : void {
1331
1338
var element = assert ( this . program . elementsLookup . get ( declaration . fileLevelInternalName ) ) ;
1332
1339
assert ( element . kind == ElementKind . CLASS_PROTOTYPE ) ;
1333
1340
this . compileClassUsingTypeArguments (
1334
1341
< ClassPrototype > element ,
1335
1342
typeArguments ,
1336
- contextualTypeArguments ,
1343
+ makeMap < string , Type > ( ) ,
1337
1344
declaration
1338
1345
) ;
1339
1346
}
1340
1347
1341
1348
compileClassUsingTypeArguments (
1342
1349
prototype : ClassPrototype ,
1343
1350
typeArguments : TypeNode [ ] ,
1344
- contextualTypeArguments : Map < string , Type > | null = null ,
1351
+ contextualTypeArguments : Map < string , Type > ,
1345
1352
alternativeReportNode : Node | null = null
1346
1353
) : void {
1347
1354
var instance = this . resolver . resolveClassInclTypeArguments (
@@ -1372,7 +1379,9 @@ export class Compiler extends DiagnosticEmitter {
1372
1379
) {
1373
1380
this . compileFunctionUsingTypeArguments (
1374
1381
< FunctionPrototype > element ,
1375
- [ ] , null , null ,
1382
+ [ ] ,
1383
+ makeMap < string , Type > ( ) ,
1384
+ null ,
1376
1385
( < FunctionPrototype > element ) . declaration . name
1377
1386
) ;
1378
1387
}
@@ -1383,15 +1392,19 @@ export class Compiler extends DiagnosticEmitter {
1383
1392
if ( getter ) {
1384
1393
this . compileFunctionUsingTypeArguments (
1385
1394
getter ,
1386
- [ ] , null , null ,
1395
+ [ ] ,
1396
+ makeMap < string , Type > ( ) ,
1397
+ null ,
1387
1398
getter . declaration . name
1388
1399
) ;
1389
1400
}
1390
1401
let setter = ( < Property > element ) . setterPrototype ;
1391
1402
if ( setter ) {
1392
1403
this . compileFunctionUsingTypeArguments (
1393
1404
setter ,
1394
- [ ] , null , null ,
1405
+ [ ] ,
1406
+ makeMap < string , Type > ( ) ,
1407
+ null ,
1395
1408
setter . declaration . name
1396
1409
) ;
1397
1410
}
@@ -1413,8 +1426,8 @@ export class Compiler extends DiagnosticEmitter {
1413
1426
this . compileFunctionUsingTypeArguments (
1414
1427
< FunctionPrototype > element ,
1415
1428
[ ] ,
1416
- instance . contextualTypeArguments ,
1417
- null , // no outer scope
1429
+ makeMap < string , Type > ( instance . contextualTypeArguments ) ,
1430
+ null ,
1418
1431
( < FunctionPrototype > element ) . declaration . name
1419
1432
) ;
1420
1433
}
@@ -1429,15 +1442,19 @@ export class Compiler extends DiagnosticEmitter {
1429
1442
if ( getter ) {
1430
1443
this . compileFunctionUsingTypeArguments (
1431
1444
getter ,
1432
- [ ] , instance . contextualTypeArguments , null ,
1445
+ [ ] ,
1446
+ makeMap < string , Type > ( instance . contextualTypeArguments ) ,
1447
+ null ,
1433
1448
getter . declaration . name
1434
1449
) ;
1435
1450
}
1436
1451
let setter = ( < Property > element ) . setterPrototype ;
1437
1452
if ( setter ) {
1438
1453
this . compileFunctionUsingTypeArguments (
1439
1454
setter ,
1440
- [ ] , instance . contextualTypeArguments , null ,
1455
+ [ ] ,
1456
+ makeMap < string , Type > ( instance . contextualTypeArguments ) ,
1457
+ null ,
1441
1458
setter . declaration . name
1442
1459
) ;
1443
1460
}
@@ -5014,7 +5031,7 @@ export class Compiler extends DiagnosticEmitter {
5014
5031
instance = this . resolver . resolveFunctionInclTypeArguments (
5015
5032
prototype ,
5016
5033
typeArguments ,
5017
- this . currentFunction . flow . contextualTypeArguments ,
5034
+ makeMap < string , Type > ( this . currentFunction . flow . contextualTypeArguments ) ,
5018
5035
expression
5019
5036
) ;
5020
5037
@@ -5088,7 +5105,7 @@ export class Compiler extends DiagnosticEmitter {
5088
5105
instance = this . resolver . resolveFunction (
5089
5106
prototype ,
5090
5107
resolvedTypeArguments ,
5091
- this . currentFunction . flow . contextualTypeArguments
5108
+ makeMap < string , Type > ( this . currentFunction . flow . contextualTypeArguments )
5092
5109
) ;
5093
5110
if ( ! instance ) return this . module . createUnreachable ( ) ;
5094
5111
return this . makeCallDirect ( instance , argumentExprs ) ;
@@ -5098,11 +5115,7 @@ export class Compiler extends DiagnosticEmitter {
5098
5115
5099
5116
// otherwise resolve the non-generic call as usual
5100
5117
} else {
5101
- instance = this . resolver . resolveFunction (
5102
- prototype ,
5103
- null ,
5104
- this . currentFunction . flow . contextualTypeArguments
5105
- ) ;
5118
+ instance = this . resolver . resolveFunction ( prototype , null ) ;
5106
5119
}
5107
5120
if ( ! instance ) return this . module . createUnreachable ( ) ;
5108
5121
@@ -5241,7 +5254,7 @@ export class Compiler extends DiagnosticEmitter {
5241
5254
typeArguments = this . resolver . resolveTypeArguments (
5242
5255
assert ( prototype . declaration . typeParameters ) ,
5243
5256
typeArgumentNodes ,
5244
- this . currentFunction . flow . contextualTypeArguments ,
5257
+ makeMap < string , Type > ( this . currentFunction . flow . contextualTypeArguments ) ,
5245
5258
expression
5246
5259
) ;
5247
5260
}
@@ -5932,7 +5945,7 @@ export class Compiler extends DiagnosticEmitter {
5932
5945
var instance = this . compileFunctionUsingTypeArguments (
5933
5946
prototype ,
5934
5947
[ ] ,
5935
- flow . contextualTypeArguments ,
5948
+ makeMap < string , Type > ( flow . contextualTypeArguments ) ,
5936
5949
flow ,
5937
5950
declaration
5938
5951
) ;
@@ -6093,7 +6106,7 @@ export class Compiler extends DiagnosticEmitter {
6093
6106
let instance = this . resolver . resolveFunction (
6094
6107
< FunctionPrototype > target ,
6095
6108
null ,
6096
- currentFunction . flow . contextualTypeArguments
6109
+ makeMap < string , Type > ( currentFunction . flow . contextualTypeArguments )
6097
6110
) ;
6098
6111
if ( ! ( instance && this . compileFunction ( instance ) ) ) return module . createUnreachable ( ) ;
6099
6112
let index = this . ensureFunctionTableEntry ( instance ) ;
@@ -6438,7 +6451,11 @@ export class Compiler extends DiagnosticEmitter {
6438
6451
6439
6452
// create the Array segment and return a pointer to it
6440
6453
var arrayPrototype = assert ( program . arrayPrototype ) ;
6441
- var arrayInstance = assert ( this . resolver . resolveClass ( arrayPrototype , [ elementType ] ) ) ;
6454
+ var arrayInstance = assert ( this . resolver . resolveClass (
6455
+ arrayPrototype ,
6456
+ [ elementType ] ,
6457
+ makeMap < string , Type > ( )
6458
+ ) ) ;
6442
6459
var arrayHeaderSize = ( arrayInstance . currentMemoryOffset + 7 ) & ~ 7 ;
6443
6460
if ( hasGC ) {
6444
6461
buf = new Uint8Array ( gcHeaderSize + arrayHeaderSize ) ;
@@ -6506,9 +6523,11 @@ export class Compiler extends DiagnosticEmitter {
6506
6523
6507
6524
// otherwise obtain the array type
6508
6525
var arrayPrototype = assert ( this . program . arrayPrototype ) ;
6509
- if ( ! arrayPrototype || arrayPrototype . kind != ElementKind . CLASS_PROTOTYPE ) return module . createUnreachable ( ) ;
6510
- var arrayInstance = this . resolver . resolveClass ( < ClassPrototype > arrayPrototype , [ elementType ] ) ;
6511
- if ( ! arrayInstance ) return module . createUnreachable ( ) ;
6526
+ var arrayInstance = assert ( this . resolver . resolveClass (
6527
+ < ClassPrototype > arrayPrototype ,
6528
+ [ elementType ] ,
6529
+ makeMap < string , Type > ( )
6530
+ ) ) ;
6512
6531
var arrayType = arrayInstance . type ;
6513
6532
6514
6533
// and compile an explicit instantiation
@@ -6660,13 +6679,13 @@ export class Compiler extends DiagnosticEmitter {
6660
6679
classInstance = this . resolver . resolveClass (
6661
6680
classPrototype ,
6662
6681
classReference . typeArguments ,
6663
- currentFunction . flow . contextualTypeArguments
6682
+ makeMap < string , Type > ( currentFunction . flow . contextualTypeArguments )
6664
6683
) ;
6665
6684
} else {
6666
6685
classInstance = this . resolver . resolveClassInclTypeArguments (
6667
6686
classPrototype ,
6668
6687
typeArguments ,
6669
- currentFunction . flow . contextualTypeArguments ,
6688
+ makeMap < string , Type > ( currentFunction . flow . contextualTypeArguments ) ,
6670
6689
expression
6671
6690
) ;
6672
6691
}
0 commit comments