Skip to content

Commit 5f737c2

Browse files
committed
fix: internal state was stored in configuration file after mutation
For simplicity ConfigurationFile object is serialized and saved to disk without any DTO, but that caused some internal state/representation to also be stored to file. To fix this internal state was changed: - Some fields are renamed, i.e. 'lengthExpr' -> 'lengthExpression' - Remove 'canIterate' field from simplehash entry - now entry is removed from Map if we can not iterate it. This is also a performance improvement.
1 parent eba2f89 commit 5f737c2

File tree

3 files changed

+44
-46
lines changed

3 files changed

+44
-46
lines changed

src/configuration.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,31 +120,31 @@ function parseConfiguration(configFile: unknown): ConfigurationFile | undefined
120120
}
121121
}
122122

123-
let lengthExpr;
123+
let lengthExpression;
124124
if ('lengthExpression' in obj) {
125-
lengthExpr = obj.lengthExpression;
126-
if (!lengthExpr) {
125+
lengthExpression = obj.lengthExpression;
126+
if (!lengthExpression) {
127127
vscode.window.showErrorMessage(`lengthExpression not provided for: ${typeName}->${memberName}`);
128128
return;
129129
}
130130

131-
if (typeof lengthExpr !== 'string') {
131+
if (typeof lengthExpression !== 'string') {
132132
vscode.window.showErrorMessage(`lengthExpression field must be string for: ${typeName}->${memberName}`);
133133
return;
134134
}
135135

136-
lengthExpr = lengthExpr.trim();
137-
if (!lengthExpr.length) {
136+
lengthExpression = lengthExpression.trim();
137+
if (!lengthExpression.length) {
138138
vscode.window.showErrorMessage('lengthExpression can not be empty string');
139139
return;
140140
}
141141
}
142142

143-
if (typeName && memberName && lengthExpr) {
143+
if (typeName && memberName && lengthExpression) {
144144
return {
145145
typeName,
146146
memberName,
147-
lengthExpr,
147+
lengthExpression,
148148
};
149149
}
150150
};
@@ -367,7 +367,7 @@ function parseConfiguration(configFile: unknown): ConfigurationFile | undefined
367367
return elements;
368368
};
369369

370-
const parseSimplehashTypes = (obj: unknown): vars.SimplehashEntryInfo[] | undefined => {
370+
const parseSimplehashTypes = (obj: unknown) => {
371371
/*
372372
* [
373373
* {
@@ -380,13 +380,12 @@ function parseConfiguration(configFile: unknown): ConfigurationFile | undefined
380380
return;
381381
}
382382

383-
const elements = [];
383+
const elements: vars.SimplehashEntryInfo[] = [];
384384
for (const o of obj) {
385385
if (!(typeof o === 'object' && o)) {
386386
continue;
387387
}
388388

389-
390389
const prefix = o.prefix;
391390
const type = o.type;
392391

@@ -395,11 +394,7 @@ function parseConfiguration(configFile: unknown): ConfigurationFile | undefined
395394
continue;
396395
}
397396

398-
elements.push({
399-
prefix,
400-
canIterate: true,
401-
elementType: type,
402-
} as vars.SimplehashEntryInfo);
397+
elements.push({prefix, type});
403398
}
404399

405400
return elements;

src/constants.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BitmaskMemberInfo,
1+
import { ArraySpecialMemberInfo, BitmaskMemberInfo,
22
HtabEntryInfo,
33
ListPtrSpecialMemberInfo,
44
SimplehashEntryInfo,
@@ -1393,11 +1393,11 @@ export interface ArraySpecialMember {
13931393
lengthExpr: string
13941394
}
13951395

1396-
export function getArraySpecialMembers(): ArraySpecialMember[] {
1397-
const _ = (typeName: string, memberName: string, lengthExpr: string) => ({
1396+
export function getArraySpecialMembers(): ArraySpecialMemberInfo[] {
1397+
const _ = (typeName: string, memberName: string, lengthExpression: string) => ({
13981398
typeName,
13991399
memberName,
1400-
lengthExpr,
1400+
lengthExpression,
14011401
});
14021402

14031403
return [
@@ -2147,9 +2147,7 @@ export function getWellKnownHTABTypes(): HtabEntryInfo[] {
21472147
};
21482148

21492149
export function getWellKnownSimpleHashTableTypes(): SimplehashEntryInfo[] {
2150-
const type = (prefix: string, elementType: string, canIterate = true) => ({
2151-
prefix, elementType, canIterate,
2152-
} as SimplehashEntryInfo);
2150+
const type = (prefix: string, type: string) => ({prefix, type});
21532151

21542152
return [
21552153
type('blockreftable', 'BlockRefTableEntry *'),
@@ -2163,16 +2161,17 @@ export function getWellKnownSimpleHashTableTypes(): SimplehashEntryInfo[] {
21632161
/*
21642162
* These simple hash tables have iteration logic trimmed,
21652163
* but leave it to show, that I hadn't forgotten it.
2164+
*
2165+
* type('backup_file', 'backup_file_entry *'),
2166+
* type('catalogid', 'CatalogIdMapEntry *'),
2167+
* type('collation_cache', 'collation_cache_entry *'),
2168+
* type('derives', 'ECDerivesEntry *'),
2169+
* type('keepwal', 'keepwal_entry *'),
2170+
* type('nsphash', 'SearchPathCacheEntry *'),
2171+
* type('pgstat_snapshot', 'PgStat_SnapshotEntry *'),
2172+
* type('rolename', 'RoleNameEntry *'),
2173+
* type('saophash', 'ScalarArrayOpExprHashEntry *'),
21662174
*/
2167-
type('backup_file', 'backup_file_entry *', false),
2168-
type('catalogid', 'CatalogIdMapEntry *', false),
2169-
type('collation_cache', 'collation_cache_entry *', false),
2170-
type('derives', 'ECDerivesEntry *', false),
2171-
type('keepwal', 'keepwal_entry *', false),
2172-
type('nsphash', 'SearchPathCacheEntry *', false),
2173-
type('pgstat_snapshot', 'PgStat_SnapshotEntry *', false),
2174-
type('rolename', 'RoleNameEntry *', false),
2175-
type('saophash', 'ScalarArrayOpExprHashEntry *', false),
21762175
];
21772176
}
21782177

src/variables.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export interface ArraySpecialMemberInfo {
8080
/* Name of member which stores array */
8181
memberName: string;
8282
/* Expression to get length of array */
83-
lengthExpr: string;
83+
lengthExpression: string;
8484
}
8585

8686
export interface ListPtrSpecialMemberInfo {
@@ -272,13 +272,7 @@ export interface SimplehashEntryInfo {
272272
* Type of element stored in this hash table.
273273
* Should be a pointer type, because no checks and adding pointer performed.
274274
*/
275-
elementType: string;
276-
277-
/*
278-
* Flag, indicating that 'start_iterate' and 'iterate' functions
279-
* and 'iterator' struct exist.
280-
*/
281-
canIterate: boolean;
275+
type: string;
282276
}
283277

284278
export class HashTableTypes {
@@ -3974,7 +3968,7 @@ export class ArraySpecialMember extends RealVariable {
39743968
* invocation instead of simple member.
39753969
*/
39763970
const parentExpr = `((${this.parent?.type})${this.parent?.getPointer()})`;
3977-
const lengthExpr = this.info.lengthExpr.replace(/{}/g, parentExpr);
3971+
const lengthExpr = this.info.lengthExpression.replace(/{}/g, parentExpr);
39783972
if (lengthExpr.startsWith('!')) {
39793973
return lengthExpr.substring(1);
39803974
} else {
@@ -4952,7 +4946,7 @@ class SimplehashMember extends RealVariable {
49524946
}
49534947

49544948
get elementType(): string {
4955-
return this.entry.elementType;
4949+
return this.entry.type;
49564950
}
49574951

49584952
constructor(entry: SimplehashEntryInfo, args: RealVariableArgs) {
@@ -5052,6 +5046,16 @@ class SimplehashElementsMember extends Variable {
50525046
private getIteratorType() {
50535047
return this.iteratorType ??= `${this.hashTable.prefix}_iterator`;
50545048
}
5049+
5050+
private removeFromContext() {
5051+
/*
5052+
* If we can not iterate over this simplehash, i.e. because of
5053+
* iteration function was trimmed from debug symbols, then we
5054+
* just remove ourselves from context, so we will not be handled
5055+
* further again.
5056+
*/
5057+
this.context.hashTableTypes.simplehash.delete(this.hashTable.prefix);
5058+
}
50555059

50565060
/*
50575061
* Allocate memory for iterator struct and invoke initialization function on it.
@@ -5068,7 +5072,7 @@ class SimplehashElementsMember extends Variable {
50685072
iteratorPtr = await this.palloc(`sizeof(${iteratorType})`);
50695073
} catch (error) {
50705074
if (error instanceof EvaluationError) {
5071-
this.hashTable.entry.canIterate = false;
5075+
this.removeFromContext();
50725076
return undefined;
50735077
}
50745078
throw error;
@@ -5087,7 +5091,7 @@ class SimplehashElementsMember extends Variable {
50875091
}
50885092

50895093
await this.pfree(iteratorPtr);
5090-
this.hashTable.entry.canIterate = false;
5094+
this.removeFromContext();
50915095
return undefined;
50925096
}
50935097

@@ -5108,8 +5112,8 @@ class SimplehashElementsMember extends Variable {
51085112
if (!(err instanceof EvaluationError)) {
51095113
throw err;
51105114
}
5111-
5112-
this.hashTable.entry.canIterate = false;
5115+
5116+
this.removeFromContext();
51135117
return undefined;
51145118
}
51155119

0 commit comments

Comments
 (0)