-
Notifications
You must be signed in to change notification settings - Fork 30
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
jextract: Indirect returns and more value type support #211
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6f8647d
ignore .index-build directory
ktoso a7787f8
Implement SwiftValue cleanup
ktoso 62b898e
SourceGen: Handle init() of value types with indirect return
ktoso 7d4b57b
Followups for handling value inits, various helper funcs
ktoso 5c585e8
SwiftArena is now a segment allocator
ktoso 6a07e93
Add $destroyed flag to wrapper types to prevent use-after-free bugs
ktoso 185a880
Use varHandle instead of offset for reading data off VWT
ktoso 79e1339
testing: skip empty lines in output matching
ktoso 3f29222
gitignore vscode build outputs
ktoso 5984bb2
test fixups
ktoso 0467deb
more tests for protecting access to destroyed objects
ktoso 0430ee1
remove commented out code
ktoso 82aa974
Merge branch 'main' into wip-value-type-fixes
ktoso d4b26a9
fix formatting
ktoso 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,18 +44,19 @@ public struct ImportedNominalType: ImportedDecl { | |
TranslatedType( | ||
cCompatibleConvention: .direct, | ||
originalSwiftType: "\(raw: swiftTypeName)", | ||
originalSwiftTypeKind: self.kind, | ||
cCompatibleSwiftType: "UnsafeRawPointer", | ||
cCompatibleJavaMemoryLayout: .heapObject, | ||
javaType: javaType | ||
) | ||
} | ||
|
||
public var isReferenceType: Bool { | ||
switch self.kind { | ||
case .class, .actor: | ||
return true | ||
case .enum, .struct: | ||
return false | ||
true | ||
default: | ||
false | ||
} | ||
} | ||
|
||
|
@@ -68,11 +69,40 @@ public struct ImportedNominalType: ImportedDecl { | |
} | ||
} | ||
|
||
// TODO: replace this with `SwiftNominalTypeDeclaration.Kind` | ||
public enum NominalTypeKind { | ||
case `actor` | ||
case `class` | ||
case `enum` | ||
case `struct` | ||
case `void` // TODO: NOT NOMINAL, BUT... | ||
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. I'll work on removing this |
||
case function // TODO: NOT NOMINAL, BUT... | ||
case primitive // TODO: NOT NOMINAL, BUT... | ||
|
||
var isReferenceType: Bool { | ||
switch self { | ||
case .actor, .class: true | ||
case .enum, .struct: false | ||
case .void, .function, .primitive: false | ||
} | ||
} | ||
|
||
var isValueType: Bool { | ||
switch self { | ||
case .actor, .class: false | ||
case .enum, .struct: true | ||
case .void, .function, .primitive: false | ||
} | ||
} | ||
|
||
var isVoid: Bool { | ||
switch self { | ||
case .actor, .class: false | ||
case .enum, .struct: false | ||
case .void: true | ||
case .function, .primitive: false | ||
} | ||
} | ||
} | ||
|
||
public struct ImportedParam { | ||
|
@@ -99,7 +129,7 @@ public struct ImportedParam { | |
var effectiveName: String? { | ||
firstName ?? secondName | ||
} | ||
|
||
var effectiveValueName: String { | ||
secondName ?? firstName ?? "_" | ||
} | ||
|
@@ -199,13 +229,13 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible { | |
case nil, .wrapper: | ||
break | ||
|
||
case .pointer: | ||
case .pointer where !isInit: | ||
let selfParam: FunctionParameterSyntax = "self$: $swift_pointer" | ||
params.append( | ||
ImportedParam(syntax: selfParam, type: parent) | ||
) | ||
|
||
case .memorySegment: | ||
case .memorySegment where !isInit: | ||
let selfParam: FunctionParameterSyntax = "self$: $java_lang_foreign_MemorySegment" | ||
var parentForSelf = parent | ||
parentForSelf.javaType = .javaForeignMemorySegment | ||
|
@@ -215,6 +245,9 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible { | |
|
||
case .swiftThunkSelf: | ||
break | ||
|
||
default: | ||
break | ||
} | ||
|
||
// TODO: add any metadata for generics and other things we may need to add here | ||
|
@@ -233,6 +266,11 @@ public struct ImportedFunc: ImportedDecl, CustomStringConvertible { | |
|
||
public var isInit: Bool = false | ||
|
||
public var isIndirectReturn: Bool { | ||
returnType.isValueType || | ||
(isInit && (parent?.isValueType ?? false)) | ||
} | ||
|
||
public init( | ||
module: String, | ||
decl: any DeclSyntaxProtocol, | ||
|
@@ -269,9 +307,9 @@ extension ImportedFunc: Hashable { | |
self.swiftDecl.id.hash(into: &hasher) | ||
} | ||
|
||
public static func ==(lhs: ImportedFunc, rhs: ImportedFunc) -> Swift.Bool { | ||
lhs.parent?.originalSwiftType.id == rhs.parent?.originalSwiftType.id && | ||
lhs.swiftDecl.id == rhs.swiftDecl.id | ||
public static func == (lhs: ImportedFunc, rhs: ImportedFunc) -> Swift.Bool { | ||
lhs.parent?.originalSwiftType.id == rhs.parent?.originalSwiftType.id | ||
&& lhs.swiftDecl.id == rhs.swiftDecl.id | ||
} | ||
} | ||
|
||
|
@@ -394,8 +432,8 @@ public struct ImportedVariable: ImportedDecl, CustomStringConvertible { | |
) | ||
|
||
case nil, | ||
.wrapper, | ||
.swiftThunkSelf: | ||
.wrapper, | ||
.swiftThunkSelf: | ||
break | ||
} | ||
} | ||
|
Oops, something went wrong.
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.
TODO: we'll want to remove this and instead pass around a SwiftNominalTypeDeclaration instead, and base the name and kind off from that.