Repository: compiler-explorer/compiler-explorer
Pull request #7079 (2024-11-09 21:58:11)

Remove ICompiler, other minor type fixes


Patch:
diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts
index 683de0f60..4285945b5 100644
--- a/lib/base-compiler.ts
+++ b/lib/base-compiler.ts
@@ -64,7 +64,7 @@ import type {
     OptPipelineBackendOptions,
     OptPipelineOutput,
 } from '../types/compilation/opt-pipeline-output.interfaces.js';
-import type {CompilerInfo, ICompiler, PreliminaryCompilerInfo} from '../types/compiler.interfaces.js';
+import type {CompilerInfo, PreliminaryCompilerInfo} from '../types/compiler.interfaces.js';
 import {
     BasicExecutionResult,
     ExecutableExecutionOptions,
@@ -179,8 +179,8 @@ export interface SimpleOutputFilenameCompiler {
     getOutputFilename(dirPath: string): string;
 }
 
-export class BaseCompiler implements ICompiler {
-    public compiler: CompilerInfo; // TODO: Some missing types still present in Compiler type
+export class BaseCompiler {
+    public compiler: CompilerInfo;
     public lang: Language;
     protected compileFilename: string;
     protected env: CompilationEnvironment;
@@ -2857,7 +2857,7 @@ export class BaseCompiler implements ICompiler {
         // it for preprocessor output.
         if ((this.compiler.lang === 'c++' || this.compiler.lang === 'c') && options.includes('-E')) {
             for (const key in filters) {
-                filters[key] = false;
+                (filters as any)[key] = false; // `any` cast is needed because filters can contain non-boolean fields
             }
 
             if (filters.binaryObject && !this.compiler.supportsBinaryObject) {
diff --git a/lib/clientstate-normalizer.ts b/lib/clientstate-normalizer.ts
index fbfab23a0..072f69644 100644
--- a/lib/clientstate-normalizer.ts
+++ b/lib/clientstate-normalizer.ts
@@ -145,14 +145,15 @@ export class ClientStateNormalizer {
         }
     }
 
-    addToolToCompiler(compilerId, toolId, args, stdin) {
+    addToolToCompiler(compilerId: number, toolId: string, args: string[], stdin: string) {
         const glCompiler = this.findCompilerInGoldenLayout(this.rootContent!, compilerId);
         if (glCompiler) {
-            let compiler;
+            let compiler: ClientStateCompiler;
             if (glCompiler.componentState.source) {
                 const session = this.normalized.findOrCreateSession(glCompiler.componentState.source);
                 compiler = session.findOrCreateCompiler(compilerId);
-            } else if (glCompiler.componentState.tree) {
+            } else {
+                assert(glCompiler.componentState.tree);
                 const tree = this.normalized.findOrCreateTree(glCompiler.componentState.tree);
                 compiler = tree.findOrCreateCompiler(compilerId);
             }
@@ -516,9 +517,9 @@ class GoldenLayoutComponents {
     createToolComponent(
         session: ClientStateSession | null,
         compilerIndex: number,
-        toolId: number,
-        args,
-        stdin,
+        toolId: string,
+        args: string[],
+        stdin: string,
         customSessionId?,
     ): GoldenLayoutComponentStruct {
         return {
@@ -832,9 +833,9 @@ export class ClientStateGoldenifier extends GoldenLayoutComponents {
     newToolStackFromCompiler(
         session: ClientStateSession,
         compilerIndex: number,
-        toolId,
-        args,
-        stdin,
+        toolId: string,
+        args: string[],
+        stdin: string,
         width: number,
     ): BasicGoldenLayoutStruct {
         return this.newStackWithOneComponent(
diff --git a/lib/compilers/cerberus.ts b/lib/compilers/cerberus.ts
index 94ef8a682..ccd8ab2c2 100644
--- a/lib/compilers/cerberus.ts
+++ b/lib/compilers/cerberus.ts
@@ -125,7 +125,7 @@ export class CerberusCompiler extends BaseCompiler {
         }
 
         const lines = result.asm.split('\n');
-        const plines = lines.map(l => ({text: l}));
+        const plines = lines.map((l: string) => ({text: l}));
         return {
             asm: plines,
             languageId: 'core',
diff --git a/lib/compilers/dosbox-compiler.ts b/lib/compilers/dosbox-compiler.ts
index 0b317c705..eb27ef826 100644
--- a/lib/compilers/dosbox-compiler.ts
+++ b/lib/compilers/dosbox-compiler.ts
@@ -154,7 +154,7 @@ export class DosboxCompiler extends BaseCompiler {
 
         const stdoutFilename = path.join(tempDir, 'STDOUT.TXT');
         const stdout = await fs.readFile(stdoutFilename);
-        (result as any).stdout = stdout.toString('utf8');
+        result.stdout = stdout.toString('utf8');
 
         return result;
     }
diff --git a/lib/compilers/ldc.ts b/lib/compilers/ldc.ts
index 65ee6e599..edd7be844 100644
--- a/lib/compilers/ldc.ts
+++ b/lib/compilers/ldc.ts
@@ -112,7 +112,7 @@ export class LDCCompiler extends BaseCompiler {
 
         return this.loadASTOutput(
             await this.runCompiler(this.compiler.exe, newOptions, this.filename(inputFilename), execOptions),
-        ) as any;
+        );
     }
 
     async loadASTOutput(result: CompilationResult): Promise<ResultLine[]> {
diff --git a/lib/compilers/nim.ts b/lib/compilers/nim.ts
index dc2940c2e..75002dc07 100644
--- a/lib/compilers/nim.ts
+++ b/lib/compilers/nim.ts
@@ -27,6 +27,7 @@ import path from 'path';
 import fs from 'fs-extra';
 import _ from 'underscore';
 
+import {CompilationResult} from '../../types/compilation/compilation.interfaces.js';
 import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
 import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
 import {unwrap} from '../assert.js';
@@ -91,14 +92,18 @@ export class NimCompiler extends BaseCompiler {
         return path.join(cacheDir, resultName);
     }
 
-    override async postProcess(result, outputFilename: string, filters: ParseFiltersAndOutputOptions) {
+    override async postProcess(
+        result: CompilationResult,
+        outputFilename: string,
+        filters: ParseFiltersAndOutputOptions,
+    ) {
         const options = result.compilationOptions;
         const cacheDir = this.cacheDir(outputFilename);
         try {
-            if (_.intersection(options, ['js', 'check']).length > 0) filters.binary = false;
+            if (_.intersection(options!, ['js', 'check']).length > 0) filters.binary = false;
             else {
                 filters.binary = true;
-                const objFile = this.getCacheFile(options, result.inputFilename, cacheDir);
+                const objFile = this.getCacheFile(options!, result.inputFilename!, cacheDir);
                 await fs.move(unwrap(objFile), outputFilename);
             }
             return super.postProcess(result, outputFilename, filters);
diff --git a/lib/handlers/source.ts b/lib/handlers/source.ts
index 9e49e60ca..b9e064913 100644
--- a/lib/handlers/source.ts
+++ b/lib/handlers/source.ts
@@ -42,7 +42,7 @@ export class SourceHandler {
     }
 
     private getActionForSource(source: Source, action: string): ((...args: unknown[]) => Promise<unknown>) | null {
-        return ALLOWED_ACTIONS.has(action) ? source[action] : null;
+        return ALLOWED_ACTIONS.has(action) ? (source as any)[action] : null;
     }
 
     public handle(req: express.Request, res: express.Response, next: express.NextFunction): void {
diff --git a/lib/s3-handler.ts b/lib/s3-handler.ts
index 7e7bdc9a9..9b4d43fec 100644
--- a/lib/s3-handler.ts
+++ b/lib/s3-handler.ts
@@ -59,7 +59,8 @@ export class S3Bucket {
         }
     }
 
-    async delete(key, path): Promise<boolean> {
+    // Unused?
+    async delete(key: string, path: string): Promise<boolean> {
         try {
             await this.instance.deleteObject({Bucket: this.bucket, Key: `${path}/${key}`});
         } catch (x: any) {
diff --git a/static/main.ts b/static/main.ts
index 8f75398a7..2a688a906 100644
--- a/static/main.ts
+++ b/static/main.ts
@@ -66,6 +66,7 @@ import {Printerinator} from './print-view.js';
 import {formatISODate, updateAndCalcTopBarHeight} from './utils.js';
 import {localStorage, sessionThenLocalStorage} from './local.js';
 import {setupRealDark, takeUsersOutOfRealDark} from './real-dark.js';
+import {ParseFiltersAndOutputOptions} from './features/filters.interfaces.js';
 
 const logos = require.context('../views/resources/logos', false, /\.(png|svg)$/);
 
@@ -256,15 +257,16 @@ function configFromEmbedded(embeddedUrl: string, defaultLangId: string) {
         throw new Error('Embed url decode error');
     }
     if (params && params.source && params.compiler) {
-        const filters = Object.fromEntries(((params.filters as string) || '').split(',').map(o => [o, true]));
-        // TODO(jeremy-rifkin): Fix types
+        const filters: ParseFiltersAndOutputOptions = Object.fromEntries(
+            ((params.filters as string) || '').split(',').map(o => [o, true]),
+        );
         return {
             content: [
                 {
                     type: 'row',
                     content: [
-                        Components.getEditorWith(1, params.source, filters as any, defaultLangId),
-                        Components.getCompilerWith(1, filters as any, params.options, params.compiler),
+                        Components.getEditorWith(1, params.source, filters, defaultLangId),
+                        Components.getCompilerWith(1, filters, params.options, params.compiler),
                     ],
                 },
             ],
diff --git a/static/panes/diff.ts b/static/panes/diff.ts
index c5b6b1b5b..32511cf7b 100644
--- a/static/panes/diff.ts
+++ b/static/panes/diff.ts
@@ -198,7 +198,7 @@ export class Diff extends MonacoPane<monaco.editor.IStandaloneDiffEditor, DiffSt
     compilers: Record<string | number, CompilerEntry> = {};
     lhs: DiffStateObject;
     rhs: DiffStateObject;
-    selectize: SelectizeType = {} as any; // will be filled in by the constructor
+    selectize: SelectizeType;
     constructor(hub: Hub, container: Container, state: MonacoPaneState & DiffState) {
         super(hub, container, state);
 
diff --git a/static/panes/gccdump-view.ts b/static/panes/gccdump-view.ts
index d52fd395e..90ebbff94 100644
--- a/static/panes/gccdump-view.ts
+++ b/static/panes/gccdump-view.ts
@@ -447,8 +447,7 @@ export class GccDump extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Gcc
 
             ...parent,
         };
-        // TODO(jeremy-rifkin)
-        return state as any;
+        return state;
     }
 
     override close() {
diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts
index 98cea8251..23b548aab 100644
--- a/types/compiler.interfaces.ts
+++ b/types/compiler.interfaces.ts
@@ -22,20 +22,11 @@
 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 // POSSIBILITY OF SUCH DAMAGE.
 
-import {
-    ActiveTool,
-    BypassCache,
-    CompilationResult,
-    ExecutionParams,
-    FiledataPair,
-} from './compilation/compilation.interfaces.js';
 import {AllCompilerOverrideOptions} from './compilation/compiler-overrides.interfaces.js';
-import {ICompilerArguments} from './compiler-arguments.interfaces.js';
 import {PossibleRuntimeTools} from './execution/execution.interfaces.js';
-import {ParseFiltersAndOutputOptions} from './features/filters.interfaces.js';
 import {InstructionSet} from './instructionsets.js';
-import {Language, LanguageKey} from './languages.interfaces.js';
-import {Library, SelectedLibraryVersion} from './libraries/libraries.interfaces.js';
+import {LanguageKey} from './languages.interfaces.js';
+import {Library} from './libraries/libraries.interfaces.js';
 import {Tool, ToolInfo} from './tool.interfaces.js';
 
 export type Remote = {
@@ -167,22 +158,3 @@ export type CompilerInfo = {
 export type PreliminaryCompilerInfo = Omit<CompilerInfo, 'version' | 'fullVersion' | 'baseName' | 'disabledFilters'> & {
     version?: string;
 };
-
-export interface ICompiler {
-    possibleArguments: ICompilerArguments;
-    lang: Language;
-    compile(
-        source: string,
-        options: string[],
-        backendOptions: Record<string, any>,
-        filters: ParseFiltersAndOutputOptions,
-        bypassCache: BypassCache,
-        tools: ActiveTool[],
-        executeParameters: ExecutionParams,
-        libraries: SelectedLibraryVersion[],
-        files: FiledataPair[],
-    ): Promise<any>;
-    cmake(files: FiledataPair[], key, bypassCache: BypassCache): Promise<CompilationResult>;
-    initialise(mtime: Date, clientOptions, isPrediscovered: boolean): Promise<ICompiler | null>;
-    getInfo(): CompilerInfo;
-}


Test patch:
diff --git a/lib/compilers/fake-for-test.ts b/lib/compilers/fake-for-test.ts
index 0ac21db74..699e010d6 100644
--- a/lib/compilers/fake-for-test.ts
+++ b/lib/compilers/fake-for-test.ts
@@ -24,13 +24,18 @@
 
 import _ from 'underscore';
 
-import {BypassCache, ExecutionParams, FiledataPair} from '../../types/compilation/compilation.interfaces.js';
-import type {ICompiler, PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
+import {
+    ActiveTool,
+    BypassCache,
+    ExecutionParams,
+    FiledataPair,
+} from '../../types/compilation/compilation.interfaces.js';
+import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
 import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
 import {SelectedLibraryVersion} from '../../types/libraries/libraries.interfaces.js';
 import {CompilerArguments} from '../compiler-arguments.js';
 
-export class FakeCompiler implements ICompiler {
+export class FakeCompiler {
     public possibleArguments: CompilerArguments;
     public lang: any;
     private compiler: any;
@@ -81,7 +86,7 @@ export class FakeCompiler implements ICompiler {
         backendOptions: Record<string, any>,
         filters: ParseFiltersAndOutputOptions,
         bypassCache: BypassCache,
-        tools,
+        tools: ActiveTool[],
         executeParameters: ExecutionParams,
         libraries: SelectedLibraryVersion[],
         files?: FiledataPair[],