Merge pull request #543 from ethereum/optimisationCN

added number of runs for optimizer
runInTestsCompilation
yann300 4 years ago committed by GitHub
commit 1d68ec3b2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      apps/remix-ide-e2e/src/tests/compiler_api.test.ts
  2. 4
      apps/remix-ide/ci/makeMockCompiler.js
  3. 4
      apps/remix-ide/src/app/compiler/compiler-helpers.js
  4. 21
      apps/remix-ide/src/app/compiler/compiler-input.js
  5. 3
      apps/remix-ide/src/app/compiler/compiler-sourceVerifier-fetchAndCompile.js
  6. 2
      apps/remix-ide/src/app/files/file-explorer.js
  7. 12
      apps/remix-ide/src/app/tabs/compile-tab.js
  8. 11
      apps/remix-ide/src/app/tabs/compileTab/compileTab.js
  9. 51
      apps/remix-ide/src/app/tabs/compileTab/compilerContainer.js
  10. 3
      apps/remix-ide/src/app/tabs/styles/compile-tab-styles.js
  11. 10
      apps/remix-ide/src/app/tabs/test-tab.js
  12. 2
      libs/remix-solidity/src/compiler/compiler-input.ts
  13. 1
      libs/remix-solidity/src/compiler/compiler.ts

@ -26,6 +26,14 @@ module.exports = {
.journalChildIncludes(`"languageversion": "0.6.8+commit.0bbfe453"`)
},
'Should compile using "compileWithParamaters" API with optimization On': function (browser: NightwatchBrowser) {
browser
.addFile('test_jsCompileWithOptimization.js', { content: jsCompileWithOptimization })
.executeScript('remix.exeCurrent()')
.pause(10000)
.journalChildIncludes(`\\"optimizer\\":{\\"enabled\\":true,\\"runs\\":300}`)
},
'Should update the compiler configuration with "setCompilerConfig" API': function (browser: NightwatchBrowser) {
browser
.addFile('test_updateConfiguration.js', { content: updateConfiguration })
@ -83,6 +91,26 @@ const jsCompile = `(async () => {
}
const result = await remix.call('solidity', 'compileWithParameters', contract, params)
console.log('result ', result)
} catch (e) {
console.log(e.message)
}
})()`
const jsCompileWithOptimization = `(async () => {
try {
const contract = {
"storage.sol": {content : \`${simpleContract}\` }
}
console.log('compile')
const params = {
optimize: true,
runs: 300,
evmVersion: null,
language: 'Solidity',
version: '0.6.8+commit.0bbfe453'
}
const result = await remix.call('solidity', 'compileWithParameters', contract, params)
console.log('result ', result)
} catch (e) {
console.log(e.message)
}

@ -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)
})

@ -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
}

@ -1,21 +0,0 @@
'use strict'
module.exports = (sources, opts) => {
return JSON.stringify({
language: 'Solidity',
sources: sources,
settings: {
optimizer: {
enabled: opts.optimize === true || opts.optimize === 1,
runs: 200
},
libraries: opts.libraries,
outputSelection: {
'*': {
'': [ 'ast'],
'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
}
}
}
})
}

@ -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)

@ -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) {

@ -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) => {

@ -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 })

@ -176,7 +176,7 @@ class CompilerContainer {
this.compileTabLogic.compiler.event.register('compilerLoaded', (version) => this.setVersionText(version))
this.fetchAllVersion((allversions, selectedVersion, isURL) => {
this.data.allversions = allversions
if(isURL) this._updateVersionSelector(selectedVersion)
if (isURL) this._updateVersionSelector(selectedVersion)
else {
this.data.selectedVersion = selectedVersion
if (this._view.versionSelector) this._updateVersionSelector()
@ -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.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.hideWarningsBox = yo`<input class="${css.autocompile} custom-control-input" onchange=${this.hideWarnings.bind(this)} id="hideWarningsBox" type="checkbox" title="Hide warnings">`
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()} 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`<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', '')
this._view.runs = yo`<input
min="1"
class="custom-select ml-2 ${css.runs}"
id="runs"
placeholder="200"
type="number"
title="Number of optimisation runs."
onchange=${() => this.onchangeRuns()}
>`
if (this.compileTabLogic.optimize) this._view.runs.removeAttribute('disabled')
else {
this._view.runs.setAttribute('disabled', '')
}
this._view.versionSelector = yo`
<select onchange="${this.onchangeLoadVersion.bind(this)}" class="custom-select" id="versionSelector" disabled>
<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>
</div>
<div class="mt-2 ${css.compilerConfig} custom-control custom-checkbox">
${this._view.optimize}
<label class="form-check-label custom-control-label" for="optimize">Enable optimization</label>
<div class="justify-content-between align-items-center d-flex">
${this._view.optimize}
<label class="form-check-label custom-control-label" for="optimize">Enable optimization</label>
${this._view.runs}
</div>
</div>
<div class="mt-2 ${css.compilerConfig} custom-control custom-checkbox">
${this._view.hideWarningsBox}
@ -327,6 +344,16 @@ class CompilerContainer {
onchangeOptimize () {
this.compileTabLogic.setOptimize(!!this._view.optimize.checked)
if (this.compileTabLogic.optimize) {
this._view.runs.removeAttribute('disabled')
} else {
this._view.runs.setAttribute('disabled', '')
}
this.compileIfAutoCompileOn()
}
onchangeRuns () {
this.compileTabLogic.setRuns(parseInt(this._view.runs.value))
this.compileIfAutoCompileOn()
}
@ -360,6 +387,7 @@ class CompilerContainer {
this.setLanguage(settings.language)
this.setEvmVersion(settings.evmVersion)
this.setOptimize(settings.optimize)
this.setRuns(settings.runs)
this.setVersion(settings.version)
}
@ -368,6 +396,13 @@ class CompilerContainer {
this.onchangeOptimize()
}
setRuns (value) {
if (value) {
this._view.runs.value = value
this.onchangeRuns()
}
}
setLanguage (lang) {
this._view.languageSelector.value = lang
this.onchangeLanguage()
@ -470,8 +505,8 @@ class CompilerContainer {
// Check if version is a URL and corresponding filename starts with 'soljson'
if (selectedVersion.startsWith('https://')) {
const urlArr = selectedVersion.split('/')
if(urlArr[urlArr.length - 1].startsWith('soljson')) isURL = true
}
if (urlArr[urlArr.length - 1].startsWith('soljson')) isURL = true
}
if (wasmRes.event.type !== 'error') {
allVersionsWasm = JSON.parse(wasmRes.json).builds.slice().reverse()
}

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

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

@ -9,7 +9,7 @@ export default (sources: Source, opts: CompilerInputOptions): string => {
settings: {
optimizer: {
enabled: opts.optimize === true || opts.optimize === 1,
runs: opts.runs
runs: opts.runs || 200
},
libraries: opts.libraries,
outputSelection: {

@ -54,6 +54,7 @@ export class Compiler {
set <K extends keyof CompilerState>(key: K, value: CompilerState[K]): void {
this.state[key] = value
if (key === 'runs') this.state['runs'] = parseInt(value)
}
/**

Loading…
Cancel
Save