Skip to content
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

Generalize factory patterns for use outside of NSValue #1095

Closed
wants to merge 31 commits into from

Conversation

phausler
Copy link
Member

@phausler phausler commented Jul 3, 2017

No description provided.

@phausler
Copy link
Member Author

phausler commented Jul 3, 2017

cc @norio-nomura, after looking at this a bit further I think we can do some really neat things. Other than the bare init case did you find any other caveats worth mentioning?

@phausler
Copy link
Member Author

phausler commented Jul 3, 2017

@swift-ci please test

1 similar comment
@phausler
Copy link
Member Author

phausler commented Jul 3, 2017

@swift-ci please test

// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if DEPLOYMENT_RUNTIME_SWIFT
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now shareable to the Darwin overlay

@norio-nomura
Copy link
Contributor

Wow! ❤️

@phausler
Copy link
Member Author

phausler commented Jul 3, 2017

oh I have more incoming. Prior to your approach we had two major differentials between the general behavior of the objc version of Foundation and swift-corelibs-foundation; factory patterns and bridging. This method effectively catches 90% of the factory pattern side of things. I have a version for NSString and NSMutableString an I am currently working on getting a few more types.

Overall this approach will vastly improve performance for swift-corelibs-foundation and dramatically get closer to the expected behavior for abstract base classes.

@phausler
Copy link
Member Author

@swift-ci please test

1 similar comment
@phausler
Copy link
Member Author

@swift-ci please test

@phausler
Copy link
Member Author

@swift-ci please test

4 similar comments
@phausler
Copy link
Member Author

@swift-ci please test

@phausler
Copy link
Member Author

@swift-ci please test

@phausler
Copy link
Member Author

@swift-ci please test

@phausler
Copy link
Member Author

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Jul 28, 2017

@phausler can you rebase this onto the latest? In particular, the project.pbxproj has recently had conflicts (which @ianpartridge resolved elsewhere) so would be good to make sure this doesn't conflict.

@phausler
Copy link
Member Author

There are a number of other changes I have pending for this - namely it does not yet work fully on Linux, once I get back to the office next week I will revise those changes onto master and attempt to get this landed

Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor observations

@@ -187,7 +187,7 @@ CF_PRIVATE CFIndex __CFActiveProcessorCount();
#if defined(DEBUG)
#define CFAssert(cond, prio, desc) do { if (!(cond)) { CFLog(prio, CFSTR(desc)); /* HALT; */ } } while (0)
#define CFAssert1(cond, prio, desc, a1) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1); /* HALT; */ } } while (0)
#define CFAssert2(cond, prio, desc, a1, a2) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1, a2); /* HALT; */ } } while (0)
#define CFAssert2(cond, prio, desc, a1, a2) do { if (!(cond)) { CFLog(prio, CFSTR(desc), a1, a2); HALT; } } while (0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the HALT uncommented here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using it to catch some failures in bridge casts

}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, but there's two empty lines here where one would do.

line.append(" = ")
line.append("\"")
line += "\""
line += " = "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we're appending these three constants together, is there a reason we don't just have them all in one constant \" = \" instead?

@@ -206,6 +206,10 @@ internal func NSInvalidArgument(_ message: String, method: String = #function, f
fatalError("\(method): \(message)", file: file, line: line)
}

internal func _NSMethodExceptionProem(_ obj: NSObject, _ cmd: StaticString = #function) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does the Proem mean here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is taken from the actual Foundation; https://www.merriam-webster.com/dictionary/proem it is a preliminary comment

public static let caseInsensitive = CompareOptions(rawValue: 1)
public static let literal = CompareOptions(rawValue: 2)
public static let backwards = CompareOptions(rawValue: 4)
public static let anchored = CompareOptions(rawValue: 8)
public static let numeric = CompareOptions(rawValue: 64)
public static let diacriticInsensitive = CompareOptions(rawValue: 128)
public static let widthInsensitive = CompareOptions(rawValue: 256)
public static let forcedOrdering = CompareOptions(rawValue: 512)
public static var forcedOrdering = CompareOptions(rawValue: 512)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this really change? Why is it a global var?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm probably shouldn't be

@@ -1149,7 +1455,7 @@ extension NSString {
if !getBytes(nil, maxLength: Int.max - 1, usedLength: &numBytes, encoding: enc, options: [], range: theRange, remaining: nil) {
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.fileWriteInapplicableStringEncoding.rawValue, userInfo: [
NSURLErrorKey: dest,
])
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indentation expected? I thought it looked better before, where it was aligned with the 'throw'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh yea this is what Xcode does :/
Once I have the linux side working I will give it a beautification pass

@@ -1159,7 +1465,7 @@ extension NSString {
if !getBytes(mutableBytes, maxLength: numBytes, usedLength: &used, encoding: enc, options: [], range: theRange, remaining: nil) {
throw NSError(domain: NSCocoaErrorDomain, code: CocoaError.fileWriteUnknown.rawValue, userInfo: [
NSURLErrorKey: dest,
])
])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have thought the alignment would be better if aligned with the throw


let singleChar = NSString(string: "😹")
XCTAssertEqual(singleChar.substring(with: NSMakeRange(0,1)), "�")
// let surrogatePairSuffix = NSString(string: "Hurray🎉")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these test failures failing, or no longer relevant? If they're broken, do we have a bug to fix them again?

Copy link
Member Author

@phausler phausler Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these tests iirc don't actually work on Darwin (objc), will have to double check

@phausler
Copy link
Member Author

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Oct 5, 2017

@phausler there was a lot of work done on this branch, but it's got out of step. Can you rebase and re-run the tests please?

@alblue
Copy link
Contributor

alblue commented Oct 16, 2017

@phausler This pull request has gone stale, and there are a number of conflicts which prevent it moving forward at this stage. I'm going to tentatively close it, and we can re-open in the future once the conflicts have been fixed.

@alblue alblue closed this Oct 16, 2017
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.

None yet

3 participants