@@ -1260,6 +1260,28 @@ std::ostream &operator<<(std::ostream &os, const FlatVariables &r) {
1260
1260
return os;
1261
1261
}
1262
1262
1263
+ bool log_diff_variable (LogLevel level, const FlatVariables &curr,
1264
+ const FlatVariables &prev, std::string &path,
1265
+ uint32_t slot) {
1266
+ const VarLayout &curr_l = curr.var_layout [slot];
1267
+ const VarLayout &prev_l = prev.var_layout [slot];
1268
+
1269
+ if (curr_l.vt != prev_l.vt ){
1270
+ jit_log (level, " %s: The variable type changed from %u to %u." ,
1271
+ path.c_str (), prev_l.vt , curr_l.vt );
1272
+ return false ;
1273
+ }
1274
+ if (curr_l.size_index != prev_l.size_index ){
1275
+ jit_log (level,
1276
+ " %s: The size equivalence class of the variable changed from "
1277
+ " %u to %u." ,
1278
+ path.c_str (), prev_l.size_index , curr_l.size_index );
1279
+ return false ;
1280
+ }
1281
+
1282
+ return true ;
1283
+ }
1284
+
1263
1285
/* *
1264
1286
* Log the difference of the layout nodes at ``index`` for the two FlatVariables.
1265
1287
*/
@@ -1270,6 +1292,28 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
1270
1292
const Layout &prev_l = prev.layout [index ];
1271
1293
index ++;
1272
1294
1295
+ if (curr_l.flags != prev_l.flags ) {
1296
+ jit_log (level, " %s: The flags of this node changed from 0x%lx to 0x%lx" ,
1297
+ path.c_str (), prev_l.flags , curr_l.flags );
1298
+ return false ;
1299
+ }
1300
+
1301
+ if (curr_l.index != prev_l.index ) {
1302
+ jit_log (level,
1303
+ " %s: The index into the array of deduplicated variables "
1304
+ " changed from s%u to s%u. This can occur if two variables "
1305
+ " referred to the same JIT index, but do no longer." ,
1306
+ path.c_str (), prev_l.index , curr_l.index );
1307
+ return false ;
1308
+ }
1309
+
1310
+ if (curr_l.flags & (uint32_t ) LayoutFlag::JitIndex &&
1311
+ !(curr_l.flags & (uint32_t ) LayoutFlag::Literal)) {
1312
+ uint32_t slot = curr_l.index ;
1313
+ if (!log_diff_variable (level, curr, prev, path, slot))
1314
+ return false ;
1315
+ }
1316
+
1273
1317
if (((bool ) curr_l.type != (bool ) prev_l.type ) ||
1274
1318
!(curr_l.type .equal (prev_l.type ))) {
1275
1319
jit_log (level, " %s: The type of this node changed from %s to %s" ,
@@ -1369,6 +1413,13 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
1369
1413
prev.layout .size (), curr.layout .size ());
1370
1414
return false ;
1371
1415
}
1416
+ if (curr.var_layout .size () != prev.var_layout .size ()){
1417
+ jit_log (level,
1418
+ " The number of opaque variables in the input changed from %u "
1419
+ " to %u." ,
1420
+ prev.layout .size (), curr.layout .size ());
1421
+ return false ;
1422
+ }
1372
1423
1373
1424
uint32_t index = 0 ;
1374
1425
std::string path;
@@ -1689,6 +1740,16 @@ nb::object FrozenFunction::operator()(nb::args args, nb::kwargs kwargs) {
1689
1740
// If new variables have been discovered that should be made
1690
1741
// opaque, we repeat traversal of the input to make them opaque.
1691
1742
// This reduces the number of variants that are saved by one.
1743
+ jit_log (LogLevel::Warn,
1744
+ " While traversing the frozen function input, new "
1745
+ " literal variables have been discovered which changed "
1746
+ " from one call to another. These will be made opaque, "
1747
+ " and the input will be traversed again. This will "
1748
+ " incur some overhead. To prevent this, make those "
1749
+ " variables opaque in beforehand. Below, a list of "
1750
+ " variables that changed will be shown." );
1751
+ if (prev_key)
1752
+ log_diff (LogLevel::Warn, *in_variables, *prev_key);
1692
1753
in_variables->release ();
1693
1754
in_variables = std::make_shared<FlatVariables>(
1694
1755
FlatVariables (in_heuristics));
0 commit comments