-
Notifications
You must be signed in to change notification settings - Fork 118
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
feat: program.pkg Module to Arc<Module> #1715
Draft
He1pa
wants to merge
1
commit into
kcl-lang:main
Choose a base branch
from
He1pa:arc_module
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.
Draft
+115
−47
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
…<Arc<Module>>> . Reduce the performance loss of module ast clone Signed-off-by: he1pa <[email protected]>
Peefy
reviewed
Oct 24, 2024
@@ -233,7 +233,11 @@ impl<'ctx> TypedResultWalker<'ctx> for Evaluator<'ctx> { | |||
if let Some(modules) = self.program.pkgs.get(&import_stmt.path.node) { | |||
self.push_pkgpath(&pkgpath); | |||
self.init_scope(&pkgpath); | |||
self.compile_ast_modules(modules); | |||
let modules: Vec<Module> = modules |
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.
There's still deep clone here. :(
Peefy
reviewed
Oct 24, 2024
@@ -209,7 +211,7 @@ pub fn validate(val_opt: ValidateOption) -> Result<bool> { | |||
match compile_res.program.pkgs.get_mut(kclvm_ast::MAIN_PKG) { | |||
Some(pkg) => { | |||
if let Some(module) = pkg.first_mut() { | |||
module.body.insert(0, assign_stmt); | |||
Arc::make_mut(module).body.insert(0, assign_stmt); |
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.
Arc::make_mut
may lead to potential deep copies, consider using Arc<Mutex<Module>>
Makes a mutable reference into the given Arc.
If there are other Arc pointers to the same allocation, then make_mut will [clone] the inner value to a new allocation to ensure unique ownership. This is also referred to as clone-on-write.
However, if there are no other Arc pointers to this allocation, but some [Weak](vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.esm.html) pointers, then the [Weak](vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.esm.html) pointers will be dissociated and the inner value will not be cloned.
See also [get_mut], which will fail rather than cloning the inner value or dissociating [Weak](vscode-file://vscode-app/Applications/Visual%20Studio%20Code.app/Contents/Resources/app/out/vs/code/electron-sandbox/workbench/workbench.esm.html) pointers.
Pull Request Test Coverage Report for Build 11497068535Details
💛 - Coveralls |
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.
program.pkg HashMap<String, Vec> -> HashMap<String, Vec<Arc>> .
Reduce the performance loss of module ast clone
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):