{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/swift/issues/233","labels_url":"https://api.github.com/repos/facebook/swift/issues/233/labels{/name}","comments_url":"https://api.github.com/repos/facebook/swift/issues/233/comments","events_url":"https://api.github.com/repos/facebook/swift/issues/233/events","html_url":"https://github.com/facebook/swift/issues/233","id":50393012,"number":233,"title":"scala collections support?","user":{"login":"stuz5000","id":7799980,"avatar_url":"https://avatars.githubusercontent.com/u/7799980?v=3","gravatar_id":"","url":"https://api.github.com/users/stuz5000","html_url":"https://github.com/stuz5000","followers_url":"https://api.github.com/users/stuz5000/followers","following_url":"https://api.github.com/users/stuz5000/following{/other_user}","gists_url":"https://api.github.com/users/stuz5000/gists{/gist_id}","starred_url":"https://api.github.com/users/stuz5000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuz5000/subscriptions","organizations_url":"https://api.github.com/users/stuz5000/orgs","repos_url":"https://api.github.com/users/stuz5000/repos","events_url":"https://api.github.com/users/stuz5000/events{/privacy}","received_events_url":"https://api.github.com/users/stuz5000/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2014-11-28T17:28:47Z","updated_at":"2015-01-26T20:42:23Z","closed_at":null,"body":"Not sure this is the right place- can't find a swift mailing list.\r\n\r\nDoes swift directly support both java and scala collections?\r\n\r\nI'm hoping to be able to take a set of abstract scala traits (dealing with existing data-types that are already easily JSON-serialiable), and expose them as RPC APIs to clients in various languages. I've read that thrift-swift will let me generate .idl files from existing interfaces. Does this include Scala, or just Java.\r\nOn the server I'm hoping I can straightforwardly directly export a Thrift server for these with Finagle. \r\n\r\nAm I on the right track? (Can I expect to export thrift .idls from Scala code, and can I easily implement my own server to match these IDL-generated clients?)\r\n\r\nI've tried running:\r\n\r\n```\r\nMY_CLASSES=$HOME/ExampleServiceMvn/target/ExampleService-1.0-SNAPSHOT.jar  # just an example\r\nSCALA_CLASSES=$HOME/.m2/repository/org/scala-lang/scala-library/2.10.2/scala-library-2.10.2.jar\r\njava -cp target/swift2thrift-generator-cli-0.15.0-SNAPSHOT-standalone.jar:$MY_CLASSES:$SCALA_CLASSES com.facebook.swift.generator.swift2thrift.Main -package com.example ExampleService -map ExampleService path/to/base.thrift -namespace py mycomany.thrift -namespace java mycompany.thrift -namespace cpp mycompany\r\n```\r\n\r\nThis works fine for the scala classes that only with Java collections, but if my service interface deals with scala collections, I get:\r\n\r\n```\r\nException in thread \"main\" java.lang.IllegalArgumentException: Type can not be coerced to a Thrift type: scala.collection.immutable.List<java.lang.String>\r\n\tat com.facebook.swift.codec.metadata.ThriftCatalog.getThriftType(ThriftCatalog.java:291)\r\n\tat com.facebook.swift.service.metadata.ThriftMethodMetadata.<init>(ThriftMethodMetadata.java:90)\r\n\tat com.facebook.swift.service.metadata.ThriftServiceMetadata.<init>(ThriftServiceMetadata.java:73)\r\n\tat com.facebook.swift.generator.swift2thrift.Swift2ThriftGenerator.convertToThrift(Swift2ThriftGenerator.java:432)\r\n\tat com.facebook.swift.generator.swift2thrift.Swift2ThriftGenerator.<init>(Swift2ThriftGenerator.java:112)\r\n```\r\n\r\nI'm happy to add scala collection support to swift2thrift if that makes sense.\r\n\r\n\r\nAlso, the above is using using the https://github.com/facebook/swift/ checkout\r\n\r\nWhat the relationship between this and finagle/finagle-swift in https://github.com/twitter/finagle?\r\n\r\nAnd how can I compile the git checkout? Tried the following:\r\n```\r\n# Succeeds, but no jars\r\ncd finagle/doc/src/sphinx/code/quickstart  && ./sbt compile\r\ncd finagle/doc/src/sphinx/code/quickstart  && ./sbt package\r\n\r\n# [error] (finagle-ostrich4/*:update) sbt.ResolveException: unresolved dependency: com.twitter#ostrich_2.10;9.6.1: not found\r\ncd finagle; ./sbt package\r\n\r\n# [error] Not a valid project ID: finagle-swift (similar: finagle-thrift, finagle-test, finagle-stats)\r\ncd finagle; ./sbt 'project finagle-swift' compile\r\n\r\n#[ERROR]     Non-resolvable parent POM: Could not find artifact com.twitter:scala-parent-2104_2.10:pom:0.1.14 in central (http://repo.maven.apache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 8, column 11 -> [Help 2]\r\ncd finagle/finagle-swift ; mvn compile\r\n\r\n# Produces ./finagle-thrift/target/scala-2.10/finagle-thrift_2.10-6.22.0.jar\r\n# but doesn't include thrift-swift\r\ncd finagle; ./sbt 'project finagle-thrift' package\r\n```\r\n\r\n\r\n-- thanks\r\n- Stuart\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/facebook/swift/issues/comments/71534060","html_url":"https://github.com/facebook/swift/issues/233#issuecomment-71534060","issue_url":"https://api.github.com/repos/facebook/swift/issues/233","id":71534060,"user":{"login":"stuz5000","id":7799980,"avatar_url":"https://avatars.githubusercontent.com/u/7799980?v=3","gravatar_id":"","url":"https://api.github.com/users/stuz5000","html_url":"https://github.com/stuz5000","followers_url":"https://api.github.com/users/stuz5000/followers","following_url":"https://api.github.com/users/stuz5000/following{/other_user}","gists_url":"https://api.github.com/users/stuz5000/gists{/gist_id}","starred_url":"https://api.github.com/users/stuz5000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuz5000/subscriptions","organizations_url":"https://api.github.com/users/stuz5000/orgs","repos_url":"https://api.github.com/users/stuz5000/repos","events_url":"https://api.github.com/users/stuz5000/events{/privacy}","received_events_url":"https://api.github.com/users/stuz5000/received_events","type":"User","site_admin":false},"created_at":"2015-01-26T20:42:23Z","updated_at":"2015-01-26T20:42:23Z","body":"I'm running into problems with recursive definitions. I believe thrift allows\r\n```\r\nstruct A {\r\n  1: list<A> children;\r\n}\r\n```\r\nbut not:\r\n```\r\nstruct A {\r\n  1: A a;\r\n}\r\n```\r\n(for the latter, in C++ this leads to: sizeof(A)==infinity).\r\n\r\nI think the former case is incorrectly disallowed in ThriftCatalog:\r\n```\r\n     private final ThreadLocal<Deque<Type>> stack = new ThreadLocal<Deque<Type>>()\r\n....\r\n    private ThriftStructMetadata extractThriftStructMetadata(Type structType)\r\n    {\r\n        Deque<Type> stack = this.stack.get();\r\n        if (stack.contains(structType)) {\r\n            ...\r\n            throw new IllegalArgumentException(\"Circular references are not allowed: \" + path);\r\n        }\r\n        stack.push(structType);\r\n        try {\r\n            ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(this, structType);\r\n            ThriftStructMetadata structMetadata = builder.build();\r\n            return structMetadata;\r\n        }\r\n        finally {\r\n            Type top = stack.pop();\r\n            ...\r\n        }\r\n    }\r\n```\r\n\r\n\r\nI'm planning to add this to my fork since we have many instances of this pattern (class A contains a collection of A) in our code and want to export APIs to them with Thrift.\r\n\r\nTo do this, some kind of forward declaration is required:\r\n```\r\ngetThriftType(  A )     // Must 'declare' a ThriftType in the catalog (perhaps with an null StructMetadata)\r\n+- getThriftType(  list<A> )\r\n    +- getThriftType(  A )  // should point original (incomplete) ThriftType, or fail if voilating Thrift requirements.\r\n```\r\nThe incomplete ThriftType for struct A would have its  ThriftStructMetadata set when the stack unwinds.\r\n\r\nRelated question: what's the difference between these in ThriftCatalog:\r\n```\r\n     private final ConcurrentMap<Class<?>, ThriftType> manualTypes = new ConcurrentHashMap<>();\r\n     private final ConcurrentMap<Type, ThriftType> typeCache = new ConcurrentHashMap<>();\r\n```"}}