-
Notifications
You must be signed in to change notification settings - Fork 1
Sai/acc syntax addition #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheDeveloper101
wants to merge
9
commits into
main
Choose a base branch
from
sai/acc-syntax-addition
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5bf88bd
first attempt at introducing acc syntax to front-end. it is currently…
TheDeveloper101 771a81c
fix test
TheDeveloper101 8248560
getting a NotImplemented error for some reason, need to do more debug…
TheDeveloper101 9b94597
working on acc precondition syntax. determined error to be with Field…
TheDeveloper101 0e4fd56
fixed issue with FieldAccess, however facing issues with name mangler
TheDeveloper101 b0e631a
fixed the acc syntax addition based on suggestions
TheDeveloper101 24be2c7
cleaned up unused imports and added better error handling. also start…
TheDeveloper101 96d2412
Permission in `acc` is now optional. Default is full permission
The-Ray-Man a43939b
Change the order of receiver and field to match similar embeddings
The-Ray-Man File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,30 +6,66 @@ | |
| package org.jetbrains.kotlin.formver.core.conversion | ||
|
|
||
| import org.jetbrains.kotlin.fir.FirLabel | ||
| import org.jetbrains.kotlin.fir.containingClassLookupTag | ||
| import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction | ||
| import org.jetbrains.kotlin.fir.declarations.FirValueParameter | ||
| import org.jetbrains.kotlin.fir.declarations.hasAnnotation | ||
| import org.jetbrains.kotlin.fir.declarations.utils.isFinal | ||
| import org.jetbrains.kotlin.fir.expressions.* | ||
| import org.jetbrains.kotlin.fir.references.symbol | ||
| import org.jetbrains.kotlin.fir.symbols.impl.* | ||
| import org.jetbrains.kotlin.fir.types.ConeCapturedType | ||
| import org.jetbrains.kotlin.fir.types.ConeDefinitelyNotNullType | ||
| import org.jetbrains.kotlin.fir.types.ConeFlexibleType | ||
| import org.jetbrains.kotlin.fir.types.ConeIntegerConstantOperatorType | ||
| import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralConstantType | ||
| import org.jetbrains.kotlin.fir.types.ConeIntersectionType | ||
| import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType | ||
| import org.jetbrains.kotlin.fir.types.ConeStubTypeForTypeVariableInSubtyping | ||
| import org.jetbrains.kotlin.fir.types.ConeTypeVariableType | ||
| import org.jetbrains.kotlin.fir.types.classId | ||
| import org.jetbrains.kotlin.fir.types.isBoolean | ||
| import org.jetbrains.kotlin.fir.types.isMarkedNullable | ||
| import org.jetbrains.kotlin.fir.types.isMarkedOrFlexiblyNullable | ||
| import org.jetbrains.kotlin.fir.types.lowerBoundIfFlexible | ||
| import org.jetbrains.kotlin.fir.types.resolvedType | ||
| import org.jetbrains.kotlin.fir.types.withNullability | ||
| import org.jetbrains.kotlin.formver.common.SnaktInternalException | ||
| import org.jetbrains.kotlin.formver.core.embeddings.FunctionBodyEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.LabelEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.callables.FullNamedFunctionSignature | ||
| import org.jetbrains.kotlin.formver.core.embeddings.callables.FunctionSignature | ||
| import org.jetbrains.kotlin.formver.core.embeddings.expression.* | ||
| import org.jetbrains.kotlin.formver.core.embeddings.properties.BackingFieldGetter | ||
| import org.jetbrains.kotlin.formver.core.embeddings.properties.ClassPropertyAccess | ||
| import org.jetbrains.kotlin.formver.core.embeddings.properties.FieldEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.properties.PropertyAccessEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.properties.UserFieldEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.properties.asPropertyAccess | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.AnyTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.BooleanTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.CharTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.ClassTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.IntTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.NothingTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.PretypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.StringTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.TypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.TypeEmbeddingFlags | ||
| import org.jetbrains.kotlin.formver.core.embeddings.types.UnitTypeEmbedding | ||
| import org.jetbrains.kotlin.formver.core.isCustom | ||
| import org.jetbrains.kotlin.formver.core.isInvariantBuilderFunctionNamed | ||
| import org.jetbrains.kotlin.formver.core.linearization.* | ||
| import org.jetbrains.kotlin.formver.core.names.ScopedKotlinName | ||
| import org.jetbrains.kotlin.formver.core.names.embedMemberPropertyName | ||
| import org.jetbrains.kotlin.formver.core.names.embedName | ||
| import org.jetbrains.kotlin.formver.core.purity.checkValidity | ||
| import org.jetbrains.kotlin.formver.core.purity.isPure | ||
| import org.jetbrains.kotlin.formver.viper.SymbolicName | ||
| import org.jetbrains.kotlin.formver.viper.ast.Exp | ||
| import org.jetbrains.kotlin.formver.viper.ast.PermExp | ||
| import org.jetbrains.kotlin.name.StandardClassIds | ||
| import org.jetbrains.kotlin.text | ||
| import org.jetbrains.kotlin.utils.addIfNotNull | ||
| import org.jetbrains.kotlin.utils.addToStdlib.ifTrue | ||
| import org.jetbrains.kotlin.utils.filterIsInstanceAnd | ||
TheDeveloper101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
@@ -235,6 +271,27 @@ fun StmtConversionContext.insertForAllFunctionCall( | |
| } | ||
| } | ||
|
|
||
| fun StmtConversionContext.insertAccFunctionCall( | ||
| field: FirPropertyAccessExpression, | ||
| perm: FirExpression, | ||
| ): ExpEmbedding { | ||
| val symbol = field.calleeReference.symbol as? FirPropertySymbol ?: throw SnaktInternalException( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could remove the |
||
| field.source, | ||
| "acc requires a property access like x.a" | ||
| ) | ||
| val fieldAccess = embedPropertyAccess(field) | ||
| val field = ((fieldAccess as ClassPropertyAccess).property.getter as BackingFieldGetter).field | ||
TheDeveloper101 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| val receiver = fieldAccess.receiver | ||
| val permExp = when(perm.source.text.toString()) { | ||
| "write" -> PermExp.WildcardPerm() | ||
| "read" -> PermExp.FullPerm() | ||
| else -> throw SnaktInternalException(symbol.source, "perm is not supported") | ||
| } | ||
| return withNoScope { | ||
| AccEmbedding(field, receiver, permExp) | ||
| } | ||
| } | ||
|
|
||
| fun StmtConversionContext.convertMethodWithBody( | ||
| declaration: FirSimpleFunction, | ||
| signature: FullNamedFunctionSignature, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ver.compiler-plugin/testData/diagnostics/conversion/classes/acc_precondition.fir.diag.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /acc_precondition.kt:(127,148): info: Generated Viper text for test_acc_precondition: | ||
| field bf$a: Ref | ||
|
|
||
| predicate p$c$X$shared(this$dispatch: Ref) { | ||
| true | ||
| } | ||
|
|
||
| predicate p$c$X$unique(this$dispatch: Ref) { | ||
| acc(this$dispatch.bf$a, write) && | ||
| df$rt$isSubtype(df$rt$typeOf(this$dispatch.bf$a), df$rt$anyType()) | ||
| } | ||
|
|
||
| predicate p$pkg$org_jetbrains_kotlin_formver_plugin$c$InvariantBuilder$shared(this$dispatch: Ref) { | ||
| true | ||
| } | ||
|
|
||
| predicate p$pkg$org_jetbrains_kotlin_formver_plugin$c$InvariantBuilder$unique(this$dispatch: Ref) { | ||
| true | ||
| } | ||
|
|
||
| method f$test_acc_precondition$TF$T$X(p$x: Ref) returns (ret$0: Ref) | ||
| requires acc(p$x.bf$a, wildcard) | ||
| ensures df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$unitType()) | ||
| { | ||
| inhale df$rt$isSubtype(df$rt$typeOf(p$x), df$rt$c$X()) | ||
| inhale acc(p$c$X$shared(p$x), wildcard) | ||
| p$x.bf$a := df$rt$intToRef(123) | ||
| label lbl$ret$0 | ||
| inhale df$rt$isSubtype(df$rt$typeOf(ret$0), df$rt$unitType()) | ||
| } | ||
|
|
||
| method pg$public$read(this$dispatch: Ref) returns (ret: Ref) | ||
|
|
||
|
|
||
| method pg$public$write(this$dispatch: Ref) returns (ret: Ref) | ||
|
|
10 changes: 10 additions & 0 deletions
10
formver.compiler-plugin/testData/diagnostics/conversion/classes/acc_precondition.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // RENDER_PREDICATES | ||
| // NEVER_VALIDATE | ||
|
|
||
| import org.jetbrains.kotlin.formver.plugin.* | ||
|
|
||
| class X(@property:Manual var a: Any) | ||
| fun <!VIPER_TEXT!>test_acc_precondition<!>(x: X) { | ||
| preconditions { acc(x.a, write) } | ||
| x.a = 123 | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not yet work with the
Builtinslogic yet, but I do not understand why we have thereadandwrite?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was because we wanted to be able to embed the read and write parameters, so we needed to add them to the builtins since they’re not functions