Skip to content

Commit 0b5c770

Browse files
committed
Revert "fix(cache): invalidate consumer codegen when inlined exports change (#22020)"
This reverts commit 9afd535.
1 parent b5817d1 commit 0b5c770

5 files changed

Lines changed: 26 additions & 118 deletions

File tree

‎lib/ChunkGraph.js‎

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const util = require("util");
99
const Entrypoint = require("./Entrypoint");
1010
const ModuleGraphConnection = require("./ModuleGraphConnection");
1111
const { DEFAULTS } = require("./config/defaults");
12-
const { isExportInlined } = require("./optimize/InlineExports");
1312
const { first } = require("./util/SetHelpers");
1413
const SortableSet = require("./util/SortableSet");
1514
const {
@@ -22,7 +21,6 @@ const {
2221
} = require("./util/comparators");
2322
const createHash = require("./util/createHash");
2423
const findGraphRoots = require("./util/findGraphRoots");
25-
const memoize = require("./util/memoize");
2624
const {
2725
RuntimeSpecMap,
2826
RuntimeSpecSet,
@@ -31,10 +29,6 @@ const {
3129
runtimeToString
3230
} = require("./util/runtime");
3331

34-
const getHarmonyImportSpecifierDependency = memoize(() =>
35-
require("./dependencies/HarmonyImportSpecifierDependency")
36-
);
37-
3832
/** @import AsyncDependenciesBlock from "./AsyncDependenciesBlock" */
3933
/** @import Chunk, { Chunks, Entrypoints, ChunkId } from "./Chunk" */
4034
/** @import ChunkGroup from "./ChunkGroup" */
@@ -75,23 +69,6 @@ const activeStateToString = (state) => {
7569
throw new Error("Not implemented active state");
7670
};
7771

78-
/**
79-
* True when an inactive connection still embeds an inlined export literal
80-
* in the referencing module's generated code (must stay in its hash).
81-
* @param {ModuleGraph} moduleGraph module graph
82-
* @param {ModuleGraphConnection} connection connection
83-
* @param {RuntimeSpec} runtime runtime
84-
* @returns {boolean} true when the connection contributes an inlined literal
85-
*/
86-
const connectionInactiveDueToInlining = (moduleGraph, connection, runtime) => {
87-
const module = connection.module;
88-
if (!module) return false;
89-
const dep = connection.dependency;
90-
// Lazy: top-level require cycles Module → ChunkGraph → dependency → Module.
91-
if (!(dep instanceof getHarmonyImportSpecifierDependency())) return false;
92-
return isExportInlined(moduleGraph, module, dep.getIds(moduleGraph), runtime);
93-
};
94-
9572
const compareModuleIterables = compareIterables(compareModulesByIdentifier);
9673

9774
/** @typedef {(c: Chunk, chunkGraph: ChunkGraph) => boolean} ChunkFilterPredicate */
@@ -1908,20 +1885,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
19081885
if (runtime === undefined || typeof runtime === "string") {
19091886
for (const connection of connections) {
19101887
const state = connection.getActiveState(runtime);
1911-
if (state === false) {
1912-
// Keep inlined imports in the hash: their literals are
1913-
// embedded in this module's codegen (#22019).
1914-
if (
1915-
connectionInactiveDueToInlining(
1916-
this.moduleGraph,
1917-
connection,
1918-
runtime
1919-
)
1920-
) {
1921-
processConnection(connection, "I");
1922-
}
1923-
continue;
1924-
}
1888+
if (state === false) continue;
19251889
processConnection(connection, state === true ? "T" : "O");
19261890
}
19271891
} else {
@@ -1941,18 +1905,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
19411905
);
19421906
if (states.size === 1) {
19431907
const state = first(states);
1944-
if (state === false) {
1945-
if (
1946-
connectionInactiveDueToInlining(
1947-
this.moduleGraph,
1948-
connection,
1949-
runtime
1950-
)
1951-
) {
1952-
processConnection(connection, "I");
1953-
}
1954-
continue;
1955-
}
1908+
if (state === false) continue;
19561909
stateInfo = activeStateToString(
19571910
/** @type {ConnectionState} */
19581911
(state)

‎lib/FlagDependencyExportsPlugin.js‎

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,15 @@ const PLUGIN_LOGGER_NAME = `webpack.${PLUGIN_NAME}`;
3030
/** @typedef {{ etag: string, data: InstanceType<RestoreProvidedData> }} MemCacheEntry */
3131

3232
/**
33-
* Cache key fragment for what changes provided exports without changing the
34-
* module's source: still-lazy barrel requests and DefinePlugin value versions.
3533
* @param {Module} module the module
3634
* @param {LazyBarrelController} lazyBarrelController the compilation's lazy barrel controller
3735
* @param {HashFunction} hashFunction hash function for long keys
38-
* @returns {string} etag for provided-exports mem/persistent cache, "" when neither applies
36+
* @returns {string} the hash
3937
*/
40-
const getProvidedExportsEtag = (module, lazyBarrelController, hashFunction) => {
41-
const lazyRequests = lazyBarrelController.getLazyRequests(module);
42-
const buildInfo = /** @type {BuildInfo | undefined} */ (module.buildInfo);
43-
const valueDependencies = buildInfo && buildInfo.valueDependencies;
44-
const hasValueDependencies =
45-
valueDependencies !== undefined && valueDependencies.size > 0;
46-
if (!lazyRequests && !hasValueDependencies) return "";
47-
/** @type {(string | string[] | undefined)[][]} */
48-
const valueEntries = [];
49-
if (hasValueDependencies) {
50-
const versions =
51-
/** @type {NonNullable<BuildInfo["valueDependencies"]>} */
52-
(valueDependencies);
53-
for (const key of [...versions.keys()].sort()) {
54-
const value = versions.get(key);
55-
// An absent version serializes as null, distinct from both other shapes
56-
valueEntries.push([
57-
key,
58-
value instanceof Set ? [...value].sort() : value
59-
]);
60-
}
61-
}
62-
// JSON, so a separator inside a request or a version cannot forge another entry
63-
const joined = JSON.stringify([
64-
lazyRequests ? [...lazyRequests] : [],
65-
valueEntries
66-
]);
38+
const getLazyRequestsHash = (module, lazyBarrelController, hashFunction) => {
39+
const lazyKeys = lazyBarrelController.getLazyRequests(module);
40+
if (!lazyKeys) return "";
41+
const joined = [...lazyKeys].join("|");
6742
if (joined.length < 100) return joined;
6843
const hash = createHash(hashFunction);
6944
hash.update(joined);
@@ -132,7 +107,7 @@ class FlagDependencyExportsPlugin {
132107
const memCache = moduleMemCaches && moduleMemCaches.get(module);
133108
/** @type {MemCacheEntry | undefined} */
134109
const memCacheEntry = memCache && memCache.get(this);
135-
const etag = getProvidedExportsEtag(
110+
const hash = getLazyRequestsHash(
136111
module,
137112
lazyBarrelController,
138113
hashFunction
@@ -141,7 +116,7 @@ class FlagDependencyExportsPlugin {
141116
// detection cannot invalidate the mem cache when the un-lazied
142117
// connections are unsafe-cached (they are skipped when comparing
143118
// references)
144-
if (memCacheEntry !== undefined && memCacheEntry.etag === etag) {
119+
if (memCacheEntry !== undefined && memCacheEntry.etag === hash) {
145120
statRestoredFromMemCache++;
146121
exportsInfo.restoreProvided(memCacheEntry.data);
147122
return callback();
@@ -151,7 +126,7 @@ class FlagDependencyExportsPlugin {
151126
);
152127
cache.get(
153128
module.identifier(),
154-
etag ? `${buildHash}|${etag}` : buildHash,
129+
hash ? `${buildHash}|${hash}` : buildHash,
155130
(err, result) => {
156131
if (err) return callback(err);
157132

@@ -374,13 +349,12 @@ class FlagDependencyExportsPlugin {
374349
changed = true;
375350
}
376351

377-
if (inlined !== undefined) {
378-
const prev = exportInfo.canInlineProvide;
379-
// Watch rebuilds keep ExportInfo; refresh when the constant changes
380-
if (prev === undefined || !prev.equals(inlined)) {
381-
exportInfo.canInlineProvide = inlined;
382-
changed = true;
383-
}
352+
if (
353+
inlined !== undefined &&
354+
exportInfo.canInlineProvide === undefined
355+
) {
356+
exportInfo.canInlineProvide = inlined;
357+
changed = true;
384358
}
385359

386360
if (terminalBinding && !exportInfo.terminalBinding) {
@@ -537,15 +511,15 @@ class FlagDependencyExportsPlugin {
537511
.getRestoreProvidedData();
538512
const memCache =
539513
moduleMemCaches && moduleMemCaches.get(module);
540-
const etag = getProvidedExportsEtag(
514+
const hash = getLazyRequestsHash(
541515
module,
542516
lazyBarrelController,
543517
hashFunction
544518
);
545519
if (memCache) {
546520
/** @type {MemCacheEntry} */
547521
const entry = {
548-
etag,
522+
etag: hash,
549523
data: cachedData
550524
};
551525
memCache.set(this, entry);
@@ -555,7 +529,7 @@ class FlagDependencyExportsPlugin {
555529
);
556530
cache.store(
557531
module.identifier(),
558-
etag ? `${buildHash}|${etag}` : buildHash,
532+
hash ? `${buildHash}|${hash}` : buildHash,
559533
cachedData,
560534
callback
561535
);

‎lib/optimize/ConstExportsPlugin.js‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,23 +189,13 @@ class ConstExportsPlugin {
189189
}
190190
for (const exportInfo of exportsInfo.ownedExports) {
191191
const inlined = exportInfo.canInline();
192-
if (inlined !== undefined && exportInfo.provided === true) {
193-
if (!exportInfo.hasUsedName()) {
194-
exportInfo.setUsedName(new InlinedUsedName(inlined));
195-
exportsInfo.markInlinedExports();
196-
} else {
197-
// Watch rebuilds keep ExportInfo; refresh a stale literal
198-
const usedName = exportInfo.getUsedName(
199-
exportInfo.name,
200-
undefined
201-
);
202-
if (
203-
usedName instanceof InlinedUsedName &&
204-
!usedName.value.equals(inlined)
205-
) {
206-
exportInfo.setUsedName(new InlinedUsedName(inlined));
207-
}
208-
}
192+
const doInline =
193+
!exportInfo.hasUsedName() &&
194+
inlined !== undefined &&
195+
exportInfo.provided === true;
196+
if (doInline) {
197+
exportInfo.setUsedName(new InlinedUsedName(inlined));
198+
exportsInfo.markInlinedExports();
209199
}
210200
if (exportInfo.exportsInfoOwned && exportInfo.exportsInfo) {
211201
const used = exportInfo.getUsed(undefined);

‎lib/optimize/InlineExports.js‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ class InlinedValue {
6060
return `(${comment}${this.renderLiteral()})`;
6161
}
6262

63-
/**
64-
* @param {InlinedValue} other other inlined value
65-
* @returns {boolean} true when kind and value match
66-
*/
67-
equals(other) {
68-
return this.kind === other.kind && this.value === other.value;
69-
}
70-
7163
/**
7264
* @param {ObjectSerializerContext} context context
7365
*/

‎types.d.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11694,7 +11694,6 @@ declare abstract class InlinedValue {
1169411694
value?: null | string | number | boolean;
1169511695
renderLiteral(): string;
1169611696
render(comment: string): string;
11697-
equals(other: InlinedValue): boolean;
1169811697
serialize(__0: ObjectSerializerContextObjectMiddlewareObject_3): void;
1169911698
deserialize(__0: ObjectDeserializerContextObjectMiddlewareObject_2): void;
1170011699
}

0 commit comments

Comments
 (0)