-
Notifications
You must be signed in to change notification settings - Fork 139
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
[Compiler] Support inherited functions and conditions through delegation #3734
Open
SupunS
wants to merge
17
commits into
feature/compiler
Choose a base branch
from
supun/generate-code-for-interfaces
base: feature/compiler
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.
Conversation
This file contains 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
SupunS
force-pushed
the
supun/generate-code-for-interfaces
branch
from
January 24, 2025 16:02
269e3d6
to
2a13f25
Compare
SupunS
changed the base branch from
supun/improve-copied-code-compilation
to
feature/compiler
January 24, 2025 16:09
SupunS
changed the title
[Compiler+VM POC] Generate code for interfaces separately
[Compiler+VM POC] Support inherited functions and conditions through delegation
Jan 24, 2025
…into supun/generate-code-for-interfaces
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:feature/compiler commit 4703a34 Collapsed results for better readability
|
SupunS
force-pushed
the
supun/generate-code-for-interfaces
branch
from
January 24, 2025 16:29
aed29ca
to
5ded59f
Compare
…into supun/generate-code-for-interfaces
SupunS
changed the title
[Compiler+VM POC] Support inherited functions and conditions through delegation
[Compiler] Support inherited functions and conditions through delegation
Jan 24, 2025
SupunS
force-pushed
the
supun/generate-code-for-interfaces
branch
from
January 24, 2025 19:55
5c1c4c0
to
47355ef
Compare
SupunS
force-pushed
the
supun/generate-code-for-interfaces
branch
from
January 24, 2025 19:58
47355ef
to
b0570bb
Compare
Out of curiosity. Why not like this ? struct interface A {
access(all) fun test(_ a: Int): Int {}
// condition gets extracted out as a function
access(all) view fun $A.test.preConditions(_ a: Int): Void {
if !(a > 10) {
panic("a must be larger than 10")
}
return
}
}
struct interface B: A {
access(all) fun test(_ a: Int): Int {}
access(all) view fun $B.test.preConditions(_ a: Int): Void {
parent.$A.test.preConditions(a)
}
}
struct C: B {
fun test(_ a: Int): Int {
parent.$B.test.preConditions(a) // calls into the inherited pre-condition function (a static function invocation)
return a + 3
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR also includes the changes added in #3727, #3728, #3729, #3731. i.e: Builds on top of the foundation of those previous PRs.
Description
Generate code for interfaces separately, and avoids copying over the code for default functions and inherited function pre/post conditions.
Default functions
Instead, injects a delegator function, which would call into the interface's default method.
becomes:
Function conditions
A function condition that is defined in an interface method gets extracted out to a separate method. Then any implementation would call into this generated/synthetic function as part of their pre/post conditions.
e.g:
becomes
TODO:
master
branchFiles changed
in the Github PR explorer