Fix compilation blocking for warnings thrown

pull/5370/head
ioedeveloper 1 year ago
parent 550f6d9a1a
commit 81aa41055c
  1. 24
      apps/circuit-compiler/src/app/app.tsx
  2. 44
      apps/circuit-compiler/src/app/services/circomPluginClient.ts
  3. 2
      apps/circuit-compiler/src/app/types/index.ts

@ -48,22 +48,33 @@ function App() {
plugin.internalEvents.on('circuit_compiling_done', (signalInputs: string[]) => {
signalInputs = (signalInputs || []).filter(input => input)
dispatch({ type: 'SET_SIGNAL_INPUTS', payload: signalInputs })
compilerSuccess()
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })
})
plugin.internalEvents.on('circuit_compiling_errored', compilerErrored)
// r1cs events
plugin.internalEvents.on('circuit_generating_r1cs_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'generating' }))
plugin.internalEvents.on('circuit_generating_r1cs_done', compilerSuccess)
plugin.internalEvents.on('circuit_generating_r1cs_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }))
plugin.internalEvents.on('circuit_generating_r1cs_errored', compilerErrored)
// witness events
plugin.internalEvents.on('circuit_computing_witness_start', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'computing' }))
plugin.internalEvents.on('circuit_computing_witness_done', compilerSuccess)
plugin.internalEvents.on('circuit_computing_witness_done', () => dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' }))
plugin.internalEvents.on('circuit_computing_witness_errored', compilerErrored)
// parsing events
plugin.internalEvents.on('circuit_parsing_done', (_, filePathToId) => dispatch({ type: 'SET_FILE_PATH_TO_ID', payload: filePathToId }))
plugin.internalEvents.on('circuit_parsing_done', (_, filePathToId) => {
dispatch({ type: 'SET_FILE_PATH_TO_ID', payload: filePathToId })
dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: null })
})
plugin.internalEvents.on('circuit_parsing_errored', (report) => {
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'errored' })
dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: report })
})
plugin.internalEvents.on('circuit_parsing_warning', (report) => {
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'warning' })
dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: report })
})
}, [])
useEffect(() => {
@ -107,11 +118,6 @@ function App() {
}
}
const compilerSuccess = () => {
dispatch({ type: 'SET_COMPILER_STATUS', payload: 'idle' })
dispatch({ type: 'SET_COMPILER_FEEDBACK', payload: null })
}
const value = {
appState,
dispatch,

@ -4,7 +4,7 @@ import EventManager from 'events'
import pathModule from 'path'
import { parse, compile, generate_witness, generate_r1cs, compiler_list } from 'circom_wasm'
import { extractNameFromKey, extractParentFromKey } from '@remix-ui/helper'
import { CompilationConfig } from '../types'
import { CompilationConfig, CompilerReport } from '../types'
export class CircomPluginClient extends PluginClient {
public internalEvents: EventManager
@ -31,7 +31,7 @@ export class CircomPluginClient extends PluginClient {
this.internalEvents.emit('circom_activated')
}
async parse(path: string, fileContent?: string): Promise<string> {
async parse(path: string, fileContent?: string): Promise<CompilerReport[]> {
if (!fileContent) {
// @ts-ignore
fileContent = await this.call('fileManager', 'readFile', path)
@ -43,7 +43,7 @@ export class CircomPluginClient extends PluginClient {
const parsedOutput = parse(path, this.lastParsedFiles)
try {
const result = JSON.parse(parsedOutput)
const result: CompilerReport[] = JSON.parse(parsedOutput)
if (result.length === 0) {
// @ts-ignore
@ -96,25 +96,32 @@ export class CircomPluginClient extends PluginClient {
await this.call('editor', 'clearErrorMarkers', [path])
}
}
} catch (e) {
console.log(e)
}
const mapFilePathToId = {}
const filePaths = Object.keys(this.lastParsedFiles)
const mapFilePathToId = {}
const filePaths = Object.keys(this.lastParsedFiles)
for (let index = 0; index < filePaths.length; index++) {
mapFilePathToId[index.toString()] = filePaths[index]
}
for (let index = 0; index < filePaths.length; index++) {
mapFilePathToId[index.toString()] = filePaths[index]
}
this.internalEvents.emit('circuit_parsing_done', parsedOutput, mapFilePathToId)
return parsedOutput
this.internalEvents.emit('circuit_parsing_done', result, mapFilePathToId)
return result
} catch (e) {
throw new Error(e)
}
}
async compile(path: string, compilationConfig?: CompilationConfig): Promise<void> {
this.internalEvents.emit('circuit_compiling_start')
const parseErrors = await this.parse(path)
if (parseErrors) throw new Error(parseErrors)
if (parseErrors && (parseErrors.length > 0)) {
if (parseErrors[0].type === 'Error') {
this.internalEvents.emit('circuit_parsing_errored', parseErrors)
return
} else if (parseErrors[0].type === 'Warning') {
this.internalEvents.emit('circuit_parsing_warning', parseErrors)
}
}
if (compilationConfig) {
const { prime, version } = compilationConfig
@ -211,7 +218,14 @@ export class CircomPluginClient extends PluginClient {
this.internalEvents.emit('circuit_generating_r1cs_start')
const parseErrors = await this.parse(path)
if (parseErrors) throw new Error(parseErrors)
if (parseErrors && (parseErrors.length > 0)) {
if (parseErrors[0].type === 'Error') {
this.internalEvents.emit('circuit_parsing_errored', parseErrors)
return
} else if (parseErrors[0].type === 'Warning') {
this.internalEvents.emit('circuit_parsing_warning', parseErrors)
}
}
if (compilationConfig) {
const { prime, version } = compilationConfig

@ -2,7 +2,7 @@ import { compiler_list } from 'circom_wasm'
import {Dispatch} from 'react'
import { CircomPluginClient } from '../services/circomPluginClient'
export type CompilerStatus = "compiling" | "generating" | "computing" | "idle" | "errored"
export type CompilerStatus = "compiling" | "generating" | "computing" | "idle" | "errored" | "warning"
export interface ICircuitAppContext {
appState: AppState
dispatch: Dispatch<Actions>,

Loading…
Cancel
Save