[Mlir-commits] [mlir] 82b6549 - [mlir:vscode] Add support for loading big bytecode files

River Riddle llvmlistbot at llvm.org
Tue Sep 6 14:49:40 PDT 2022


Author: River Riddle
Date: 2022-09-06T14:49:16-07:00
New Revision: 82b65496540fbee7720a4fa47ebc3c3dac128980

URL: https://github.com/llvm/llvm-project/commit/82b65496540fbee7720a4fa47ebc3c3dac128980
DIFF: https://github.com/llvm/llvm-project/commit/82b65496540fbee7720a4fa47ebc3c3dac128980.diff

LOG: [mlir:vscode] Add support for loading big bytecode files

VSCode doesn't let our extension manage files >50mb. This commit
adds a proper diagnostic in this case, and also gives the user an option
to open as a temporary .mlir file instead.

Differential Revision: https://reviews.llvm.org/D133242

Added: 
    

Modified: 
    mlir/utils/vscode/src/MLIR/bytecodeProvider.ts

Removed: 
    


################################################################################
diff  --git a/mlir/utils/vscode/src/MLIR/bytecodeProvider.ts b/mlir/utils/vscode/src/MLIR/bytecodeProvider.ts
index a9e90555e6118..28ce02398a312 100644
--- a/mlir/utils/vscode/src/MLIR/bytecodeProvider.ts
+++ b/mlir/utils/vscode/src/MLIR/bytecodeProvider.ts
@@ -70,16 +70,40 @@ class BytecodeFS implements vscode.FileSystemProvider {
       throw new Error(
           'Failed to activate mlir language server to read bytecode');
     }
+
     // Ask the client to do the conversion.
-    let convertParams: ConvertBytecodeParams = {uri : uri.toString()};
+    let result: ConvertBytecodeResult;
     try {
-      const result: ConvertBytecodeResult =
-          await client.sendRequest('mlir/convertFromBytecode', convertParams);
-      return new TextEncoder().encode(result.output);
+      let params: ConvertBytecodeParams = {uri : uri.toString()};
+      result = await client.sendRequest('mlir/convertFromBytecode', params);
     } catch (e) {
       vscode.window.showErrorMessage(e.message);
       throw new Error(`Failed to read bytecode file: ${e}`);
     }
+    let resultBuffer = new TextEncoder().encode(result.output);
+
+    // NOTE: VSCode does not allow for extensions to manage files above 50mb.
+    // Detect that here and if our result is too large for us to manage, alert
+    // the user and open it as a new temporary .mlir file.
+    if (resultBuffer.length > (50 * 1024 * 1024)) {
+      const openAsTempInstead: vscode.MessageItem = {
+        title : 'Open as temporary .mlir instead',
+      };
+      const message: string = `Failed to open bytecode file "${
+          uri.toString()}". Cannot edit converted bytecode files larger than 50MB.`;
+      const errorResult: vscode.MessageItem|undefined =
+          await vscode.window.showErrorMessage(message, openAsTempInstead);
+      if (errorResult === openAsTempInstead) {
+        let tempFile = await vscode.workspace.openTextDocument({
+          language : 'mlir',
+          content : result.output,
+        });
+        await vscode.window.showTextDocument(tempFile);
+      }
+      throw new Error(message);
+    }
+
+    return resultBuffer;
   }
 
   /*


        


More information about the Mlir-commits mailing list