diff --git a/src/main/grammars/MoveParser.bnf b/src/main/grammars/MoveParser.bnf index d6d3a647e..2fc89601a 100644 --- a/src/main/grammars/MoveParser.bnf +++ b/src/main/grammars/MoveParser.bnf @@ -459,7 +459,7 @@ private ReturnTypeItem_with_recover ::= Type } private ReturnTypeItem_recover ::= !( '{' | ';' | acquires | reads | writes | pure | '!' ) -ResourceAccessItemList ::= <> ResourceAccessItem* +ResourceAccessItemList ::= <> ResourceAccessItem* ResourceAccessItem ::= pure | (('!')? (acquires | reads | writes) AccessSpecifierList) AccessSpecifierList ::= <> diff --git a/src/main/kotlin/org/move/cli/runConfigurations/aptos/Aptos.kt b/src/main/kotlin/org/move/cli/runConfigurations/aptos/Aptos.kt index 4637fc406..9adb4178e 100644 --- a/src/main/kotlin/org/move/cli/runConfigurations/aptos/Aptos.kt +++ b/src/main/kotlin/org/move/cli/runConfigurations/aptos/Aptos.kt @@ -226,7 +226,7 @@ data class AptosCompileArgs( workingDirectory, additionalArguments, enviroment, - addCompilerV2Flags = moveSettings.addCompilerV2FlagsToCLI, + addCompilerV2Flags = moveSettings.addCompilerV2CLIFlags, skipLatestGitDeps = moveSettings.skipFetchLatestGitDeps ) } diff --git a/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducerBase.kt b/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducerBase.kt index c53c3d0a5..9f25686a3 100644 --- a/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducerBase.kt +++ b/src/main/kotlin/org/move/cli/runConfigurations/producers/TestCommandConfigurationProducerBase.kt @@ -123,7 +123,7 @@ abstract class TestCommandConfigurationProducerBase: private fun initEnvironmentVariables(project: Project): EnvironmentVariablesData { val environmentMap = linkedMapOf() - if (project.moveSettings.addCompilerV2FlagsToCLI) { + if (project.moveSettings.addCompilerV2CLIFlags) { environmentMap[Consts.MOVE_COMPILER_V2_ENV] = "true" } return EnvironmentVariablesData.create(environmentMap, true) @@ -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") } } diff --git a/src/main/kotlin/org/move/cli/settings/MvProjectSettingsService.kt b/src/main/kotlin/org/move/cli/settings/MvProjectSettingsService.kt index 5f0124cd8..1d02a295c 100644 --- a/src/main/kotlin/org/move/cli/settings/MvProjectSettingsService.kt +++ b/src/main/kotlin/org/move/cli/settings/MvProjectSettingsService.kt @@ -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() { @@ -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) @@ -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() diff --git a/src/main/kotlin/org/move/cli/settings/PerProjectAptosConfigurable.kt b/src/main/kotlin/org/move/cli/settings/PerProjectAptosConfigurable.kt index ce6eafa96..7e0f097af 100644 --- a/src/main/kotlin/org/move/cli/settings/PerProjectAptosConfigurable.kt +++ b/src/main/kotlin/org/move/cli/settings/PerProjectAptosConfigurable.kt @@ -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 @@ -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() } .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 " + + "(reads, writes, pure 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") { @@ -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 } } diff --git a/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt b/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt index 10d3041fe..8e07aee97 100644 --- a/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt +++ b/src/main/kotlin/org/move/lang/core/MoveParserUtil.kt @@ -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 @@ -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 { diff --git a/src/main/kotlin/org/move/lang/core/completion/KeywordCompletionContributor.kt b/src/main/kotlin/org/move/lang/core/completion/KeywordCompletionContributor.kt index 9c5dff615..6eeba0245 100644 --- a/src/main/kotlin/org/move/lang/core/completion/KeywordCompletionContributor.kt +++ b/src/main/kotlin/org/move/lang/core/completion/KeywordCompletionContributor.kt @@ -130,7 +130,7 @@ class KeywordCompletionContributor: CompletionContributor() { KeywordCompletionProvider { buildList { add("acquires") - if (it.moveSettings.isCompilerV2) { + if (it.moveSettings.enableResourceAccessControl) { addAll(listOf("reads", "writes", "pure")) } } diff --git a/src/main/kotlin/org/move/utils/tests/MvLightTestBase.kt b/src/main/kotlin/org/move/utils/tests/MvLightTestBase.kt index 7fffc7140..c1888e198 100644 --- a/src/main/kotlin/org/move/utils/tests/MvLightTestBase.kt +++ b/src/main/kotlin/org/move/utils/tests/MvLightTestBase.kt @@ -10,9 +10,9 @@ abstract class MvLightTestBase: BasePlatformTestCase() { val isDebugMode = this.findAnnotationInstance()?.enabled ?: true setRegistryKey("org.move.debug.enabled", isDebugMode) - val isCompilerV2 = this.findAnnotationInstance() != null + val isResourceAccess = this.findAnnotationInstance() != null project.moveSettings.modifyTemporary(testRootDisposable) { - it.isCompilerV2 = isCompilerV2 + it.enableResourceAccessControl = isResourceAccess } } } \ No newline at end of file diff --git a/src/main/kotlin/org/move/utils/tests/MvProjectTestBase.kt b/src/main/kotlin/org/move/utils/tests/MvProjectTestBase.kt index de3c53508..acca660c1 100644 --- a/src/main/kotlin/org/move/utils/tests/MvProjectTestBase.kt +++ b/src/main/kotlin/org/move/utils/tests/MvProjectTestBase.kt @@ -34,10 +34,10 @@ abstract class MvProjectTestBase: CodeInsightFixtureTestCase()?.enabled ?: true setRegistryKey("org.move.debug.enabled", isDebugMode) - val isCompilerV2 = this.findAnnotationInstance() != null + val isResourceAccess = this.findAnnotationInstance() != null // triggers projects refresh project.moveSettings.modify { - it.isCompilerV2 = isCompilerV2 + it.enableResourceAccessControl = isResourceAccess } } diff --git a/src/main/kotlin/org/move/utils/tests/MvTestBase.kt b/src/main/kotlin/org/move/utils/tests/MvTestBase.kt index e7b57b3e4..753a118bf 100644 --- a/src/main/kotlin/org/move/utils/tests/MvTestBase.kt +++ b/src/main/kotlin/org/move/utils/tests/MvTestBase.kt @@ -29,7 +29,7 @@ annotation class WithEnabledInspections(vararg val inspections: KClass() != null + val isResourceAccess = this.findAnnotationInstance() != null project.moveSettings.modifyTemporary(testRootDisposable) { - it.isCompilerV2 = isCompilerV2 + it.enableResourceAccessControl = isResourceAccess } } diff --git a/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt b/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt index 13332d65e..107d7841a 100644 --- a/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt +++ b/src/test/kotlin/org/move/cli/runConfigurations/TestCommandConfigurationProducerTest.kt @@ -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") { @@ -296,7 +295,6 @@ class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("te checkOnFsItem(mainFile) } - @CompilerV2 fun `test test run for compiler v2 without cli flag`() { testProject { namedMoveToml("MyPackage") @@ -324,7 +322,6 @@ class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("te checkOnElement() } - @CompilerV2 fun `test test run for compiler v2`() { testProject { namedMoveToml("MyPackage") @@ -348,7 +345,7 @@ class TestCommandConfigurationProducerTest: RunConfigurationProducerTestBase("te } project.moveSettings.modifyTemporary(this.testRootDisposable) { it.skipFetchLatestGitDeps = false - it.addCompilerV2Flags = true + it.addCompilerV2CLIFlags = true } checkOnElement() } diff --git a/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt b/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt index f327a4c1f..ce90d8ccd 100644 --- a/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt +++ b/src/test/kotlin/org/move/ide/annotator/HighlightingAnnotatorTest.kt @@ -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) { @@ -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() reads R writes T, S reads G {} diff --git a/src/test/kotlin/org/move/ide/hints/InlayParameterHintsTest.kt b/src/test/kotlin/org/move/ide/hints/InlayParameterHintsTest.kt index 4e14ccf77..5be3723c0 100644 --- a/src/test/kotlin/org/move/ide/hints/InlayParameterHintsTest.kt +++ b/src/test/kotlin/org/move/ide/hints/InlayParameterHintsTest.kt @@ -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 { @@ -62,7 +61,6 @@ class InlayParameterHintsTest : MvTestBase() { """ ) - @CompilerV2 fun `test receiver style fun`() = checkByText( """ module 0x1::m { diff --git a/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt b/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt index 658466ead..7905a1328 100644 --- a/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt +++ b/src/test/kotlin/org/move/ide/hints/ParameterInfoHandlerTest.kt @@ -1,78 +1,96 @@ package org.move.ide.hints import org.move.lang.core.psi.MvValueArgumentList -import org.move.utils.tests.CompilerV2 import org.move.utils.tests.ParameterInfoHandlerTestCase class ParameterInfoHandlerTest : ParameterInfoHandlerTestCase(FunctionParameterInfoHandler()) { - fun `test fun no args`() = checkByText(""" + fun `test fun no args`() = checkByText( + """ module M { fun foo() {} fun main() { foo(/*caret*/); } } - """, "", 0) + """, "", 0 + ) - fun `test fun no args before args`() = checkByText(""" + fun `test fun no args before args`() = checkByText( + """ module M { fun foo() {} fun main() { foo/*caret*/(); } } - """, "", -1) + """, "", -1 + ) - fun `test fun one arg`() = checkByText(""" + fun `test fun one arg`() = checkByText( + """ module M { fun foo(arg: u8) {} fun main() { foo(/*caret*/); } } - """, "arg: u8", 0) + """, "arg: u8", 0 + ) - fun `test fun one arg end`() = checkByText(""" + fun `test fun one arg end`() = checkByText( + """ module M { fun foo(arg: u8) {} fun main() { foo(42/*caret*/); } } - """, "arg: u8", 0) + """, "arg: u8", 0 + ) - fun `test fun many args`() = checkByText(""" + fun `test fun many args`() = checkByText( + """ module M { fun foo(arg: u8, s: &signer, v: vector) {} fun main() { foo(/*caret*/); } } - """, "arg: u8, s: &signer, v: vector", 0) + """, "arg: u8, s: &signer, v: vector", 0 + ) - fun `test fun many args vector u8`() = checkByText(""" + fun `test fun many args vector u8`() = checkByText( + """ module 0x1::M { fun call(a: u8, b: vector, c: vector) {} fun m() { call(1, b"11", b"22"/*caret*/); } } - """, "a: u8, b: vector, c: vector", 2) + """, "a: u8, b: vector, c: vector", 2 + ) - fun `test fun poorly formatted args`() = checkByText(""" + fun `test fun poorly formatted args`() = checkByText( + """ module M { fun foo(arg: u8, s: &signer, v : vector) {} fun main() { foo(/*caret*/); } } - """, "arg: u8, s: &signer, v: vector", 0) + """, "arg: u8, s: &signer, v: vector", 0 + ) - fun `test fun args index 0`() = checkByText(""" + fun `test fun args index 0`() = checkByText( + """ module M { fun foo(val1: u8, val2: u8) {} fun main() { foo(42/*caret*/); } } - """, "val1: u8, val2: u8", 0) + """, "val1: u8, val2: u8", 0 + ) - fun `test fun args index 1`() = checkByText(""" + fun `test fun args index 1`() = checkByText( + """ module M { fun foo(val1: u8, val2: u8) {} fun main() { foo(42, 10/*caret*/); } } - """, "val1: u8, val2: u8", 1) + """, "val1: u8, val2: u8", 1 + ) - fun `test multiline call`() = checkByText(""" + fun `test multiline call`() = checkByText( + """ module M { fun foo(val1: u8, val2: u8) {} fun main() { @@ -82,17 +100,21 @@ class ParameterInfoHandlerTest ); } } - """, "val1: u8, val2: u8", 0) + """, "val1: u8, val2: u8", 0 + ) - fun `test builtin function`() = checkByText(""" + fun `test builtin function`() = checkByText( + """ module M { fun main() { borrow_global(/*caret*/); } } - """, "addr: address", 0) + """, "addr: address", 0 + ) - fun `test aliased function`() = checkByText(""" + fun `test aliased function`() = checkByText( + """ module 0x1::string { public fun call(addr: address) {} } @@ -102,13 +124,16 @@ class ParameterInfoHandlerTest mycall(/*caret*/); } } - """, "addr: address", 0) + """, "addr: address", 0 + ) - fun `test not applied within declaration`() = checkByText(""" + fun `test not applied within declaration`() = checkByText( + """ module M { fun foo(val1/*caret*/: u8, val2: u8) {} } - """, "", -1) + """, "", -1 + ) fun `test fun incomplete args index 1`() = checkByText( """ @@ -116,7 +141,8 @@ class ParameterInfoHandlerTest fun call(val1: u8, val2: u8) {} fun main() { call(42, /*caret*/); } } - """, "val1: u8, val2: u8", 1) + """, "val1: u8, val2: u8", 1 + ) fun `test fun incomplete args index 2`() = checkByText( """ @@ -124,9 +150,9 @@ class ParameterInfoHandlerTest fun call(val1: u8, val2: u8, val3: u8) {} fun main() { call(42, 10, /*caret*/); } } - """, "val1: u8, val2: u8, val3: u8", 2) + """, "val1: u8, val2: u8, val3: u8", 2 + ) - @CompilerV2 fun `test receiver style fun`() = checkByText( """ module 0x1::m { @@ -136,5 +162,6 @@ class ParameterInfoHandlerTest s.get_val(/*caret*/); } } - """, "modifier: bool", 0) + """, "modifier: bool", 0 + ) } diff --git a/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt b/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt index 923510d16..2525728dd 100644 --- a/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt +++ b/src/test/kotlin/org/move/lang/completion/KeywordCompletionTest.kt @@ -1,6 +1,6 @@ package org.move.lang.completion -import org.move.utils.tests.CompilerV2 +import org.move.utils.tests.EnableResourceAccessControl import org.move.utils.tests.completion.CompletionTestCase class KeywordCompletionTest : CompletionTestCase() { @@ -617,7 +617,7 @@ class KeywordCompletionTest : CompletionTestCase() { """ ) - @CompilerV2 + @EnableResourceAccessControl fun `test completion for resource access modifiers`() = checkContainsCompletion( listOf("reads", "writes", "pure", "acquires"), """ diff --git a/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt b/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt index 4a0f9f02b..09dd9af41 100644 --- a/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt +++ b/src/test/kotlin/org/move/lang/parser/CompleteParsingTest.kt @@ -1,6 +1,6 @@ package org.move.lang.parser -import org.move.utils.tests.CompilerV2 +import org.move.utils.tests.EnableResourceAccessControl import org.move.utils.tests.parser.MvParsingTestCase class CompleteParsingTest : MvParsingTestCase("complete") { @@ -43,7 +43,7 @@ class CompleteParsingTest : MvParsingTestCase("complete") { fun `test macros`() = doTest() fun `test loops`() = doTest() - @CompilerV2 + @EnableResourceAccessControl fun `test access control`() = doTest() fun doTest() { diff --git a/src/test/kotlin/org/move/lang/resolve/ResolveResourceAccessSpecifiersTest.kt b/src/test/kotlin/org/move/lang/resolve/ResolveResourceAccessSpecifiersTest.kt index 1b7b2f466..3af3bfd33 100644 --- a/src/test/kotlin/org/move/lang/resolve/ResolveResourceAccessSpecifiersTest.kt +++ b/src/test/kotlin/org/move/lang/resolve/ResolveResourceAccessSpecifiersTest.kt @@ -1,9 +1,9 @@ package org.move.lang.resolve -import org.move.utils.tests.CompilerV2 +import org.move.utils.tests.EnableResourceAccessControl import org.move.utils.tests.resolve.ResolveTestCase -@CompilerV2 +@EnableResourceAccessControl class ResolveResourceAccessSpecifiersTest: ResolveTestCase() { fun `test resolve type for reads`() = checkByCode(""" module 0x1::main {