Skip to content

Commit

Permalink
change compiler v2 flag into resource access control
Browse files Browse the repository at this point in the history
  • Loading branch information
mkurnikov committed Jun 16, 2024
1 parent 99edaa7 commit df74500
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/main/grammars/MoveParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private ReturnTypeItem_with_recover ::= Type
}
private ReturnTypeItem_recover ::= !( '{' | ';' | acquires | reads | writes | pure | '!' )

ResourceAccessItemList ::= <<isCompilerV2>> ResourceAccessItem*
ResourceAccessItemList ::= <<isResourceAccessEnabled>> ResourceAccessItem*
ResourceAccessItem ::= pure | (('!')? (acquires | reads | writes) AccessSpecifierList)

AccessSpecifierList ::= <<non_empty_comma_sep_items AccessSpecifier>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ data class AptosCompileArgs(
workingDirectory,
additionalArguments,
enviroment,
addCompilerV2Flags = moveSettings.addCompilerV2FlagsToCLI,
addCompilerV2Flags = moveSettings.addCompilerV2CLIFlags,
skipLatestGitDeps = moveSettings.skipFetchLatestGitDeps
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ abstract class TestCommandConfigurationProducerBase:

private fun initEnvironmentVariables(project: Project): EnvironmentVariablesData {
val environmentMap = linkedMapOf<String, String>()
if (project.moveSettings.addCompilerV2FlagsToCLI) {
if (project.moveSettings.addCompilerV2CLIFlags) {
environmentMap[Consts.MOVE_COMPILER_V2_ENV] = "true"
}
return EnvironmentVariablesData.create(environmentMap, true)
Expand All @@ -136,7 +136,7 @@ abstract class TestCommandConfigurationProducerBase:
if (project.moveSettings.dumpStateOnTestFailure) {
append(" --dump")
}
if (project.moveSettings.addCompilerV2FlagsToCLI) {
if (project.moveSettings.addCompilerV2CLIFlags) {
append(" --compiler-version v2 --language-version 2.0")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class MvProjectSettingsService(
val aptosExecType: AptosExecType get() = state.aptosExecType
val localAptosPath: String? get() = state.localAptosPath

val isCompilerV2: Boolean get() = state.isCompilerV2
val fetchAptosDeps: Boolean get() = state.fetchAptosDeps

val disableTelemetry: Boolean get() = state.disableTelemetry
val skipFetchLatestGitDeps: Boolean get() = state.skipFetchLatestGitDeps
val dumpStateOnTestFailure: Boolean get() = state.dumpStateOnTestFailure

val addCompilerV2FlagsToCLI: Boolean get() = state.isCompilerV2 && state.addCompilerV2Flags
val enableResourceAccessControl: Boolean get() = state.enableResourceAccessControl
val addCompilerV2CLIFlags: Boolean get() = state.addCompilerV2CLIFlags

// default values for settings
class MoveProjectSettings: MvProjectSettingsBase<MoveProjectSettings>() {
Expand All @@ -48,7 +48,7 @@ class MvProjectSettingsService(
var localAptosPath: String? by string()

@AffectsParseTree
var isCompilerV2: Boolean by property(false)
var enableResourceAccessControl: Boolean by property(false)

@AffectsMoveProjectsMetadata
var fetchAptosDeps: Boolean by property(false)
Expand All @@ -59,7 +59,7 @@ class MvProjectSettingsService(
var skipFetchLatestGitDeps: Boolean by property(true)
var dumpStateOnTestFailure: Boolean by property(false)

var addCompilerV2Flags: Boolean by property(false)
var addCompilerV2CLIFlags: Boolean by property(false)

override fun copy(): MoveProjectSettings {
val state = MoveProjectSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.util.Disposer
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.dsl.builder.AlignX
import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.layout.selected
import org.move.cli.settings.aptos.ChooseAptosCliPanel
import org.move.openapiext.showSettingsDialog

Expand All @@ -28,28 +26,30 @@ class PerProjectAptosConfigurable(val project: Project): BoundConfigurable("Apto

group {
row {
checkBox("Fetch external dependencies on project reload")
checkBox("Fetch external packages on project reload")
.bindSelected(state::fetchAptosDeps)
link("Configure project reload schedule") {
ProjectManager.getInstance().defaultProject.showSettingsDialog<ExternalSystemGroupConfigurable>()
}
.align(AlignX.RIGHT)
}
val compilerV2Box = JBCheckBox("Enable V2 compiler")
row {
cell(compilerV2Box)
.comment(
"Enables features of the Aptos V2 compiler " +
"(receiver style functions, access control, etc.)"
)
.bindSelected(state::isCompilerV2)
}
indent {
group("Compiler V2") {
row {
checkBox("Set Compiler V2 for CLI")
.comment(
"Adds `--compiler-version v2 --language-version 2.0` " +
"to all generated Aptos CLI commands"
)
.bindSelected(state::addCompilerV2CLIFlags)
}
row {
checkBox("Set Compiler V2 in CLI commands")
.comment("Adds `--compiler-version v2 --language-version 2.0` to all generated Aptos CLI commands")
.enabledIf(compilerV2Box.selected)
.bindSelected(state::addCompilerV2Flags)
checkBox("Enable resource-access control")
.comment(
"Enables resource access control specifies " +
"(<code>reads, writes, pure</code> for functions) in the parser. " +
"Requires re-parsing of all Move files in the project, can be slow."
)
.bindSelected(state::enableResourceAccessControl)
}
}
group("Command Line Options") {
Expand Down Expand Up @@ -101,8 +101,8 @@ class PerProjectAptosConfigurable(val project: Project): BoundConfigurable("Apto
it.disableTelemetry = state.disableTelemetry
it.skipFetchLatestGitDeps = state.skipFetchLatestGitDeps
it.dumpStateOnTestFailure = state.dumpStateOnTestFailure
it.isCompilerV2 = state.isCompilerV2
it.addCompilerV2Flags = state.addCompilerV2Flags
it.enableResourceAccessControl = state.enableResourceAccessControl
it.addCompilerV2CLIFlags = state.addCompilerV2CLIFlags
it.fetchAptosDeps = state.fetchAptosDeps
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/org/move/lang/core/MoveParserUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum class FunModifier {
}

@Suppress("UNUSED_PARAMETER")
object MoveParserUtil : GeneratedParserUtilBase() {
object MoveParserUtil: GeneratedParserUtilBase() {
@JvmField
val ADJACENT_LINE_COMMENTS = WhitespacesAndCommentsBinder { tokens, _, getter ->
var candidate = tokens.size
Expand Down Expand Up @@ -199,7 +199,8 @@ object MoveParserUtil : GeneratedParserUtilBase() {
}

@JvmStatic
fun isCompilerV2(b: PsiBuilder, level: Int): Boolean = b.project.moveSettings.isCompilerV2
fun isResourceAccessEnabled(b: PsiBuilder, level: Int): Boolean =
b.project.moveSettings.enableResourceAccessControl

@JvmStatic
fun includeStmtMode(b: PsiBuilder, level: Int, parser: Parser): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class KeywordCompletionContributor: CompletionContributor() {
KeywordCompletionProvider {
buildList {
add("acquires")
if (it.moveSettings.isCompilerV2) {
if (it.moveSettings.enableResourceAccessControl) {
addAll(listOf("reads", "writes", "pure"))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/move/utils/tests/MvLightTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ abstract class MvLightTestBase: BasePlatformTestCase() {
val isDebugMode = this.findAnnotationInstance<DebugMode>()?.enabled ?: true
setRegistryKey("org.move.debug.enabled", isDebugMode)

val isCompilerV2 = this.findAnnotationInstance<CompilerV2>() != null
val isResourceAccess = this.findAnnotationInstance<EnableResourceAccessControl>() != null
project.moveSettings.modifyTemporary(testRootDisposable) {
it.isCompilerV2 = isCompilerV2
it.enableResourceAccessControl = isResourceAccess
}
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/org/move/utils/tests/MvProjectTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ abstract class MvProjectTestBase: CodeInsightFixtureTestCase<ModuleFixtureBuilde
val isDebugMode = this.findAnnotationInstance<DebugMode>()?.enabled ?: true
setRegistryKey("org.move.debug.enabled", isDebugMode)

val isCompilerV2 = this.findAnnotationInstance<CompilerV2>() != null
val isResourceAccess = this.findAnnotationInstance<EnableResourceAccessControl>() != null
// triggers projects refresh
project.moveSettings.modify {
it.isCompilerV2 = isCompilerV2
it.enableResourceAccessControl = isResourceAccess
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/move/utils/tests/MvTestBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ annotation class WithEnabledInspections(vararg val inspections: KClass<out Inspe
@Inherited
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class CompilerV2
annotation class EnableResourceAccessControl

abstract class MvTestBase: MvLightTestBase(),
MvTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.move.utils.tests.completion

import org.intellij.lang.annotations.Language
import org.move.cli.settings.moveSettings
import org.move.utils.tests.CompilerV2
import org.move.utils.tests.MvLightTestBase
import org.move.utils.tests.findAnnotationInstance

abstract class CompletionTestCase: MvLightTestBase() {
lateinit var completionFixture: MvCompletionTestFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.jetbrains.annotations.NonNls
import org.move.cli.settings.MvProjectSettingsService
import org.move.cli.settings.moveSettings
import org.move.lang.MoveParserDefinition
import org.move.utils.tests.CompilerV2
import org.move.utils.tests.EnableResourceAccessControl
import org.move.utils.tests.base.TestCase
import org.move.utils.tests.findAnnotationInstance

Expand All @@ -21,9 +21,9 @@ abstract class MvParsingTestCase(@NonNls dataPath: String) : ParsingTestCase(

project.registerService(MvProjectSettingsService::class.java)

val isCompilerV2 = this.findAnnotationInstance<CompilerV2>() != null
val isResourceAccess = this.findAnnotationInstance<EnableResourceAccessControl>() != null
project.moveSettings.modifyTemporary(testRootDisposable) {
it.isCompilerV2 = isCompilerV2
it.enableResourceAccessControl = isResourceAccess
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import org.move.cli.settings.moveSettings
import org.move.lang.core.psi.MvFunction
import org.move.lang.core.psi.MvModule
import org.move.openapiext.toPsiDirectory
import org.move.utils.tests.CompilerV2
import org.move.utils.tests.RunConfigurationProducerTestBase

class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("test") {
Expand Down Expand Up @@ -296,7 +295,6 @@ class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("te
checkOnFsItem(mainFile)
}

@CompilerV2
fun `test test run for compiler v2 without cli flag`() {
testProject {
namedMoveToml("MyPackage")
Expand Down Expand Up @@ -324,7 +322,6 @@ class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("te
checkOnElement<MvFunction>()
}

@CompilerV2
fun `test test run for compiler v2`() {
testProject {
namedMoveToml("MyPackage")
Expand All @@ -348,7 +345,7 @@ class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("te
}
project.moveSettings.modifyTemporary(this.testRootDisposable) {
it.skipFetchLatestGitDeps = false
it.addCompilerV2Flags = true
it.addCompilerV2CLIFlags = true
}
checkOnElement<MvFunction>()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.move.ide.annotator

import org.move.ide.colors.MvColor
import org.move.utils.tests.CompilerV2
import org.move.utils.tests.EnableResourceAccessControl
import org.move.utils.tests.annotation.AnnotatorTestCase

class HighlightingAnnotatorTest : AnnotatorTestCase(HighlightingAnnotator::class) {
Expand Down Expand Up @@ -301,7 +301,7 @@ class HighlightingAnnotatorTest : AnnotatorTestCase(HighlightingAnnotator::class
}
""")

@CompilerV2
@EnableResourceAccessControl
fun `test resource access control keywords highlighting`() = checkHighlighting("""
module 0x1::m {
fun f_multiple() <KEYWORD>reads</KEYWORD> R <KEYWORD>writes</KEYWORD> T, S <KEYWORD>reads</KEYWORD> G<u64> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package org.move.ide.hints

import com.intellij.codeInsight.daemon.impl.HintRenderer
import org.intellij.lang.annotations.Language
import org.move.utils.tests.CompilerV2
import org.move.utils.tests.MvTestBase

class InlayParameterHintsTest : MvTestBase() {
class InlayParameterHintsTest: MvTestBase() {
fun `test fun`() = checkByText(
"""
module 0x1::M {
Expand Down Expand Up @@ -62,7 +61,6 @@ class InlayParameterHintsTest : MvTestBase() {
"""
)

@CompilerV2
fun `test receiver style fun`() = checkByText(
"""
module 0x1::m {
Expand Down
Loading

0 comments on commit df74500

Please sign in to comment.