Comments (12)
Hi @basert, We don't have a flag in Scrooge to generate scala.collection.immutable.Seq
from Thrift files. You are welcome to make a PR for this. Internally at Twitter, we haven't upgraded to Scala 2.13 yet.
The scala-collection-compat library can help with cross-building between Scala 2.12 and 2.13. https://github.com/scala/scala-collection-compat
from scrooge.
Sure, we at ESL are more than happy to contribute. Can you maybe point me to some general code guidelines?
For implementation: Should this maybe be the default behavior for Scala 2.13 or would you like to have it behind a flag to keep the current behavior.
from scrooge.
I did some more looking around and it seems basic support for immutable structures was introduced here: 2324adb#diff-addb06caaaca5169adf6c1ff3535cd24b6b3dd5447a88c7718af7aa0ee9b1fadR224
Unfortunately it only mentions for historical reasons
as comment to why it's not using collection.immutable.Seq
. Would this be the correct place to add the compiler_flag?
from scrooge.
To add another CLI flag, start in the ScroogeOptionParser and add another field to ScroogeConfig
for generating immutable Seq.
Yes, the ScalaGenerator.scala is the right place to convert ListType to scala.collection.immutable.Seq
. You can use the immutable argument in the genType method to get the immutable collection.
case ListType(x, _) =>
prefix + "Seq[" + genType(x, immutable).toData + "]"
I believe the "for historical reasons" note refers to backwards compatibility since scala.Seq[A] is an alias for scala.collection.Seq[A] in Scala 2.12.
Should this maybe be the default behavior for Scala 2.13 or would you like to have it behind a flag to keep the current behavior.
I think keeping it behind a flag to maintain the current behavior is the safer choice.
This is the Contributing.md general code guideline https://github.com/twitter/scrooge/blob/develop/CONTRIBUTING.md
Please let me know if you want more guidance navigating the Scrooge codebase.
from scrooge.
Hey, thanks for your guidance.
I did some more digging around and found the language-flags
feature. While it seems that it's currently not used anywhere, it is the perfect use for this. I implemented an initial version & added some Gold files to verify the result: #350
Please let me know if it needs some changes or if I should change it to a real scrooge option.
from scrooge.
Hey!
I was able to finish work on the pull request. It requires two changes:
- Add the mentioned
language-flag
parameter and generate immutable code - Change
TProtocols
to explicitly convert theArrayBuffer
intoSeq
type. This should be a no-op operation for Scala 2.12 and lower because they are of the same type. For Scala 2.13, this will return the immutable instance of Seq.
from scrooge.
Hi @basert , thank you for the contribution! Smart approach! Your code looks great, I especially appreciate all the new tests! To help me understand more about your change, would you mind pointing me to the language-flags
feature you mentioned? I don't think anyone is using that internally, so I wanted to understand the impact of this change, this could also help us with passing the knowledge to our internal customers. Thank you again!
from scrooge.
The language-flags
is a command line option that forwards a list of strings to the language generator. You can invoke it like this:
java -cp <full-cp> com.twitter.scrooge.Main --finagle --language-flag=immutable-sequences --language scala --dest dist --disable-strict --gen-file-map MyThrift.thrift
We are using it in pants via this buildfile alias:
java_thrift_library(
compiler='scrooge',
compiler_args=['--finagle', '--language-flag=immutable-sequences'],
language='scala',
strict_deps=True,
sources=['*.thrift'],
)
from scrooge.
Sounds great! Thank you for elaborating on it!
from scrooge.
Your change in pr#350 has merged, thank you again for your contribution!
from scrooge.
Awesome, this solved the last blocker to upgrade our monorepo to 2.13
from scrooge.
Thank you for the great work!
from scrooge.
Related Issues (20)
- Parse failure. HOT 3
- Support Scala 2.13 RC1 and beyond HOT 10
- Support i8 type HOT 2
- scrooge-sbt-plugin fails to build
- Can 'passthrough_fields' be a private field if wanted when Scrooge generates codes (sbt plugin)? HOT 1
- building linter fails - util-logging_2.12:19.10.0-Snapshot not found in Maven repo HOT 3
- Generate traits decoupled from Thrift dependencies HOT 3
- Closing of finagle-thrift client with scrooge generated service HOT 2
- Scala 2.13 version deprecation warning HOT 1
- twitter.github.io/scrooge is missing HOT 2
- com.twitter.scrooge.ast.Field.default is not callable from Java
- Interested in adding support for typescript? HOT 3
- Unavoidable "[Importer$] Expected to find just 1 match" warnings in sbt sub-project builds HOT 6
- Feature Suggestion: Custom type adapters HOT 1
- MultiImporter warnings for duplicates due to root importer HOT 1
- Add configuration choice of getting an immutable type in code generation for `bytes` thrift type HOT 1
- scrooge-generator: Update Apache Thrift `Processor.process` signature HOT 5
- Add option to generate higher-kinded-type service interface HOT 2
- Upgrading libthrift to a newer version, security vulnerabilities HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scrooge.