@@ -1329,9 +1329,9 @@ function initSearch(rawSearchIndex) {
1329
1329
*/
1330
1330
function unifyFunctionTypes ( fnTypesIn , queryElems , whereClause , mgensIn , solutionCb ) {
1331
1331
/**
1332
- * @type Map<integer, integer>
1332
+ * @type Map<integer, integer>|null
1333
1333
*/
1334
- let mgens = new Map ( mgensIn ) ;
1334
+ let mgens = mgensIn === null ? null : new Map ( mgensIn ) ;
1335
1335
if ( queryElems . length === 0 ) {
1336
1336
return ! solutionCb || solutionCb ( mgens ) ;
1337
1337
}
@@ -1382,12 +1382,14 @@ function initSearch(rawSearchIndex) {
1382
1382
fnTypesOffset,
1383
1383
unbox,
1384
1384
} = backtracking . pop ( ) ;
1385
- mgens = new Map ( mgensScratch ) ;
1385
+ mgens = mgensScratch !== null ? new Map ( mgensScratch ) : null ;
1386
1386
const fnType = fnTypesScratch [ fnTypesOffset ] ;
1387
1387
const queryElem = queryElems [ queryElemsOffset ] ;
1388
1388
if ( unbox ) {
1389
1389
if ( fnType . id < 0 ) {
1390
- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1390
+ if ( mgens === null ) {
1391
+ mgens = new Map ( ) ;
1392
+ } else if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1391
1393
continue ;
1392
1394
}
1393
1395
mgens . set ( fnType . id , 0 ) ;
@@ -1401,7 +1403,9 @@ function initSearch(rawSearchIndex) {
1401
1403
i = queryElemsOffset - 1 ;
1402
1404
} else {
1403
1405
if ( fnType . id < 0 ) {
1404
- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
1406
+ if ( mgens === null ) {
1407
+ mgens = new Map ( ) ;
1408
+ } else if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
1405
1409
continue ;
1406
1410
}
1407
1411
mgens . set ( fnType . id , queryElem . id ) ;
@@ -1456,7 +1460,7 @@ function initSearch(rawSearchIndex) {
1456
1460
if ( ! fnTypesScratch ) {
1457
1461
fnTypesScratch = fnTypes . slice ( ) ;
1458
1462
}
1459
- if ( ! mgensScratch ) {
1463
+ if ( ! mgensScratch && mgens !== null ) {
1460
1464
mgensScratch = new Map ( mgens ) ;
1461
1465
}
1462
1466
backtracking . push ( {
@@ -1478,10 +1482,19 @@ function initSearch(rawSearchIndex) {
1478
1482
// use the current candidate
1479
1483
const { fnTypesOffset : candidate , mgensScratch : mgensNew } = matchCandidates . pop ( ) ;
1480
1484
if ( fnTypes [ candidate ] . id < 0 && queryElems [ i ] . id < 0 ) {
1485
+ if ( mgens === null ) {
1486
+ mgens = new Map ( ) ;
1487
+ }
1481
1488
mgens . set ( fnTypes [ candidate ] . id , queryElems [ i ] . id ) ;
1482
1489
}
1483
- for ( const [ fid , qid ] of mgensNew ) {
1484
- mgens . set ( fid , qid ) ;
1490
+ if ( mgensNew !== null ) {
1491
+ if ( mgens === null ) {
1492
+ mgens = mgensNew ;
1493
+ } else {
1494
+ for ( const [ fid , qid ] of mgensNew ) {
1495
+ mgens . set ( fid , qid ) ;
1496
+ }
1497
+ }
1485
1498
}
1486
1499
// `i` and `j` are paired off
1487
1500
// `queryElems[i]` is left in place
@@ -1514,15 +1527,17 @@ function initSearch(rawSearchIndex) {
1514
1527
// or, if mgens[fnType.id] = 0, then we've matched this generic with a bare trait
1515
1528
// and should make that same decision everywhere it appears
1516
1529
if ( fnType . id < 0 && queryElem . id < 0 ) {
1517
- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
1518
- return false ;
1519
- }
1520
- for ( const [ fid , qid ] of mgens . entries ( ) ) {
1521
- if ( fnType . id !== fid && queryElem . id === qid ) {
1530
+ if ( mgens !== null ) {
1531
+ if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== queryElem . id ) {
1522
1532
return false ;
1523
1533
}
1524
- if ( fnType . id === fid && queryElem . id !== qid ) {
1525
- return false ;
1534
+ for ( const [ fid , qid ] of mgens . entries ( ) ) {
1535
+ if ( fnType . id !== fid && queryElem . id === qid ) {
1536
+ return false ;
1537
+ }
1538
+ if ( fnType . id === fid && queryElem . id !== qid ) {
1539
+ return false ;
1540
+ }
1526
1541
}
1527
1542
}
1528
1543
} else {
@@ -1575,7 +1590,7 @@ function initSearch(rawSearchIndex) {
1575
1590
}
1576
1591
// mgens[fnType.id] === 0 indicates that we committed to unboxing this generic
1577
1592
// mgens[fnType.id] === null indicates that we haven't decided yet
1578
- if ( mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1593
+ if ( mgens !== null && mgens . has ( fnType . id ) && mgens . get ( fnType . id ) !== 0 ) {
1579
1594
return false ;
1580
1595
}
1581
1596
// This is only a potential unbox if the search query appears in the where clause
0 commit comments