-
Notifications
You must be signed in to change notification settings - Fork 24
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: copy structures implementation [fixes LNG-102] #646
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
654c96c
parser for copy and tests
DieMyst c997194
raw for copy
DieMyst 9ba791b
Merge remote-tracking branch 'origin/main' into LNG-102_copy_structs
DieMyst 13e0ba0
copy implementation with debug info
DieMyst 146c771
Merge remote-tracking branch 'origin/main' into LNG-102_copy_structs
DieMyst 1175888
rewrite properties inliner
DieMyst d3eabc9
use test branch
DieMyst 06979b2
fix unit tests
DieMyst 335efc2
fix PR
DieMyst d59be64
fix e2e
DieMyst 28d8471
fix literal properties
DieMyst 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
There are no files selected for viewing
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
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
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
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
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
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
59 changes: 59 additions & 0 deletions
59
model/inline/src/main/scala/aqua/model/inline/raw/ApplyIntoCopyRawInliner.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package aqua.model.inline.raw | ||
|
||
import aqua.model.{CallModel, CallServiceModel, LiteralModel, OpModel, SeqModel, ValueModel, VarModel} | ||
import aqua.model.inline.{Inline, SeqMode} | ||
import aqua.model.inline.MakeStructRawInliner.createObj | ||
import aqua.model.inline.RawValueInliner.unfold | ||
import aqua.model.inline.state.{Arrows, Exports, Mangler} | ||
import aqua.raw.value.{IntoCopyRaw, LiteralRaw} | ||
import aqua.types.ScalarType | ||
import cats.data.{Chain, NonEmptyMap, State} | ||
import scribe.Logging | ||
import cats.syntax.traverse.* | ||
import cats.syntax.monoid.* | ||
import cats.syntax.functor.* | ||
import cats.syntax.flatMap.* | ||
import cats.syntax.apply.* | ||
|
||
object ApplyIntoCopyRawInliner extends Logging { | ||
|
||
private def copyObj(value: VarModel, fields: NonEmptyMap[String, ValueModel], result: VarModel): OpModel.Tree = { | ||
val args = fields.toSortedMap.toList.flatMap { case (name, value) => | ||
LiteralModel.fromRaw(LiteralRaw.quote(name)) :: value :: Nil | ||
} | ||
CallServiceModel( | ||
LiteralModel("\"json\"", ScalarType.string), | ||
"puts", | ||
CallModel( | ||
value +: args, | ||
CallModel.Export(result.name, result.`type`) :: Nil | ||
) | ||
).leaf | ||
} | ||
|
||
def apply[S: Mangler: Exports: Arrows]( | ||
value: VarModel, intoCopy: IntoCopyRaw | ||
): State[S, (VarModel, Inline)] = { | ||
value match { | ||
case v @ VarModel(name, _, _) => | ||
for { | ||
name <- Mangler[S].findAndForbidName(name + "_obj_copy") | ||
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.
|
||
foldedFields <- intoCopy.fields.nonEmptyTraverse(unfold(_)) | ||
} yield { | ||
val varModel = VarModel(name, v.baseType) | ||
val valsInline = foldedFields.toSortedMap.values.map(_._2).fold(Inline.empty)(_ |+| _) | ||
val fields = foldedFields.map(_._1) | ||
val objCreation = copyObj(v, fields, varModel) | ||
( | ||
varModel, | ||
Inline( | ||
valsInline.flattenValues, | ||
Chain.one(SeqModel.wrap((valsInline.predo :+ objCreation).toList: _*)), | ||
SeqMode | ||
) | ||
) | ||
} | ||
} | ||
|
||
} | ||
} |
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.
Why
ListMap
? Comment plz