Skip to content
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

[SIL] Add cloneModule #39093

Closed
wants to merge 1 commit into from
Closed

Conversation

justinfargnoli
Copy link

This PR adds the cloneModule() function to SILCloner. cloneModule() returns a deep copy of the originalModule SILModule. The implementation is modeled after llvm::CloneModule().

I wrote this as part of my Alive2 for SIL GSoC project. I'm submitting the PR in case the functionality will be useful to others. An important part of the review process will be deciding if it will in fact be useful to others.

@CodaFi could you review this?

@CodaFi CodaFi requested review from gottesmm and atrick August 29, 2021 23:38
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for posting this.

I can't make a good argument to keep it the source base without an active use case. But I also don't see the harm in having it in tree as long as there's at least one artificial test case to make sure it's still working. We definitely don't want to keep code in tree that might be stale.

@@ -0,0 +1,107 @@
//===--- SILCloner.h - Defines the SILCloner class --------------*- C++ -*-===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file comment needs to be update with the correct filename and date.


// copy the \c SILGlobalVariable initializers
// Is this even needed? I'm unsure how to generate a program that uses
// a global variables static initalizer. I would assume `let x = 1` would
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do anything in the initializer other than assign a constant value, it should be generated and lazily invoked. There are test/SILOptimizer/global_init & globalopt tests for this.

@@ -490,6 +490,8 @@ class SILFunctionCloner : public SILClonerWithScopes<SILFunctionCloner> {
}
};

std::unique_ptr<SILModule> cloneModule(SILModule &originalModule);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cloning modify the original SILModule or is there some sharing going on (i.e. is this not a deep copy)? I would've expected originalModule to be const SILModule & and not SILModule &.

Comment on lines +26 to +28
assert((originalModule.getStage() != SILStage::Canonical ||
originalModule.getStage() != SILStage::Lowered) &&
"cloneModule doesn't support SILStage::Lowered.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this assertion condition is always going to be true, and the assertion string is out-of-sync from the condition. Could you clarify what is intended to be checked here?

@justinfargnoli
Copy link
Author

Unfortunately, I don't think I'll be able to follow up on this PR, so I'm going to close it. Thanks to @atrick and @varungandhi-apple for your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants