added number of runs for optimizer

pull/543/head
LianaHus 4 years ago
parent 5f2587a3d4
commit a3cf9ec6e1
  1. 4
      apps/remix-ide/ci/makeMockCompiler.js
  2. 4
      apps/remix-ide/src/app/compiler/compiler-helpers.js
  3. 2
      apps/remix-ide/src/app/compiler/compiler-input.js
  4. 3
      apps/remix-ide/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js
  5. 2
      apps/remix-ide/src/app/files/file-explorer.js
  6. 10
      apps/remix-ide/src/app/tabs/compile-tab.js
  7. 11
      apps/remix-ide/src/app/tabs/compileTab/compileTab.js
  8. 32
      apps/remix-ide/src/app/tabs/compileTab/compilerContainer.js
  9. 3
      apps/remix-ide/src/app/tabs/styles/compile-tab-styles.js
  10. 10
      apps/remix-ide/src/app/tabs/test-tab.js
  11. 575
      package-lock.json

@ -37,10 +37,10 @@ function gatherCompilationResults (dir, compilationResult, solcSnapshot) {
return compilationResult return compilationResult
} }
function compile (solcSnapshot, source, optimization, addCompilationResult) { function compile (solcSnapshot, source, optimization, runs, addCompilationResult) {
var missingInputs = [] var missingInputs = []
try { try {
var input = compilerInput(source, {optimize: optimization}) var input = compilerInput(source, {optimize: optimization, runs: runs})
var result = solcSnapshot.compileStandardWrapper(input, function (path) { var result = solcSnapshot.compileStandardWrapper(input, function (path) {
missingInputs.push(path) missingInputs.push(path)
}) })

@ -4,12 +4,13 @@ import { Compiler } from '@remix-project/remix-solidity'
import CompilerAbstract from './compiler-abstract' import CompilerAbstract from './compiler-abstract'
export const compile = async (compilationTargets, settings) => { export const compile = async (compilationTargets, settings) => {
return await (() => { const res = await (() => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const compiler = new Compiler(() => {}) const compiler = new Compiler(() => {})
compiler.set('evmVersion', settings.evmVersion) compiler.set('evmVersion', settings.evmVersion)
compiler.set('optimize', settings.optimize) compiler.set('optimize', settings.optimize)
compiler.set('language', settings.language) compiler.set('language', settings.language)
compiler.set('runs', settings.runs)
compiler.loadVersion(canUseWorker(settings.version), urlFromVersion(settings.version)) compiler.loadVersion(canUseWorker(settings.version), urlFromVersion(settings.version))
compiler.event.register('compilationFinished', (success, compilationData, source) => { compiler.event.register('compilationFinished', (success, compilationData, source) => {
resolve(new CompilerAbstract(settings.version, 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, '')) compiler.event.register('compilerLoaded', _ => compiler.compile(compilationTargets, ''))
}) })
})() })()
return res
} }

@ -7,7 +7,7 @@ module.exports = (sources, opts) => {
settings: { settings: {
optimizer: { optimizer: {
enabled: opts.optimize === true || opts.optimize === 1, enabled: opts.optimize === true || opts.optimize === 1,
runs: 200 runs: opts.runs
}, },
libraries: opts.libraries, libraries: opts.libraries,
outputSelection: { outputSelection: {

@ -107,7 +107,8 @@ export default class FetchAndCompile extends Plugin {
version: data.metadata.compiler.version, version: data.metadata.compiler.version,
language: data.metadata.language, language: data.metadata.language,
evmVersion: data.metadata.settings.evmVersion, evmVersion: data.metadata.settings.evmVersion,
optimize: data.metadata.settings.optimizer.enabled optimize: data.metadata.settings.optimizer.enabled,
runs: data.metadata.settings.runs
} }
try { try {
setTimeout(_ => this.emit('compiling', settings), 0) setTimeout(_ => this.emit('compiling', settings), 0)

@ -516,7 +516,7 @@ fileExplorer.prototype.toGist = function (id) {
) )
} else { } 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=' + 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 }) const gists = new Gists({ token: tokenAccess })
if (id) { if (id) {

@ -218,10 +218,11 @@ class CompileTab extends ViewPlugin {
* The module UI will *not* be updated, the compilation result is returned * The module UI will *not* be updated, the compilation result is returned
* This function is used by remix-plugin compiler API. * This function is used by remix-plugin compiler API.
* @param {object} map of source files. * @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) { 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 // This function is used for passing the compiler remix-tests
@ -234,14 +235,15 @@ class CompileTab extends ViewPlugin {
return { return {
currentVersion: this.compilerContainer.data.selectedVersion, currentVersion: this.compilerContainer.data.selectedVersion,
evmVersion: this.compileTabLogic.evmVersion, evmVersion: this.compileTabLogic.evmVersion,
optimize: this.compileTabLogic.optimize optimize: this.compileTabLogic.optimize,
runs: this.compileTabLogic.runs
} }
} }
/** /**
* set the compiler configuration * set the compiler configuration
* This function is used by remix-plugin compiler API. * 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) { setCompilerConfig (settings) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

@ -26,6 +26,11 @@ class CompileTab {
this.queryParams.update({ optimize: this.optimize }) this.queryParams.update({ optimize: this.optimize })
this.compiler.set('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 this.evmVersion = this.queryParams.get().evmVersion
if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) { if (this.evmVersion === 'undefined' || this.evmVersion === 'null' || !this.evmVersion) {
this.evmVersion = null this.evmVersion = null
@ -40,6 +45,12 @@ class CompileTab {
this.compiler.set('optimize', this.optimize) 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) { setEvmVersion (newEvmVersion) {
this.evmVersion = newEvmVersion this.evmVersion = newEvmVersion
this.queryParams.update({ evmVersion: this.evmVersion }) this.queryParams.update({ evmVersion: this.evmVersion })

@ -185,14 +185,28 @@ class CompilerContainer {
this._view.warnCompilationSlow = yo`<i title="Compilation Slow" style="visibility:hidden" class="${css.warnCompilationSlow} fas fa-exclamation-triangle" aria-hidden="true"></i>` this._view.warnCompilationSlow = yo`<i title="Compilation Slow" style="visibility:hidden" class="${css.warnCompilationSlow} fas fa-exclamation-triangle" aria-hidden="true"></i>`
this._view.compileIcon = yo`<i class="fas fa-sync ${css.icon}" aria-hidden="true"></i>` this._view.compileIcon = yo`<i class="fas fa-sync ${css.icon}" aria-hidden="true"></i>`
this._view.autoCompile = yo`<input class="${css.autocompile} custom-control-input" onchange=${this.updateAutoCompile.bind(this)} data-id="compilerContainerAutoCompile" id="autoCompile" type="checkbox" title="Auto compile">` this._view.autoCompile = yo`<input class="${css.autocompile} custom-control-input" onchange=${() => this.updateAutoCompile()} data-id="compilerContainerAutoCompile" id="autoCompile" type="checkbox" title="Auto compile">`
this._view.hideWarningsBox = yo`<input class="${css.autocompile} custom-control-input" onchange=${this.hideWarnings.bind(this)} id="hideWarningsBox" type="checkbox" title="Hide warnings">` this._view.hideWarningsBox = yo`<input class="${css.autocompile} custom-control-input" onchange=${() => this.hideWarnings()} id="hideWarningsBox" type="checkbox" title="Hide warnings">`
if (this.data.autoCompile) this._view.autoCompile.setAttribute('checked', '') if (this.data.autoCompile) this._view.autoCompile.setAttribute('checked', '')
if (this.data.hideWarnings) this._view.hideWarningsBox.setAttribute('checked', '') if (this.data.hideWarnings) this._view.hideWarningsBox.setAttribute('checked', '')
this._view.optimize = yo`<input onchange=${this.onchangeOptimize.bind(this)} class="custom-control-input" id="optimize" type="checkbox">` this._view.optimize = yo`<input onchange=${() => this.onchangeOptimize()} class="custom-control-input" id="optimize" type="checkbox">`
if (this.compileTabLogic.optimize) this._view.optimize.setAttribute('checked', '') if (this.compileTabLogic.optimize) this._view.optimize.setAttribute('checked', '')
this._view.runs = yo`<input
onkeypress="return event.charCode >= 48"
min="1"
class="custom-select ml-2 w-50"
id="runs"
placeholder="200"
type="number"
title="Number of optimisation runs."
>`
if (this.compileTabLogic.optimize) this._view.runs.removeAttribute('disabled')
else {
this._view.runs.setAttribute('disabled', '')
}
this._view.versionSelector = yo` this._view.versionSelector = yo`
<select onchange="${this.onchangeLoadVersion.bind(this)}" class="custom-select" id="versionSelector" disabled> <select onchange="${this.onchangeLoadVersion.bind(this)}" class="custom-select" id="versionSelector" disabled>
<option disabled selected>${this.data.defaultVersion}</option> <option disabled selected>${this.data.defaultVersion}</option>
@ -267,8 +281,11 @@ class CompilerContainer {
<label class="form-check-label custom-control-label" for="autoCompile">Auto compile</label> <label class="form-check-label custom-control-label" for="autoCompile">Auto compile</label>
</div> </div>
<div class="mt-2 ${css.compilerConfig} custom-control custom-checkbox"> <div class="mt-2 ${css.compilerConfig} custom-control custom-checkbox">
<div class="justify-content-between align-items-center d-flex">
${this._view.optimize} ${this._view.optimize}
<label class="form-check-label custom-control-label" for="optimize">Enable optimization</label> <label class="form-check-label custom-control-label" for="optimize">Enable optimization</label>
${this._view.runs}
</div>
</div> </div>
<div class="mt-2 ${css.compilerConfig} custom-control custom-checkbox"> <div class="mt-2 ${css.compilerConfig} custom-control custom-checkbox">
${this._view.hideWarningsBox} ${this._view.hideWarningsBox}
@ -327,6 +344,10 @@ class CompilerContainer {
onchangeOptimize () { onchangeOptimize () {
this.compileTabLogic.setOptimize(!!this._view.optimize.checked) this.compileTabLogic.setOptimize(!!this._view.optimize.checked)
if (this.compileTabLogic.optimize) this._view.runs.removeAttribute('disabled')
else {
this._view.runs.setAttribute('disabled', '')
}
this.compileIfAutoCompileOn() this.compileIfAutoCompileOn()
} }
@ -360,6 +381,7 @@ class CompilerContainer {
this.setLanguage(settings.language) this.setLanguage(settings.language)
this.setEvmVersion(settings.evmVersion) this.setEvmVersion(settings.evmVersion)
this.setOptimize(settings.optimize) this.setOptimize(settings.optimize)
this.setRuns(settings.runs)
this.setVersion(settings.version) this.setVersion(settings.version)
} }
@ -368,6 +390,10 @@ class CompilerContainer {
this.onchangeOptimize() this.onchangeOptimize()
} }
setRuns (value) {
this._view.runs.value = value
}
setLanguage (lang) { setLanguage (lang) {
this._view.languageSelector.value = lang this._view.languageSelector.value = lang
this.onchangeLanguage() this.onchangeLanguage()

@ -43,6 +43,9 @@ const css = csjs`
display: flex; display: flex;
align-items: center; align-items: center;
} }
.runs {
width: 40%;
}
.hideWarningsContainer { .hideWarningsContainer {
display: flex; display: flex;
align-items: center; align-items: center;

@ -360,13 +360,14 @@ module.exports = class TestTab extends ViewPlugin {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let runningTest = {} let runningTest = {}
runningTest[path] = { content } runningTest[path] = { content }
const {currentVersion, evmVersion, optimize} = this.compileTab.getCurrentCompilerConfig() const {currentVersion, evmVersion, optimize, runs} = this.compileTab.getCurrentCompilerConfig()
const currentCompilerUrl = urlFromVersion(currentVersion) const currentCompilerUrl = urlFromVersion(currentVersion)
const compilerConfig = { const compilerConfig = {
currentCompilerUrl, currentCompilerUrl,
evmVersion, evmVersion,
optimize, optimize,
usingWorker: canUseWorker(currentVersion) usingWorker: canUseWorker(currentVersion),
runs
} }
remixTests.runTestSources(runningTest, compilerConfig, () => {}, () => {}, (error, result) => { remixTests.runTestSources(runningTest, compilerConfig, () => {}, () => {}, (error, result) => {
if (error) return reject(error) if (error) return reject(error)
@ -386,13 +387,14 @@ module.exports = class TestTab extends ViewPlugin {
this.fileManager.readFile(testFilePath).then((content) => { this.fileManager.readFile(testFilePath).then((content) => {
const runningTests = {} const runningTests = {}
runningTests[testFilePath] = { content } runningTests[testFilePath] = { content }
const {currentVersion, evmVersion, optimize} = this.compileTab.getCurrentCompilerConfig() const {currentVersion, evmVersion, optimize, runs} = this.compileTab.getCurrentCompilerConfig()
const currentCompilerUrl = urlFromVersion(currentVersion) const currentCompilerUrl = urlFromVersion(currentVersion)
const compilerConfig = { const compilerConfig = {
currentCompilerUrl, currentCompilerUrl,
evmVersion, evmVersion,
optimize, optimize,
usingWorker: canUseWorker(currentVersion) usingWorker: canUseWorker(currentVersion),
runs
} }
remixTests.runTestSources( remixTests.runTestSources(
runningTests, runningTests,

575
package-lock.json generated

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save