-
Notifications
You must be signed in to change notification settings - Fork 57
Type contexts #101
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
Type contexts #101
Conversation
There should always be a context associated with everything, it just might happen to be the global context. Could you drop the optionals? |
Sources/LLVM/StructType.swift
Outdated
public init(elementTypes: [IRType], isPacked: Bool = false) { | ||
/// - parameter context: The context to create this type in | ||
/// - SeeAlso: http://llvm.org/docs/ProgrammersManual.html#achieving-isolation-with-llvmcontext | ||
public init(elementTypes: [IRType], isPacked: Bool = false, in context: Context? = nil) { |
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.
This one is still optional
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.
Just call the ...InContext
one here. It's what happens eventually on the else branch anyway.
} | ||
|
||
/// 16-bit floating point value in the global context | ||
public static let half = FloatType(kind: .half) |
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.
Maybe also make a func half(Context: Context)
?
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.
The initializer should cover it, right?
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.
It does FloatType(.half, in: context)
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.
I suppose that’s fine, but it’s less convenient.
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.
Most people won't use contexts other than the global, so this approach favors progressive disclosure. It also lessens the API change by making things like FloatType.double
still work.
Sources/LLVM/IRType.swift
Outdated
@@ -30,6 +30,11 @@ public extension IRType { | |||
return LLVMConstPointerNull(asLLVM()) | |||
} | |||
|
|||
/// Returns the context associated with this type | |||
public func context() -> Context { |
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.
We need to make sure this doesn’t call the context’s deinit. That means we probably need to have a let ownsRef: Bool
inside Context
, otherwise this class will dispose the context prematurely.
Two minor things:
|
Now that this is done, I notice we don't actually have a wrapper for |
Ah, good point we have this on our fork, let me just add those changes to this PR |
⛵️ |
Without the ability to emit types specific to a context modules with non global contexts are invalid if they contain any types.
Note this does change some public interfaces. Most notably
FloatType
is no longer just anenum
of value as it must also store an associatedContext