Skip to content

SE-0093 - Add public base property to slices #2929

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 2 commits into from
Jun 8, 2016

Conversation

ultramiraculous
Copy link
Contributor

What's in this pull request?

Implement SE-0093 with a readonly property on Slice that returns the internal value _base.


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@gribozavr
Copy link
Contributor

Thank you! Could you add some tests? They should go into ./validation-test/stdlib/Slice.swift.gyb.

For this one, a test that constructs a slice around a reference-typed collection, and then checks that the .base property returns the same reference, would be sufficient. But please don't use NSArray, define a custom reference-typed collection, so that the test can run on Linux.

@@ -435,6 +435,13 @@ public struct ${Self}<Base : ${BaseRequirements}>
% else:
internal let _base: Base
% end

/// The underlying collection of the slice.
public var base: Base {
Copy link
Contributor

Choose a reason for hiding this comment

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

public var base: Base {
  return _base
}

would be sufficient. (No need for get {}.)

@ultramiraculous
Copy link
Contributor Author

Addressed the comment and added a basic test.

@ultramiraculous
Copy link
Contributor Author

On second thought, should it actually be copying the collection passed in instead of just referencing it? It seems like you could mutate the reference-type collection you pass in as base and basically break Slice in unexpected ways.

@gribozavr
Copy link
Contributor

It seems like you could mutate the reference-type collection you pass in as base and basically break Slice in unexpected ways.

This is expected. Slices inherit value or reference semantics from the base collection.

@@ -69,6 +91,12 @@ SliceTests.test("${Slice}/init(base:bounds:)") {
}
}

SliceTests.test("${Slice}/baseProperty") {
let referenceCollection = ReferenceCollection()
let testSlice = ${Collection}(base: ReferenceCollection(), bounds: 0..<1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid this wouldn't compile because ReferenceCollection is only a Collection, but some slices have stronger requirements. Since all slice types are generated from the same code, let's only test the most simple Slice type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah this isn't going to work at all. It looks like I didn't stage all my changes (sign I was working too late 😐). To start with ${Collection} isn't the right variable, and it's not using referenceCollection at all in this iteration. I was intending to just use Slice, like you suggested, but I also figured out how to test a few more by filtering out RangeReplaceable and Mutable slices.

@gribozavr
Copy link
Contributor

@swift-ci Please smoke test

@gribozavr
Copy link
Contributor

@ultramiraculous Could you take a look at the test failures?

@gribozavr
Copy link
Contributor

@swift-ci Please test

@gribozavr gribozavr merged commit 09c0b60 into swiftlang:master Jun 8, 2016
@lattner
Copy link
Contributor

lattner commented Jun 8, 2016

Awesome, thanks Chris. Please add an entry to the changelog too.

MaxDesiatov added a commit that referenced this pull request Apr 19, 2021
[pull] swiftwasm from main
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.

3 participants