[JExtract] Import Foundation.Data if used#301
Conversation
a53dbd4 to
9f2c63e
Compare
Foundation.Data if usedFoundation.Data if used
ktoso
left a comment
There was a problem hiding this comment.
Very cool, lgtm -- some minor things inline
| // FIXME: Make this conditional. | ||
| outputSwiftFiles += [ | ||
| outputSwiftDirectory.appending(path: "Data+SwiftJava.swift") | ||
| ] |
There was a problem hiding this comment.
That FIXME will be hard to resolve... we'd have to grep files manually for any foundation imports etc I guess before we run any of the commands :(
But yeah, good to keep that fixme
| var str = retBytes.getString(0); | ||
| SwiftRuntime.trace("retStr=" + str); | ||
| }); | ||
| } |
There was a problem hiding this comment.
Very nice!
btw I'm thinking we should start trying to move all these examples into tests, so we'll get a better report "what failed" when CI fails.
But this we can do later separately
| self.expectedOutputSwiftFiles.insert("\(translator.swiftModuleName)Module+SwiftJava.swift") | ||
|
|
||
| // FIXME: Can we avoid this? | ||
| self.expectedOutputSwiftFiles.insert("Data+SwiftJava.swift") |
There was a problem hiding this comment.
Yeah, this is unavoidable in today's SwiftPM.
Can we call the file Foundation_Data+SwiftJava.swift maybe? just to lessen the chance of clashing with some user defined Data type?
FYI ongoing sadness with build plugins @bnbarham heh
| if let dataDecl = self.symbolTable[.data] { | ||
| if self.isUsing(dataDecl) { | ||
| visitor.visit(nominalDecl: dataDecl.syntax!.asNominal!, in: nil) | ||
| } |
There was a problem hiding this comment.
👍 Good enough for our current needs.
| public init(cString: UnsafePointer<Int8>) | ||
| public func withCString(_ body: (UnsafePointer<Int8>) -> Void) | ||
| } | ||
| """ |
There was a problem hiding this comment.
Makes sense but I'm a bit worried about those "inline" pseudo-interface files... While we can't use the real files... maybe we could make this info at least real files and not just strings hardcoded like this, put them in SwiftTypes/KnownModules/Foundation.swiftinterface and then use them using the Bundle APIs? Seems that could work?
There was a problem hiding this comment.
I will try making them resources in followups
| // If we have already recorded a nominal type with the name in this module, | ||
| // it's an invalid redeclaration. | ||
| if let _ = symbolTable.lookupType(node.name.text, parent: parent) { | ||
| // TODO: Diagnose? |
There was a problem hiding this comment.
might be good to at least log on debug here
There was a problem hiding this comment.
Oh yeah, I forgot to hook up the Logger passed in to SwiftSymbolTable.setup()
There was a problem hiding this comment.
That’s be nice to do probably, thank you
| if importedType.methods.contains(where: check) { | ||
| return true | ||
| } | ||
| if importedGlobalVariables.contains(where: check) { |
There was a problem hiding this comment.
| if importedGlobalVariables.contains(where: check) { | |
| if importedType.variables.contains(where: check) { |
Instead of the pointer to the value witness table. Witnesses expect type metadata.
* Introduce `KnownSwiftModules` to represent `Swift` and `Foundation` modules. * `SwiftSymbolTable.setup()` is now a factory method to create `SwiftSymbolTable`. It scans the source file for module dependency. If `import Foundation` is found, add `Foundation` from the `KnownSwiftModules` (Just `Data` for now) * In `Swift2JavaTranslator` import `Data` APIs if any of the imported APIs use `Data` * `Data` has limited hardcoded APIs `init(bytes:count:)`, `getter:count`, and `withUnsafeBytes(_:)`. * Add `import Foundation` in Swift thunk if any of the the original source files import it
9d37c22 to
c2f683e
Compare
KnownSwiftModulesto representSwiftandFoundationmodules.SwiftSymbolTable.setup()is now a factory method to createSwiftSymbolTable. It scans the source file for module dependency. Ifimport Foundationis found, addFoundationfrom theKnownSwiftModules(JustDatafor now)Swift2JavaTranslatorimportDataAPIs if any of the imported APIs useDataDatahas limited hardcoded APIsinit(bytes:count:),getter:count, andwithUnsafeBytes(_:).import Foundationin Swift thunk if any of the the original source files import it