Starter project: API to upgrade AnySequence to Any*Collection

Hi,

If someone looks for a starter project in the standard library with
intermediate complexity (prior experience with Swift generics
required), here's one.

This is in the area of existential sequence and collection wrappers.

Upgrading AnyForwardCollection to AnyRandomAccessCollection works:

(swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3]))
// r2 : AnyRandomAccessCollection<Int>? =
Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box:
Swift._CollectionBox<Swift.Array<Swift.Int>>))

Seems like we don't provide APIs to upgrade AnySequence to Any*Collection:

(swift) AnyRandomAccessCollection(AnySequence([1,2,3]))
<REPL Input>:1:1: error: cannot invoke initializer for type
'AnyRandomAccessCollection<_>' with an argument list of type
'(AnySequence<Int>)'

Of course, this should work without copying the underlying collection.

https://bugs.swift.org/browse/SR-119

Dmitri

···

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

Would this require a review/proposal, since it involves an API change?

···

On Mon, Dec 7, 2015 at 2:08 PM, Dmitri Gribenko via swift-dev < swift-dev@swift.org> wrote:

Hi,

If someone looks for a starter project in the standard library with
intermediate complexity (prior experience with Swift generics
required), here's one.

This is in the area of existential sequence and collection wrappers.

Upgrading AnyForwardCollection to AnyRandomAccessCollection works:

(swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3]))
// r2 : AnyRandomAccessCollection<Int>? =
Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box:
Swift._CollectionBox<Swift.Array<Swift.Int>>))

Seems like we don't provide APIs to upgrade AnySequence to Any*Collection:

(swift) AnyRandomAccessCollection(AnySequence([1,2,3]))
<REPL Input>:1:1: error: cannot invoke initializer for type
'AnyRandomAccessCollection<_>' with an argument list of type
'(AnySequence<Int>)'

Of course, this should work without copying the underlying collection.

[SR-119] API to upgrade AnySequence to Any*Collection · Issue #42741 · apple/swift · GitHub

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Hi all,

If someone is looking for a starter project in our tooling support area, here’s one you can dig your teeth into:

SourceKit contains indentation logic that is not exposed in the libIDE library; this is not desirable, primarily because SourceKit is not cross-platform. Here are some steps to improve on this:

  • Move the indentation logic from SourceKit to libIDE. Have SourceKit just expose the functionality contained in libIDE.
  • Start a 'swift-format’ command-line tool that uses the indentation mechanism from libIDE; given a file and source range it auto-indents it.
  • See prior work for 'clang-format' (http://clang.llvm.org/docs/ClangFormat.html\) for investigation on how to specify and provide formatting options.

This is tracked via https://bugs.swift.org/browse/SR-146

-Argyrios

It would require a proposal and a review, but the implementation is
more challenging here than the API design. The proposal would be
trivial, just one extra API, if I'm imagining this correctly.

Dmitri

···

On Mon, Dec 7, 2015 at 2:10 PM, Austin Zheng <austinzheng@gmail.com> wrote:

Would this require a review/proposal, since it involves an API change?

On Mon, Dec 7, 2015 at 2:08 PM, Dmitri Gribenko via swift-dev > <swift-dev@swift.org> wrote:

Hi,

If someone looks for a starter project in the standard library with
intermediate complexity (prior experience with Swift generics
required), here's one.

This is in the area of existential sequence and collection wrappers.

Upgrading AnyForwardCollection to AnyRandomAccessCollection works:

(swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3]))
// r2 : AnyRandomAccessCollection<Int>? =
Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box:
Swift._CollectionBox<Swift.Array<Swift.Int>>))

Seems like we don't provide APIs to upgrade AnySequence to Any*Collection:

(swift) AnyRandomAccessCollection(AnySequence([1,2,3]))
<REPL Input>:1:1: error: cannot invoke initializer for type
'AnyRandomAccessCollection<_>' with an argument list of type
'(AnySequence<Int>)'

Of course, this should work without copying the underlying collection.

[SR-119] API to upgrade AnySequence to Any*Collection · Issue #42741 · apple/swift · GitHub

Dmitri

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

I was actually planning on doing this in the near future. It'll be
interesting to dig into SourceKit from the inside for once!

···

On Tue, Dec 8, 2015 at 13:17 Argyrios Kyrtzidis via swift-dev < swift-dev@swift.org> wrote:

Hi all,

If someone is looking for a starter project in our tooling support area,
here’s one you can dig your teeth into:

SourceKit contains indentation logic that is not exposed in the libIDE
library; this is not desirable, primarily because SourceKit is not
cross-platform. Here are some steps to improve on this:

• Move the indentation logic from SourceKit to libIDE. Have SourceKit just
expose the functionality contained in libIDE.
• Start a 'swift-format’ command-line tool that uses the indentation
mechanism from libIDE; given a file and source range it auto-indents it.
• See prior work for 'clang-format' (
http://clang.llvm.org/docs/ClangFormat.html\) for investigation on how to
specify and provide formatting options.

This is tracked via [SR-146] Move the swift indentation mechanism from SourceKit to libIDE and utilize it for a 'swift-format' tool · Issue #42768 · apple/swift · GitHub

-Argyrios
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

What do you mean by "without copying the underlying collection"? Is this
specifically for the case where the AnySequence is wrapping a collection
(which is not always the case)?

···

On Mon, Dec 7, 2015 at 2:18 PM, Dmitri Gribenko via swift-dev < swift-dev@swift.org> wrote:

It would require a proposal and a review, but the implementation is
more challenging here than the API design. The proposal would be
trivial, just one extra API, if I'm imagining this correctly.

Dmitri

On Mon, Dec 7, 2015 at 2:10 PM, Austin Zheng <austinzheng@gmail.com> > wrote:
> Would this require a review/proposal, since it involves an API change?
>
> On Mon, Dec 7, 2015 at 2:08 PM, Dmitri Gribenko via swift-dev > > <swift-dev@swift.org> wrote:
>>
>> Hi,
>>
>> If someone looks for a starter project in the standard library with
>> intermediate complexity (prior experience with Swift generics
>> required), here's one.
>>
>> This is in the area of existential sequence and collection wrappers.
>>
>> Upgrading AnyForwardCollection to AnyRandomAccessCollection works:
>>
>> (swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3]))
>> // r2 : AnyRandomAccessCollection<Int>? =
>> Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box:
>> Swift._CollectionBox<Swift.Array<Swift.Int>>))
>>
>> Seems like we don't provide APIs to upgrade AnySequence to
Any*Collection:
>>
>> (swift) AnyRandomAccessCollection(AnySequence([1,2,3]))
>> <REPL Input>:1:1: error: cannot invoke initializer for type
>> 'AnyRandomAccessCollection<_>' with an argument list of type
>> '(AnySequence<Int>)'
>>
>> Of course, this should work without copying the underlying collection.
>>
>> [SR-119] API to upgrade AnySequence to Any*Collection · Issue #42741 · apple/swift · GitHub
>>
>> Dmitri
>>
>> --
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
>> _______________________________________________
>> swift-dev mailing list
>> swift-dev@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-dev
>
>

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

What do you mean by "without copying the underlying collection"?

The original collection should be preserved through this upgrade, and
not, say, copied into a fresh Array.

Is this
specifically for the case where the AnySequence is wrapping a collection
(which is not always the case)?

Exactly.

Dmitri

···

On Mon, Dec 7, 2015 at 2:27 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:

On Mon, Dec 7, 2015 at 2:18 PM, Dmitri Gribenko via swift-dev > <swift-dev@swift.org> wrote:

It would require a proposal and a review, but the implementation is
more challenging here than the API design. The proposal would be
trivial, just one extra API, if I'm imagining this correctly.

Dmitri

On Mon, Dec 7, 2015 at 2:10 PM, Austin Zheng <austinzheng@gmail.com> >> wrote:
> Would this require a review/proposal, since it involves an API change?
>
> On Mon, Dec 7, 2015 at 2:08 PM, Dmitri Gribenko via swift-dev >> > <swift-dev@swift.org> wrote:
>>
>> Hi,
>>
>> If someone looks for a starter project in the standard library with
>> intermediate complexity (prior experience with Swift generics
>> required), here's one.
>>
>> This is in the area of existential sequence and collection wrappers.
>>
>> Upgrading AnyForwardCollection to AnyRandomAccessCollection works:
>>
>> (swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3]))
>> // r2 : AnyRandomAccessCollection<Int>? =
>> Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box:
>> Swift._CollectionBox<Swift.Array<Swift.Int>>))
>>
>> Seems like we don't provide APIs to upgrade AnySequence to
>> Any*Collection:
>>
>> (swift) AnyRandomAccessCollection(AnySequence([1,2,3]))
>> <REPL Input>:1:1: error: cannot invoke initializer for type
>> 'AnyRandomAccessCollection<_>' with an argument list of type
>> '(AnySequence<Int>)'
>>
>> Of course, this should work without copying the underlying collection.
>>
>> [SR-119] API to upgrade AnySequence to Any*Collection · Issue #42741 · apple/swift · GitHub
>>
>> Dmitri
>>
>> --
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
>> _______________________________________________
>> swift-dev mailing list
>> swift-dev@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-dev
>
>

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/

I'd be interested in taking it but I have another ticket already, so if
someone else wants it they should take it.

Austin

···

On Mon, Dec 7, 2015 at 2:35 PM, Dmitri Gribenko <gribozavr@gmail.com> wrote:

On Mon, Dec 7, 2015 at 2:27 PM, Jacob Bandes-Storch <jtbandes@gmail.com> > wrote:
> What do you mean by "without copying the underlying collection"?

The original collection should be preserved through this upgrade, and
not, say, copied into a fresh Array.

> Is this
> specifically for the case where the AnySequence is wrapping a collection
> (which is not always the case)?

Exactly.

Dmitri

> On Mon, Dec 7, 2015 at 2:18 PM, Dmitri Gribenko via swift-dev > > <swift-dev@swift.org> wrote:
>>
>> It would require a proposal and a review, but the implementation is
>> more challenging here than the API design. The proposal would be
>> trivial, just one extra API, if I'm imagining this correctly.
>>
>> Dmitri
>>
>> On Mon, Dec 7, 2015 at 2:10 PM, Austin Zheng <austinzheng@gmail.com> > >> wrote:
>> > Would this require a review/proposal, since it involves an API change?
>> >
>> > On Mon, Dec 7, 2015 at 2:08 PM, Dmitri Gribenko via swift-dev > >> > <swift-dev@swift.org> wrote:
>> >>
>> >> Hi,
>> >>
>> >> If someone looks for a starter project in the standard library with
>> >> intermediate complexity (prior experience with Swift generics
>> >> required), here's one.
>> >>
>> >> This is in the area of existential sequence and collection wrappers.
>> >>
>> >> Upgrading AnyForwardCollection to AnyRandomAccessCollection works:
>> >>
>> >> (swift) AnyRandomAccessCollection(AnyForwardCollection([1,2,3]))
>> >> // r2 : AnyRandomAccessCollection<Int>? =
>> >> Optional(Swift.AnyRandomAccessCollection<Swift.Int>(_box:
>> >> Swift._CollectionBox<Swift.Array<Swift.Int>>))
>> >>
>> >> Seems like we don't provide APIs to upgrade AnySequence to
>> >> Any*Collection:
>> >>
>> >> (swift) AnyRandomAccessCollection(AnySequence([1,2,3]))
>> >> <REPL Input>:1:1: error: cannot invoke initializer for type
>> >> 'AnyRandomAccessCollection<_>' with an argument list of type
>> >> '(AnySequence<Int>)'
>> >>
>> >> Of course, this should work without copying the underlying
collection.
>> >>
>> >> [SR-119] API to upgrade AnySequence to Any*Collection · Issue #42741 · apple/swift · GitHub
>> >>
>> >> Dmitri
>> >>
>> >> --
>> >> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> >> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
>> >> _______________________________________________
>> >> swift-dev mailing list
>> >> swift-dev@swift.org
>> >> https://lists.swift.org/mailman/listinfo/swift-dev
>> >
>> >
>>
>>
>>
>> --
>> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
>> _______________________________________________
>> swift-dev mailing list
>> swift-dev@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-dev
>
>

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/