I am right now trying to move my very simple implementation into the standard library, and I am meeting a few obstacles, never having tried to build/test the entire swift codebase before.
I have a few questions, but I don't know if this is the correct forum to ask the questions in.
If it's not the best place to ask these questions, please have me excused.
For reference, here is my first shot (still lacking tests for Array and Dictionary):
For Optional, I have added the implementation to stdlib/public/core/Optional.swift right after the conditional conformance to Equatable.
For testing the Optional conditional conformance to Hashable, I have basically duplicated the tests for Equatable:
OptionalTests.test("Hashable") {
expectEqual([true, false, false, false, false, true], testRelation { $0.hashValue == $1.hashValue })
expectEqual([false, true, true, true, true, false], testRelation { $0.hashValue != $1.hashValue })
}
So this verifies that equal optionals have equal hashes (and for these specific values that the non-equal optionals also happen to have non-equal hashes).
Is this a sufficient test?
With regards to Array, I have added the implementation to stdlib/public/core/Arrays.swift.gyb.
Here I have also followed the style for Equatable cond. conf. so my implementation is added for both ContiguousArray, ArraySlice and Array. Does this choice make sense? I am uncertain.
With regards to Dictionary, the implementation is added to stdlib/public/core/HashedCollections.swift.gyb - where the (unconditional) conformance for Set already resides.
Here I am a bit uncertain as to whether I need special cases for cocoa vs. native Dictionaries - or whether my more 'naive' implementation is fine.
For both Array and Dictionary I have no clue as to where I should add the tests.
Regarding the build/test process:
Is the easiest way to build/test to:
- Follow build instructions
- Run initial test before making changes
- After changing stdlib only, run ninja swift-stdlib from SWIFT_BUILD_DIR
- Run utils/build-script --test from 'swift' dir
Number 4 takes quite a lot of time. I have tried adding --test-paths test/stdlib/Optional.swift command line arg to build-script, but I'm guessing that's not the correct format, because it didn't appear to work.
Anyone with experience in building and running tests for the swift project, please feel free to comment if I am on the right track or not. :-)
Sincerely,
/morten