Skip to content

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

Merged
merged 9 commits into from
Sep 13, 2017
Merged

Type contexts #101

merged 9 commits into from
Sep 13, 2017

Conversation

vdka
Copy link
Contributor

@vdka vdka commented Sep 11, 2017

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 an enum of value as it must also store an associated Context

@CodaFi
Copy link
Member

CodaFi commented Sep 11, 2017

There should always be a context associated with everything, it just might happen to be the global context. Could you drop the optionals?

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) {
Copy link
Member

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

Copy link
Member

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)
Copy link
Member

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)?

Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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.

@@ -30,6 +30,11 @@ public extension IRType {
return LLVMConstPointerNull(asLLVM())
}

/// Returns the context associated with this type
public func context() -> Context {
Copy link
Member

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.

@CodaFi
Copy link
Member

CodaFi commented Sep 12, 2017

Two minor things:

  • All the docs for the context members still reads
/// Returns the context associated with this module.
  • Please fix the merge conflict.

@CodaFi
Copy link
Member

CodaFi commented Sep 12, 2017

Now that this is done, I notice we don't actually have a wrapper for LLVMContextCreate 🤣

@vdka
Copy link
Contributor Author

vdka commented Sep 12, 2017

Ah, good point we have this on our fork, let me just add those changes to this PR

@CodaFi
Copy link
Member

CodaFi commented Sep 13, 2017

⛵️

@CodaFi CodaFi merged commit 52862d4 into llvm-swift:master Sep 13, 2017
@vdka vdka deleted the type-contexts branch September 18, 2017 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants