diff --git a/apps/remix-ide/ci/makeMockCompiler.js b/apps/remix-ide/ci/makeMockCompiler.js index 155331d4cf..45387a80d6 100644 --- a/apps/remix-ide/ci/makeMockCompiler.js +++ b/apps/remix-ide/ci/makeMockCompiler.js @@ -37,10 +37,10 @@ function gatherCompilationResults (dir, compilationResult, solcSnapshot) { return compilationResult } -function compile (solcSnapshot, source, optimization, addCompilationResult) { +function compile (solcSnapshot, source, optimization, runs, addCompilationResult) { var missingInputs = [] try { - var input = compilerInput(source, {optimize: optimization}) + var input = compilerInput(source, {optimize: optimization, runs: runs}) var result = solcSnapshot.compileStandardWrapper(input, function (path) { missingInputs.push(path) }) diff --git a/apps/remix-ide/src/app/compiler/compiler-helpers.js b/apps/remix-ide/src/app/compiler/compiler-helpers.js index b5b84dea0a..d1f8399607 100644 --- a/apps/remix-ide/src/app/compiler/compiler-helpers.js +++ b/apps/remix-ide/src/app/compiler/compiler-helpers.js @@ -4,12 +4,13 @@ import { Compiler } from '@remix-project/remix-solidity' import CompilerAbstract from './compiler-abstract' export const compile = async (compilationTargets, settings) => { - return await (() => { + const res = await (() => { return new Promise((resolve, reject) => { const compiler = new Compiler(() => {}) compiler.set('evmVersion', settings.evmVersion) compiler.set('optimize', settings.optimize) compiler.set('language', settings.language) + compiler.set('runs', settings.runs) compiler.loadVersion(canUseWorker(settings.version), urlFromVersion(settings.version)) compiler.event.register('compilationFinished', (success, compilationData, source) => { resolve(new CompilerAbstract(settings.version, compilationData, source)) @@ -17,4 +18,5 @@ export const compile = async (compilationTargets, settings) => { compiler.event.register('compilerLoaded', _ => compiler.compile(compilationTargets, '')) }) })() + return res } diff --git a/apps/remix-ide/src/app/compiler/compiler-input.js b/apps/remix-ide/src/app/compiler/compiler-input.js index 150ca56173..274c27bcd3 100644 --- a/apps/remix-ide/src/app/compiler/compiler-input.js +++ b/apps/remix-ide/src/app/compiler/compiler-input.js @@ -7,7 +7,7 @@ module.exports = (sources, opts) => { settings: { optimizer: { enabled: opts.optimize === true || opts.optimize === 1, - runs: 200 + runs: opts.runs }, libraries: opts.libraries, outputSelection: { diff --git a/apps/remix-ide/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js b/apps/remix-ide/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js index 7a22ef4beb..62f0d87411 100644 --- a/apps/remix-ide/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js +++ b/apps/remix-ide/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js @@ -107,7 +107,8 @@ export default class FetchAndCompile extends Plugin { version: data.metadata.compiler.version, language: data.metadata.language, evmVersion: data.metadata.settings.evmVersion, - optimize: data.metadata.settings.optimizer.enabled + optimize: data.metadata.settings.optimizer.enabled, + runs: data.metadata.settings.runs } try { setTimeout(_ => this.emit('compiling', settings), 0) diff --git a/apps/remix-ide/src/app/files/file-explorer.js b/apps/remix-ide/src/app/files/file-explorer.js index 1b6d89797e..dd9af1861d 100644 --- a/apps/remix-ide/src/app/files/file-explorer.js +++ b/apps/remix-ide/src/app/files/file-explorer.js @@ -516,7 +516,7 @@ fileExplorer.prototype.toGist = function (id) { ) } else { const description = 'Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. \n Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=' + - queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&gist=' + queryParams.get().version + '&optimize=' + queryParams.get().optimize + '&runs' + queryParams.get().runs + '&gist=' const gists = new Gists({ token: tokenAccess }) if (id) { diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index 42413443ae..05bdb94087 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -213,15 +213,16 @@ class CompileTab extends ViewPlugin { return this.compileTabLogic.compileFile(fileName) } - /** + /** * compile using @arg compilationTargets and @arg settings * The module UI will *not* be updated, the compilation result is returned * This function is used by remix-plugin compiler API. * @param {object} map of source files. - * @param {object} settings {evmVersion, optimize, version, language} + * @param {object} settings {evmVersion, optimize, runs, version, language} */ async compileWithParameters (compilationTargets, settings) { - return await compile(compilationTargets, settings) + const res = await compile(compilationTargets, settings) + return res } // This function is used for passing the compiler remix-tests @@ -234,14 +235,15 @@ class CompileTab extends ViewPlugin { return { currentVersion: this.compilerContainer.data.selectedVersion, evmVersion: this.compileTabLogic.evmVersion, - optimize: this.compileTabLogic.optimize + optimize: this.compileTabLogic.optimize, + runs: this.compileTabLogic.runs } } /** * set the compiler configuration * This function is used by remix-plugin compiler API. - * @param {object} settings {evmVersion, optimize, version, language} + * @param {object} settings {evmVersion, optimize, runs, version, language} */ setCompilerConfig (settings) { return new Promise((resolve, reject) => { diff --git a/apps/remix-ide/src/app/tabs/compileTab/compileTab.js b/apps/remix-ide/src/app/tabs/compileTab/compileTab.js index c4d2965c4d..991430eefc 100644 --- a/apps/remix-ide/src/app/tabs/compileTab/compileTab.js +++ b/apps/remix-ide/src/app/tabs/compileTab/compileTab.js @@ -26,6 +26,11 @@ class CompileTab { this.queryParams.update({ optimize: this.optimize }) this.compiler.set('optimize', this.optimize) + this.runs = this.queryParams.get().runs + this.runs = this.runs || 200 + this.queryParams.update({ runs: this.runs }) + this.compiler.set('runs', this.runs) + this.evmVersion = this.queryParams.get().evmVersion if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) { this.evmVersion = null @@ -40,6 +45,12 @@ class CompileTab { this.compiler.set('optimize', this.optimize) } + setRuns (runs) { + this.runs = runs + this.queryParams.update({ runs: this.runs }) + this.compiler.set('runs', this.runs) + } + setEvmVersion (newEvmVersion) { this.evmVersion = newEvmVersion this.queryParams.update({ evmVersion: this.evmVersion }) diff --git a/apps/remix-ide/src/app/tabs/compileTab/compilerContainer.js b/apps/remix-ide/src/app/tabs/compileTab/compilerContainer.js index c6d278a9ba..bd8d60e925 100644 --- a/apps/remix-ide/src/app/tabs/compileTab/compilerContainer.js +++ b/apps/remix-ide/src/app/tabs/compileTab/compilerContainer.js @@ -185,14 +185,28 @@ class CompilerContainer { this._view.warnCompilationSlow = yo`` this._view.compileIcon = yo`` - this._view.autoCompile = yo`` - this._view.hideWarningsBox = yo`` + this._view.autoCompile = yo` this.updateAutoCompile()} data-id="compilerContainerAutoCompile" id="autoCompile" type="checkbox" title="Auto compile">` + this._view.hideWarningsBox = yo` this.hideWarnings()} id="hideWarningsBox" type="checkbox" title="Hide warnings">` if (this.data.autoCompile) this._view.autoCompile.setAttribute('checked', '') if (this.data.hideWarnings) this._view.hideWarningsBox.setAttribute('checked', '') - this._view.optimize = yo`` + this._view.optimize = yo` this.onchangeOptimize()} class="custom-control-input" id="optimize" type="checkbox">` if (this.compileTabLogic.optimize) this._view.optimize.setAttribute('checked', '') + this._view.runs = yo`` + if (this.compileTabLogic.optimize) this._view.runs.removeAttribute('disabled') + else { + this._view.runs.setAttribute('disabled', '') + } + this._view.versionSelector = yo`